diff --git a/dom/media/AudioSampleFormat.h b/dom/media/AudioSampleFormat.h index ebfa68c4c5b9..997180c65bc4 100644 --- a/dom/media/AudioSampleFormat.h +++ b/dom/media/AudioSampleFormat.h @@ -80,6 +80,11 @@ AudioSampleToFloat(int16_t aValue) { return aValue/32768.0f; } +inline float +AudioSampleToFloat(int32_t aValue) +{ + return aValue/(float)(1U<<31); +} template T FloatToAudioSample(float aValue); diff --git a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp index a15bb13ef596..55cd4c000d2b 100644 --- a/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegAudioDecoder.cpp @@ -91,6 +91,25 @@ CopyAndPackAudio(AVFrame* aFrame, uint32_t aNumChannels, uint32_t aNumAFrames) *tmp++ = AudioSampleToFloat(data[channel][frame]); } } + } else if (aFrame->format == AV_SAMPLE_FMT_S32) { + // Audio data already packed. Need to convert from S16 to 32 bits Float + AudioDataValue* tmp = audio.get(); + int32_t* data = reinterpret_cast(aFrame->data)[0]; + for (uint32_t frame = 0; frame < aNumAFrames; frame++) { + for (uint32_t channel = 0; channel < aNumChannels; channel++) { + *tmp++ = AudioSampleToFloat(*data++); + } + } + } else if (aFrame->format == AV_SAMPLE_FMT_S32P) { + // Planar audio data. Convert it from S32 to 32 bits float + // and pack it into something we can understand. + AudioDataValue* tmp = audio.get(); + int32_t** data = reinterpret_cast(aFrame->data); + for (uint32_t frame = 0; frame < aNumAFrames; frame++) { + for (uint32_t channel = 0; channel < aNumChannels; channel++) { + *tmp++ = AudioSampleToFloat(data[channel][frame]); + } + } } return audio; @@ -176,9 +195,9 @@ FFmpegAudioDecoder::GetCodecId(const nsACString& aMimeType) { if (aMimeType.EqualsLiteral("audio/mpeg")) { return AV_CODEC_ID_MP3; - } - - if (aMimeType.EqualsLiteral("audio/mp4a-latm")) { + } else if (aMimeType.EqualsLiteral("audio/flac")) { + return AV_CODEC_ID_FLAC; + } else if (aMimeType.EqualsLiteral("audio/mp4a-latm")) { return AV_CODEC_ID_AAC; } diff --git a/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp index 55b071d5a3ae..390e92a053da 100644 --- a/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp +++ b/dom/media/platforms/ffmpeg/FFmpegDataDecoder.cpp @@ -90,7 +90,9 @@ FFmpegDataDecoder::InitDecoder() mCodecContext->sample_fmt != AV_SAMPLE_FMT_FLT && mCodecContext->sample_fmt != AV_SAMPLE_FMT_FLTP && mCodecContext->sample_fmt != AV_SAMPLE_FMT_S16 && - mCodecContext->sample_fmt != AV_SAMPLE_FMT_S16P) { + mCodecContext->sample_fmt != AV_SAMPLE_FMT_S16P && + mCodecContext->sample_fmt != AV_SAMPLE_FMT_S32 && + mCodecContext->sample_fmt != AV_SAMPLE_FMT_S32P) { NS_WARNING("FFmpeg audio decoder outputs unsupported audio format."); return NS_ERROR_FAILURE; } diff --git a/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h b/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h index 8e2da51679f8..969ac7e0be23 100644 --- a/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h +++ b/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h @@ -45,35 +45,24 @@ public: already_AddRefed CreateAudioDecoder(const CreateDecoderParams& aParams) override { -#ifdef USING_MOZFFVPX - return nullptr; -#else RefPtr decoder = new FFmpegAudioDecoder(mLib, aParams.mTaskQueue, aParams.mCallback, aParams.AudioConfig()); return decoder.forget(); -#endif } bool SupportsMimeType(const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const override { AVCodecID videoCodec = FFmpegVideoDecoder::GetCodecId(aMimeType); -#ifdef USING_MOZFFVPX - if (videoCodec == AV_CODEC_ID_NONE) { - return false; - } - return !!FFmpegDataDecoder::FindAVCodec(mLib, videoCodec); -#else AVCodecID audioCodec = FFmpegAudioDecoder::GetCodecId(aMimeType); if (audioCodec == AV_CODEC_ID_NONE && videoCodec == AV_CODEC_ID_NONE) { return false; } AVCodecID codec = audioCodec != AV_CODEC_ID_NONE ? audioCodec : videoCodec; return !!FFmpegDataDecoder::FindAVCodec(mLib, codec); -#endif } ConversionRequired diff --git a/dom/media/platforms/ffmpeg/FFmpegLibs.h b/dom/media/platforms/ffmpeg/FFmpegLibs.h index ec1fa57035c9..291ed77898ae 100644 --- a/dom/media/platforms/ffmpeg/FFmpegLibs.h +++ b/dom/media/platforms/ffmpeg/FFmpegLibs.h @@ -26,6 +26,7 @@ extern "C" { #define AV_CODEC_ID_MP3 CODEC_ID_MP3 #define AV_CODEC_ID_VP8 CODEC_ID_VP8 #define AV_CODEC_ID_NONE CODEC_ID_NONE +#define AV_CODEC_ID_FLAC CODEC_ID_FLAC typedef CodecID AVCodecID; #endif diff --git a/dom/media/platforms/ffmpeg/ffvpx/moz.build b/dom/media/platforms/ffmpeg/ffvpx/moz.build index f3de587ef556..aee58b5b0d29 100644 --- a/dom/media/platforms/ffmpeg/ffvpx/moz.build +++ b/dom/media/platforms/ffmpeg/ffvpx/moz.build @@ -10,6 +10,7 @@ EXPORTS += [ ] UNIFIED_SOURCES += [ + '../FFmpegAudioDecoder.cpp', '../FFmpegDataDecoder.cpp', '../FFmpegDecoderModule.cpp', '../FFmpegVideoDecoder.cpp',