From patchwork Wed Dec 8 01:06:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 32119 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp7044015iog; Tue, 7 Dec 2021 17:08:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+ajGQSqG+n3s/23hy8wfl/7Mv7w5uP1z06LrOqqX6u4S2G9GFJ19/fuxghlLGpti1K20c X-Received: by 2002:a05:6402:26cb:: with SMTP id x11mr14390580edd.149.1638925727348; Tue, 07 Dec 2021 17:08:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638925727; cv=none; d=google.com; s=arc-20160816; b=rpjYYJ2snKP0UvP454zSOtcSmF9AZ2Fno481d3kzzGxsNfzTH2zD2WbzDkZATfGZ9N /hkrd8O0RItbWXA5J2/PvbQ9vojV8iuUNjZQCeaizuvNGJHgE++GIGLYsINhXR2fe45x drrw+TFpQgRLhzRy3sf+8ui6ywAp4tkx7cEiQWjrQbB825NRERO+08dwL5oQwcXA+d5i xStnuh5qlPa0S7UZyo2j5P6XwzB7YcdERHBriQWOuhJtJqxvYQuOTHpeXvt5tt+EkLh/ YkiIUG4ailCZ3WZefWocYQRO3nrWRApy5+f4xUkATXwUG1QxhXgxleW0cMl5zkNTwZOl rGvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=VYOM+OEEw4cVvZ7WGC5nHVAdkRoW9U4QtoQIKbDyvZ4=; b=x9y35aonmchS1z/cRLlWkxRMBCuZP5+NJi+j6Z4QMWnEzKEqQ6vO9eMgbv92eDNja4 qozQ4sLTOkosedB24UyFdbFIS4eigrbqbLS4KOuOttxjKaO5/b96dTcelBF81xzjOind vAWJJAg/0N8gmzL47fOhR0P6aiZK7QZAZ8KmegFqG/dE/RQU4VfS4qliFJ3fiKPkxTl0 9YkaosB5B2egKUpv1ifizhi1lWlEHCZa2MY2WPv5qcNGgiKj+26aHgj3b/NNjw95t+jU YvqVvYLpfXV8wR5r/Q1ck9YLioH0/Tx9vyMJjdpKedmhM/YDRRewxgGOjFOWFIozFeSO qqrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=SYVm82wW; 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=QUARANTINE 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 p8si2652532edj.225.2021.12.07.17.08.46; Tue, 07 Dec 2021 17:08:47 -0800 (PST) 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=20210112 header.b=SYVm82wW; 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=QUARANTINE 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 3AB9E68A993; Wed, 8 Dec 2021 03:07:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-vk1-f172.google.com (mail-vk1-f172.google.com [209.85.221.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2EEB668A852 for ; Wed, 8 Dec 2021 03:07:34 +0200 (EET) Received: by mail-vk1-f172.google.com with SMTP id j1so588405vkr.1 for ; Tue, 07 Dec 2021 17:07:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=tDkXROml0zMFczgrJaq9EcUtxudwTCREE5h3ne8Y/BQ=; b=SYVm82wWO+3hV+M/NjWLJ/5TbHhI1SqhStxmrJKO5YhWvMORWp7vp5zGGje+Z93krt Eeeo+61rie1uTJuVCxgaHi92I4MrmaBIZPqCTPLjLjOUbxn4svbaGuFI00oYx7q4eexc 2wg3vXSEfaW39AgW6L+vqyJBCt8Ew7o7YXLAB+2PxpwAcxk+LWJZKTsjbN09VcVR0Qv0 52fswoS1tFLp6krQlQBFRoQfSKYzccg/89ukQCtxizVXXNwnO8t7O9KJX+vWYuJdjvKd a+Kjj4iALEkYhwcpQupeNbkihNuELSbrhSPP43pp4Ms4xnGGhpDLxOom/A77noLo9o5g TAtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tDkXROml0zMFczgrJaq9EcUtxudwTCREE5h3ne8Y/BQ=; b=RPJYo1F6ZoRRzC4rp6rtoFylbZ3DxVpN8tROA4BssBaOx5/o1vvE2uVCgQFQVdM5/5 EMYSuMpfyloGhKE+k6Kqlh3jY5ix+lKLTbK13lL+Q1fpaWDVgvEZ74LRPnApvE78TTmZ WvpqEkgQ73kD0pitK9619zqEerKOog9dsjZclcQ4z7X4m4DmjvMnGLLdBvUY+eRTwuiC Lvn6wIBsKkS9FhPBwFGd8Q6TXLAPB4KhYR0KnuWz1OaP2OY+Q9Lrfu/rTFbWBrPtlAQM CHOAN1Qc1Bum/zoeUkgPiREiNfIzWtz/mdORZwIBL5x/LCQ6SfvrDBSxxnUZLS8swQZd 2vlQ== X-Gm-Message-State: AOAM531SlBT5pTiSxgu+5GFXGCUVnQJiqk7yqIwwvcaBmWtmMAC+Ignr A0W9w170YLiHC9YiVPitfSJthmWXBWKBF0pR X-Received: by 2002:a1f:7f01:: with SMTP id o1mr58011738vki.40.1638925653452; Tue, 07 Dec 2021 17:07:33 -0800 (PST) Received: from localhost.localdomain ([181.170.250.138]) by smtp.gmail.com with ESMTPSA id b8sm949898vsl.19.2021.12.07.17.07.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 17:07:33 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 22:06:23 -0300 Message-Id: <20211208010649.381-8-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211208010649.381-1-jamrial@gmail.com> References: <20211208010649.381-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 007/279] lavf: add a temporary compat layer for the channel layout API change X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: wRQ0A41fjuEr From: Anton Khirnov Mediates between old-style (de)muxers and new-style callers. Will be removed once all the (de)muxers are converted to the new API. Signed-off-by: James Almer --- libavformat/demux.c | 12 ++++++++++++ libavformat/mux.c | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/libavformat/demux.c b/libavformat/demux.c index 745dc8687c..cb02c84f33 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -194,6 +194,18 @@ static int update_stream_avctx(AVFormatContext *s) sti->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(sti->avctx, st->codecpar); if (ret < 0) diff --git a/libavformat/mux.c b/libavformat/mux.c index d93dc73f8e..fc9199230c 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -272,6 +272,16 @@ static int init_muxer(AVFormatContext *s, AVDictionary **options) 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;