From fa9ebb2a07c2313ea5e7fd8c1b8403aa80705a84 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Sun, 6 Nov 2022 21:22:04 +0100
Subject: [PATCH 1/2] lavc/audiotoolboxdec: Reorder decoder initialization.

Simplifies the following patch.
---
 libavcodec/audiotoolboxdec.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c
index 82babe3d31..f36294f84c 100644
--- a/libavcodec/audiotoolboxdec.c
+++ b/libavcodec/audiotoolboxdec.c
@@ -306,22 +306,11 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx,
     ATDecodeContext *at = avctx->priv_data;
     OSStatus status;
     int i;
-
-    enum AVSampleFormat sample_fmt = (avctx->bits_per_raw_sample == 32) ?
-                                     AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
-
+    enum AVSampleFormat sample_fmt;
     AudioStreamBasicDescription in_format = {
         .mFormatID = ffat_get_format_id(avctx->codec_id, avctx->profile),
         .mBytesPerPacket = (avctx->codec_id == AV_CODEC_ID_ILBC) ? avctx->block_align : 0,
     };
-    AudioStreamBasicDescription out_format = {
-        .mFormatID = kAudioFormatLinearPCM,
-        .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
-        .mFramesPerPacket = 1,
-        .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
-    };
-
-    avctx->sample_fmt = sample_fmt;
 
     if (ffat_usable_extradata(avctx)) {
         UInt32 format_size = sizeof(in_format);
@@ -370,6 +359,17 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx,
         in_format.mChannelsPerFrame = avctx->ch_layout.nb_channels ? avctx->ch_layout.nb_channels : 1;
     }
 
+        sample_fmt = avctx->bits_per_raw_sample == 32 ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S16;
+
+    AudioStreamBasicDescription out_format = {
+        .mFormatID = kAudioFormatLinearPCM,
+        .mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked,
+        .mFramesPerPacket = 1,
+        .mBitsPerChannel = av_get_bytes_per_sample(sample_fmt) * 8,
+    };
+
+    avctx->sample_fmt = sample_fmt;
+
     avctx->sample_rate = out_format.mSampleRate = in_format.mSampleRate;
     av_channel_layout_uninit(&avctx->ch_layout);
     avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-- 
2.37.0 (Apple Git-136)

