"git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "5247f7b6a019290bd2a838dc0baa8acec5fe484a"
Unverified Commit 375cfdf5 authored by Robert-André Mauchin's avatar Robert-André Mauchin Committed by GitHub
Browse files

Add compatibility with FFMPEG 7.0 (#8408)


Co-authored-by: default avatarNicolas Hug <nh.nicolas.hug@gmail.com>
Co-authored-by: default avatarNicolas Hug <contact@nicolas-hug.com>
parent a839642c
...@@ -48,6 +48,23 @@ bool AudioSampler::init(const SamplerParameters& params) { ...@@ -48,6 +48,23 @@ bool AudioSampler::init(const SamplerParameters& params) {
return false; return false;
} }
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
SwrContext* swrContext_ = NULL;
AVChannelLayout channel_out;
AVChannelLayout channel_in;
av_channel_layout_default(&channel_out, params.out.audio.channels);
av_channel_layout_default(&channel_in, params.in.audio.channels);
int ret = swr_alloc_set_opts2(
&swrContext_,
&channel_out,
(AVSampleFormat)params.out.audio.format,
params.out.audio.samples,
&channel_in,
(AVSampleFormat)params.in.audio.format,
params.in.audio.samples,
0,
logCtx_);
#else
swrContext_ = swr_alloc_set_opts( swrContext_ = swr_alloc_set_opts(
nullptr, nullptr,
av_get_default_channel_layout(params.out.audio.channels), av_get_default_channel_layout(params.out.audio.channels),
...@@ -58,6 +75,7 @@ bool AudioSampler::init(const SamplerParameters& params) { ...@@ -58,6 +75,7 @@ bool AudioSampler::init(const SamplerParameters& params) {
params.in.audio.samples, params.in.audio.samples,
0, 0,
logCtx_); logCtx_);
#endif
if (swrContext_ == nullptr) { if (swrContext_ == nullptr) {
LOG(ERROR) << "Cannot allocate SwrContext"; LOG(ERROR) << "Cannot allocate SwrContext";
return false; return false;
......
...@@ -6,26 +6,36 @@ ...@@ -6,26 +6,36 @@
namespace ffmpeg { namespace ffmpeg {
namespace { namespace {
static int get_nb_channels(const AVFrame* frame, const AVCodecContext* codec) {
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
return frame ? frame->ch_layout.nb_channels : codec->ch_layout.nb_channels;
#else
return frame ? frame->channels : codec->channels;
#endif
}
bool operator==(const AudioFormat& x, const AVFrame& y) { bool operator==(const AudioFormat& x, const AVFrame& y) {
return x.samples == static_cast<size_t>(y.sample_rate) && return x.samples == static_cast<size_t>(y.sample_rate) &&
x.channels == static_cast<size_t>(y.channels) && x.format == y.format; x.channels == static_cast<size_t>(get_nb_channels(&y, nullptr)) &&
x.format == y.format;
} }
bool operator==(const AudioFormat& x, const AVCodecContext& y) { bool operator==(const AudioFormat& x, const AVCodecContext& y) {
return x.samples == static_cast<size_t>(y.sample_rate) && return x.samples == static_cast<size_t>(y.sample_rate) &&
x.channels == static_cast<size_t>(y.channels) && x.format == y.sample_fmt; x.channels == static_cast<size_t>(get_nb_channels(nullptr, &y)) &&
x.format == y.sample_fmt;
} }
AudioFormat& toAudioFormat(AudioFormat& x, const AVFrame& y) { AudioFormat& toAudioFormat(AudioFormat& x, const AVFrame& y) {
x.samples = y.sample_rate; x.samples = y.sample_rate;
x.channels = y.channels; x.channels = get_nb_channels(&y, nullptr);
x.format = y.format; x.format = y.format;
return x; return x;
} }
AudioFormat& toAudioFormat(AudioFormat& x, const AVCodecContext& y) { AudioFormat& toAudioFormat(AudioFormat& x, const AVCodecContext& y) {
x.samples = y.sample_rate; x.samples = y.sample_rate;
x.channels = y.channels; x.channels = get_nb_channels(nullptr, &y);
x.format = y.sample_fmt; x.format = y.sample_fmt;
return x; return x;
} }
...@@ -54,9 +64,15 @@ int AudioStream::initFormat() { ...@@ -54,9 +64,15 @@ int AudioStream::initFormat() {
if (format_.format.audio.samples == 0) { if (format_.format.audio.samples == 0) {
format_.format.audio.samples = codecCtx_->sample_rate; format_.format.audio.samples = codecCtx_->sample_rate;
} }
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
if (format_.format.audio.channels == 0) {
format_.format.audio.channels = codecCtx_->ch_layout.nb_channels;
}
#else
if (format_.format.audio.channels == 0) { if (format_.format.audio.channels == 0) {
format_.format.audio.channels = codecCtx_->channels; format_.format.audio.channels = codecCtx_->channels;
} }
#endif
if (format_.format.audio.format == AV_SAMPLE_FMT_NONE) { if (format_.format.audio.format == AV_SAMPLE_FMT_NONE) {
format_.format.audio.format = codecCtx_->sample_fmt; format_.format.audio.format = codecCtx_->sample_fmt;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment