summaryrefslogtreecommitdiff
path: root/gst/mpegtsdemux/tsdemux.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst/mpegtsdemux/tsdemux.c')
-rw-r--r--gst/mpegtsdemux/tsdemux.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/gst/mpegtsdemux/tsdemux.c b/gst/mpegtsdemux/tsdemux.c
index 166089ba5..03814b6d4 100644
--- a/gst/mpegtsdemux/tsdemux.c
+++ b/gst/mpegtsdemux/tsdemux.c
@@ -44,7 +44,7 @@
#include "payload_parsers.h"
#include "pesparse.h"
-/*
+/*
* tsdemux
*
* See TODO for explanations on improvements needed
@@ -56,7 +56,7 @@
#define TABLE_ID_UNSET 0xFF
/* Size of the pendingbuffers array. */
-#define TS_MAX_PENDING_BUFFERS 256
+#define TS_MAX_PENDING_BUFFERS 256
#define PCR_WRAP_SIZE_128KBPS (((gint64)1490)*(1024*1024))
/* small PCR for wrap detection */
@@ -1363,10 +1363,10 @@ process_section (MpegTSBase * base)
MpegTSPacketizerPacket packet;
MpegTSPacketizerPacketReturn pret;
- while ((!done)
- && ((pret =
- mpegts_packetizer_next_packet (base->packetizer,
- &packet)) != PACKET_NEED_MORE)) {
+ while ((!done) &&
+ ((pret = mpegts_packetizer_next_packet (base->packetizer, &packet))
+ != PACKET_NEED_MORE)) {
+
if (G_UNLIKELY (pret == PACKET_BAD))
/* bad header, skip the packet */
goto next;
@@ -1375,8 +1375,9 @@ process_section (MpegTSBase * base)
if (packet.payload != NULL && mpegts_base_is_psi (base, &packet)) {
MpegTSPacketizerSection section;
- based =
- mpegts_packetizer_push_section (base->packetizer, &packet, &section);
+ based = mpegts_packetizer_push_section (base->packetizer, &packet,
+ &section);
+
if (G_UNLIKELY (!based))
/* bad section data */
goto next;
@@ -1412,10 +1413,9 @@ process_pes (MpegTSBase * base, TSPcrOffset * pcroffset)
GstTSDemux *demux = GST_TS_DEMUX (base);
guint16 pcr_pid = 0;
- while ((!done)
- && ((pret =
- mpegts_packetizer_next_packet (base->packetizer,
- &packet)) != PACKET_NEED_MORE)) {
+ while ((!done) &&
+ ((pret = mpegts_packetizer_next_packet (base->packetizer, &packet))
+ != PACKET_NEED_MORE)) {
if (G_UNLIKELY (pret == PACKET_BAD))
/* bad header, skip the packet */
goto next;
@@ -1428,8 +1428,9 @@ process_pes (MpegTSBase * base, TSPcrOffset * pcroffset)
if (packet.payload != NULL && mpegts_base_is_psi (base, &packet)) {
MpegTSPacketizerSection section;
- based =
- mpegts_packetizer_push_section (base->packetizer, &packet, &section);
+ based = mpegts_packetizer_push_section (base->packetizer, &packet,
+ &section);
+
if (G_UNLIKELY (!based))
/* bad section data */
goto next;
@@ -1587,16 +1588,15 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
GST_DEBUG ("Scanning for timestamps");
- /* Flush what remained from before */
- mpegts_packetizer_clear (base->packetizer);
+ /* Start scanning from now PAT offset */
- /* Start scanning from know PAT offset */
while (!done) {
- ret =
- gst_pad_pull_range (base->sinkpad, i * 50 * MPEGTS_MAX_PACKETSIZE,
+ ret = gst_pad_pull_range (base->sinkpad, i * 50 * MPEGTS_MAX_PACKETSIZE,
50 * MPEGTS_MAX_PACKETSIZE, &buf);
+
if (ret != GST_FLOW_OK)
goto beach;
+
mpegts_packetizer_push (base->packetizer, buf);
done = process_section (base);
i++;
@@ -1605,7 +1605,6 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
done = FALSE;
i = 1;
-
*offset = base->seek_offset;
/* Search for the first PCRs */
@@ -1617,7 +1616,7 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
}
mpegts_packetizer_clear (base->packetizer);
- /* Remove current program so we ensure looking for a PAT when scanning the
+ /* Remove current program so we ensure looking for a PAT when scanning
* for the final PCR */
gst_structure_free (base->pat);
base->pat = NULL;
@@ -1628,9 +1627,9 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
if (G_UNLIKELY (!gst_pad_query_peer_duration (base->sinkpad, &format,
&total_bytes) || format != GST_FORMAT_BYTES)) {
GST_WARNING_OBJECT (base, "Couldn't get upstream size in bytes");
- ret = GST_FLOW_ERROR;
mpegts_packetizer_clear (base->packetizer);
- return ret;
+
+ return GST_FLOW_ERROR;
}
GST_DEBUG ("Upstream is %" G_GINT64_FORMAT " bytes", total_bytes);
@@ -1640,10 +1639,11 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
GST_DEBUG ("Scanning for last sync point between:%" G_GINT64_FORMAT
" and the end:%" G_GINT64_FORMAT, scan_offset, total_bytes);
+
while ((!done) && (scan_offset < total_bytes)) {
- ret =
- gst_pad_pull_range (base->sinkpad,
- scan_offset, 50 * MPEGTS_MAX_PACKETSIZE, &buf);
+ ret = gst_pad_pull_range (base->sinkpad, scan_offset,
+ 50 * MPEGTS_MAX_PACKETSIZE, &buf);
+
if (ret != GST_FLOW_OK)
goto beach;
@@ -1654,10 +1654,8 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
mpegts_packetizer_clear (base->packetizer);
- GST_DEBUG ("Searching PCR");
- ret =
- process_pcr (base, scan_offset - 50 * MPEGTS_MAX_PACKETSIZE, &final, 10,
- FALSE);
+ ret = process_pcr (base, scan_offset - 50 * MPEGTS_MAX_PACKETSIZE, &final,
+ 10, FALSE);
if (ret != GST_FLOW_OK) {
GST_DEBUG ("Problem getting last PCRs");
@@ -1669,6 +1667,7 @@ find_timestamps (MpegTSBase * base, guint64 initoff, guint64 * offset)
gst_segment_set_duration (&demux->segment, GST_FORMAT_TIME,
demux->last_pcr.gsttime - demux->first_pcr.gsttime);
demux->duration = demux->last_pcr.gsttime - demux->first_pcr.gsttime;
+
GST_DEBUG ("Done, duration:%" GST_TIME_FORMAT,
GST_TIME_ARGS (demux->duration));
@@ -1726,8 +1725,7 @@ process_pcr (MpegTSBase * base, guint64 initoff, TSPcrOffset * pcroffset,
for (i = 0; (i < 20) && (nbpcr < numpcr); i++) {
guint offset, size;
- ret =
- gst_pad_pull_range (base->sinkpad,
+ ret = gst_pad_pull_range (base->sinkpad,
initoff + i * 500 * base->packetsize, 500 * base->packetsize, &buf);
if (G_UNLIKELY (ret != GST_FLOW_OK))