Bug 1270016: P2. Make the FFVPX PDM work with FLAC. r=kentuckyfriedtakahe

MozReview-Commit-ID: BmwtZF3NSEI

--HG--
extra : rebase_source : 4b7bc5d49bf129f8442314d3d43110577c0c7484
This commit is contained in:
Jean-Yves Avenard 2016-08-02 22:54:26 +10:00
Родитель 3aef074dd4
Коммит cc1aaa08e8
6 изменённых файлов: 32 добавлений и 15 удалений

Просмотреть файл

@ -80,6 +80,11 @@ AudioSampleToFloat(int16_t aValue)
{
return aValue/32768.0f;
}
inline float
AudioSampleToFloat(int32_t aValue)
{
return aValue/(float)(1U<<31);
}
template <typename T> T FloatToAudioSample(float aValue);

Просмотреть файл

@ -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<int32_t**>(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<int32_t**>(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<LIBAV_VER>::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;
}

Просмотреть файл

@ -90,7 +90,9 @@ FFmpegDataDecoder<LIBAV_VER>::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;
}

Просмотреть файл

@ -45,35 +45,24 @@ public:
already_AddRefed<MediaDataDecoder>
CreateAudioDecoder(const CreateDecoderParams& aParams) override
{
#ifdef USING_MOZFFVPX
return nullptr;
#else
RefPtr<MediaDataDecoder> decoder =
new FFmpegAudioDecoder<V>(mLib,
aParams.mTaskQueue,
aParams.mCallback,
aParams.AudioConfig());
return decoder.forget();
#endif
}
bool SupportsMimeType(const nsACString& aMimeType,
DecoderDoctorDiagnostics* aDiagnostics) const override
{
AVCodecID videoCodec = FFmpegVideoDecoder<V>::GetCodecId(aMimeType);
#ifdef USING_MOZFFVPX
if (videoCodec == AV_CODEC_ID_NONE) {
return false;
}
return !!FFmpegDataDecoder<V>::FindAVCodec(mLib, videoCodec);
#else
AVCodecID audioCodec = FFmpegAudioDecoder<V>::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<V>::FindAVCodec(mLib, codec);
#endif
}
ConversionRequired

Просмотреть файл

@ -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

Просмотреть файл

@ -10,6 +10,7 @@ EXPORTS += [
]
UNIFIED_SOURCES += [
'../FFmpegAudioDecoder.cpp',
'../FFmpegDataDecoder.cpp',
'../FFmpegDecoderModule.cpp',
'../FFmpegVideoDecoder.cpp',