[FFmpeg-devel] [PATCH 2/5] mpegts: factorize mpegts filter creator code

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


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

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index a6589c2..0dcd64a 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -396,13 +396,10 @@ static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1,
     }
 }
 
-static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
-                                         SectionCallback *section_cb, void *opaque,
-                                         int check_crc)
-
+static MpegTSFilter *mpegts_open_filter(MpegTSContext *ts, unsigned int pid,
+                                        enum MpegTSFilterType type)
 {
     MpegTSFilter *filter;
-    MpegTSSectionFilter *sec;
 
     av_dlog(ts->stream, "Filter: pid=0x%x\n", pid);
 
@@ -412,11 +409,25 @@ static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int
     if (!filter)
         return NULL;
     ts->pids[pid] = filter;
-    filter->type = MPEGTS_SECTION;
+    filter->type = type;
     filter->pid = pid;
     filter->es_id = -1;
     filter->last_cc = -1;
     filter->last_pcr = -1;
+
+    return filter;
+}
+
+static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int pid,
+                                         SectionCallback *section_cb, void *opaque,
+                                         int check_crc)
+
+{
+    MpegTSFilter *filter;
+    MpegTSSectionFilter *sec;
+
+    if (!(filter = mpegts_open_filter(ts, pid, MPEGTS_SECTION)))
+        return NULL;
     sec = &filter->u.section_filter;
     sec->section_cb = section_cb;
     sec->opaque = opaque;
@@ -436,17 +447,8 @@ static MpegTSFilter *mpegts_open_pes_filter(MpegTSContext *ts, unsigned int pid,
     MpegTSFilter *filter;
     MpegTSPESFilter *pes;
 
-    if (pid >= NB_PID_MAX || ts->pids[pid])
+    if (!(filter = mpegts_open_filter(ts, pid, MPEGTS_PES)))
         return NULL;
-    filter = av_mallocz(sizeof(MpegTSFilter));
-    if (!filter)
-        return NULL;
-    ts->pids[pid] = filter;
-    filter->type = MPEGTS_PES;
-    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;
-- 
1.8.4.5



More information about the ffmpeg-devel mailing list