[FFmpeg-cvslog] mpegts: add pcr filter for tracking standalone pcr pids

Marton Balint git at videolan.org
Sun Mar 23 00:10:46 CET 2014


ffmpeg | branch: master | Marton Balint <cus at passwd.hu> | Sun Mar  2 01:47:17 2014 +0100| [d83a5b52184f12d8be995dfb4682e43cbb828100] | committer: Marton Balint

mpegts: add pcr filter for tracking standalone pcr pids

Signed-off-by: Marton Balint <cus at passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d83a5b52184f12d8be995dfb4682e43cbb828100
---

 libavformat/mpegts.c |   21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 05ed940..8a5d8c7 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -55,6 +55,7 @@
 enum MpegTSFilterType {
     MPEGTS_PES,
     MPEGTS_SECTION,
+    MPEGTS_PCR,
 };
 
 typedef struct MpegTSFilter MpegTSFilter;
@@ -467,6 +468,11 @@ static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
     return filter;
 }
 
+static MpegTSFilter *mpegts_open_pcr_filter(MpegTSContext *ts, unsigned int pid)
+{
+    return mpegts_open_filter(ts, pid, MPEGTS_PCR);
+}
+
 static void mpegts_close_filter(MpegTSContext *ts, MpegTSFilter *filter)
 {
     int pid;
@@ -1824,6 +1830,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
         p = desc_list_end;
     }
 
+    if (!ts->pids[pcr_pid])
+        mpegts_open_pcr_filter(ts, pcr_pid);
+
 out:
     for (i = 0; i < mp4_descr_count; i++)
         av_free(mp4_descr[i].dec_config_descr);
@@ -2029,7 +2038,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
         }
     }
 
-    if (!has_payload)
+    if (!has_payload && tss->type != MPEGTS_PCR)
         return 0;
     p = packet + 4;
     if (has_adaptation) {
@@ -2038,7 +2047,7 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
     }
     /* if past the end of packet, ignore */
     p_end = packet + TS_PACKET_SIZE;
-    if (p >= p_end)
+    if (p > p_end || (p == p_end && tss->type != MPEGTS_PCR))
         return 0;
 
     pos = avio_tell(ts->stream->pb);
@@ -2096,9 +2105,11 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
         if (parse_pcr(&pcr_h, &pcr_l, packet) == 0)
             tss->last_pcr = pcr_h * 300 + pcr_l;
         // Note: The position here points actually behind the current packet.
-        if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,
-                                            pos - ts->raw_packet_size)) < 0)
-            return ret;
+        if (tss->type == MPEGTS_PES) {
+            if ((ret = tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start,
+                                                pos - ts->raw_packet_size)) < 0)
+                return ret;
+        }
     }
 
     return 0;



More information about the ffmpeg-cvslog mailing list