From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8908540DB9 for ; Fri, 31 Dec 2021 05:23:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C068B68AF82; Fri, 31 Dec 2021 07:23:41 +0200 (EET) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B98C66801EB for ; Fri, 31 Dec 2021 07:23:35 +0200 (EET) Received: by mail-pl1-f178.google.com with SMTP id z3so19584246plg.8 for ; Thu, 30 Dec 2021 21:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hrJb8byynpCl3jRKD9Lb9HXpSXijIY9zdEK2RtotpzY=; b=bV+jXqbf1XJQ79vXGnhAz29uz3oP4c6UXlV073xqNk6ZU19sLqGD1WzSCQyBXmSGWs LhQUYsHA492iqD0VLVJHkVGJ1OW0s/T/oaR6wB/HVCgVn7zXg6nxO3QUifKTWmAySUf3 WBcmsFlgj7bfr1ggzbk+5Tsd94L6bXwv6a7U//m05azS2AT79YLfwfMqu2yZ+GiaPfjp SruU6VGCdMSEPwdajOmWzxtI5ing/r8Nb8kJLaBB6cwhtkDSDOxY9g1yIgbZ5OGUtn87 JuE1elRQTxTfd1tEkQmtrhr5c95iphmy9SPF9PiPnhkUurd0WcRDh7jq03Jbssctq88U nVUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hrJb8byynpCl3jRKD9Lb9HXpSXijIY9zdEK2RtotpzY=; b=3A0iRoXLzJjlowTbS0IXlZV8iXhDL26bE7MxyKoB0tk3r8n/EFjvEpR1RcVGauj5lg /BrR092ivqORgDhEIJUJLPEdtkOug4K1CfdOWxnSe3xFnP33qQ9RgegaNxgnT3l11S9/ PHl9cGz0KZmAkorI4MWblTYESp//9RqTpvhOQ/xYgEkRnfPrKbf8s+XRURej3+F9pne/ SfT9Gmt/B8DqIwcsUbawTSgzVfdB9znIYVR9iikmLXBvD456jvggQmAVargCjhjjHW/A oEMZ8d8PfaOxhvByEJaLDCpZWOaRUndrF6bNS0+HThElrt6ipapy73d4psd9db4CP5KI 6EnA== X-Gm-Message-State: AOAM533Xe0HTzWjridVj0jmIQKB1Oc9se/LGWCwuvrSIzof4skm3XDrD G4ftHQaFKYU0wPuHDhgLvs0va6D4nuUcRg== X-Google-Smtp-Source: ABdhPJzZpczQkdSbUy2TQMyP8iAVpgctG75pvwI6+Cyn1GIN4ZAN+s2FWDnIWVi0i+PCxNNSXD1AmQ== X-Received: by 2002:a17:902:7c85:b0:148:ddc3:7d2f with SMTP id y5-20020a1709027c8500b00148ddc37d2fmr33787177pll.80.1640928213712; Thu, 30 Dec 2021 21:23:33 -0800 (PST) Received: from localhost.localdomain ([2600:6c51:4c3f:8ead:3103:3039:5ba3:a82f]) by smtp.gmail.com with ESMTPSA id t10sm30569387pfg.105.2021.12.30.21.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Dec 2021 21:23:33 -0800 (PST) From: Christopher Snowhill To: ffmpeg-devel@ffmpeg.org Date: Thu, 30 Dec 2021 21:23:30 -0800 Message-Id: <20211231052330.42471-1-kode54@gmail.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 X-Unsent: 1 Subject: [FFmpeg-devel] [PATCH] avcodec/audiotoolboxdec: Decode appropriate formats to float 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: Christopher Snowhill Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: These candidate formats are likely already decoded in floating point internally anyway, so request float output so that it's also possible to clip or peak level as necessary. Signed-off-by: Christopher Snowhill --- libavcodec/audiotoolboxdec.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c index 4abcb63a03..427f143468 100644 --- a/libavcodec/audiotoolboxdec.c +++ b/libavcodec/audiotoolboxdec.c @@ -297,6 +297,25 @@ static int ffat_set_extradata(AVCodecContext *avctx) return 0; } +static bool ffat_get_format_is_float(enum AVCodecID codec) +{ + switch (codec) { + case AV_CODEC_ID_AAC: + case AV_CODEC_ID_AC3: + case AV_CODEC_ID_AMR_NB: + case AV_CODEC_ID_EAC3: + case AV_CODEC_ID_ILBC: + case AV_CODEC_ID_MP1: + case AV_CODEC_ID_MP2: + case AV_CODEC_ID_MP3: + case AV_CODEC_ID_QDMC: + case AV_CODEC_ID_QDM2: + return true; + default: + return false; + } +} + static av_cold int ffat_create_decoder(AVCodecContext *avctx, const AVPacket *pkt) { @@ -304,8 +323,12 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx, OSStatus status; int i; - enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ? - AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16; + bool sample_fmt_is_float = ffat_get_format_is_float(avctx->codec_id); + + enum AVSampleFormat sample_fmt = sample_fmt_is_float ? + AV_SAMPLE_FMT_FLT : + ((avctx->bits_per_raw_sample == 32) ? + AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16); AudioStreamBasicDescription in_format = { .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile), @@ -313,7 +336,10 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx, }; AudioStreamBasicDescription out_format = { .mFormatID = kAudioFormatLinearPCM, - .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked, + .mFormatFlags = (sample_fmt_is_float ? + kAudioFormatFlagIsFloat : + kAudioFormatFlagIsSignedInteger) | + kAudioFormatFlagIsPacked, .mFramesPerPacket = 1, .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8, }; @@ -471,7 +497,9 @@ static OSStatus ffat_decode_callback(AudioConverterRef converter, UInt32 *nb_pac static void ffat_copy_samples(AVCodecContext *avctx, AVFrame *frame) { ATDecodeContext *at = avctx->priv_data; - if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) { + if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { + COPY_SAMPLES(float); + } else if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) { COPY_SAMPLES(int32_t); } else { COPY_SAMPLES(int16_t); -- 2.32.0 (Apple Git-132) _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".