diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp index 48c47d8930..bca32a3cbe 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp @@ -766,6 +766,10 @@ AVCodecDecoder::_ApplyEssentialAudioContainerPropertiesToContext() = static_cast(containerProperties.frame_size); ConvertRawAudioFormatToAVSampleFormat( containerProperties.output.format, fContext->sample_fmt); +#if LIBAVCODEC_VERSION_INT > ((52 << 16) | (114 << 8)) + ConvertRawAudioFormatToAVSampleFormat( + containerProperties.output.format, fContext->request_sample_fmt); +#endif fContext->sample_rate = static_cast(containerProperties.output.frame_rate); fContext->channels @@ -904,8 +908,18 @@ AVCodecDecoder::_MoveAudioFramesToRawDecodedAudioAndUpdateStartTimes() debugger("fDecodedDataBufferSize not multiple of frame size!"); size_t remainingSize = frames * fOutputFrameSize; + +#if 0 + // Some decoders do not support format conversion on themselves, or use + // "planar" audio (each channel separated instead of interleaved samples). + // If this is a problem we will need to use swresample to convert the data + // here, instead of directly copying it. + swr_convert(fResampleContext, fRawDecodedAudio->data, + fDecodedDataBuffer->data + fDecodedDataBufferOffset, frames); +#else memcpy(fRawDecodedAudio->data[0], fDecodedDataBuffer->data[0] + fDecodedDataBufferOffset, remainingSize); +#endif bool firstAudioFramesCopiedToRawDecodedAudio = fRawDecodedAudio->data[0] != fDecodedData; diff --git a/src/add-ons/media/plugins/ffmpeg/Utilities.h b/src/add-ons/media/plugins/ffmpeg/Utilities.h index 4702459927..209bd1eb17 100644 --- a/src/add-ons/media/plugins/ffmpeg/Utilities.h +++ b/src/add-ons/media/plugins/ffmpeg/Utilities.h @@ -235,7 +235,7 @@ inline void ConvertRawAudioFormatToAVSampleFormat(uint32 rawAudioFormatIn, AVSampleFormat& sampleFormatOut) { - switch(rawAudioFormatIn) { + switch (rawAudioFormatIn) { case media_raw_audio_format::B_AUDIO_FLOAT: sampleFormatOut = AV_SAMPLE_FMT_FLT; return; @@ -281,24 +281,29 @@ inline void ConvertAVSampleFormatToRawAudioFormat(AVSampleFormat sampleFormatIn, uint32& rawAudioFormatOut) { - switch(sampleFormatIn) { + switch (sampleFormatIn) { case AV_SAMPLE_FMT_FLT: + case AV_SAMPLE_FMT_FLTP: rawAudioFormatOut = media_raw_audio_format::B_AUDIO_FLOAT; return; case AV_SAMPLE_FMT_DBL: + case AV_SAMPLE_FMT_DBLP: rawAudioFormatOut = media_raw_audio_format::B_AUDIO_DOUBLE; return; case AV_SAMPLE_FMT_S32: + case AV_SAMPLE_FMT_S32P: rawAudioFormatOut = media_raw_audio_format::B_AUDIO_INT; return; case AV_SAMPLE_FMT_S16: + case AV_SAMPLE_FMT_S16P: rawAudioFormatOut = media_raw_audio_format::B_AUDIO_SHORT; return; case AV_SAMPLE_FMT_U8: + case AV_SAMPLE_FMT_U8P: rawAudioFormatOut = media_raw_audio_format::B_AUDIO_UCHAR; return; @@ -311,4 +316,5 @@ ConvertAVSampleFormatToRawAudioFormat(AVSampleFormat sampleFormatIn, rawAudioFormatOut = kBAudioNone; } + #endif // UTILITIES_H