[FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: Keep track of the program for each service

Michael Niedermayer michael at niedermayer.cc
Wed Mar 23 04:46:28 CET 2016


Simplifies code

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
---
 libavformat/mpegtsenc.c |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 68f9867..3e4e418 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -56,6 +56,7 @@ typedef struct MpegTSService {
     int pcr_pid;
     int pcr_packet_count;
     int pcr_packet_period;
+    AVProgram *program;
 } MpegTSService;
 
 // service_type values as defined in ETSI 300 468
@@ -275,15 +276,12 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
         AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
 
         if (s->nb_programs) {
-            int j, k, found = 0;
-
-            for (j = 0; j < s->nb_programs; j++)
-                if (s->programs[j]->id == service->sid) {
-                    for (k = 0; k < s->programs[j]->nb_stream_indexes; k++)
-                        if (s->programs[j]->stream_index[k] == i) {
-                            found = 1;
-                            break;
-                        }
+            int k, found = 0;
+            AVProgram *program = service->program;
+
+            for (k = 0; k < program->nb_stream_indexes; k++)
+                if (program->stream_index[k] == i) {
+                    found = 1;
                     break;
                 }
 
@@ -784,6 +782,7 @@ static int mpegts_init(AVFormatContext *s)
             service->pmt.write_packet = section_write_packet;
             service->pmt.opaque       = s;
             service->pmt.cc           = 15;
+            service->program          = program;
         }
     }
 
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list