Bug 1055974 - Enable MP3 decoding in WMF PDM. r=padenot

This commit is contained in:
Chris Pearce 2014-08-22 13:37:57 +12:00
Родитель 0dce9d91bc
Коммит 53a822ef94
4 изменённых файлов: 64 добавлений и 11 удалений

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

@ -76,9 +76,17 @@ WMFAudioMFTManager::WMFAudioMFTManager(
, mMustRecaptureAudioPosition(true)
{
MOZ_COUNT_CTOR(WMFAudioMFTManager);
AACAudioSpecificConfigToUserData(&aConfig.audio_specific_config[0],
aConfig.audio_specific_config.length(),
mUserData);
if (!strcmp(aConfig.mime_type, "audio/mpeg")) {
mStreamType = MP3;
} else if (!strcmp(aConfig.mime_type, "audio/mp4a-latm")) {
mStreamType = AAC;
AACAudioSpecificConfigToUserData(&aConfig.audio_specific_config[0],
aConfig.audio_specific_config.length(),
mUserData);
} else {
mStreamType = Unknown;
}
}
WMFAudioMFTManager::~WMFAudioMFTManager()
@ -86,12 +94,36 @@ WMFAudioMFTManager::~WMFAudioMFTManager()
MOZ_COUNT_DTOR(WMFAudioMFTManager);
}
const GUID&
WMFAudioMFTManager::GetMFTGUID()
{
MOZ_ASSERT(mStreamType != Unknown);
switch (mStreamType) {
case AAC: return CLSID_CMSAACDecMFT;
case MP3: return CLSID_CMP3DecMediaObject;
default: return GUID_NULL;
};
}
const GUID&
WMFAudioMFTManager::GetMediaSubtypeGUID()
{
MOZ_ASSERT(mStreamType != Unknown);
switch (mStreamType) {
case AAC: return MFAudioFormat_AAC;
case MP3: return MFAudioFormat_MP3;
default: return GUID_NULL;
};
}
TemporaryRef<MFTDecoder>
WMFAudioMFTManager::Init()
{
NS_ENSURE_TRUE(mStreamType != Unknown, nullptr);
RefPtr<MFTDecoder> decoder(new MFTDecoder());
HRESULT hr = decoder->Create(CLSID_CMSAACDecMFT);
HRESULT hr = decoder->Create(GetMFTGUID());
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
// Setup input/output media types
@ -103,7 +135,7 @@ WMFAudioMFTManager::Init()
hr = type->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Audio);
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
hr = type->SetGUID(MF_MT_SUBTYPE, MFAudioFormat_AAC);
hr = type->SetGUID(MF_MT_SUBTYPE, GetMediaSubtypeGUID());
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
hr = type->SetUINT32(MF_MT_AUDIO_SAMPLES_PER_SECOND, mAudioRate);
@ -112,13 +144,15 @@ WMFAudioMFTManager::Init()
hr = type->SetUINT32(MF_MT_AUDIO_NUM_CHANNELS, mAudioChannels);
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
hr = type->SetUINT32(MF_MT_AAC_PAYLOAD_TYPE, 0x1); // ADTS
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
if (mStreamType == AAC) {
hr = type->SetUINT32(MF_MT_AAC_PAYLOAD_TYPE, 0x1); // ADTS
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
hr = type->SetBlob(MF_MT_USER_DATA,
mUserData.Elements(),
mUserData.Length());
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
hr = type->SetBlob(MF_MT_USER_DATA,
mUserData.Elements(),
mUserData.Length());
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
}
hr = decoder->SetMediaTypes(type, MFAudioFormat_PCM);
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);

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

@ -48,6 +48,16 @@ private:
// discontinuity.
int64_t mAudioFrameSum;
enum StreamType {
Unknown,
AAC,
MP3
};
StreamType mStreamType;
const GUID& GetMFTGUID();
const GUID& GetMediaSubtypeGUID();
// True if we need to re-initialize mAudioFrameOffset and mAudioFrameSum
// from the next audio packet we decode. This happens after a seek, since
// WMF doesn't mark a stream as having a discontinuity after a seek(0).

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

@ -92,4 +92,11 @@ WMFDecoderModule::CreateAudioDecoder(const mp4_demuxer::AudioDecoderConfig& aCon
return decoder.forget();
}
bool
WMFDecoderModule::SupportsAudioMimeType(const char* aMimeType)
{
return !strcmp(aMimeType, "audio/mp4a-latm") ||
!strcmp(aMimeType, "audio/mpeg");
}
} // namespace mozilla

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

@ -34,6 +34,8 @@ public:
MediaTaskQueue* aAudioTaskQueue,
MediaDataDecoderCallback* aCallback) MOZ_OVERRIDE;
bool SupportsAudioMimeType(const char* aMimeType) MOZ_OVERRIDE;
// Called on main thread.
static void Init();
private: