diff mbox

[FFmpeg-devel,3/3] avformat/mpegts: add support for non-standard NIT pid

Message ID 20191003124352.31565-3-anthony.2lannoy@gmail.com
State New
Headers show

Commit Message

Anthony Delannoy Oct. 3, 2019, 12:43 p.m. UTC
---
 libavformat/mpegts.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

Comments

Anthony Delannoy Oct. 13, 2019, 4:17 p.m. UTC | #1
Ping
Marton Balint Oct. 18, 2019, 11:25 p.m. UTC | #2
On Sun, 13 Oct 2019, Anthony Delannoy wrote:

> Ping

I have mixed feelings about this, definitely seems less useful than EPG. I 
am asking other developers, should we add NIT as a data stream to the 
mpegts demuxer?

Thanks,
Marton
diff mbox

Patch

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 5a3e71d9ab..02da272325 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -169,6 +169,7 @@  struct MpegTSContext {
     MpegTSFilter *pids[NB_PID_MAX];
     int current_pid;
 
+    int nit_pid;
     AVStream *epg_stream, *nit_stream;
 };
 
@@ -2432,15 +2433,6 @@  static void nit_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
     const uint8_t *p, *p_end;
     SectionHeader h1, *h = &h1;
 
-    if (!ts->nit_stream) {
-        ts->nit_stream = avformat_new_stream(ts->stream, NULL);
-        if (!ts->nit_stream)
-            return;
-        ts->nit_stream->id = NIT_PID;
-        ts->nit_stream->codecpar->codec_type = AVMEDIA_TYPE_DATA;
-        ts->nit_stream->codecpar->codec_id = AV_CODEC_ID_NIT;
-    }
-
     if (ts->nit_stream->discard == AVDISCARD_ALL)
         return;
 
@@ -2508,7 +2500,25 @@  static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
 
         if (sid == 0x0000) {
             /* NIT info */
-            // XXX for now we only use default NIT_PID
+            if (!ts->nit_stream) {
+                ts->nit_pid = pmt_pid;
+
+                if (ts->nit_pid != NIT_PID)
+                    av_log(ts->stream, AV_LOG_WARNING,
+                           "Using non-standard PID %i for NIT table.\n", pmt_pid);
+
+                if (ts->pids[ts->nit_pid])
+                    mpegts_close_filter(ts, ts->pids[ts->nit_pid]);
+
+                mpegts_open_section_filter(ts, ts->nit_pid, nit_cb, ts, 1);
+
+                ts->nit_stream = avformat_new_stream(ts->stream, NULL);
+                if (!ts->nit_stream)
+                    return;
+                ts->nit_stream->id = ts->nit_pid;
+                ts->nit_stream->codecpar->codec_type = AVMEDIA_TYPE_DATA;
+                ts->nit_stream->codecpar->codec_id = AV_CODEC_ID_NIT;
+            }
         } else {
             MpegTSFilter *fil = ts->pids[pmt_pid];
             program = av_new_program(ts->stream, sid);
@@ -3084,7 +3094,6 @@  static int mpegts_read_header(AVFormatContext *s)
         mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
         mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
         mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1);
-        mpegts_open_section_filter(ts, NIT_PID, nit_cb, ts, 1);
 
         handle_packets(ts, probesize / ts->raw_packet_size);
         /* if could not find service, enable auto_guess */
@@ -3343,7 +3352,6 @@  MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext *s)
     mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
     mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1);
     mpegts_open_section_filter(ts, EIT_PID, eit_cb, ts, 1);
-    mpegts_open_section_filter(ts, NIT_PID, nit_cb, ts, 1);
 
     return ts;
 }