From patchwork Fri Dec 6 10:17:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 16625 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7740E44ABC2 for ; Fri, 6 Dec 2019 12:19:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 660D968B681; Fri, 6 Dec 2019 12:19:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1E8C168B678 for ; Fri, 6 Dec 2019 12:19:08 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id BF7172945B6 for ; Fri, 6 Dec 2019 11:19:08 +0100 (CET) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id tfKltwoPdRMK for ; Fri, 6 Dec 2019 11:19:08 +0100 (CET) Received: from quelana.khirnov.net (unknown [IPv6:2002:b061:f0a:201:5e:e696:5100:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 146542945B4 for ; Fri, 6 Dec 2019 11:19:08 +0100 (CET) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 69D6F7F85D for ; Fri, 6 Dec 2019 11:18:58 +0100 (CET) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id O7spaOK0KKAt for ; Fri, 6 Dec 2019 11:18:57 +0100 (CET) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 920957F95D for ; Fri, 6 Dec 2019 11:18:47 +0100 (CET) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id 9659420E014D; Fri, 6 Dec 2019 11:17:48 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 6 Dec 2019 11:17:00 +0100 Message-Id: <20191206101710.22028-6-anton@khirnov.net> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191206101710.22028-1-anton@khirnov.net> References: <20191206101710.22028-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 006/244] lavf: add a temporary compat layer for the channel layout API change 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" Mediates between old-style (de)muxers and new-style callers. Will be removed once all the (de)muxers are converted to the new API. --- libavformat/mux.c | 10 ++++++++++ libavformat/utils.c | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/libavformat/mux.c b/libavformat/mux.c index 411cca3fb2..ae1f26c3da 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -323,6 +323,16 @@ FF_ENABLE_DEPRECATION_WARNINGS ret = AVERROR(EINVAL); goto fail; } + + /* if the new-style channel layout is set, convert it to old one + * for old-style muxers */ + if (par->ch_layout.nb_channels && + !par->channels) { + par->channels = par->ch_layout.nb_channels; + par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? + par->ch_layout.u.mask : 0; + } + if (!par->block_align) par->block_align = par->channels * av_get_bits_per_sample(par->codec_id) >> 3; diff --git a/libavformat/utils.c b/libavformat/utils.c index b6b5f0f308..13eadbbfd0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -516,6 +516,18 @@ static int update_stream_avctx(AVFormatContext *s) st->parser = NULL; } + /* if the demuxer exports old channel layouts, convert it to new */ + if (!st->codecpar->ch_layout.nb_channels && + st->codecpar->channels) { + if (st->codecpar->channel_layout) { + av_channel_layout_from_mask(&st->codecpar->ch_layout, + st->codecpar->channel_layout); + } else { + st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + st->codecpar->ch_layout.nb_channels = st->codecpar->channels; + } + } + /* update internal codec context, for the parser */ ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar); if (ret < 0)