From patchwork Sat Oct 28 01:49:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 5731 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp164510jah; Fri, 27 Oct 2017 18:55:41 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RW5o10e61+XYa4ldIveuh7+zxyHOjdXA7+XBYMTrzazJZhrvu7wwczvFx3sRT5TR9XLMHZ X-Received: by 10.223.151.221 with SMTP id t29mr1767247wrb.34.1509155741526; Fri, 27 Oct 2017 18:55:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509155741; cv=none; d=google.com; s=arc-20160816; b=qRlT8VpdukA6niBY+EQG9Z/MkWUB0UwBHY646im0oyBRQEKJP/O74FAd+KMx75y4Wl QbTSV65tCblT/obMHLuhHu50WYt3S7419rO16yb0YOhWPYG8YOOhD1mKmP+Ek14QUbGW ZAKAahygsHtqLr58jiBCeIAp5cAqW/gpJFieljio7ugWdEdqp4fsVLr+14jLcXx9LZ8j DxWFp0xi46eSsVXQxNFAO86oW31OotSc2Bt0/cJaxG1ov7uugxBSDP5vG1cq6SlO2Np2 JU5rA1j//+Oy8ZowSB/eohOGqazIEX45VcDVGCDA22Dlx/sZDWA1+OrpwSHhbVVLImmY LH9g== 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=FTgrTJvNBYEx3A3Jclr1awSd6Rx6yYsWDS7kF4uifm0=; b=u5LJm8N55WQ+00YdBRZJFC/YKXMjXMhjOeCyw9MhKPlD9mo8qYHDRHOVwZOkR49Nkm +XN7mwpzHQ/FygX1GCKpKkf4BHO+xyoyT5a0ebSmFP19MsNJccHcGbuMcM3PUIp8EBp2 M60EfqcwVnd1lgZReoO4iJkMeuj1XkUAH3cNEk/CGztMmOd4iNi2ZeOpIuZtO7RtT/b4 +mmHm5Er1nKbhrOySOeyV690HC1yJTjKUBHZNcQoRGoght8DyaRQRQKlUNDnRf8L8X7+ o+cAP0gxHtyUGJehlr401pgFamBuXH2MGVgehVmtUfByjf7/rZ8C0kHMVacspIXtBn8a 4iMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=c9lKLzFt; 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 v16si2131908wmc.6.2017.10.27.18.55.41; Fri, 27 Oct 2017 18:55:41 -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=c9lKLzFt; 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 CB2EB689D75; Sat, 28 Oct 2017 04:55:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E338F68836C for ; Sat, 28 Oct 2017 04:55:25 +0300 (EEST) Received: by mail-wm0-f46.google.com with SMTP id s66so6121345wmf.5 for ; Fri, 27 Oct 2017 18:55:34 -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=GI7+axJx/jnfQJ/DPQEDGf1YJTuUkHGLo0T1nxz4ak8=; b=c9lKLzFtrLSXyGXuwRgpGHXxiC7CaL4O0YNxI7r90MSLIHTXFgv+dC+ZkdhjLCrjEI qjEi8X9wDILliw7OY9RytbqeZB8Q0ivUoQxvh9qgwW8JuZukCMn5z7CZ04z+cIF3zTf9 QySjpsWs0AXAnh/tDR9HVw0WBKfa1K5ExxeZY7InoIlbKexsiEpjitPwVtxnv6W7TB7k QSBwAS5t+Rm0VPBSp1TwXsCTV/URhxAgAzb3W1VwZH7H6DoMVEbc1WMcepPnr6MkH6uJ hSTCKteQCB4XlaW/4/JJfaM7Zx2zBOe9ufCkwDIOkiLVCKz3GxgNJ82tI3yET1Z7BcRu MMsg== 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=GI7+axJx/jnfQJ/DPQEDGf1YJTuUkHGLo0T1nxz4ak8=; b=o9gHBXnGL6PUz3TVdHvkio1w+M7G9yN24aSp4BYQQmyE6CnNS5s+FiLJ0TjLZryIU9 lCvkfFB0iMZntCb1OODgKJQEaVgZKSF3VpXyaTsYrQbhNyFVFeo0NihwKveJDbu7jtD7 rXQNN+kXx2Tj+O0U/4oZEnviKvsOowZJvYpsm45twl20JGJtRdo7y6MKNcSupEci2G1O Q8UL4QiF1qcM5EUzeCCaH3x8XTPXkjpSsjIpCpFAMSHlBzWr0ziR62ZH8W1JAXkOfl9D //a/umcMVhxG4UWU7vMyiVZ56IYVa7F7OrarqenKUt1u6CQJThHboXdyj229+t4Y8xOu kL/A== X-Gm-Message-State: AMCzsaUfeEjFR2U54ym8btpzt3foqimk64yoHI7R4FRUhzC/pH4HZRu6 v/QAEQN0hP1JICC8c2eDMdO32Q== X-Received: by 10.28.236.216 with SMTP id h85mr1833462wmi.100.1509155356322; Fri, 27 Oct 2017 18:49:16 -0700 (PDT) Received: from [192.168.0.2] ([176.159.7.188]) by smtp.googlemail.com with ESMTPSA id p128sm2207644wmb.1.2017.10.27.18.49.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Oct 2017 18:49:15 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <103114c7-8ba7-d798-6353-83d346990995@gmail.com> <20170914154635.GD7726@sunshine.barsnick.net> <20171025014520.GP6009@nb4> From: "pkv.stream" Message-ID: <2461eb3e-d3ba-7d7f-e02c-69d704deb187@gmail.com> Date: Sat, 28 Oct 2017 03:49:13 +0200 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: <20171025014520.GP6009@nb4> Content-Language: fr Subject: [FFmpeg-devel] [PATCH v4 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" 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); + 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; + for (i = 0; i < buf_size; i++) { + memcpy(q++, buf+i, 1); + } + 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 */