[FFmpeg-devel] [PATCH v3] avformat: keep track of PMT details in AVStream

Aman Gupta ffmpeg at tmm1.net
Fri May 18 03:54:08 EEST 2018


From: Aman Gupta <aman at tmm1.net>

With these fields, the user has enough information
to make the same decisions externally that the demuxer
does internally when merge_pmt_versions=1.

An API user would monitor the AVProgram they're interested in
to see if (flags&AV_PROGRAM_CHANGED), and would then iterate over
the program's streams to find ones where the version matched.

If new versions of any streams exist, then the user would first try
to replace existing streams where stream_identifier was the same.
If stream_identifier is unknown, then the user would compare
pmt_stream_idx instead to replace the stream that was previously
at the same position within the PMT.

Signed-off-by: Aman Gupta <aman at tmm1.net>
---
 doc/APIchanges         |  1 +
 libavformat/avformat.h |  7 +++++++
 libavformat/mpegts.c   | 11 ++++++++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index bca2e7485e..0bc056482e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -19,6 +19,7 @@ API changes, most recent first:
   Remove unused AV_PROGRAM_RUNNING
   Add AV_PROGRAM_CHANGED
   Add pmt_version field to AVProgram
+  Add program_num, pmt_version, pmt_stream_idx to AVStream
 
 2018-05-xx - xxxxxxxxxx - lavf 58.14.100 - avformat.h
   Add AV_DISPOSITION_STILL_IMAGE
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 91285f34f8..3f7060b98a 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1103,6 +1103,13 @@ typedef struct AVStream {
      */
     int stream_identifier;
 
+    /**
+     * Details of the MPEG-TS program which created this stream.
+     */
+    int program_num;
+    int pmt_version;
+    int pmt_stream_idx;
+
     int64_t interleaver_chunk_size;
     int64_t interleaver_chunk_duration;
 
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 287d7954a9..776c435ece 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -2162,7 +2162,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
     set_pmt_found(ts, h->id);
 
 
-    for (;;) {
+    for (i = 0; ; i++) {
         st = 0;
         pes = NULL;
         stream_type = get8(&p, p_end);
@@ -2193,6 +2193,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
                 if (!pes->st)
                     goto out;
                 pes->st->id = pes->pid;
+                pes->st->program_num = h->id;
+                pes->st->pmt_version = h->version;
+                pes->st->pmt_stream_idx = i;
             }
             st = pes->st;
         } else if (is_pes_stream(stream_type, prog_reg_desc)) {
@@ -2211,6 +2214,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
                 if (!st)
                     goto out;
                 st->id = pes->pid;
+                st->program_num = h->id;
+                st->pmt_version = h->version;
+                st->pmt_stream_idx = i;
             }
         } else {
             int idx = ff_find_stream_index(ts->stream, pid);
@@ -2225,6 +2231,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
                 if (!st)
                     goto out;
                 st->id = pid;
+                st->program_num = h->id;
+                st->pmt_version = h->version;
+                st->pmt_stream_idx = i;
                 st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
                 if (stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI")) {
                     mpegts_find_stream_type(st, stream_type, SCTE_types);
-- 
2.14.2



More information about the ffmpeg-devel mailing list