avformat/mpegtsenc: Keep track of the program for each service
authorMichael Niedermayer <michael@niedermayer.cc>
Wed, 23 Mar 2016 01:52:03 +0000 (02:52 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Thu, 24 Mar 2016 11:27:23 +0000 (12:27 +0100)
Simplifies code

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/mpegtsenc.c

index 68f9867..3e4e418 100644 (file)
@@ -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;
         }
     }