From patchwork Tue Oct 31 23:25:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 5798 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp77847jah; Tue, 31 Oct 2017 16:31:06 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Si1shj3/adiBMABxMmsdVwIRS/3seF5P0n4iMkfMIxgIe7UTUmOdJ9xPimzrWm5EWzY7yg X-Received: by 10.223.180.66 with SMTP id v2mr3249472wrd.188.1509492666478; Tue, 31 Oct 2017 16:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509492666; cv=none; d=google.com; s=arc-20160816; b=JxtXSd/sJFz5zRme1ZaqxjhN2l5pqlc1x5Wk/5LYoTTjDfilB3q8H4ztyv+hFuFo1Z 99soHKXkpMJaePa59GosML9UBY1LE4n1CoUty6kb/jSsAFIc1Pb9PTBLNV2dy5Pwl3vY z1Buu0LyDBbe+lMPkZFS5yocmL8WdKBoG32VexTZgO/cWay7uaMFctBmSqDQLOnhv7AD aqJs68KT7fp7o21tV8vDpj1iF3vAwST6okX2YYZH70FIF0Da0z/OqnyxocZL3s863VPs Ak8cb+sB7iYb3TBqhQ4KtAdldZ6M1pNEqkaa8JZktU5jlBkGf+6FMK4ThuYrqXpPE7wD 1pgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=ZLWSvOFGfdk7B1nKt2Vjfk0PKTPDiyraS1yYJ4mrpR0=; b=chTzwLhKqrvWRpDkUJ7m17POi5UkcCeRfQHUR0azQfOv+J0nIUZRXOvqTVbEX+Wbk0 MCSyd8S2w/44P1drV4S0GGKpp/HVKgUctg6Ujt5ezL/OmkykW8FlN0s4/BNLa/btgrQ7 7uRJckJwRcB+0FUuIn9Wth/0oYpr/YVkS2ZiASLjl4UFbK9QZZcXJ7FQxCo8UVAR/q7Q RozwW0XWhbw7c1tmWWl70UqGTKlRXqy+qki80ohHkbdGLsgvBgtfrFb/wW8j78P8Gojo cSmkVanZ7bIZnYPENU7vrtLehW9K8/HsjMQW9eeuPe/LmWWaGOC8a4Ky1X8IfJ/DzWW1 sKiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=YldFrVPc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e137si2453101wmd.96.2017.10.31.16.31.05; Tue, 31 Oct 2017 16:31:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=YldFrVPc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1B71689723; Wed, 1 Nov 2017 01:30:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 87DEA6806BC for ; Wed, 1 Nov 2017 01:30:48 +0200 (EET) Received: by mail-wr0-f169.google.com with SMTP id y39so519247wrd.4 for ; Tue, 31 Oct 2017 16:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=VGBP6ajy0A+JvYGnVH9gZYpeeHRHXKm2bRmoDg8D10Q=; b=YldFrVPcTGu6uWQuT4TLZ2WrOi0+Zi8UbX4R8jDu0q7AMNriOycp9aDt9GV05hQTK3 7yfSmAS3qUvYMR3BMT65MIRYSj1pKH+m9nwJSGFcrkiJANoD6MdUNhRMLtPE71NrMSCK vM61QufXuewyd0mXL27BmEQiwiavI1+yZy2Og5NVqyKTNi5Z0n9i7e7hkjjVyp76IbWp ZaeiDsgWwtdT0saf3zNy+xFmVa3qzVNKR50tiS/ofrDpNpyu0oIlXc0VcRyiJdVMk7X0 p5QUy6Py9TC4mGIagrcnV42fivaeC34mzY+nmh3jWWjZPUzEB93cJAmdo7gRnDRDynqf 1mmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=VGBP6ajy0A+JvYGnVH9gZYpeeHRHXKm2bRmoDg8D10Q=; b=el8//YhrSezTW76KsauX861JO11AxhSzPQ7R6yH1nPTvTHy6UK9fZ54N9Bu/s3qY5m LXDYpeHdNIF3yoPN6ekkkH/DVCi1L04jub7zrjs0qtKW0aR11Ua/9o6uzMVG9Q9Qow9j jUiRTTUxChXahhpaCdmaHNjd7iZqAk6vPd21ZaUzv+VO6GM4aiWvQZ5YBDFKc/EhXMTv oI6xB6I6qY3AmDn7tphTxaWP2kbNVzIcULKTMa+XxoAYgiO07IS4THPr84Awogacan/8 /N3tqfavaDPmpLAmy/0QtwUXJM1pYuF9mrp6ith+dRvLchiMx1Au2aGi5GIy/vuFv9ml Z9/Q== X-Gm-Message-State: AMCzsaVm0ZFWpDXZhd2muapNEHe1L3i5tyJchEfsTVRz2V/8jybX9hSr xjDtyI613OACC0dOw02NwaQyYg== X-Received: by 10.223.155.208 with SMTP id e16mr908865wrc.161.1509492309949; Tue, 31 Oct 2017 16:25:09 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id k9sm2865009wrk.88.2017.10.31.16.25.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Oct 2017 16:25:09 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <103114c7-8ba7-d798-6353-83d346990995@gmail.com> <20170914154635.GD7726@sunshine.barsnick.net> <20171025014520.GP6009@nb4> <2461eb3e-d3ba-7d7f-e02c-69d704deb187@gmail.com> <20171029154450.GQ6009@nb4> <0c33b65c-295a-01e2-1463-f4444613abb4@gmail.com> <20171031172800.GQ6009@nb4> From: "pkv.stream" Message-ID: Date: Wed, 1 Nov 2017 00:25:07 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171031172800.GQ6009@nb4> Content-Language: fr X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH v6 2/2 ] avformat/mpegts: opus demuxing for mapping family 255 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Le 31/10/2017 à 6:28 PM, Michael Niedermayer a écrit : > mpegts.c | 84 > ++++++++++++++++++++++++++++++++++++++++++++++++++++----------- >> 1 file changed, 70 insertions(+), 14 deletions(-) >> 6648bab53735f1efaf0d6cd698dbc2398b483c3f 0002-libavf-mpegts-opus-demuxing-for-mapping-family-255.patch >> From 2e0504728b81e0f35ba856c24cff14fa70680d8b Mon Sep 17 00:00:00 2001 >> From: pkviet >> Date: Sun, 29 Oct 2017 22:57:25 +0100 >> Subject: [PATCH 2/2] libavf/mpegts: opus demuxing for mapping family 255 >> >> Adds to mpegts muxer the capability to demux libopus with mapping >> family 255, following the provisional spec for opus in mepg-ts >> (https://people.xiph.org/~tterribe/opus/ETSI_TS_opus-v0.1.3-draft.doc). >> >> Signed-off-by: pkviet >> --- >> libavformat/mpegts.c | 84 +++++++++++++++++++++++++++++++++++++++++++--------- >> 1 file changed, 70 insertions(+), 14 deletions(-) >> >> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c >> index 53cbcfb..3aa06f0 100644 >> --- a/libavformat/mpegts.c >> +++ b/libavformat/mpegts.c >> @@ -37,6 +37,7 @@ >> #include "avio_internal.h" >> #include "mpeg.h" >> #include "isom.h" >> +#include "math.h" >> >> /* maximum size in which we look for synchronization if >> * synchronization is lost */ >> @@ -1633,7 +1634,7 @@ static const uint8_t opus_stream_cnt[9] = { >> 1, 1, 1, 2, 2, 3, 4, 4, 5, >> }; >> >> -static const uint8_t opus_channel_map[8][8] = { >> +static const uint8_t opus_channel_map_a[8][8] = { >> { 0 }, >> { 0,1 }, >> { 0,2,1 }, >> @@ -1644,13 +1645,25 @@ static const uint8_t opus_channel_map[8][8] = { >> { 0,6,1,2,3,4,5,7 }, >> }; >> >> +static const uint8_t opus_channel_map_b[8][8] = { >> + { 0 }, >> + { 0,1 }, >> + { 0,1,2 }, >> + { 0,1,2,3 }, >> + { 0,1,2,3,4 }, >> + { 0,1,2,3,4,5 }, >> + { 0,1,2,3,4,5,6 }, >> + { 0,1,2,3,4,5,6,7 }, >> +}; >> + >> int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, >> const uint8_t **pp, const uint8_t *desc_list_end, >> Mp4Descr *mp4_descr, int mp4_descr_count, int pid, >> MpegTSContext *ts) >> { >> const uint8_t *desc_end; >> - int desc_len, desc_tag, desc_es_id, ext_desc_tag, channels, channel_config_code; >> + int desc_len, desc_tag, desc_es_id, ext_desc_tag, channels, channel_config_code, channel_count, mapping_family, stream_count, coupled_stream_count; >> + GetBitContext gb; >> char language[252]; >> int i; >> >> @@ -1660,6 +1673,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type >> desc_len = get8(pp, desc_list_end); >> if (desc_len < 0) >> return AVERROR_INVALIDDATA; >> + >> desc_end = *pp + desc_len; >> if (desc_end > desc_list_end) >> return AVERROR_INVALIDDATA; >> @@ -1871,26 +1885,68 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type >> if (st->codecpar->codec_id == AV_CODEC_ID_OPUS && >> ext_desc_tag == 0x80) { /* User defined (provisional Opus) */ >> if (!st->codecpar->extradata) { >> - st->codecpar->extradata = av_mallocz(sizeof(opus_default_extradata) + >> - AV_INPUT_BUFFER_PADDING_SIZE); >> - if (!st->codecpar->extradata) >> - return AVERROR(ENOMEM); >> - >> - st->codecpar->extradata_size = sizeof(opus_default_extradata); >> - memcpy(st->codecpar->extradata, opus_default_extradata, sizeof(opus_default_extradata)); >> - >> channel_config_code = get8(pp, desc_end); >> if (channel_config_code < 0) >> return AVERROR_INVALIDDATA; >> + >> + if (channel_config_code != 0x81) { >> + st->codecpar->extradata = av_mallocz(sizeof(opus_default_extradata) + >> + AV_INPUT_BUFFER_PADDING_SIZE); >> + if (!st->codecpar->extradata) >> + return AVERROR(ENOMEM); >> + st->codecpar->extradata_size = sizeof(opus_default_extradata); >> + memcpy(st->codecpar->extradata, opus_default_extradata, sizeof(opus_default_extradata)); >> + } >> + >> if (channel_config_code <= 0x8) { >> st->codecpar->extradata[9] = channels = channel_config_code ? channel_config_code : 2; >> st->codecpar->extradata[18] = channel_config_code ? (channels > 2) : /* Dual Mono */ 255; >> st->codecpar->extradata[19] = opus_stream_cnt[channel_config_code]; >> st->codecpar->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; >> - memcpy(&st->codecpar->extradata[21], opus_channel_map[channels - 1], channels); >> - } else { >> - avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); >> - } >> + memcpy(&st->codecpar->extradata[21], opus_channel_map_a[channels - 1], channels); >> + } else if (channel_config_code == 0x81) { >> + channel_count = get8(pp, desc_end); >> + mapping_family = get8(pp, desc_end); >> + if (channel_count < 0 || channel_count > 255) >> + return AVERROR_INVALIDDATA; >> + if (mapping_family < 0 || mapping_family > 255) >> + return AVERROR_INVALIDDATA; > > 255 is impossible i think > hello Michael, quite right, check removed; >> + st->codecpar->extradata_size = 22 + channel_count; >> + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); >> + if (!st->codecpar->extradata) >> + return AVERROR(ENOMEM); >> + for (i = 0; i < 9; i++) { >> + st->codecpar->extradata[i] = opus_default_extradata[i]; >> + } >> + st->codecpar->extradata[9] = channel_count; >> + st->codecpar->extradata[18] = mapping_family; >> + init_get_bits(&gb, *pp, (channel_count + 2 + AV_INPUT_BUFFER_PADDING_SIZE) * 8); > The AV_INPUT_BUFFER_PADDING_SIZE looks odd here > right again, I misread the API, sorry. >> + stream_count = get_bits(&gb, av_ceil_log2_c(channel_count)) + 1; >> + coupled_stream_count = get_bits(&gb, av_ceil_log2_c(stream_count + 1)); >> + if (stream_count < 0 || stream_count > channel_count) >> + return AVERROR_INVALIDDATA; >> + if (coupled_stream_count < 0 || coupled_stream_count > stream_count) >> + return AVERROR_INVALIDDATA; > get_bits shouldnt return negative numbers > ok check removed >> + st->codecpar->extradata[19] = stream_count; >> + st->codecpar->extradata[20] = coupled_stream_count; >> + for (i = 0; i < channel_count; i++) { >> + st->codecpar->extradata[21 + i] = get_bits(&gb, av_ceil_log2_c(stream_count + coupled_stream_count + 1)); >> + if (st->codecpar->extradata[21 + i] > stream_count + coupled_stream_count >> + || st->codecpar->extradata[21 + i] > (int)(pow(2, stream_count + coupled_stream_count + 1) -1)) >> + return AVERROR_INVALIDDATA; > pow(2 can be changed to a simple shift done > also a temporary variable would be cleaner than using > st->codecpar->extradata[21 + i] 3 times done I've also corrected a mistake for channel_config_code >= 0x82 and shortened long lines. Regards pkv > > [...] > > > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From c33999c06a1204fb086386716419811427c585bb Mon Sep 17 00:00:00 2001 From: pkviet Date: Sun, 29 Oct 2017 22:57:25 +0100 Subject: [PATCH 2/2] libavf/mpegts: opus demuxing for mapping family 255 Adds to mpegts muxer the capability to demux libopus with mapping family 255, following the provisional spec for opus in mepg-ts (https://people.xiph.org/~tterribe/opus/ETSI_TS_opus-v0.1.3-draft.doc). --- libavformat/mpegts.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 53cbcfb..6f5998e 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -1633,7 +1633,7 @@ static const uint8_t opus_stream_cnt[9] = { 1, 1, 1, 2, 2, 3, 4, 4, 5, }; -static const uint8_t opus_channel_map[8][8] = { +static const uint8_t opus_channel_map_a[8][8] = { { 0 }, { 0,1 }, { 0,2,1 }, @@ -1644,6 +1644,17 @@ static const uint8_t opus_channel_map[8][8] = { { 0,6,1,2,3,4,5,7 }, }; +static const uint8_t opus_channel_map_b[8][8] = { + { 0 }, + { 0,1 }, + { 0,1,2 }, + { 0,1,2,3 }, + { 0,1,2,3,4 }, + { 0,1,2,3,4,5 }, + { 0,1,2,3,4,5,6 }, + { 0,1,2,3,4,5,6,7 }, +}; + int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, const uint8_t **pp, const uint8_t *desc_list_end, Mp4Descr *mp4_descr, int mp4_descr_count, int pid, @@ -1651,6 +1662,8 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type { const uint8_t *desc_end; int desc_len, desc_tag, desc_es_id, ext_desc_tag, channels, channel_config_code; + uint8_t channel_count, mapping_family, stream_count, coupled_stream_count, channel_mapping, sc_csc; + GetBitContext gb; char language[252]; int i; @@ -1871,26 +1884,73 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type if (st->codecpar->codec_id == AV_CODEC_ID_OPUS && ext_desc_tag == 0x80) { /* User defined (provisional Opus) */ if (!st->codecpar->extradata) { - st->codecpar->extradata = av_mallocz(sizeof(opus_default_extradata) + - AV_INPUT_BUFFER_PADDING_SIZE); - if (!st->codecpar->extradata) - return AVERROR(ENOMEM); - - st->codecpar->extradata_size = sizeof(opus_default_extradata); - memcpy(st->codecpar->extradata, opus_default_extradata, sizeof(opus_default_extradata)); - channel_config_code = get8(pp, desc_end); if (channel_config_code < 0) return AVERROR_INVALIDDATA; + + if (channel_config_code != 0x81) { + st->codecpar->extradata = av_mallocz(sizeof(opus_default_extradata) + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) + return AVERROR(ENOMEM); + st->codecpar->extradata_size = sizeof(opus_default_extradata); + memcpy(st->codecpar->extradata, opus_default_extradata, + sizeof(opus_default_extradata)); + } + if (channel_config_code <= 0x8) { st->codecpar->extradata[9] = channels = channel_config_code ? channel_config_code : 2; st->codecpar->extradata[18] = channel_config_code ? (channels > 2) : /* Dual Mono */ 255; st->codecpar->extradata[19] = opus_stream_cnt[channel_config_code]; st->codecpar->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; - memcpy(&st->codecpar->extradata[21], opus_channel_map[channels - 1], channels); - } else { - avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); - } + memcpy(&st->codecpar->extradata[21], opus_channel_map_a[channels - 1], channels); + } else if (channel_config_code == 0x81) { + channel_count = get8(pp, desc_end); + mapping_family = get8(pp, desc_end); + if (channel_count < 0) + return AVERROR_INVALIDDATA; + if (mapping_family < 0) + return AVERROR_INVALIDDATA; + st->codecpar->extradata_size = 22 + channel_count; + st->codecpar->extradata = av_mallocz(st->codecpar->extradata_size + + AV_INPUT_BUFFER_PADDING_SIZE); + if (!st->codecpar->extradata) + return AVERROR(ENOMEM); + for (i = 0; i < 9; i++) { + st->codecpar->extradata[i] = opus_default_extradata[i]; + } + st->codecpar->extradata[9] = channel_count; + st->codecpar->extradata[18] = mapping_family; + init_get_bits(&gb, *pp, (channel_count + 2) * 8); + stream_count = get_bits(&gb, av_ceil_log2_c(channel_count)) + 1; + coupled_stream_count = get_bits(&gb, av_ceil_log2_c(stream_count + 1)); + sc_csc = stream_count + coupled_stream_count; + if (stream_count > channel_count) + return AVERROR_INVALIDDATA; + if (coupled_stream_count > stream_count) + return AVERROR_INVALIDDATA; + st->codecpar->extradata[19] = stream_count; + st->codecpar->extradata[20] = coupled_stream_count; + for (i = 0; i < channel_count; i++) { + channel_mapping = get_bits(&gb, av_ceil_log2_c(sc_csc + 1)); + if (channel_mapping > sc_csc + || channel_mapping > (1 << sc_csc + 1) -1) + return AVERROR_INVALIDDATA; + st->codecpar->extradata[21 + i] = channel_mapping; + } + } else if ((channel_config_code >= 0x82) && + (channel_config_code <= 0x88)) { + channels = channel_config_code - 0x80; + st->codecpar->extradata[9] = channels; + st->codecpar->extradata[18] = 1; + st->codecpar->extradata[19] = channels; + st->codecpar->extradata[20] = 0; + memcpy(&st->codecpar->extradata[21], + opus_channel_map_b[channels - 1], channels); + } else { + avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code %i", + channel_config_code); + } st->need_parsing = AVSTREAM_PARSE_FULL; st->internal->need_context_update = 1; }