From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 62FB8405DC for ; Wed, 26 Jan 2022 15:26:10 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 17A0068AF86; Wed, 26 Jan 2022 17:26:08 +0200 (EET) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1217C68AE77 for ; Wed, 26 Jan 2022 17:26:01 +0200 (EET) Received: by mail-lf1-f42.google.com with SMTP id x23so16702605lfc.0 for ; Wed, 26 Jan 2022 07:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:from:subject:to :content-language:content-transfer-encoding; bh=mZqLZcfiZLYSmkCZ94pltQ4Hf6OPrT+iJeZqrljB7aM=; b=mrmidjzJFz/XBVH2f1ix6rH4XcBhfmUU+xqviuWcrlEcPT0NrkORrZWgLjG4oFLjMU CFfoSei5i6mVUwCq3iTeDiR0BPVx4z5EuT0RrLp5cbIz/3zTmyWxc40j2/3tbUqN5RG8 2urMY+7eewUYO/EQBxrnCDHGpZPfPqlq93kPh4mP0hHpZl+TKvHJilSiCuD6p1mGbhm7 pNRpSmLB0/G+ekpTWlyhX4jd9e8z87TWaoCt4z9MPFIT4KlzYJWwflFsT50BQetRD/Vd oRGgZz7ck24oYKkZAo8iuXYITbnJ/tid32hfPrpzdv5uAC6Ph70LQxRhikxi4qDoK7HP xNlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from :subject:to:content-language:content-transfer-encoding; bh=mZqLZcfiZLYSmkCZ94pltQ4Hf6OPrT+iJeZqrljB7aM=; b=JfS5P3Z826/g08SyFEk/S2drW5x/NZwjDzjD+3yj6MWGPgtlje5LL/gkHb1De2V3Bo MNCkgCA6loZGHn8FlbYW62hceOwJQl+lze3UdbbcmEcnaH1gDfYlySJt5sD5LtuN0EE4 QodjSRK0LEmD9LuNqE5JLXensluknIRWyShB+u6kP+dm8tBlNKdhT4mL/kq2bznK1gJ/ ZxZ8DNqWXaZJkb7mGZnGUt7iSmRLy2YK7Iv04nggrXBYUfqnkNARrI9B9WMVsBieYkZf Js5wqPzAu/5OjNvVHlqk3JxMJMlfke7NGt+bDsMhKI/3tdMHJxhX29FMs4qnyLzagAv/ o2sA== X-Gm-Message-State: AOAM530gF5sUawjptky24xGHnklQaylDGiOYV+9MR8j7YK1kQJFbTfh1 GbxAWHcRyoWFvLSnI574WrKjFiJlDM1iKA== X-Google-Smtp-Source: ABdhPJx4zEhI7j5hJuTrcWURZzX2rdpi8APXtl3wp8kJAweqbXhNP+KIlzV1u9xMoBPd78iMnjnj1Q== X-Received: by 2002:a05:6512:92a:: with SMTP id f10mr21176075lft.362.1643210760014; Wed, 26 Jan 2022 07:26:00 -0800 (PST) Received: from [0.0.0.0] (tor-exit.las1.1800867.xyz. [209.141.50.178]) by smtp.gmail.com with ESMTPSA id f13sm887488lfg.69.2022.01.26.07.25.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jan 2022 07:25:59 -0800 (PST) Message-ID: <4f9481d0-dd39-f6af-b9ad-5221977e7fe2@gmail.com> Date: Wed, 26 Jan 2022 18:25:51 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 From: "Leonid V.Panoff" To: ffmpeg-devel@ffmpeg.org Content-Language: en-US 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 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Leonid V.Panoff --- 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".