From patchwork Thu Sep 14 16:48:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 5141 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp904493jaa; Thu, 14 Sep 2017 09:48:48 -0700 (PDT) X-Received: by 10.28.60.4 with SMTP id j4mr573096wma.46.1505407728056; Thu, 14 Sep 2017 09:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505407728; cv=none; d=google.com; s=arc-20160816; b=cZ42n3wmE45TQDvREHMgsWTCSm07RKq4R7YrL5I1p7/0kLbz2E+2KIYPSNtRTTN3hI WPYPl7TtV5q5LsMep9z3QFet3iwl5cG6rtRyWwvoDxKg3Fg2kNYuvV2MIGp2z/r/DoRr HX69x5R+95Cv/APBjEC11Bme9lq9koayW6FEq1J5U+qy+Dv4KcRD05m8BQvokZUPM73G 9RpbW2ZbdzvCtXiRBMe/IRnf/kW1HI3FjTd8cZe0FXuIvbk1f1AILCWPQ70+RbeLJlwS 88zmf/lw9+cqMBClatmGgbuDXie9taouGcxfcHrzw6XaXtwnFa/YOnoirz6cXJMcSXKX J7Ag== 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=h7L9oMXJ2sUGq9/OioRpGKeet3IBUS4izDDeS6R+SuM=; b=QrpProDTqKAnn+fUqcDRNBCDwRoRFZyGVMfZNKp8OpmrFk89UYmTxAOVHHJrbPqe19 Kqi67krDfhWgRXNpdTd0NOLHzVRSbTP9Q83xTjXqAaTsouAp5Ov/KF7i1nkVKMNK3+MY PeJwwLrTOusqzBKcfrpgPN2cGJRDAklKIw1NgB9EyLUi1cA7WkEkQSetxc9Jd0jyrLws MTqpXQocDhwDPgDHEO7HEeR7uV4/riUsG5qrC817FOo4e6YfVnSZYC5g8dg/D3RgdGAY rsscqHQRbkY6tP8bBOxLQnWIKkgbcOwX1Y5k1L+uuV/luZqapbDL/HoexW0guFGim4St T37g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=gOQ4iTre; 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 s50si14009726wrc.520.2017.09.14.09.48.45; Thu, 14 Sep 2017 09:48:48 -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=gOQ4iTre; 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 C78C9689C4D; Thu, 14 Sep 2017 19:48:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF862689A48 for ; Thu, 14 Sep 2017 19:48:31 +0300 (EEST) Received: by mail-wm0-f54.google.com with SMTP id 13so2142935wmq.2 for ; Thu, 14 Sep 2017 09:48:38 -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=AGszKsUFuzhvOAqbVQJJQLGYFUQ2D626/sfhoXFXlk0=; b=gOQ4iTreh69dL9fLyYXwFwsRoFbdxMA+ulDZN5OyaXOaemvJDqQHN7TdERnMZBnJHs wiUXxgUm98Tia/opPvYyNK0lEJyGFiNqdlzmwSyIHkjws72eIs9MFLlzM3fh3I4JWPfD B+jmmmLdocYxkVl1EPowUJmoeRFg4H+AjtjrAmSJ0qfGsErZVD0VSQ7vW3wCIdE8HSqo Litj+ApZMe/4pKzXL2mkcCRhDtN694yGkF6NWutRK7CXdUUrxbN5oHE643L4OuyGYyH0 AMoGGEXK5hN8CpLsNetdrcdKWj/ucFZUEgTZ/gnGErONSDM3oenEy+Kj/0Xpk8nFMjBX onfQ== 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=AGszKsUFuzhvOAqbVQJJQLGYFUQ2D626/sfhoXFXlk0=; b=WRameFm52m5NrV/C1BJiixQ/nGvRSLrlyaod5OU8kDc8beIg/aLzOK7g9HzXozXk2w zalZZxVQgALAXXsBGuqvoapBskjO13GQqcxaIddv5fMEuFTXDPJJSsGOOrjJio+YkrZn GNQDsFLZ40OUJ/STd7P4aE/0D/eEQdIbr9lVd0qFz6e83qYFVMrm0Zjd/zXpO3jO+iFW EaMxIagdz/kZ4g3joHBk1Hy/LpQqAVfny2qwZ32yAR5NhZFmVBQGUcto0t4l4aWZyMa5 YfsdWOS9Zxaep9C+EJ/R78JvIKtKVNqVH4rxg2ThhnmNQ4D258NrzmTRVBFvRrZSvfq+ EfRg== X-Gm-Message-State: AHPjjUg++AHEnY/RwLpWihocC6Nvc96qJJ5yk4lKuPoq6haHamSlx2IB 2f69NOg5ZbyNuiLO X-Google-Smtp-Source: ADKCNb5Tg1YPBYkZCIFg7MPBuIVbK3uT5BEjLRqfTpdlIzzqnD8IwgfWKZWnJhQlf08CYkW4d8Myyw== X-Received: by 10.80.136.21 with SMTP id b21mr17324558edb.83.1505407717878; Thu, 14 Sep 2017 09:48:37 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id l50sm4332590eda.80.2017.09.14.09.48.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Sep 2017 09:48:36 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <103114c7-8ba7-d798-6353-83d346990995@gmail.com> <20170914154635.GD7726@sunshine.barsnick.net> From: "pkv.stream" Message-ID: Date: Thu, 14 Sep 2017 18:48:33 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170914154635.GD7726@sunshine.barsnick.net> Content-Language: fr Subject: Re: [FFmpeg-devel] [PATCHv3] avformat/mpegts: opus muxing & 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" Thanks for your comments Moritz. Corrected patch in attachment. Regards Le 14/09/2017 à 5:46 PM, Moritz Barsnick a écrit : > On Fri, Sep 08, 2017 at 01:46:38 +0200, pkv.stream wrote: >> - avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); > [...] >> + avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code"); > You probably need to mention the channel_config_code in the new > message. > >> + for (j = 0; j < channels; j++) { >> + opus_channel_map255[j] = j; >> + } > Misplaced closing bracket. > > Moritz > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From 9175cb61dabce42417199cc6d6272d8290c39a5c Mon Sep 17 00:00:00 2001 From: pkviet Date: Fri, 8 Sep 2017 01:34:22 +0200 Subject: [PATCH] avformat/mpegts: opus muxing & demuxing expanded Support for opus in mpegts demuxer was brought by commit 9cfa68c560bdec82d2d5ec079f9c5b0f9ca37af0 (Kieran Kunhya). Support for opus in mpegts muxer was then added by commit 01509cdf9287b975eced1fd609a8201fbd1438e3 (S. Droge). Later commit 37941878f193a2316c514bd5ba55bfe9d2dfdfcf by Michael Graczyk added support of mapping_family encoder parameter which allows for up to 255 audio channels (for family 255). While matroska muxer & demuxer readily accepts mapping_family, it is not the case for mpegts muxer & demuxer for all the range of the parameter (family 255 and also part of family 1 with channel_config_code > 0x81 unsupported). This commit brings such a support. --- libavformat/mpegts.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++--- libavformat/mpegtsenc.c | 19 ++++++++++----- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 4d2f5c6..8d8977b 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, @@ -1887,9 +1898,56 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type 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); + memcpy(&st->codecpar->extradata[21], opus_channel_map_a[channels - 1], channels); } else { - avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); + if (channel_config_code == 0x81) { + channels = get8(pp, desc_end); + st->codecpar->extradata_size = 22 + channels; + size_t extradata_size; + extradata_size = (22 + channels) * sizeof(uint8_t); + uint8_t *extradata; + extradata = av_malloc(extradata_size); + if (!extradata) + return AVERROR(ENOMEM); + for (i = 0; i <= (22+channels); i++) { + if (i < 9) { + extradata[i] = opus_default_extradata[i]; + } + else { + extradata[i] = 0; + } + } + memcpy(st->codecpar->extradata, extradata, sizeof(extradata)); + av_free(extradata); + st->codecpar->extradata[9] = channels; + st->codecpar->extradata[18] = 255; + st->codecpar->extradata[19] = channels; + st->codecpar->extradata[20] = 0; + size_t channel_map_size = channels * sizeof(uint8_t); + uint8_t *opus_channel_map255; + opus_channel_map255 = av_malloc(channel_map_size); + if (!opus_channel_map255) + return AVERROR(ENOMEM); + uint8_t j; + for (j = 0; j < channels; j++) { + opus_channel_map255[j] = j; + } + memcpy(&st->codecpar->extradata[21], opus_channel_map255, channels); + av_free(opus_channel_map255); + } else { + if ((channel_config_code >= 0x82) && (channel_config_code <= 0x88)) { + channels = get8(pp, desc_end); + 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; diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index fdfa544..af1dfc6 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -421,8 +421,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 'D'; } if (st->codecpar->codec_id==AV_CODEC_ID_OPUS) { - /* 6 bytes registration descriptor, 4 bytes Opus audio descriptor */ - if (q - data > SECTION_LENGTH - 6 - 4) { + /* 6 bytes registration descriptor, 6 bytes Opus audio descriptor */ + if (q - data > SECTION_LENGTH - 6 - 6) { err = 1; break; } @@ -435,7 +435,7 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 's'; *q++ = 0x7f; /* DVB extension descriptor */ - *q++ = 2; + *q++ = 4; *q++ = 0x80; if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) { @@ -483,9 +483,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 0xff; } } else { - /* Unsupported */ - av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codecpar->extradata[18]); - *q++ = 0xff; + /* mapping family 255 , set channel_config_code to 0x81 */ + if (st->codecpar->extradata[18] == 255) { + *q++ = 0x81; + } else { + /* Unsupported */ + av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codecpar->extradata[18]); + *q++ = 0xff; + } } } else if (st->codecpar->channels <= 2) { /* Assume RTP mapping family */ @@ -495,6 +500,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping"); *q++ = 0xff; } + *q++ = st->codecpar->extradata[9]; + *q++ = st->codecpar->extradata[18]; } if (lang) {