Skip to content

Commit

Permalink
fix: Support ffmpeg AVChannelLayout API
Browse files Browse the repository at this point in the history
The old channel API was deprecated in ffmpeg 5.1 and removed in 7.0.
Support for the old API is maintained for compabiility with ffmpeg
versions < 5.1.
  • Loading branch information
oscarwcl committed Jun 27, 2024
1 parent e4e9ed2 commit 55f7aad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/modules/newtek/producer/newtek_ndi_producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ struct newtek_ndi_producer : public core::frame_producer
if (audio_frame.p_data != nullptr) {
audio_frame_32s.reference_level = 0;
ndi_lib_->util_audio_to_interleaved_32s_v2(&audio_frame, &audio_frame_32s);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100)
av_channel_layout_default(&a_frame->ch_layout, audio_frame_32s.no_channels);
#else
a_frame->channels = audio_frame_32s.no_channels;
#endif
a_frame->sample_rate = audio_frame_32s.sample_rate;
a_frame->nb_samples = audio_frame_32s.no_samples;
a_frame->data[0] = reinterpret_cast<uint8_t*>(audio_frame_32s.p_data);
Expand Down
10 changes: 9 additions & 1 deletion src/modules/oal/consumer/oal_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,12 @@ struct oal_consumer : public core::frame_consumer
auto dst = std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame* ptr) { av_frame_free(&ptr); });
dst->format = AV_SAMPLE_FMT_S16;
dst->sample_rate = format_desc_.audio_sample_rate;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100)
av_channel_layout_default(&dst->ch_layout, 2);
#else
dst->channels = 2;
dst->channel_layout = av_get_default_channel_layout(dst->channels);
#endif
dst->nb_samples = duration_;
if (av_frame_get_buffer(dst.get(), 32) < 0) {
// TODO FF error
Expand All @@ -277,9 +281,13 @@ struct oal_consumer : public core::frame_consumer
auto src = std::shared_ptr<AVFrame>(av_frame_alloc(), [](AVFrame* ptr) { av_frame_free(&ptr); });
src->format = AV_SAMPLE_FMT_S32;
src->sample_rate = format_desc_.audio_sample_rate;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100)
av_channel_layout_default(&src->ch_layout, format_desc_.audio_channels);
#else
src->channels = format_desc_.audio_channels;
src->channel_layout = av_get_default_channel_layout(src->channels);
src->nb_samples = static_cast<int>(frame.audio_data().size() / src->channels);
#endif
src->nb_samples = static_cast<int>(frame.audio_data().size() / format_desc_.audio_channels);
src->extended_data[0] = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(frame.audio_data().data()));
src->linesize[0] = static_cast<int>(frame.audio_data().size() * sizeof(int32_t));

Expand Down

0 comments on commit 55f7aad

Please sign in to comment.