From c9d1f8ccb0da91954b3362a0652a8770259ade73 Mon Sep 17 00:00:00 2001 From: Alex Murkoff <413x1nkp@gmail.com> Date: Sat, 8 Aug 2026 15:24:42 +0700 Subject: [PATCH] fix: update deprecated api for ffmpeg 9.0 --- src/hlsoutputstream.cc | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/hlsoutputstream.cc b/src/hlsoutputstream.cc index f7021d7..8e4fad0 100644 --- a/src/hlsoutputstream.cc +++ b/src/hlsoutputstream.cc @@ -96,15 +96,28 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id) if ((*codec)->type != AVMEDIA_TYPE_AUDIO) return Error ("codec type must be audio"); - m_enc->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP; + const int *supported_samplerates = NULL; + const AVSampleFormat *sample_fmts = NULL; + const AVChannelLayout *ch_layouts = NULL; +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 13, 100) + supported_samplerates = (*codec)->supported_samplerates; + sample_fmts = (*codec)->sample_fmts; + ch_layouts = (*codec)->ch_layouts; +#else + avcodec_get_supported_config(m_enc, *codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0, (const void**) &supported_samplerates, NULL); + avcodec_get_supported_config(m_enc, *codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void**) &sample_fmts, NULL); + avcodec_get_supported_config(m_enc, *codec, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, (const void**) &ch_layouts, NULL); +#endif + + m_enc->sample_fmt = sample_fmts ? sample_fmts[0] : AV_SAMPLE_FMT_FLTP; m_enc->bit_rate = m_bit_rate; m_enc->sample_rate = m_sample_rate; - if ((*codec)->supported_samplerates) + if (supported_samplerates) { bool match = false; - for (int i = 0; (*codec)->supported_samplerates[i]; i++) + for (int i = 0; supported_samplerates[i]; i++) { - if ((*codec)->supported_samplerates[i] == m_sample_rate) + if (supported_samplerates[i] == m_sample_rate) { m_enc->sample_rate = m_sample_rate; match = true; @@ -120,15 +133,15 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id) return Error (string_printf ("bad channel layout '%s'", m_channel_layout.c_str())); av_channel_layout_uninit (&m_enc->ch_layout); av_channel_layout_copy (&m_enc->ch_layout, &channel_layout); - if ((*codec)->ch_layouts) + if (ch_layouts) { av_channel_layout_uninit (&m_enc->ch_layout); - av_channel_layout_copy (&m_enc->ch_layout, &(*codec)->ch_layouts[0]); - for (int i = 0; (*codec)->ch_layouts[i].nb_channels; i++) + av_channel_layout_copy (&m_enc->ch_layout, &ch_layouts[0]); + for (int i = 0; ch_layouts[i].nb_channels; i++) { - if (av_channel_layout_compare (&(*codec)->ch_layouts[i], &channel_layout) == 0) { + if (av_channel_layout_compare (&ch_layouts[i], &channel_layout) == 0) { av_channel_layout_uninit (&m_enc->ch_layout); - av_channel_layout_copy (&m_enc->ch_layout, &(*codec)->ch_layouts[i]); + av_channel_layout_copy (&m_enc->ch_layout, &ch_layouts[i]); } } }