Skip to content

Commit

Permalink
libav: use undeprecated features
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jan 19, 2025
1 parent ff5f720 commit 95b8009
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
27 changes: 22 additions & 5 deletions src/plugins/score-plugin-gfx/Gfx/Libav/LibavOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,19 @@ void LibavOutputSettingsWidget::on_vcodecChange(int codec_index)
return;

auto codec = mux.vcodecs[codec_index];
if(codec->codec->pix_fmts == nullptr)

const AVPixelFormat* supported_pixfmts{};
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 100)
avcodec_get_supported_config(
nullptr, codec->codec, AV_CODEC_CONFIG_PIX_FORMAT, 0,
(const void**)&supported_pixfmts, nullptr);
#else
supported_pixfmts = codec->codec->pix_fmts;
#endif
if(!supported_pixfmts)
return;

for(auto fmt = codec->codec->pix_fmts; *fmt != AVPixelFormat(-1); ++fmt)
for(auto fmt = supported_pixfmts; *fmt != AV_PIX_FMT_NONE; ++fmt)
{
if(auto desc = av_pix_fmt_desc_get(*fmt))
m_pixfmt->addItem(desc->name);
Expand All @@ -526,10 +535,18 @@ void LibavOutputSettingsWidget::on_acodecChange(int codec_index)
return;

auto codec = mux.acodecs[codec_index];
if(codec->codec->sample_fmts == nullptr)
AVSampleFormat* supported_sample_fmts{};

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 100)
avcodec_get_supported_config(
nullptr, codec->codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0,
(const void**)&supported_sample_fmts, nullptr);
#else
supported_sample_fmts = codec->codec->sample_fmts;
#endif
if(!supported_sample_fmts)
return;

for(auto fmt = codec->codec->sample_fmts; *fmt != AVSampleFormat(-1); ++fmt)
for(auto fmt = supported_sample_fmts; *fmt != AV_SAMPLE_FMT_NONE; ++fmt)
{
if(auto desc = av_get_sample_fmt_name(*fmt))
m_smpfmt->addItem(desc);
Expand Down
31 changes: 22 additions & 9 deletions src/plugins/score-plugin-gfx/Gfx/Libav/LibavOutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,31 @@ struct OutputStream
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 24, 100)
c->sample_fmt = av_get_sample_fmt(set.audio_converted_smpfmt.toStdString().c_str());

if(codec->supported_samplerates)
{
c->sample_rate = codec->supported_samplerates[0];
for(int i = 0; codec->supported_samplerates[i]; i++)
const int* supported_samplerates{};
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(61, 19, 100)
avcodec_get_supported_config(
c, codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0, (const void**)&supported_samplerates,
nullptr);
#else
supported_samplerates = codec->supported_samplerates;
#endif
if(supported_samplerates)
{
if(codec->supported_samplerates[i] == set.audio_sample_rate)
c->sample_rate = set.audio_sample_rate;
c->sample_rate = supported_samplerates[0];
for(int i = 0; supported_samplerates[i]; i++)
{
if(supported_samplerates[i] == set.audio_sample_rate)
{
c->sample_rate = set.audio_sample_rate;
break;
}
}
}
else
{
c->sample_rate = set.audio_sample_rate;
}
}
else
{
c->sample_rate = set.audio_sample_rate;
}

c->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
Expand Down

0 comments on commit 95b8009

Please sign in to comment.