From patchwork Tue Oct 31 23:25:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 5799 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp78725jah; Tue, 31 Oct 2017 16:32:20 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RgQmEEteuWTZY13s1KhhV33SUCTdccYH8+mVeePeW21PZ5fwkC5jUTWwwv2w8KZZ8xOvwX X-Received: by 10.28.238.148 with SMTP id j20mr2995335wmi.23.1509492740681; Tue, 31 Oct 2017 16:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509492740; cv=none; d=google.com; s=arc-20160816; b=Amdgsl/si7uKCQ1SApgoii89m/0/fRw5qcTcTBa6KE7SVIaebsre7+p3auYEtLw6lq ysFhN7uKt8Y32QJV6hFoor6V6QOydKrvKu+BGK3U4mICEH5TObtwfiW7J42Nb9ElX5rr 0tVR+kewlGhcUJkqZmy0WWhgWgs/A5NoVT0h6Db7Fkm+HhHaNlnXCFZQ0dcqO7VeUifg PMJXVZq3TamSNQPrn7V4lirTf1ltTAyn1AM0n3oBiM8G4RUqAkFSRRilHPzjinYtPGFW eZ9gEFdsQ0nlQ/ZbRFF7Ude9+dfOIU1qDGU1vI1Tv1gEFvrYDV9aSELRWjmGlxjJhdps 3QxQ== 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=MCn5HyEiV4wyg7hVMkzbbut1rWYos0WCbeYnfcLatOE=; b=vPZPDsrnl/0aoCc25Qe2kke3ZuKN7Ye9BYs81jIU4fA4S8lb+vQftC6SPqDLHFNnoN NRkdPc5yZBP/7Q0m3cYWNzx/eFcrryuvMI8Wx35/xLJW15ppNWkNLSeiiit2eWlSn6Tt whP+jddSSe+Y9mgrzN5gmV6m+p9QMIn5q8MKKmjgQKRSVx/eNtAFKbBBbRI58O0f6Dv2 clwZNZxxMROYCtUNTtP/LMReASM8wut3mSA0QTHPS5RKOLhwmZP3uSZRgPywmMX9gapD z0jjUpvyLthttrzqojHQoCTu9S/deu0i6fHsNGA8eF03KR7AtpsThhbt0KiX5EujBi0d AgPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=OIGeIBFo; 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 x3si2335752wrd.245.2017.10.31.16.32.20; Tue, 31 Oct 2017 16:32:20 -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=OIGeIBFo; 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 6685E689E05; Wed, 1 Nov 2017 01:32:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 039DB689723 for ; Wed, 1 Nov 2017 01:32:03 +0200 (EET) Received: by mail-wm0-f45.google.com with SMTP id r196so1846982wmf.2 for ; Tue, 31 Oct 2017 16:32:13 -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=GsURzY9uLUZodYOu/tAntxmfQXJkkdPcZpP2tGL/lyA=; b=OIGeIBFoQK9yu1knn+VRoG+4ZXVMUeIpb0zKBqqV0Mq7oCBJrxrjf1GkQToBqercB5 tFOGvawME3AnjugeMWCa3gJtg/9UqVKTUuUHYdWVui2BIt6N2PYl1Kjbl3asbQXE9Z6n LwMg15wfzfiOBhiIAu2s7YVId/GWjq/NGIDJS5lKsUSJM+rSL/N/C8V0t/xKBxkgTFyQ 6ifI+t3kDiczHpDLtxrq830tzb6L0VTJ28XwQ+n7plP2U+DtxdOkPLZd1QzTO0pkfAQY qKaT5n7HO6csZrI8BItI3nHggXKCn3U8vrewh80xvQjDOmeOYsHg8NF7B9i+AZS386YC yhig== 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=GsURzY9uLUZodYOu/tAntxmfQXJkkdPcZpP2tGL/lyA=; b=JcRCKGjwS1XXSiILOEeQ2uvtzAShJk18lsM1lYQ86tp6NM/cRKa9ptks+i7ewnB1e5 38YqED+RkjBu+AxEVOJyjFkYCp/HYsMIGdNc+ffUy7ZtqVBokg0GP2/B7tiOEhR1fmjQ Z7jvrFQpHqqryqmH+vLQy9iArPnsGL9dyWTc1tXwS9AH0nBF9CpqqluTaP4ADY1xKyHY dQ0lhl1xOrnil2vtp8bipWFfovEga0378DXZWudamNE9UD2+Pn1N72YRztxgHLgAd0S3 jA4owCbfKjbibRnUJHMXHX1X6hFgnmDTNl09DG0EXebMyTJp4Jwj1hSY8owjdEZT86vV vy9Q== X-Gm-Message-State: AMCzsaVl/KSOfokRRnt9eu0rO3RVU3bmnCw+MlL3zMidgK4Cb/XcchCC BTIgx9UI52Df3AX780vwtA7A8A== X-Received: by 10.80.202.134 with SMTP id x6mr4823681edh.14.1509492307075; Tue, 31 Oct 2017 16:25:07 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id 88sm1926615edq.49.2017.10.31.16.25.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Oct 2017 16:25:06 -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: <5e3b1495-22de-346f-ab85-f022739c73a3@gmail.com> Date: Wed, 1 Nov 2017 00:25:04 +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 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH v6 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)); >> + if (!buf) { >> + av_freep(buf); > that looks wrong > > >> + 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() > > >> + for (i = 0; i < buf_size; i++) { >> + memcpy(q++, buf+i, 1); > memcpy isnt needed for seting one char > > thx > > [...] > > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel hi Michael fixes all that you spotted + fix an error in opus audio descriptor length. thanks a lot pkv From 2cb9cad8a02c5d62c149de5401858d137bdf2d62 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). --- libavformat/mpegtsenc.c | 69 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c index fdfa544..c9aba76 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, opus_audio_descriptor_size; q = data; put16(&q, 0xe000 | service->pcr_pid); @@ -421,8 +425,36 @@ 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) { + /* opus_audio_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; + opus_audio_descriptor_size = buf_size + 6; + } else { + opus_audio_descriptor_size = 4; + } + /* 6 bytes registration descriptor, 4 bytes Opus audio descriptor + * (unless channel_config_code is 0x81) + */ + if (q - data > SECTION_LENGTH - 6 - opus_audio_descriptor_size) { err = 1; break; } @@ -435,8 +467,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service) *q++ = 's'; *q++ = 0x7f; /* DVB extension descriptor */ - *q++ = 2; - *q++ = 0x80; + *q++ = opus_audio_descriptor_size - 2; /* descriptor_length */ + *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 +515,32 @@ 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 */