[FFmpeg-devel] pat/pmt changes on mpegts

Rainer Hochecker fernetmenta at online.de
Sat Dec 1 10:31:30 CET 2012


Hi,

in order to select appropriate streams we (XBMC) need information about
currently active streams of a program. Joakim and I discussed several approaches
for a solution. This is the result:

- update streams in AVProgram
- sent notification packet via a data stream

diff --git lib/ffmpeg/libavformat/mpegts.c lib/ffmpeg/libavformat/mpegts.c
index 6da6db5..9f574e4 100644
--- lib/ffmpeg/libavformat/mpegts.c
+++ lib/ffmpeg/libavformat/mpegts.c
@@ -183,10 +183,25 @@ typedef struct PESContext {
 
 extern AVInputFormat ff_mpegts_demuxer;
 
+static void clear_avprogram(MpegTSContext *ts, unsigned int programid)
+{
+    AVProgram *prg = NULL;
+    int i;
+    for(i=0; i<ts->stream->nb_programs; i++)
+        if(ts->stream->programs[i]->id == programid){
+            prg = ts->stream->programs[i];
+            break;
+        }
+    if (!prg)
+        return;
+    prg->nb_stream_indexes = 0;
+}
+
 static void clear_program(MpegTSContext *ts, unsigned int programid)
 {
     int i;
 
+    clear_avprogram(ts, programid);
     for(i=0; i<ts->nb_prg; i++)
         if(ts->prg[i].id == programid)
             ts->prg[i].nb_pids = 0;
@@ -194,6 +209,9 @@ static void clear_program(MpegTSContext *ts, unsigned int
programid)
 
 static void clear_programs(MpegTSContext *ts)
 {
+    int i;
+    for(i=0; i<ts->nb_prg; i++)
+        clear_avprogram(ts, ts->prg[i].id);
     av_freep(&ts->prg);
     ts->nb_prg=0;
 }
@@ -1542,6 +1560,25 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t
*section, int section_len
         p = desc_list_end;
     }
 
+    if (ts->pkt) {
+        AVStream *st;
+        /* PID of PAT is 0x00, we use this for data stream id */
+        int idx = ff_find_stream_index(ts->stream, 0x00);
+        if (idx >= 0) {
+            st = ts->stream->streams[idx];
+        } else {
+            st = avformat_new_stream(ts->stream, NULL);
+            st->id = 0x00;
+            st->codec->codec_type = AVMEDIA_TYPE_DATA;
+        }
+        ff_program_add_stream_index(ts->stream, h->id, st->index);
+        av_init_packet(ts->pkt);
+        ts->pkt->data = section;
+        ts->pkt->size = section_len;
+        ts->pkt->stream_index = st->index;
+        ts->stop_parse = 1;
+    }
+
  out:
     for (i = 0; i < mp4_descr_count; i++)
         av_free(mp4_descr[i].dec_config_descr);




More information about the ffmpeg-devel mailing list