From: "Leonid V.Panoff" <l.v.panoff@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Allow to recognize SCTE-35 stream in MPEG TS if Registration descriptor put on stream section instead of program. Some muxers (Harmonic for example) do it Date: Wed, 26 Jan 2022 18:25:51 +0300 Message-ID: <4f9481d0-dd39-f6af-b9ad-5221977e7fe2@gmail.com> (raw) Signed-off-by: Leonid V.Panoff <l.v.panoff@gmail.com> --- libavformat/mpegts.c | 48 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 2479cb6f7d..0774b53b18 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2301,6 +2301,42 @@ static int is_pes_stream(int stream_type, uint32_t prog_reg_desc) (stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI")) ); } +static int is_scte35_descr_in_stream(const uint8_t *p, const uint8_t *p_end, int stream_type) +{ + int desc_list_len, desc_tag, desc_len; + const uint8_t *desc_list_end, *desc_end; + + const uint8_t *ppp = p; + desc_list_len = get16(&ppp, p_end); + if (desc_list_len < 0) + return 0; + desc_list_len &= 0xfff; + desc_list_end = ppp + desc_list_len; + while (desc_list_end <= p_end) + { + desc_tag = get8(&ppp, desc_list_end); + if (desc_tag < 0) + return 0; + + desc_len = get8(&ppp, desc_list_end); + if (desc_len < 0) + return 0; + + desc_end = ppp + desc_len; + if (desc_end > desc_list_end) + return 0; + + if (desc_tag == REGISTRATION_DESCRIPTOR) + { + uint32_t codec_tag = bytestream_get_le32(&ppp); + if (stream_type == 0x86 && codec_tag == AV_RL32("CUEI")) + return 1; + } + ppp = desc_end; + } + return 0; +} + static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { MpegTSContext *ts = filter->u.section_filter.opaque; @@ -2316,6 +2352,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len int stream_identifier = -1; struct Program *prg; + int is_scte35_hack = 0; int mp4_descr_count = 0; Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = { { 0 } }; int i; @@ -2404,6 +2441,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len for (i = 0; i < MAX_STREAMS_PER_PROGRAM; i++) { st = 0; pes = NULL; + stream_type = get8(&p, p_end); if (stream_type < 0) break; @@ -2416,10 +2454,12 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len stream_identifier = parse_stream_identifier_desc(p, p_end) + 1; + is_scte35_hack = prog_reg_desc == 0 ? is_scte35_descr_in_stream(p,p_end, stream_type) : 0; + /* now create stream */ - if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) { + if ( ! is_scte35_hack && ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) { pes = ts->pids[pid]->u.pes_filter.opaque; - if (ts->merge_pmt_versions && !pes->st) { + if (!is_scte35_hack && ts->merge_pmt_versions && !pes->st) { st = find_matching_stream(ts, pid, h->id, stream_identifier, i, &old_program); if (st) { pes->st = st; @@ -2434,7 +2474,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len pes->st->id = pes->pid; } st = pes->st; - } else if (is_pes_stream(stream_type, prog_reg_desc)) { + } else if (! is_scte35_hack && is_pes_stream(stream_type, prog_reg_desc)) { if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); // wrongly added sdt filter probably pes = add_pes_stream(ts, pid, pcr_pid); @@ -2466,7 +2506,7 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len goto out; st->id = pid; st->codecpar->codec_type = AVMEDIA_TYPE_DATA; - if (stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI")) { + if (is_scte35_hack || ( stream_type == 0x86 && prog_reg_desc == AV_RL32("CUEI"))) { mpegts_find_stream_type(st, stream_type, SCTE_types); mpegts_open_section_filter(ts, pid, scte_data_cb, ts, 1); } -- 2.30.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
reply other threads:[~2022-01-26 15:26 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=4f9481d0-dd39-f6af-b9ad-5221977e7fe2@gmail.com \ --to=l.v.panoff@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git