From patchwork Fri Feb 23 20:41:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Beauxis X-Patchwork-Id: 46500 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51b:b0:19e:cdac:8cce with SMTP id gm27csp124527pzb; Fri, 23 Feb 2024 12:41:33 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXo2VFtV1SVb0k1zO4X29tANfban4TYzJQscuum7tHt2bsmsDEl293wMTLo9/UmPrt8t5K6pMoVAgXR+Oz1MNkDN59g9U+GtlDR+Q== X-Google-Smtp-Source: AGHT+IHd9i6ekPBDDW2Z2PUd37rc0KDltb9aJZYrRfyzzQKwwT9rcV+LRkEfwqymauP5Eay1ordP X-Received: by 2002:a17:906:309b:b0:a3e:21f5:7af6 with SMTP id 27-20020a170906309b00b00a3e21f57af6mr499072ejv.3.1708720892847; Fri, 23 Feb 2024 12:41:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708720892; cv=none; d=google.com; s=arc-20160816; b=KLe9K2XqA9uGTmed2MKhVxufF8aclbVVnrMh4ZsmAVrUN14wn23Garlnu2XdNrCL2x 4li39M84EbKTK5wqZ10VY9gETVTBbcxe/EwJXxHIqO9tUCjtHUOApV6G8q3Q+v3JA4Jy o2pGKajfmQnJoqQ2TYhkdmu9amkCZ1JaAE9Yfde00nGGJg9Yqi3BCw2w7PBBnJ0My6xX cjWTND+iUFVAMXx2JPMIoqMvwb0+d6lwoF9DL3U4Q8YRgfxEhfPShJsV/bRjeRsEj0hd xDQs6OcNXh2spHgcjPskL9c4HxW73EXsNNoZKXGQZNwhFj74SjQe99BcRHS9ZuCqgieP qGBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=OK7ugBysH6B4VS7jb3MdGjkIanmj9Y5ZWA38wBa1R2U=; fh=Dy2HmWbIgzG07YKb/uJ0dh3GBmODWRQaNOnRjO8Xj4c=; b=bH7sNVHyoArTC1CL5M0a8EHZSSYGpx9JNUFvd1EXObnR7YYAUpFOmwPiKw0ekEEUyH sRxcAvX4vGW344lQ+0mAWVnem0NV2e/yGjNSxTJE+Jbw+vnS5KjBx/arYTnKwEq/huo6 gCx9/eHIXEhayTpAW5JB/FEL1hI9f+l5aOz0e2RugNa8K/JO7/MJmZ2mGCOyv/cdwKnE VGToApmHVOyzfg0SzOTqKTh1V5tUfIzxsafq1/efRtM1IH152eSQ94alnyi7xlyGEe7j T7MU5C8Sgk2L9jY53Ai7+J3Ip4fD6xwCJmgclL1wMQ/9wKBS7NCrfeIFZt0NPIZDCKEz DZwg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u23-20020a170906069700b00a3f0ec6e162si3257258ejb.462.2024.02.23.12.41.32; Fri, 23 Feb 2024 12:41:32 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3885068C5B1; Fri, 23 Feb 2024 22:41:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 230CA68C18E for ; Fri, 23 Feb 2024 22:41:22 +0200 (EET) Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-6e2b466d213so176801a34.0 for ; Fri, 23 Feb 2024 12:41:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708720880; x=1709325680; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ryYT8e/a4RoedG7PvOuOiqMHHBQjnWd5Ed1O1aWg68k=; b=FspsT9vZKKo5GPn0ghR8ZFJrqZL7VjBmQAMUmeY87a88psRyUEsRoiB77t1nl7Q2+s J0MMhFKTFMysGBYFHagp1jf+wcB22jd0BjTDIelZ90S8xsh5a3xAdYrgG+TlogD/sNOO wF3oONVdjv0SJLptjOHYOkKOX6UpUi97p7EKb/aL8l+My3tSHNqk+Ny0XomXE8vydthw 4q6jSqpw+Yu9BNgY/yxnNm2NYHHmhz1MlpsSSV4LyB87OpsfSu8Fxqgm6XR2bZarDHGX 2wKcP7kFYymKviUlgIfe46u0EMENdeWNDFUrT3IpZjX9azm0kgDm/DFpqh4wmVJBeuAf kI+A== X-Gm-Message-State: AOJu0YwI5g5oDKkowQ6fI3m3sbmfkt+MQHvdB9nKjkvZijKiQHTxJaI/ utLTJ86KQX9STFliBN18kjWVKcqlYchb+HuuSTOR5qBofRVMqE642nHGHRZ2A58= X-Received: by 2002:a9d:7490:0:b0:6e4:7a84:6a4f with SMTP id t16-20020a9d7490000000b006e47a846a4fmr1042496otk.0.1708720879932; Fri, 23 Feb 2024 12:41:19 -0800 (PST) Received: from romains-mbp-2.lan ([2600:8807:4040:e0:b53c:960f:9185:8308]) by smtp.gmail.com with ESMTPSA id k9-20020a9d7dc9000000b006e2e64d2e14sm2618989otn.75.2024.02.23.12.41.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 23 Feb 2024 12:41:19 -0800 (PST) From: Romain Beauxis To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Feb 2024 14:41:06 -0600 Message-Id: <20240223204105.95953-1-toots@rastageeks.org> X-Mailer: git-send-email 2.39.3 (Apple Git-145) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] Set native order for wav channel layouts up until 8 channels. 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 Cc: Romain Beauxis Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eTdGshzXTcv3 The new default channel layout for the various RIFF/WAV decoders is not backward compatible. Historically, most decoders will expect the channel layouts to follow the native layout up-to a reasonable number of channels. Additionally, non-native layouts are causing troubles with filters chaining. This PR changes the default channel layout reported by RIFF/WAV decoders to default to the native layout when the number of channels is up-to 8. The logic for these changes is the same as the logic for the vorbis/opus decoders. Romain --- libavformat/riff.h | 1 + libavformat/riffdec.c | 31 ++++++++++++++++++++++++++++--- libavformat/wavdec.c | 4 +--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libavformat/riff.h b/libavformat/riff.h index a93eadfeca..f474efdce9 100644 --- a/libavformat/riff.h +++ b/libavformat/riff.h @@ -67,6 +67,7 @@ void ff_put_bmp_header(AVIOContext *pb, AVCodecParameters *par, int for_asf, int int ff_put_wav_header(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, int flags); enum AVCodecID ff_wav_codec_get_id(unsigned int tag, int bps); +void ff_get_wav_ch_layout(AVChannelLayout *ch_layout, int channels); int ff_get_wav_header(void *logctx, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian); diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index 0fe4e02b7b..bb7c01c5f5 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -90,6 +90,33 @@ static void parse_waveformatex(void *logctx, AVIOContext *pb, AVCodecParameters } } +const AVChannelLayout ff_wav_demux_ch_layouts[9] = { + AV_CHANNEL_LAYOUT_MONO, + AV_CHANNEL_LAYOUT_STEREO, + AV_CHANNEL_LAYOUT_SURROUND, + AV_CHANNEL_LAYOUT_QUAD, + AV_CHANNEL_LAYOUT_5POINT0_BACK, + AV_CHANNEL_LAYOUT_5POINT1_BACK, + { + .nb_channels = 7, + .order = AV_CHANNEL_ORDER_NATIVE, + .u.mask = AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER, + }, + AV_CHANNEL_LAYOUT_7POINT1, + { 0 } +}; + +void ff_get_wav_ch_layout(AVChannelLayout *ch_layout, int channels) +{ + av_channel_layout_uninit(ch_layout); + if (channels > 8) { + ch_layout->order = AV_CHANNEL_ORDER_UNSPEC; + ch_layout->nb_channels = channels; + } else { + av_channel_layout_copy(ch_layout, &ff_wav_demux_ch_layouts[channels - 1]); + } +} + /* "big_endian" values are needed for RIFX file format */ int ff_get_wav_header(void *logctx, AVIOContext *pb, AVCodecParameters *par, int size, int big_endian) @@ -195,9 +222,7 @@ int ff_get_wav_header(void *logctx, AVIOContext *pb, /* ignore WAVEFORMATEXTENSIBLE layout if different from channel count */ if (channels != par->ch_layout.nb_channels) { - av_channel_layout_uninit(&par->ch_layout); - par->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - par->ch_layout.nb_channels = channels; + ff_get_wav_ch_layout(&par->ch_layout, channels); } return 0; diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 0c6629b157..282e1ae017 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -222,9 +222,7 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t size, AVStream *st) channels += avio_r8(pb); avio_skip(pb, 3); } - av_channel_layout_uninit(&st->codecpar->ch_layout); - st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; - st->codecpar->ch_layout.nb_channels = channels; + ff_get_wav_ch_layout(&st->codecpar->ch_layout, channels); if (st->codecpar->ch_layout.nb_channels <= 0 || st->codecpar->sample_rate <= 0) return AVERROR_INVALIDDATA;