2012-12-18 00:49:58 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WMF.h"
|
|
|
|
#include "WMFDecoder.h"
|
|
|
|
#include "WMFReader.h"
|
|
|
|
#include "WMFUtils.h"
|
|
|
|
#include "MediaDecoderStateMachine.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2013-03-26 07:40:01 -07:00
|
|
|
#include "WinUtils.h"
|
|
|
|
|
2013-08-12 21:49:25 -07:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
#include "DirectShowDecoder.h"
|
|
|
|
#endif
|
|
|
|
|
2013-03-26 07:40:01 -07:00
|
|
|
using namespace mozilla::widget;
|
2012-12-18 00:49:58 -08:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
MediaDecoderStateMachine* WMFDecoder::CreateStateMachine()
|
|
|
|
{
|
|
|
|
return new MediaDecoderStateMachine(this, new WMFReader(this));
|
|
|
|
}
|
|
|
|
|
2013-04-18 19:54:26 -07:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
WMFDecoder::IsMP3Supported()
|
|
|
|
{
|
2013-04-30 03:14:18 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
|
2013-08-12 21:49:25 -07:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
if (DirectShowDecoder::IsEnabled()) {
|
|
|
|
// DirectShowDecoder is enabled, we use that in preference to the WMF
|
|
|
|
// backend.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (!MediaDecoder::IsWMFEnabled()) {
|
2013-04-18 19:54:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (WinUtils::GetWindowsVersion() != WinUtils::WIN7_VERSION) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// We're on Windows 7. MP3 support is disabled if no service pack
|
|
|
|
// is installed, as it's crashy on Win7 SP0.
|
|
|
|
UINT spMajorVer = 0, spMinorVer = 0;
|
|
|
|
if (!WinUtils::GetWindowsServicePackVersion(spMajorVer, spMinorVer)) {
|
|
|
|
// Um... We can't determine the service pack version... Just block
|
|
|
|
// MP3 as a precaution...
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return spMajorVer != 0;
|
|
|
|
}
|
|
|
|
|
2012-12-18 00:49:58 -08:00
|
|
|
bool
|
|
|
|
WMFDecoder::GetSupportedCodecs(const nsACString& aType,
|
|
|
|
char const *const ** aCodecList)
|
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsWMFEnabled() ||
|
|
|
|
NS_FAILED(LoadDLLs()))
|
|
|
|
return false;
|
|
|
|
|
2013-02-26 12:27:43 -08:00
|
|
|
// Assume that if LoadDLLs() didn't fail, we can playback the types that
|
2013-04-18 19:54:26 -07:00
|
|
|
// we know should be supported by Windows Media Foundation.
|
2012-12-18 00:49:58 -08:00
|
|
|
static char const *const mp3AudioCodecs[] = {
|
2013-02-26 12:27:43 -08:00
|
|
|
"mp3",
|
2012-12-18 00:49:58 -08:00
|
|
|
nullptr
|
|
|
|
};
|
2013-04-18 19:54:26 -07:00
|
|
|
if ((aType.EqualsASCII("audio/mpeg") || aType.EqualsASCII("audio/mp3")) &&
|
|
|
|
IsMP3Supported()) {
|
|
|
|
// Note: We block MP3 playback on Window 7 SP0 since it seems to crash
|
|
|
|
// in some circumstances.
|
2012-12-18 00:49:58 -08:00
|
|
|
if (aCodecList) {
|
|
|
|
*aCodecList = mp3AudioCodecs;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// AAC in M4A.
|
|
|
|
static char const *const aacAudioCodecs[] = {
|
|
|
|
"mp4a.40.2", // AAC-LC
|
|
|
|
nullptr
|
|
|
|
};
|
2013-02-26 12:27:43 -08:00
|
|
|
if (aType.EqualsASCII("audio/mp4") ||
|
|
|
|
aType.EqualsASCII("audio/x-m4a")) {
|
2012-12-18 00:49:58 -08:00
|
|
|
if (aCodecList) {
|
|
|
|
*aCodecList = aacAudioCodecs;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// H.264 + AAC in MP4.
|
|
|
|
static char const *const H264Codecs[] = {
|
|
|
|
"avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0
|
|
|
|
"avc1.42001E", // H.264 Baseline Profile Level 3.0
|
|
|
|
"avc1.58A01E", // H.264 Extended Profile Level 3.0
|
|
|
|
"avc1.4D401E", // H.264 Main Profile Level 3.0
|
|
|
|
"avc1.64001E", // H.264 High Profile Level 3.0
|
|
|
|
"avc1.64001F", // H.264 High Profile Level 3.1
|
|
|
|
"mp4a.40.2", // AAC-LC
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
if (aType.EqualsASCII("video/mp4")) {
|
|
|
|
if (aCodecList) {
|
|
|
|
*aCodecList = H264Codecs;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
WMFDecoder::LoadDLLs()
|
|
|
|
{
|
|
|
|
return SUCCEEDED(wmf::LoadDLLs()) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WMFDecoder::UnloadDLLs()
|
|
|
|
{
|
|
|
|
wmf::UnloadDLLs();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
WMFDecoder::IsEnabled()
|
|
|
|
{
|
2013-03-26 07:40:01 -07:00
|
|
|
// We only use WMF on Windows Vista and up
|
|
|
|
return WinUtils::GetWindowsVersion() >= WinUtils::VISTA_VERSION &&
|
2012-12-18 00:49:58 -08:00
|
|
|
Preferences::GetBool("media.windows-media-foundation.enabled");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|