[FFmpeg-devel] [PATCH 1/5] mpegts: move last_pcr to MpegTSFilter level

Marton Balint cus at passwd.hu
Sun Mar 2 18:34:46 CET 2014


Signed-off-by: Marton Balint <cus at passwd.hu>
---
 libavformat/mpegts.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 242d353..a6589c2 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -53,7 +53,7 @@ enum MpegTSFilterType {
 
 typedef struct MpegTSFilter MpegTSFilter;
 
-typedef int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos, int64_t cur_pcr);
+typedef int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start, int64_t pos);
 
 typedef struct MpegTSPESFilter {
     PESCallback *pes_cb;
@@ -78,6 +78,7 @@ struct MpegTSFilter {
     int pid;
     int es_id;
     int last_cc; /* last cc code (-1 if first packet) */
+    int64_t last_pcr;
     enum MpegTSFilterType type;
     union {
         MpegTSPESFilter pes_filter;
@@ -207,7 +208,6 @@ typedef struct PESContext {
     uint8_t header[MAX_PES_HEADER_SIZE];
     AVBufferRef *buffer;
     SLConfigDescr sl;
-    int64_t last_pcr;
 } PESContext;
 
 extern AVInputFormat ff_mpegts_demuxer;
@@ -416,6 +416,7 @@ static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int
     filter->pid = pid;
     filter->es_id = -1;
     filter->last_cc = -1;
+    filter->last_pcr = -1;
     sec = &filter->u.section_filter;
     sec->section_cb = section_cb;
     sec->opaque = opaque;
@@ -445,6 +446,7 @@ static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
     filter->pid = pid;
     filter->es_id = -1;
     filter->last_cc = -1;
+    filter->last_pcr = -1;
     pes = &filter->u.pes_filter;
     pes->pes_cb = pes_cb;
     pes->opaque = opaque;
@@ -869,7 +871,7 @@ static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf
 /* return non zero if a packet could be constructed */
 static int mpegts_push_data(MpegTSFilter *filter,
                             const uint8_t *buf, int buf_size, int is_start,
-                            int64_t pos, int64_t pcr)
+                            int64_t pos)
 {
     PESContext *pes = filter->u.pes_filter.opaque;
     MpegTSContext *ts = pes->ts;
@@ -879,9 +881,6 @@ static int mpegts_push_data(MpegTSFilter *filter,
     if(!ts->pkt)
         return 0;
 
-    if (pcr != -1)
-        pes->last_pcr = pcr;
-
     if (is_start) {
         if (pes->state == MPEGTS_PAYLOAD && pes->data_index > 0) {
             new_pes_packet(pes, ts->pkt);
@@ -1041,12 +1040,12 @@ static int mpegts_push_data(MpegTSFilter *filter,
                             MpegTSFilter *f = pes->ts->pids[p->pcr_pid];
                             if (f && f->type == MPEGTS_PES) {
                                 PESContext *pcrpes = f->u.pes_filter.opaque;
-                                if (pcrpes && pcrpes->last_pcr != -1 && pcrpes->st && pcrpes->st->discard != AVDISCARD_ALL) {
+                                if (f->last_pcr != -1 && pcrpes && pcrpes->st && pcrpes->st->discard != AVDISCARD_ALL) {
                                     // teletext packets do not always have correct timestamps,
                                     // the standard says they should be handled after 40.6 ms at most,
                                     // and the pcr error to this packet should be no more than 100 ms.
                                     // TODO: we should interpolate the PCR, not just use the last one
-                                    int64_t pcr = pcrpes->last_pcr / 300;
+                                    int64_t pcr = f->last_pcr / 300;
                                     pes->st->pts_wrap_reference = pcrpes->st->pts_wrap_reference;
                                     pes->st->pts_wrap_behavior = pcrpes->st->pts_wrap_behavior;
                                     if (pes->dts == AV_NOPTS_VALUE || pes->dts < pcr) {
@@ -1116,7 +1115,6 @@ static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid)
     pes->state = MPEGTS_SKIP;
     pes->pts = AV_NOPTS_VALUE;
     pes->dts = AV_NOPTS_VALUE;
-    pes->last_pcr = -1;
     tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes);
     if (!tss) {
         av_free(pes);
@@ -2032,14 +2030,13 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
 
     } else {
         int ret;
-        int64_t pcr = -1;
         int64_t pcr_h;
         int pcr_l;
         if (parse_pcr(&pcr_h, &pcr_l, packet) == 0)
-            pcr = pcr_h * 300 + pcr_l;
+            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, pcr)) < 0)
+                                            pos - ts->raw_packet_size)) < 0)
             return ret;
     }
 
@@ -2154,9 +2151,9 @@ static int handle_packets(MpegTSContext *ts, int nb_packets)
                    av_buffer_unref(&pes->buffer);
                    pes->data_index = 0;
                    pes->state = MPEGTS_SKIP; /* skip until pes header */
-                   pes->last_pcr = -1;
                 }
                 ts->pids[i]->last_cc = -1;
+                ts->pids[i]->last_pcr = -1;
             }
         }
     }
-- 
1.8.4.5



More information about the ffmpeg-devel mailing list