From patchwork Sun Oct 29 22:11:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 5751 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp1988168jah; Sun, 29 Oct 2017 15:19:37 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SP1YwkDsbqzO5lEQh3NPyoOJYB6WdZLEnPG/gCJ1lavPyhNwel3kOCphwJDT1iAZNJtUOf X-Received: by 10.28.62.145 with SMTP id l139mr2251849wma.150.1509315577276; Sun, 29 Oct 2017 15:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509315577; cv=none; d=google.com; s=arc-20160816; b=VH5LOZytj3NE6PPfkPapTwZBBH0BC4KzkMiej203GmLEtqZjhhZP+MNhc63ba8v5Wh vUXcvHAVIpbJ+zJ9nA5jIFbMEK+p8otGPSUMyBU1JwLiVgHRDavheff7PnllicGoJgmg f5ETAHkCP3uIxS4sNVAADzrzZlCHssp5YUTafcpCLG6tBaVUpcIuRVDqefSGyJOchVnD Cp6BXJ3I1SNzXgXasAqY3cA9nFoVDkldkF9bxcoi0YkxVnpVmgrG31G455NZfBGEGqIs xgDcnnbBECeeSjwKi/XNthwRH8LDkVgNrE1Klzm365u5rdkFJf7Yjl1hen9mApiZEn35 UuzQ== 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=6sg5PbJrViYTmvcjW3G293MZ4pBL0kvwDeYEtilqYyg=; b=geFeCR44gri/cC7e8uu6tx1iV08+zh1ROXxHeaBMDa/wsN5K0ctQ8pDPmJREtk8BBr +Pkra1VYbs/UsVbNOwuwGbWIFeLZwDOwTaEL2HnUoR3kTIzvqa3JHKciVv+0rJtMfxCr QTeIkfFrsqugKrGmzUUT03JMFKLPDJ0mOuflWBLDCBlHK8lj12WngppQseeoQ72qqtTg kmmw7nA/kXQE1WOh7E6MfU+NrUVB+NIbJJ1rhXaL0IsY1PMsVvfTwikrHVG2aRUE+R9n ycziJbPEqOeuAGiLMFEuP4WgFLHtwOXZF5nEjxin5VMHL2zphEvfMDuRPZiuuB5DN39d 4kYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=qxJvQQb3; 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 c127si1759455wme.156.2017.10.29.15.19.36; Sun, 29 Oct 2017 15:19:37 -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=qxJvQQb3; 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 A4F5E68A32B; Mon, 30 Oct 2017 00:19:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE08B689D7C for ; Mon, 30 Oct 2017 00:19:19 +0200 (EET) Received: by mail-wm0-f68.google.com with SMTP id y80so5478925wmd.0 for ; Sun, 29 Oct 2017 15:19:29 -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=cQ2NbowyWHc7ekqHKtxcy8obg4AHygdP7AWG5OHkJ0U=; b=qxJvQQb3+hP1aLF5n1lR2/jjJbC/uqtk1k4W7xnNrVyOHHR7InnydYaiwQASrXsfn6 TBfD0HnMoRfCwXUjDgRVk7mlbVfIL6SO2sA9GD50XySvTubclL6oXU9kWScXzp2tD/+n hqtrOvHSYz3qQaU23ULPIdQMoeYhuPMp7/GNHS8+OwPLEBGHSDIKAaECklAx9D9/SAnA cF5ByJJhpXvOVuHi9XzMtATId1YdHkHQK8fd9zmQFWrUd0K9G44mkN+74cmvTjXDCvFA n5EAOzsopnTId6o1l6/baQIrmCKXEWMwxvXS710GfgEvKGK8J8BLPV0mfqdNKAVW9Ket MpFg== 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=cQ2NbowyWHc7ekqHKtxcy8obg4AHygdP7AWG5OHkJ0U=; b=fBj+wxlPA6j1FJWOJPEeiQQbFSlOvg+PbwDPCUmRPJ9zRu0DF2qSZD6VVx+Yf8us0q uEJF2v/ihmvPI+GCxDHIFkzQBZS4wp+E8dI5dDmcHh8zD7o1ywb5Me+l0+Xtod7qiwhO VusuNMqtv5RdSEBVqtVKjyWQI09CqoMHYTgcDRcz/eUI9dVSXJMRNGe4SNe0YXDcyFX0 SF4hZxlNhk/QfDqa8pieNcwpxXebSPo6jhub6MEDx2Ic4L/ygXg3KYQK3VGSgoa0wBBX hWkF93j69T5XP6wOyGSV1oaoIGz8yK4JtoVdjzfoGkQtrlI34v3l/+ZjMnSI38iJiD2f q/tg== X-Gm-Message-State: AMCzsaWT+uqUlSIb/Vor1u+MY9wXMG/arRa1T9aUyrQeKBLS2qCsgLXg M9Ijj0jPUomwrW3z6ZgDyD098g== X-Received: by 10.28.94.3 with SMTP id s3mr2325670wmb.78.1509315101761; Sun, 29 Oct 2017 15:11:41 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id k130sm2926971wmg.12.2017.10.29.15.11.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Oct 2017 15:11:41 -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> From: "pkv.stream" Message-ID: <31aa3082-b348-098e-c8de-113aa9551d29@gmail.com> Date: Sun, 29 Oct 2017 23:11:39 +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: <20171029154450.GQ6009@nb4> Content-Language: fr Subject: [FFmpeg-devel] [PATCH v5 1/2 ] avformat/mpegts: opus muxing 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 29/10/2017 à 4:44 PM, Michael Niedermayer a écrit : > On Sat, Oct 28, 2017 at 03:49:13AM +0200, pkv.stream wrote: >> >> mpegtsenc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- >> 1 file changed, 60 insertions(+), 7 deletions(-) >> 1423a193788547952e3c4cdcb424b4724b0f1157 0001-libavf-mpegts-opus-muxing-for-mapping-family-255.patch >> From 105f20b8af8ce5376165ca30a81276dae2e61e40 Mon Sep 17 00:00:00 2001 >> From: pkviet >> Date: Sat, 28 Oct 2017 02:48:08 +0200 >> Subject: [PATCH 1/2] libavf/mpegts: opus muxing for mapping family 255 >> >> Adds to mpegts muxer the capability to mux 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/mpegtsenc.c | 67 +++++++++++++++++++++++++++++++++++++++++++------ >> 1 file changed, 60 insertions(+), 7 deletions(-) >> >> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c >> index fdfa544..a31663c 100644 >> --- a/libavformat/mpegtsenc.c >> +++ b/libavformat/mpegtsenc.c >> @@ -28,6 +28,7 @@ >> #include "libavutil/opt.h" >> >> #include "libavcodec/internal.h" >> +#include "libavcodec/put_bits.h" >> >> #include "avformat.h" >> #include "avio_internal.h" >> @@ -291,6 +292,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) >> MpegTSWrite *ts = s->priv_data; >> uint8_t data[SECTION_LENGTH], *q, *desc_length_ptr, *program_info_length_ptr; >> int val, stream_type, i, err = 0; >> + uint8_t channel_count, stream_count, coupled_stream_count, *buf; >> + PutBitContext pbc; >> + size_t buf_size; >> >> q = data; >> put16(&q, 0xe000 | service->pcr_pid); >> @@ -421,8 +425,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,8 +439,19 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) >> *q++ = 's'; >> >> *q++ = 0x7f; /* DVB extension descriptor */ >> - *q++ = 2; >> - *q++ = 0x80; >> + /* descriptor_length */ >> + if (st->codecpar->extradata[18] == 255) { >> + /* dual mono */ >> + if (st->codecpar->channels == 2) { >> + *q++ = 2; >> + } else { >> + /* channel_config_code 0x81 */ >> + *q++ = st->codecpar->channels + 6; >> + } >> + } else { >> + *q++ = 2; >> + } >> + *q++ = 0x80; /* descriptor_tag_extension */ >> >> if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) { >> if (st->codecpar->extradata[18] == 0 && st->codecpar->channels <= 2) { >> @@ -483,9 +498,47 @@ 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 except for dual-mono */ >> + if (st->codecpar->extradata[18] == 255) { >> + /* dual mono */ >> + if (st->codecpar->channels == 2 && st->codecpar->extradata[19] == 1) { >> + *q++ = 0x00; >> + } else if (st->codecpar->channels == 2 && st->codecpar->extradata[19] == 2) { >> + *q++ = 0x80; >> + } else { >> + /* application defined channel configuration */ >> + *q++ = 0x81; >> + *q++ = st->codecpar->channels; >> + *q++ = st->codecpar->extradata[18]; >> + channel_count = st->codecpar->channels; >> + stream_count = st->codecpar->extradata[19]; >> + coupled_stream_count = st->codecpar->extradata[20]; >> + buf = av_mallocz_array( st->codecpar->channels + 2 , sizeof(uint8_t)); Hello Michael thanks again for your reviews. >> + if (!buf) { >> + av_freep(buf); > that looks wrong > right; fixed. >> + return AVERROR(ENOMEM); >> + } >> + init_put_bits(&pbc, buf, (st->codecpar->channels + 2)); >> + put_bits(&pbc, av_ceil_log2_c(channel_count), st->codecpar->extradata[19] - 1); >> + put_bits(&pbc, av_ceil_log2_c(stream_count + 1), st->codecpar->extradata[20]); >> + for (i = 0; i < channel_count; i++) { >> + put_bits(&pbc, av_ceil_log2_c(stream_count + coupled_stream_count + 1), st->codecpar->extradata[21 + i]); >> + } >> + flush_put_bits(&pbc); >> + buf_size = av_ceil_log2_c(channel_count) + av_ceil_log2_c(stream_count + 1) >> + + channel_count * (av_ceil_log2_c(stream_count + coupled_stream_count + 1)) >> + + (8 * (2 + channel_count) - av_ceil_log2_c(channel_count) - av_ceil_log2_c(stream_count + 1) >> + - channel_count * (av_ceil_log2_c(stream_count + coupled_stream_count + 1))) % 8; > this duplicates previious expressions > also it can probably be simplified with put_bits_count() > thanks alot for pointing to  put_bits_count. followed your suggestion. >> + for (i = 0; i < buf_size; i++) { >> + memcpy(q++, buf+i, 1); > memcpy isnt needed for seting one char fixed; I moved also the buffer size calculation earlier where it was first required in the (draft) spec and factorized where i could. Passes fate + patcheck. Thanks very much for your patience. Much appreciated. From 72ffc2f5e57f6f730dc255aaff4a0ce8b64143de Mon Sep 17 00:00:00 2001 From: pkviet Date: Sat, 28 Oct 2017 02:48:08 +0200 Subject: [PATCH 1/2] libavf/mpegts: opus muxing for mapping family 255 Adds to mpegts muxer the capability to mux 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/mpegtsenc.c | 58 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index fdfa544..1de520d 100644 --- a/libavformat/mpegtsenc.c +++ b/libavformat/mpegtsenc.c @@ -28,6 +28,7 @@ #include "libavutil/opt.h" #include "libavcodec/internal.h" +#include "libavcodec/put_bits.h" #include "avformat.h" #include "avio_internal.h" @@ -291,6 +292,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) MpegTSWrite *ts = s->priv_data; uint8_t data[SECTION_LENGTH], *q, *desc_length_ptr, *program_info_length_ptr; int val, stream_type, i, err = 0; + uint8_t channel_count, stream_count, coupled_stream_count, *buf; + PutBitContext pbc; + size_t buf_size; q = data; put16(&q, 0xe000 | service->pcr_pid); @@ -421,8 +425,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,8 +439,29 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 's'; *q++ = 0x7f; /* DVB extension descriptor */ - *q++ = 2; - *q++ = 0x80; + /* descriptor_length */ + if (st->codecpar->extradata[18] == 255 && st->codecpar->channels > 2) { + /* channel_config_code 0x81 */ + channel_count = st->codecpar->channels; + stream_count = st->codecpar->extradata[19]; + coupled_stream_count = st->codecpar->extradata[20]; + buf = av_mallocz_array(channel_count + 6, sizeof(uint8_t)); + if (!buf) { + return AVERROR(ENOMEM); + } + init_put_bits(&pbc, buf, (channel_count + 6)); + put_bits(&pbc, av_ceil_log2_c(channel_count), st->codecpar->extradata[19] - 1); + put_bits(&pbc, av_ceil_log2_c(stream_count + 1), st->codecpar->extradata[20]); + for (i = 0; i < channel_count; i++) { + put_bits(&pbc, av_ceil_log2_c(stream_count + coupled_stream_count + 1), st->codecpar->extradata[21 + i]); + } + flush_put_bits(&pbc); + buf_size = put_bits_count(&pbc) / 8; + *q++ = buf_size + 4; + } else { + *q++ = 2; + } + *q++ = 0x80; /* descriptor_tag_extension */ if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) { if (st->codecpar->extradata[18] == 0 && st->codecpar->channels <= 2) { @@ -483,9 +508,28 @@ 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 except for dual-mono */ + if (st->codecpar->extradata[18] == 255) { + /* dual mono */ + if (st->codecpar->channels == 2 && st->codecpar->extradata[19] == 1) { + *q++ = 0x00; + } else if (st->codecpar->channels == 2 && st->codecpar->extradata[19] == 2) { + *q++ = 0x80; + } else { + /* application defined channel configuration 0x81 */ + *q++ = 0x81; + *q++ = st->codecpar->channels; + *q++ = st->codecpar->extradata[18]; + for (i = 0; i < buf_size; i++) { + *q++ = *(buf + i); + } + av_freep(&buf); + } + } 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 */