Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioDecoder: support ffmpeg 7.0 #3380

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions gazebo/common/AudioDecoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ bool AudioDecoder::Decode(uint8_t **_outBuffer, unsigned int *_outBufferSize)
return false;
}

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 24, 100)
int numChannels = this->codecCtx->ch_layout.nb_channels;
#else
int numChannels = this->codecCtx->channels;
#endif

// Total size of the data. Some padding can be added to
// decodedFrame->data[0], which is why we can't use
// decodedFrame->linesize[0].
int size = decodedFrame->nb_samples *
av_get_bytes_per_sample(this->codecCtx->sample_fmt) *
this->codecCtx->channels;
numChannels;

// Resize the audio buffer as necessary
if (*_outBufferSize + size > maxBufferSize)
Expand Down Expand Up @@ -331,22 +337,6 @@ bool AudioDecoder::SetFile(const std::string &_filename)
return false;
}

// This copy should be done by avcodec_parameters_to_context, but at least on
// conda-forge with 5.0.0 h594f047_1 this is not happening for some reason.
// As temporary workaround, we copy directly the data structures, taking the code from
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/codec_par.c#L120
AVCodecParameters* par = this->formatCtx->streams[this->audioStream]->codecpar;
this->codecCtx->sample_fmt = static_cast<AVSampleFormat>(par->format);
this->codecCtx->channel_layout = par->channel_layout;
this->codecCtx->channels = par->channels;
this->codecCtx->sample_rate = par->sample_rate;
this->codecCtx->block_align = par->block_align;
this->codecCtx->frame_size = par->frame_size;
this->codecCtx->delay =
this->codecCtx->initial_padding = par->initial_padding;
this->codecCtx->trailing_padding = par->trailing_padding;
this->codecCtx->seek_preroll = par->seek_preroll;

// It would be better to just define codec as const AVCodec *,
// but that is not done to avoid ABI problem. Anyhow, as codec
// it is a private attribute there should be no problem
Expand Down
Loading