From 239ba800f1788a528f9b5420f6bc09d0dc2540f3 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Mon, 5 Oct 2015 14:34:44 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1211339) for m3 test failures on a CLOSED TREE Backed out changeset 91bff7bc67d7 (bug 1211339) Backed out changeset d34f694b13cf (bug 1211339) --- dom/media/DecoderTraits.cpp | 4 +- dom/media/VideoUtils.cpp | 9 -- dom/media/VideoUtils.h | 3 - dom/media/fmp4/MP4Decoder.cpp | 117 +++++++++--------- dom/media/fmp4/MP4Decoder.h | 7 +- dom/media/platforms/wmf/WMFAudioMFTManager.h | 3 - dom/media/platforms/wmf/WMFDecoderModule.cpp | 97 +++++++-------- dom/media/platforms/wmf/WMFDecoderModule.h | 7 ++ .../platforms/wmf/WMFVideoMFTManager.cpp | 2 +- 9 files changed, 122 insertions(+), 127 deletions(-) diff --git a/dom/media/DecoderTraits.cpp b/dom/media/DecoderTraits.cpp index aa1c11fadedd..26fe5bbb6ae2 100644 --- a/dom/media/DecoderTraits.cpp +++ b/dom/media/DecoderTraits.cpp @@ -347,7 +347,9 @@ static bool IsMP4SupportedType(const nsACString& aType, const nsAString& aCodecs = EmptyString()) { - return MP4Decoder::CanHandleMediaType(aType, aCodecs); + // MP4Decoder/Reader is currently used for MSE and mp4 files local playback. + bool haveAAC, haveMP3, haveH264; + return MP4Decoder::CanHandleMediaType(aType, aCodecs, haveAAC, haveH264, haveMP3); } #endif diff --git a/dom/media/VideoUtils.cpp b/dom/media/VideoUtils.cpp index ebdc7b1f74b7..e9382ba05b45 100644 --- a/dom/media/VideoUtils.cpp +++ b/dom/media/VideoUtils.cpp @@ -469,15 +469,6 @@ LogToBrowserConsole(const nsAString& aMsg) console->LogStringMessage(msg.get()); } -bool -IsAACCodecString(const nsAString& aCodec) -{ - return - aCodec.EqualsLiteral("mp4a.40.2") || // MPEG4 AAC-LC - aCodec.EqualsLiteral("mp4a.40.5") || // MPEG4 HE-AAC - aCodec.EqualsLiteral("mp4a.67"); // MPEG2 AAC-LC} -} - bool ParseCodecsString(const nsAString& aCodecs, nsTArray& aOutCodecs) { diff --git a/dom/media/VideoUtils.h b/dom/media/VideoUtils.h index baeb15ddfddf..a42517dbb16a 100644 --- a/dom/media/VideoUtils.h +++ b/dom/media/VideoUtils.h @@ -338,9 +338,6 @@ IsH264ContentType(const nsAString& aContentType); bool IsAACContentType(const nsAString& aContentType); -bool -IsAACCodecString(const nsAString& aCodec); - } // end namespace mozilla #endif diff --git a/dom/media/fmp4/MP4Decoder.cpp b/dom/media/fmp4/MP4Decoder.cpp index c65b0a94c0bf..5e0a6c6aff8c 100644 --- a/dom/media/fmp4/MP4Decoder.cpp +++ b/dom/media/fmp4/MP4Decoder.cpp @@ -16,7 +16,6 @@ #include "mozilla/Logging.h" #include "nsMimeTypes.h" #include "nsContentTypeParser.h" -#include "VideoUtils.h" #ifdef XP_WIN #include "mozilla/WindowsVersion.h" @@ -54,7 +53,30 @@ MediaDecoderStateMachine* MP4Decoder::CreateStateMachine() } static bool -IsWhitelistedH264Codec(const nsAString& aCodec) +IsSupportedAudioCodec(const nsAString& aCodec, + bool& aOutContainsAAC, + bool& aOutContainsMP3) +{ + // AAC-LC or HE-AAC in M4A. + aOutContainsAAC = aCodec.EqualsASCII("mp4a.40.2") // MPEG4 AAC-LC + || aCodec.EqualsASCII("mp4a.40.5") // MPEG4 HE-AAC + || aCodec.EqualsASCII("mp4a.67"); // MPEG2 AAC-LC + if (aOutContainsAAC) { + return true; + } +#ifndef MOZ_GONK_MEDIACODEC // B2G doesn't support MP3 in MP4 yet. + aOutContainsMP3 = aCodec.EqualsASCII("mp3"); + if (aOutContainsMP3) { + return true; + } +#else + aOutContainsMP3 = false; +#endif + return false; +} + +static bool +IsSupportedH264Codec(const nsAString& aCodec) { int16_t profile = 0, level = 0; @@ -88,74 +110,52 @@ IsWhitelistedH264Codec(const nsAString& aCodec) /* static */ bool -MP4Decoder::CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs, - const nsAString& aCodecs) +MP4Decoder::CanHandleMediaType(const nsACString& aType, + const nsAString& aCodecs, + bool& aOutContainsAAC, + bool& aOutContainsH264, + bool& aOutContainsMP3) { if (!IsEnabled()) { return false; } - // Whitelist MP4 types, so they explicitly match what we encounter on - // the web, as opposed to what we use internally (i.e. what our demuxers - // etc output). - if (!aMIMETypeExcludingCodecs.EqualsASCII("audio/mp4") && - !aMIMETypeExcludingCodecs.EqualsASCII("audio/x-m4a") && - !aMIMETypeExcludingCodecs.EqualsASCII("video/mp4") && - !aMIMETypeExcludingCodecs.EqualsASCII("video/x-m4v")) { - return false; + if (aType.EqualsASCII("audio/mp4") || aType.EqualsASCII("audio/x-m4a")) { + return MP4Decoder::CanCreateAACDecoder() && + (aCodecs.IsEmpty() || + IsSupportedAudioCodec(aCodecs, + aOutContainsAAC, + aOutContainsMP3)); } #ifdef MOZ_GONK_MEDIACODEC - if (aMIMETypeExcludingCodecs.EqualsASCII(VIDEO_3GPP)) { + if (aType.EqualsASCII(VIDEO_3GPP)) { return Preferences::GetBool("media.fragmented-mp4.gonk.enabled", false); } #endif - - nsTArray codecMimes; - if (aCodecs.IsEmpty()) { - // No codecs specified. Assume AAC/H.264 - if (aMIMETypeExcludingCodecs.EqualsLiteral("audio/mp4") || - aMIMETypeExcludingCodecs.EqualsLiteral("audio/x-m4a")) { - codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mp4a-latm")); - } else if (aMIMETypeExcludingCodecs.EqualsLiteral("video/mp4") || - aMIMETypeExcludingCodecs.EqualsLiteral("video/x-m4v")) { - codecMimes.AppendElement(NS_LITERAL_CSTRING("video/avc")); - } - } else { - // Verify that all the codecs specified are ones that we expect that - // we can play. - nsTArray codecs; - if (!ParseCodecsString(aCodecs, codecs)) { - return false; - } - for (const nsString& codec : codecs) { - if (IsAACCodecString(codec)) { - codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mp4a-latm")); - continue; - } - if (codec.EqualsLiteral("mp3")) { - codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mpeg")); - continue; - } - if (IsWhitelistedH264Codec(codec)) { - codecMimes.AppendElement(NS_LITERAL_CSTRING("video/avc")); - continue; - } - // Some unsupported codec. - return false; - } - } - - // Verify that we have a PDM that supports the whitelisted types. - PlatformDecoderModule::Init(); - nsRefPtr platform = PlatformDecoderModule::Create(); - if (!platform) { + if ((!aType.EqualsASCII("video/mp4") && !aType.EqualsASCII("video/x-m4v")) || + !MP4Decoder::CanCreateH264Decoder()) { return false; } - for (const nsCString& codecMime : codecMimes) { - if (!platform->SupportsMimeType(codecMime)) { - return false; + + // Verify that all the codecs specifed are ones that we expect that + // we can play. + nsTArray codecs; + if (!ParseCodecsString(aCodecs, codecs)) { + return false; + } + for (const nsString& codec : codecs) { + if (IsSupportedAudioCodec(codec, + aOutContainsAAC, + aOutContainsMP3)) { + continue; } + if (IsSupportedH264Codec(codec)) { + aOutContainsH264 = true; + continue; + } + // Some unsupported codec. + return false; } return true; @@ -173,7 +173,10 @@ MP4Decoder::CanHandleMediaType(const nsAString& aContentType) nsString codecs; parser.GetParameter("codecs", codecs); - return CanHandleMediaType(NS_ConvertUTF16toUTF8(mimeType), codecs); + bool ignoreAAC, ignoreH264, ignoreMP3; + return CanHandleMediaType(NS_ConvertUTF16toUTF8(mimeType), + codecs, + ignoreAAC, ignoreH264, ignoreMP3); } static bool diff --git a/dom/media/fmp4/MP4Decoder.h b/dom/media/fmp4/MP4Decoder.h index aceec851aec9..e3342b7220f4 100644 --- a/dom/media/fmp4/MP4Decoder.h +++ b/dom/media/fmp4/MP4Decoder.h @@ -29,8 +29,11 @@ public: // a MP4 platform decoder backend. If aCodecs is non emtpy, it is filled // with a comma-delimited list of codecs to check support for. Notes in // out params wether the codecs string contains AAC or H.264. - static bool CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs, - const nsAString& aCodecs); + static bool CanHandleMediaType(const nsACString& aMIMEType, + const nsAString& aCodecs, + bool& aOutContainsAAC, + bool& aOutContainsH264, + bool& aOutContainsMP3); static bool CanHandleMediaType(const nsAString& aMIMEType); diff --git a/dom/media/platforms/wmf/WMFAudioMFTManager.h b/dom/media/platforms/wmf/WMFAudioMFTManager.h index c5738b5f4310..f6c7b6b8d2f6 100644 --- a/dom/media/platforms/wmf/WMFAudioMFTManager.h +++ b/dom/media/platforms/wmf/WMFAudioMFTManager.h @@ -12,9 +12,6 @@ #include "mozilla/RefPtr.h" #include "WMFMediaDataDecoder.h" -extern const GUID CLSID_WebmMfVp8Dec; -extern const GUID CLSID_WebmMfVp9Dec; - namespace mozilla { class WMFAudioMFTManager : public MFTManager { diff --git a/dom/media/platforms/wmf/WMFDecoderModule.cpp b/dom/media/platforms/wmf/WMFDecoderModule.cpp index a1befe80ce5b..872ea3cac0c2 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.cpp +++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp @@ -21,7 +21,6 @@ #include "gfxWindowsPlatform.h" #include "MediaInfo.h" #include "prsystem.h" -#include "mozilla/Maybe.h" namespace mozilla { @@ -124,59 +123,16 @@ WMFDecoderModule::CreateAudioDecoder(const AudioInfo& aConfig, return decoder.forget(); } -static bool -CanCreateMFTDecoder(const GUID& aGuid) -{ - if (FAILED(wmf::MFStartup())) { - return false; - } - RefPtr decoder(new MFTDecoder()); - bool hasH264 = SUCCEEDED(decoder->Create(aGuid)); - wmf::MFShutdown(); - return hasH264; -} - -template -static bool -CanCreateWMFDecoder() -{ - static Maybe result; - if (result.isNothing()) { - result.emplace(CanCreateMFTDecoder(aGuid)); - } - return result.value(); -} - bool WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType) { - if ((aMimeType.EqualsLiteral("audio/mp4a-latm") || - aMimeType.EqualsLiteral("audio/mp4")) && - CanCreateWMFDecoder()) { - return true; - } - if ((aMimeType.EqualsLiteral("video/avc") || - aMimeType.EqualsLiteral("video/mp4")) && - CanCreateWMFDecoder()) { - return true; - } - if (aMimeType.EqualsLiteral("audio/mpeg") && - CanCreateWMFDecoder()) { - return true; - } - if (sIsIntelDecoderEnabled) { - if (aMimeType.EqualsLiteral("video/webm; codecs=vp8") && - CanCreateWMFDecoder()) { - return true; - } - if (aMimeType.EqualsLiteral("video/webm; codecs=vp9") && - CanCreateWMFDecoder()) { - return true; - } - } - - // Some unsupported codec. - return false; + return aMimeType.EqualsLiteral("video/mp4") || + aMimeType.EqualsLiteral("video/avc") || + aMimeType.EqualsLiteral("audio/mp4a-latm") || + aMimeType.EqualsLiteral("audio/mpeg") || + (sIsIntelDecoderEnabled && + (aMimeType.EqualsLiteral("video/webm; codecs=vp8") || + aMimeType.EqualsLiteral("video/webm; codecs=vp9"))); } PlatformDecoderModule::ConversionRequired @@ -191,4 +147,43 @@ WMFDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const } } +static bool +ClassesRootRegKeyExists(const nsAString& aRegKeyPath) +{ + nsresult rv; + + nsCOMPtr regKey = + do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + + rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT, + aRegKeyPath, + nsIWindowsRegKey::ACCESS_READ); + if (NS_FAILED(rv)) { + return false; + } + + regKey->Close(); + + return true; +} + +/* static */ bool +WMFDecoderModule::HasH264() +{ + // CLSID_CMSH264DecoderMFT + return ClassesRootRegKeyExists( + NS_LITERAL_STRING("CLSID\\{32D186A7-218F-4C75-8876-DD77273A8999}")); +} + +/* static */ bool +WMFDecoderModule::HasAAC() +{ + // CLSID_CMSAACDecMFT + return ClassesRootRegKeyExists( + NS_LITERAL_STRING("CLSID\\{62CE7E72-4C71-4D20-B15D-452831A87D9D}")); +} + } // namespace mozilla diff --git a/dom/media/platforms/wmf/WMFDecoderModule.h b/dom/media/platforms/wmf/WMFDecoderModule.h index ebcf001aac05..e959ebdad45f 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.h +++ b/dom/media/platforms/wmf/WMFDecoderModule.h @@ -36,6 +36,13 @@ public: ConversionRequired DecoderNeedsConversion(const TrackInfo& aConfig) const override; + // Accessors that report whether we have the required MFTs available + // on the system to play various codecs. Windows Vista doesn't have the + // H.264/AAC decoders if the "Platform Update Supplement for Windows Vista" + // is not installed. + static bool HasAAC(); + static bool HasH264(); + // Called on main thread. static void Init(); diff --git a/dom/media/platforms/wmf/WMFVideoMFTManager.cpp b/dom/media/platforms/wmf/WMFVideoMFTManager.cpp index 3ddf10b26d2f..a71c166576c3 100644 --- a/dom/media/platforms/wmf/WMFVideoMFTManager.cpp +++ b/dom/media/platforms/wmf/WMFVideoMFTManager.cpp @@ -168,7 +168,7 @@ WMFVideoMFTManager::InitializeDXVA(bool aForceD3D9) } // The DXVA manager must be created on the main thread. - nsRefPtr event = + nsRefPtr event = new CreateDXVAManagerEvent(aForceD3D9 ? LayersBackend::LAYERS_D3D9 : mLayersBackend, mDXVAFailureReason); if (NS_IsMainThread()) {