From patchwork Thu Jan 13 01:57:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33405 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp29954iog; Wed, 12 Jan 2022 18:20:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQuG+VWdm36NIiEpZG6aBqPmEdS8+GpjsXBnvzG7+/3rkX8aiNUP8U4dwI/RFuUrvRDaZQ X-Received: by 2002:a17:906:314a:: with SMTP id e10mr1916250eje.672.1642040410481; Wed, 12 Jan 2022 18:20:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642040410; cv=none; d=google.com; s=arc-20160816; b=ae7c2T4UJa9fzYyocd/bOk3/eplZH/RA6TswZHMqs97ss0m9RxpRRt0JohclQHtHXs NLvwKikgO6TmxqBo1REhdjrUDv3YhHB7nKEk+tG0gEsyOlfe9muc46v/CsQsm+H2LKMX vWS2lbU4VBBZFl9qbEdRJet/ZENJUr0noBG5znYDXeaPaoYkngS3BLtBpfVZRV2yc1hY 2AL2gJ787w0gMLCmtmSwi9OCBfOeyt3UncLHGqt5NxQdI3SguRxPxqWciQlmtLO5hLs+ gEZV3IsL1dYtgOSfBs4l5bQxrDxc6M9Zzl3M1qRvtRdF8bWq/qKWVEdFOozsMO1CjFSI LGTQ== 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=DM1veLtjerYdmLxDtUw4eTvDWkboYFAUfNWEgtydqJA=; b=DRUq6CR7udDVahK6il88l8TEZ4PZqNq3n+isRfNpdbCbDaVCaT1MM0fjuL4KDAMKjz +VGbvSpsAFu90+9LEvhO0fhn8dUArz79VrlgDmdpTWQslB/sFYUGsPfWySRM1tnXCBfU 8zibRvrGduPeIMtgJk12/LsuP8aNmF74PKULlwINjSEFUh6at5KMXpzTuRGGWgJiJfcA eihWw803aK6ramj54CCo40KvgozwNp9n8rKS1SXR374Q9MdfnqIDPGEMMDxXYGe3DlTb 05qRCYYeQyLNwXVeV1XxVOCUedhBuDNG1In3pizhpd4MsOgXWWDzraSkmuRVG2Ro7aGL OGeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=LtgGUPUK; 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 r6si897476edv.7.2022.01.12.18.20.09; Wed, 12 Jan 2022 18:20:10 -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=LtgGUPUK; 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 E6C6968B377; Thu, 13 Jan 2022 03:58:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2CDE268B354 for ; Thu, 13 Jan 2022 03:58:39 +0200 (EET) Received: by mail-qt1-f180.google.com with SMTP id q24so1550832qtp.5 for ; Wed, 12 Jan 2022 17:58:39 -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=KGJIgX/PSOWDX7NLMRAwP0SSyMFbVPY8sn5MGkKPLT4=; b=LtgGUPUKS48HrA4uqYvDGc7NNRP91UGbObKQy0sScnLWncH8Iz8AJY4F4BPXNG7G35 UC2OXtiCAkmEkZwrJIjq0Ol51B2cUY8lkLW7u5y96uVKK5TBxO51uAzrs4EnTumPK9vB Lae1DQmogp3heEyvvsFnmYGQzIl7nn2hS1ziIRc2ERNK9cnN/4JlkIKSsrpHwf3PJF/8 c3+VjfkvEEUct9mYQHeWrpA9D4sgexNemG1h1IZMgi561wa7sC9MWrONqtAmd9yNCFHk X2YMMh87PhWyonAx1p1r3u+gNbPhBCz4yhIUeHDl1hW/m1Rn2ZTJUREtdOzN1RfXdr5A FPSQ== 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=KGJIgX/PSOWDX7NLMRAwP0SSyMFbVPY8sn5MGkKPLT4=; b=wNmzPvxjf29hWU1onX37QQNdYm0peqK9DPddDf3Wlc7x+hUwVND0V+VIi358OVl6py iH/lHUUGNSEuK13XX9ZI+YaBapVvAxUdE4aMgDQhL88CJa9/baRmVXMcbED3YbISaN54 j+bNPjmpun1AFP2PTTg3gyuJpqZ3LMPEKs6R/jB8Txra90U/NRrSFFuGM+GeChsw1Jtg PgNSaIAT+UcQVtmeZeRC4a8C/9EINdoHpHoHH6f87dTPhZD7fdfIeV6ArLJm3+D8uaP0 S7RMKwsTQLzPwImV+y6oJjXaXk0Qy1RrusRkbY3zmRxx0K6M1V2+T2EGulGOUkscUdU0 G7+w== X-Gm-Message-State: AOAM531PrWVjj0FTfhbCuQDz7gZYETxtJDzBRzuo+hKxCGiGP4KVARwE cvXjp/6EdHV/N2m+YA2E27gUXOXHsDg= X-Received: by 2002:ac8:7607:: with SMTP id t7mr2024622qtq.286.1642039118135; Wed, 12 Jan 2022 17:58:38 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id u19sm893081qke.1.2022.01.12.17.58.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 17:58:37 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 22:57:46 -0300 Message-Id: <20220113015806.519-11-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 129/281] riff: convert to new channel layout API 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: lC+xgiQEYxiT From: Vittorio Giovara Signed-off-by: Vittorio Giovara Signed-off-by: Anton Khirnov Signed-off-by: James Almer --- libavformat/riffdec.c | 20 +++++++++++++------- libavformat/riffenc.c | 18 +++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index bd32e59837..a62e9c070f 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -61,11 +61,14 @@ static void parse_waveformatex(AVFormatContext *s, AVIOContext *pb, AVCodecParam { ff_asf_guid subformat; int bps; + uint64_t mask; bps = avio_rl16(pb); if (bps) par->bits_per_coded_sample = bps; - par->channel_layout = avio_rl32(pb); /* dwChannelMask */ + + mask = avio_rl32(pb); /* dwChannelMask */ + av_channel_layout_from_mask(&par->ch_layout, mask); ff_get_guid(pb, &subformat); if (!memcmp(subformat + 4, @@ -90,7 +93,7 @@ static void parse_waveformatex(AVFormatContext *s, AVIOContext *pb, AVCodecParam int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian) { - int id; + int id, channels; uint64_t bitrate = 0; if (size < 14) { @@ -102,14 +105,14 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, if (!big_endian) { id = avio_rl16(pb); if (id != 0x0165) { - par->channels = avio_rl16(pb); + channels = avio_rl16(pb); par->sample_rate = avio_rl32(pb); bitrate = avio_rl32(pb) * 8LL; par->block_align = avio_rl16(pb); } } else { id = avio_rb16(pb); - par->channels = avio_rb16(pb); + channels = avio_rb16(pb); par->sample_rate = avio_rb32(pb); bitrate = avio_rb32(pb) * 8LL; par->block_align = avio_rb16(pb); @@ -160,12 +163,12 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, return AVERROR(ENOMEM); nb_streams = AV_RL16(par->extradata + 4); par->sample_rate = AV_RL32(par->extradata + 12); - par->channels = 0; + channels = 0; bitrate = 0; if (size < 8 + nb_streams * 20) return AVERROR_INVALIDDATA; for (i = 0; i < nb_streams; i++) - par->channels += par->extradata[8 + i * 20 + 17]; + channels += par->extradata[8 + i * 20 + 17]; } par->bit_rate = bitrate; @@ -178,13 +181,16 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, if (par->codec_id == AV_CODEC_ID_AAC_LATM) { /* Channels and sample_rate values are those prior to applying SBR * and/or PS. */ - par->channels = 0; + channels = 0; par->sample_rate = 0; } /* override bits_per_coded_sample for G.726 */ if (par->codec_id == AV_CODEC_ID_ADPCM_G726 && par->sample_rate) par->bits_per_coded_sample = par->bit_rate / par->sample_rate; + par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + par->ch_layout.nb_channels = channels; + return 0; } diff --git a/libavformat/riffenc.c b/libavformat/riffenc.c index ffccfa3d48..04cde7b37f 100644 --- a/libavformat/riffenc.c +++ b/libavformat/riffenc.c @@ -77,9 +77,9 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, * for indicating packet duration. */ frame_size = av_get_audio_frame_duration2(par, par->block_align); - waveformatextensible = (par->channels > 2 && par->channel_layout) || - par->channels == 1 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_MONO || - par->channels == 2 && par->channel_layout && par->channel_layout != AV_CH_LAYOUT_STEREO || + waveformatextensible = (par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE && + av_channel_layout_compare(&par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO) && + av_channel_layout_compare(&par->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO)) || par->sample_rate > 48000 || par->codec_id == AV_CODEC_ID_EAC3 || av_get_bits_per_sample(par->codec_id) > 16; @@ -89,7 +89,7 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, else avio_wl16(pb, par->codec_tag); - avio_wl16(pb, par->channels); + avio_wl16(pb, par->ch_layout.nb_channels); avio_wl32(pb, par->sample_rate); if (par->codec_id == AV_CODEC_ID_ATRAC3 || par->codec_id == AV_CODEC_ID_G723_1 || @@ -119,13 +119,13 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, } else if (par->codec_id == AV_CODEC_ID_AC3) { blkalign = 3840; /* maximum bytes per frame */ } else if (par->codec_id == AV_CODEC_ID_AAC) { - blkalign = 768 * par->channels; /* maximum bytes per frame */ + blkalign = 768 * par->ch_layout.nb_channels; /* maximum bytes per frame */ } else if (par->codec_id == AV_CODEC_ID_G723_1) { blkalign = 24; } else if (par->block_align != 0) { /* specified by the codec */ blkalign = par->block_align; } else - blkalign = bps * par->channels / av_gcd(8, bps); + blkalign = bps * par->ch_layout.nb_channels / av_gcd(8, bps); if (par->codec_id == AV_CODEC_ID_PCM_U8 || par->codec_id == AV_CODEC_ID_PCM_S24LE || par->codec_id == AV_CODEC_ID_PCM_S32LE || @@ -153,7 +153,7 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, /* dwHeadBitrate */ bytestream_put_le32(&riff_extradata, par->bit_rate); /* fwHeadMode */ - bytestream_put_le16(&riff_extradata, par->channels == 2 ? 1 : 8); + bytestream_put_le16(&riff_extradata, par->ch_layout.nb_channels == 2 ? 1 : 8); /* fwHeadModeExt */ bytestream_put_le16(&riff_extradata, 0); /* wHeadEmphasis */ @@ -180,13 +180,13 @@ int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, if (waveformatextensible) { int write_channel_mask = !(flags & FF_PUT_WAV_HEADER_SKIP_CHANNELMASK) && (s->strict_std_compliance < FF_COMPLIANCE_NORMAL || - par->channel_layout < 0x40000); + par->ch_layout.u.mask < 0x40000); /* 22 is WAVEFORMATEXTENSIBLE size */ avio_wl16(pb, riff_extradata - riff_extradata_start + 22); /* ValidBitsPerSample || SamplesPerBlock || Reserved */ avio_wl16(pb, bps); /* dwChannelMask */ - avio_wl32(pb, write_channel_mask ? par->channel_layout : 0); + avio_wl32(pb, write_channel_mask ? par->ch_layout.u.mask : 0); /* GUID + next 3 */ if (par->codec_id == AV_CODEC_ID_EAC3) { ff_put_guid(pb, ff_get_codec_guid(par->codec_id, ff_codec_wav_guids));