From 4f07ca94f1aa5d3701dbbf9d320c112f2d773224 Mon Sep 17 00:00:00 2001 From: Fumihiko Kobayashi Date: Wed, 1 Jan 2025 13:19:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?FFmpeg=207.0=E3=81=A7=E3=81=AEAPI=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=81=AB=E4=BC=B4=E3=81=86=E3=82=B3=E3=83=B3=E3=83=91?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Linux/Siv3D/AudioCodec/CAudioCodec.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp index eb3ba3278..6fd9f00a8 100644 --- a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp +++ b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp @@ -186,15 +186,18 @@ namespace s3d } // initialize swr context - int64_t out_channel_layout = AV_CH_LAYOUT_STEREO; + AVChannelLayout out_channel_layout; + av_channel_layout_subset(&out_channel_layout, AV_CH_LAYOUT_STEREO); int out_nb_samples = m_codec_context->frame_size; AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_FLT; m_out_sample_rate = m_codec_context->sample_rate; - m_swr_context = swr_alloc_set_opts(m_swr_context, - out_channel_layout, out_sample_fmt, m_out_sample_rate, - av_get_default_channel_layout(m_codec_context->channels), + AVChannelLayout default_channel_layout; + av_channel_layout_default(&default_channel_layout, m_codec_context->ch_layout.nb_channels); + int allocation_result = swr_alloc_set_opts2(&m_swr_context, + &out_channel_layout, out_sample_fmt, m_out_sample_rate, + &default_channel_layout, m_codec_context->sample_fmt, m_codec_context->sample_rate, 0, nullptr); - if (m_swr_context == nullptr) + if (allocation_result < 0) { LOG_TRACE(U"AACDecoder: swr_alloc() failed ({})"_fmt(m_path)); return false; @@ -207,7 +210,7 @@ namespace s3d } // allocate output buffer - int out_nb_channels = av_get_channel_layout_nb_channels(out_channel_layout); + int out_nb_channels = out_channel_layout.nb_channels; int buf_size = av_samples_get_buffer_size(nullptr, out_nb_channels, out_nb_samples, out_sample_fmt, 0); m_out_buf = (uint8_t*)av_malloc(buf_size); From f4409ce70fe743ecd788a0e5b47c1bbced913715 Mon Sep 17 00:00:00 2001 From: Fumihiko Kobayashi Date: Wed, 1 Jan 2025 23:36:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?FFmpeg=207.0=E3=82=88=E3=82=8A=E3=82=82?= =?UTF-8?q?=E5=89=8D=E3=81=AE=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=A7=E3=81=AF=E4=BB=8A=E3=81=BE=E3=81=A7=E3=81=A8=E5=90=8C?= =?UTF-8?q?=E3=81=98=E3=82=B3=E3=83=BC=E3=83=89=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Linux/Siv3D/AudioCodec/CAudioCodec.cpp | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp index 6fd9f00a8..741c72414 100644 --- a/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp +++ b/Siv3D/src/Siv3D-Platform/Linux/Siv3D/AudioCodec/CAudioCodec.cpp @@ -186,11 +186,16 @@ namespace s3d } // initialize swr context +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 3, 100) AVChannelLayout out_channel_layout; av_channel_layout_subset(&out_channel_layout, AV_CH_LAYOUT_STEREO); +#else + int64_t out_channel_layout = AV_CH_LAYOUT_STEREO; +#endif int out_nb_samples = m_codec_context->frame_size; AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_FLT; m_out_sample_rate = m_codec_context->sample_rate; +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 3, 100) AVChannelLayout default_channel_layout; av_channel_layout_default(&default_channel_layout, m_codec_context->ch_layout.nb_channels); int allocation_result = swr_alloc_set_opts2(&m_swr_context, @@ -202,6 +207,17 @@ namespace s3d LOG_TRACE(U"AACDecoder: swr_alloc() failed ({})"_fmt(m_path)); return false; } +#else + m_swr_context = swr_alloc_set_opts(m_swr_context, + out_channel_layout, out_sample_fmt, m_out_sample_rate, + av_get_default_channel_layout(m_codec_context->channels), + m_codec_context->sample_fmt, m_codec_context->sample_rate, 0, nullptr); + if (m_swr_context == nullptr) + { + LOG_TRACE(U"AACDecoder: swr_alloc() failed ({})"_fmt(m_path)); + return false; + } +#endif [[maybe_unused]] int averr = swr_init(m_swr_context); if (swr_is_initialized(m_swr_context) == 0) { @@ -210,7 +226,11 @@ namespace s3d } // allocate output buffer +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 3, 100) int out_nb_channels = out_channel_layout.nb_channels; +#else + int out_nb_channels = av_get_channel_layout_nb_channels(out_channel_layout); +#endif int buf_size = av_samples_get_buffer_size(nullptr, out_nb_channels, out_nb_samples, out_sample_fmt, 0); m_out_buf = (uint8_t*)av_malloc(buf_size);