Skip to content

Commit

Permalink
Fix Building Against Newer Version Of FFmpeg
Browse files Browse the repository at this point in the history
When building against a newer version:
* Use `ch_layout.order` & `ch_layout.nb_channels` instead of `channel_layout` & `channels`.
*  Workaround `read_probe` no longer being exposed by calling `av_probe_input_format`
  • Loading branch information
CuriousTommy committed Aug 18, 2024
1 parent bc55338 commit 31b9e86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/CoreAudio/AFAVFormatComponent/AudioFileFormatGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ void AudioFileFormatGeneric::GetFileTypeName(CFStringRef *outName)

UncertainResult AudioFileFormatGeneric::FileDataIsThisFormat(UInt32 inDataByteSize, const void* inData)
{
const AVInputFormat* fmt = av_find_input_format(m_avformatShortName);
if (!fmt)
return false;

std::vector<uint8_t> buf;
AVProbeData probeData;

Expand All @@ -96,7 +92,15 @@ UncertainResult AudioFileFormatGeneric::FileDataIsThisFormat(UInt32 inDataByteSi
probeData.buf = buf.data();
probeData.buf_size = inDataByteSize;

#warning "TODO: Remove old `read_probe` call once we no longer support older distros"
#if LIBAVCODEC_VERSION_MAJOR >= 61
return av_probe_input_format(&probeData, false) != nullptr ? kTrue : kFalse;
#else
const AVInputFormat* fmt = av_find_input_format(m_avformatShortName);
if (!fmt)
return false;
return fmt->read_probe(&probeData) ? kTrue : kFalse;
#endif
}

AudioFileObject* AudioFileFormatGeneric::New()
Expand Down
7 changes: 5 additions & 2 deletions src/CoreAudio/AudioToolbox/AudioConverterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,13 @@ void AudioConverter::initEncoder()
m_encoder->bit_rate = m_outBitRate;
#warning "TODO: Remove deprecated 'channels' once we no longer support older distros"
#if LIBAVCODEC_VERSION_MAJOR >= 61
m_encoder->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
m_encoder->ch_layout.nb_channels = m_destinationFormat.mChannelsPerFrame;
#else
m_encoder->channels = m_destinationFormat.mChannelsPerFrame;
m_encoder->channel_layout = CAChannelCountToLayout(m_destinationFormat.mChannelsPerFrame);
#endif
m_encoder->sample_rate = m_destinationFormat.mSampleRate;
m_encoder->channel_layout = CAChannelCountToLayout(m_destinationFormat.mChannelsPerFrame);
m_encoder->sample_fmt = CACodecSampleFormat(&m_destinationFormat);

#ifdef DEBUG_AUDIOCONVERTER
Expand Down Expand Up @@ -175,12 +176,14 @@ void AudioConverter::allocateBuffers()

m_audioFrame->nb_samples = ENCODER_FRAME_SAMPLES;
m_audioFrame->format = m_encoder->sample_fmt;
m_audioFrame->channel_layout = m_encoder->channel_layout;

#warning "TODO: Remove deprecated 'channels' once we no longer support older distros"
#if LIBAVCODEC_VERSION_MAJOR >= 61
m_audioFrame->ch_layout.order = m_encoder->ch_layout.order;
m_audioFrame->ch_layout.nb_channels = m_encoder->ch_layout.nb_channels;
int audioSampleBuffer_size = av_samples_get_buffer_size(nullptr, m_encoder->ch_layout.nb_channels, m_audioFrame->nb_samples, m_encoder->sample_fmt, 0);
#else
m_audioFrame->channel_layout = m_encoder->channel_layout;
int audioSampleBuffer_size = av_samples_get_buffer_size(nullptr, m_encoder->channels, m_audioFrame->nb_samples, m_encoder->sample_fmt, 0);
#endif
void* audioSampleBuffer = (uint8_t*) av_malloc(audioSampleBuffer_size);
Expand Down

0 comments on commit 31b9e86

Please sign in to comment.