Bug 1290284 - Centralise string comparisons for H264 and VPX detection. r=cpearce draft
authorBryce Van Dyk <bvandyk@mozilla.com>
Fri, 29 Jul 2016 14:12:54 +1200
changeset 394814 c013c4ebe28d5afedbb91ddfffadb40d23fd0ee3
parent 394782 4a18b5cacb1b21a3e8b4b1dada6b2dd3dba51cb1
child 526877 81e61a9d2c202cab5330bce182a026f25f45362b
push id24642
push userbvandyk@mozilla.com
push dateMon, 01 Aug 2016 02:22:56 +0000
reviewerscpearce
bugs1290284
milestone50.0a1
Bug 1290284 - Centralise string comparisons for H264 and VPX detection. r=cpearce Remove string comparisons to determine from mime types if content is VPX or H264. Replace with calls to VPXDecoder::IsVPX or MP4Decoder::IsH264 to centralise such logic. This patch introduces MP4Decoder:IsH264, and moves the similar functionality out of H264Convertor for the sake of consistently having these functions in decoders. MozReview-Commit-ID: 5nfYusYHrUR
dom/media/fmp4/MP4Decoder.cpp
dom/media/fmp4/MP4Decoder.h
dom/media/platforms/PDMFactory.cpp
dom/media/platforms/agnostic/VPXDecoder.h
dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
dom/media/platforms/omx/OmxPlatformLayer.cpp
dom/media/platforms/wmf/WMFDecoderModule.cpp
dom/media/platforms/wmf/WMFVideoMFTManager.cpp
dom/media/platforms/wrappers/H264Converter.cpp
dom/media/platforms/wrappers/H264Converter.h
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -168,16 +168,24 @@ MP4Decoder::CanHandleMediaType(const nsA
 
   return CanHandleMediaType(NS_ConvertUTF16toUTF8(mimeType),
                             codecs,
                             aDiagnostics);
 }
 
 /* static */
 bool
+MP4Decoder::IsH264(const nsACString& aMimeType)
+{
+  return aMimeType.EqualsLiteral("video/mp4") ||
+         aMimeType.EqualsLiteral("video/avc");
+}
+
+/* static */
+bool
 MP4Decoder::IsEnabled()
 {
   return Preferences::GetBool("media.mp4.enabled", true);
 }
 
 // sTestH264ExtraData represents the content of the avcC atom found in
 // an AVC1 h264 video. It contains the H264 SPS and PPS NAL.
 // the structure of the avcC atom is as follow:
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -33,16 +33,21 @@ public:
   // out params wether the codecs string contains AAC or H.264.
   static bool CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
                                  const nsAString& aCodecs,
                                  DecoderDoctorDiagnostics* aDiagnostics);
 
   static bool CanHandleMediaType(const nsAString& aMIMEType,
                                  DecoderDoctorDiagnostics* aDiagnostics);
 
+  // Return true if aMimeType is a one of the strings used by our demuxers to
+  // identify H264. Does not parse general content type strings, i.e. white
+  // space matters.
+  static bool IsH264(const nsACString& aMimeType);
+
   // Returns true if the MP4 backend is preffed on.
   static bool IsEnabled();
 
   static already_AddRefed<dom::Promise>
   IsVideoAccelerated(layers::LayersBackend aBackend, nsIGlobalObject* aParent);
 
   void GetMozDebugReaderData(nsAString& aString) override;
 
--- a/dom/media/platforms/PDMFactory.cpp
+++ b/dom/media/platforms/PDMFactory.cpp
@@ -41,16 +41,18 @@
 
 #ifdef MOZ_EME
 #include "EMEDecoderModule.h"
 #include "mozilla/CDMProxy.h"
 #endif
 
 #include "DecoderDoctorDiagnostics.h"
 
+#include "MP4Decoder.h"
+
 
 namespace mozilla {
 
 extern already_AddRefed<PlatformDecoderModule> CreateAgnosticDecoderModule();
 extern already_AddRefed<PlatformDecoderModule> CreateBlankDecoderModule();
 
 class PDMFactoryImpl final {
 public:
@@ -178,17 +180,17 @@ PDMFactory::CreateDecoderWithPDM(Platfor
       TimeDuration::FromMilliseconds(MediaPrefs::PDMFuzzingInterval()));
     callbackWrapper->SetDontDelayInputExhausted(!MediaPrefs::PDMFuzzingDelayInputExhausted());
     callback = callbackWrapper.get();
   }
 
   CreateDecoderParams params = aParams;
   params.mCallback = callback;
 
-  if (H264Converter::IsH264(config)) {
+  if (MP4Decoder::IsH264(config.mMimeType)) {
     RefPtr<H264Converter> h = new H264Converter(aPDM, params);
     const nsresult rv = h->GetLastError();
     if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) {
       // The H264Converter either successfully created the wrapped decoder,
       // or there wasn't enough AVCC data to do so. Otherwise, there was some
       // problem, for example WMF DLLs were missing.
       m = h.forget();
     }
--- a/dom/media/platforms/agnostic/VPXDecoder.h
+++ b/dom/media/platforms/agnostic/VPXDecoder.h
@@ -34,17 +34,19 @@ public:
     return "libvpx video decoder";
   }
 
   enum Codec: uint8_t {
     VP8 = 1 << 0,
     VP9 = 1 << 1
   };
 
-  // Return true if mimetype is a VPX codec of given types.
+  // Return true if aMimeType is a one of the strings used by our demuxers to
+  // identify VPX of the specified type. Does not parse general content type
+  // strings, i.e. white space matters.
   static bool IsVPX(const nsACString& aMimeType, uint8_t aCodecMask=VP8|VP9);
   static bool IsVP8(const nsACString& aMimeType);
   static bool IsVP9(const nsACString& aMimeType);
 
 private:
   void ProcessDecode(MediaRawData* aSample);
   int DoDecode(MediaRawData* aSample);
   void ProcessDrain();
--- a/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEDecoderModule.cpp
@@ -11,16 +11,17 @@
 #include "mozIGeckoMediaPluginService.h"
 #include "mozilla/CDMProxy.h"
 #include "mozilla/unused.h"
 #include "nsAutoPtr.h"
 #include "nsServiceManagerUtils.h"
 #include "MediaInfo.h"
 #include "nsClassHashtable.h"
 #include "GMPDecoderModule.h"
+#include "MP4Decoder.h"
 
 namespace mozilla {
 
 typedef MozPromiseRequestHolder<CDMProxy::DecryptPromise> DecryptPromiseRequestHolder;
 
 class EMEDecryptor : public MediaDataDecoder {
 
 public:
@@ -287,19 +288,17 @@ EMEDecoderModule::CreateAudioDecoder(con
                                                        mProxy,
                                                        AbstractThread::GetCurrent()->AsTaskQueue()));
   return emeDecoder.forget();
 }
 
 PlatformDecoderModule::ConversionRequired
 EMEDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
 {
-  if (aConfig.IsVideo() &&
-      (aConfig.mMimeType.EqualsLiteral("video/avc") ||
-       aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
+  if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
     return kNeedAVCC;
   } else {
     return kNeedNone;
   }
 }
 
 bool
 EMEDecoderModule::SupportsMimeType(const nsACString& aMimeType,
--- a/dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/eme/EMEVideoDecoder.cpp
@@ -3,16 +3,17 @@
 /* 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 "EMEVideoDecoder.h"
 #include "GMPVideoEncodedFrameImpl.h"
 #include "mozilla/CDMProxy.h"
 #include "MediaData.h"
+#include "MP4Decoder.h"
 #include "VPXDecoder.h"
 
 namespace mozilla {
 
 void
 EMEVideoCallbackAdapter::Error(GMPErr aErr)
 {
   if (aErr == GMPNoKeyErr) {
@@ -32,18 +33,17 @@ EMEVideoDecoder::EMEVideoDecoder(CDMProx
                                                 aParams.mImageContainer)))
   , mProxy(aProxy)
 {}
 
 void
 EMEVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
   VideoInfo config = GetConfig();
-  if (config.mMimeType.EqualsLiteral("video/avc") ||
-      config.mMimeType.EqualsLiteral("video/mp4")) {
+  if (MP4Decoder::IsH264(config.mMimeType)) {
     aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
   } else if (VPXDecoder::IsVP8(config.mMimeType)) {
     aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
   } else if (VPXDecoder::IsVP9(config.mMimeType)) {
     aTags.AppendElement(NS_LITERAL_CSTRING("vp9"));
   }
   aTags.AppendElement(NS_ConvertUTF16toUTF8(mProxy->KeySystem()));
 }
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -11,16 +11,17 @@
 #include "MediaDataDecoderProxy.h"
 #include "MediaPrefs.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/EMEUtils.h"
 #include "mozilla/StaticMutex.h"
 #include "gmp-audio-decode.h"
 #include "gmp-video-decode.h"
+#include "MP4Decoder.h"
 #include "VPXDecoder.h"
 #ifdef XP_WIN
 #include "WMFDecoderModule.h"
 #endif
 
 namespace mozilla {
 
 GMPDecoderModule::GMPDecoderModule()
@@ -44,18 +45,17 @@ CreateDecoderWrapper(MediaDataDecoderCal
   }
   RefPtr<MediaDataDecoderProxy> decoder(new MediaDataDecoderProxy(thread.forget(), aCallback));
   return decoder.forget();
 }
 
 already_AddRefed<MediaDataDecoder>
 GMPDecoderModule::CreateVideoDecoder(const CreateDecoderParams& aParams)
 {
-  if (!aParams.mConfig.mMimeType.EqualsLiteral("video/avc") &&
-      !aParams.mConfig.mMimeType.EqualsLiteral("video/mp4") &&
+  if (!MP4Decoder::IsH264(aParams.mConfig.mMimeType) &&
       !VPXDecoder::IsVP8(aParams.mConfig.mMimeType) &&
       !VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
     return nullptr;
   }
 
   if (aParams.mDiagnostics) {
     const Maybe<nsCString> preferredGMP = PreferredGMP(aParams.mConfig.mMimeType);
     if (preferredGMP.isSome()) {
@@ -88,19 +88,17 @@ GMPDecoderModule::CreateAudioDecoder(con
   wrapper->SetProxyTarget(new GMPAudioDecoder(params));
   return wrapper.forget();
 }
 
 PlatformDecoderModule::ConversionRequired
 GMPDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
 {
   // GMPVideoCodecType::kGMPVideoCodecH264 specifies that encoded frames must be in AVCC format.
-  if (aConfig.IsVideo() &&
-      (aConfig.mMimeType.EqualsLiteral("video/avc") ||
-       aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
+  if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
     return kNeedAVCC;
   } else {
     return kNeedNone;
   }
 }
 
 static bool
 HasGMPFor(const nsACString& aAPI,
@@ -198,45 +196,38 @@ GMPDecoderModule::PreferredGMP(const nsA
   if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
     switch (MediaPrefs::GMPAACPreferred()) {
       case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
       case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
       default: break;
     }
   }
 
-  if (aMimeType.EqualsLiteral("video/avc") ||
-      aMimeType.EqualsLiteral("video/mp4")) {
+  if (MP4Decoder::IsH264(aMimeType)) {
     switch (MediaPrefs::GMPH264Preferred()) {
       case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
       case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
       default: break;
     }
   }
 
   return rv;
 }
 
 /* static */
 bool
 GMPDecoderModule::SupportsMimeType(const nsACString& aMimeType,
                                    const Maybe<nsCString>& aGMP)
 {
-  const bool isAAC = aMimeType.EqualsLiteral("audio/mp4a-latm");
-  const bool isH264 = aMimeType.EqualsLiteral("video/avc") ||
-                      aMimeType.EqualsLiteral("video/mp4");
-  const bool isVP8 = VPXDecoder::IsVP8(aMimeType);
-  const bool isVP9 = VPXDecoder::IsVP9(aMimeType);
-
   StaticMutexAutoLock lock(sGMPCodecsMutex);
   for (GMPCodecs& gmp : sGMPCodecs) {
-    if (((isAAC && gmp.mHasAAC) ||
-         (isH264 && gmp.mHasH264) ||
-         (isVP8 && gmp.mHasVP8) ||
-         (isVP9 && gmp.mHasVP9)) &&
+    if (((aMimeType.EqualsLiteral("audio/mp4a-latm") && gmp.mHasAAC) ||
+         (MP4Decoder::IsH264(aMimeType) && gmp.mHasH264) ||
+         (VPXDecoder::IsVP8(aMimeType) && gmp.mHasVP8) ||
+         (VPXDecoder::IsVP9(aMimeType) && gmp.mHasVP9)) &&
         (aGMP.isNothing() || aGMP.value().EqualsASCII(gmp.mKeySystem))) {
       return true;
     }
   }
 
   return false;
 }
 
--- a/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPVideoDecoder.cpp
@@ -151,18 +151,17 @@ GMPVideoDecoder::GMPVideoDecoder(const G
                                                   mConfig.mDisplay.height),
                                         aParams.mImageContainer);
   }
 }
 
 void
 GMPVideoDecoder::InitTags(nsTArray<nsCString>& aTags)
 {
-  if (mConfig.mMimeType.EqualsLiteral("video/avc") ||
-      mConfig.mMimeType.EqualsLiteral("video/mp4")) {
+  if (MP4Decoder::IsH264(mConfig.mMimeType)) {
     aTags.AppendElement(NS_LITERAL_CSTRING("h264"));
     const Maybe<nsCString> gmp(
       GMPDecoderModule::PreferredGMP(NS_LITERAL_CSTRING("video/avc")));
     if (gmp.isSome()) {
       aTags.AppendElement(gmp.value());
     }
   } else if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
     aTags.AppendElement(NS_LITERAL_CSTRING("vp8"));
@@ -244,18 +243,17 @@ GMPVideoDecoder::GMPInitDone(GMPVideoDec
     return;
   }
 
   GMPVideoCodec codec;
   memset(&codec, 0, sizeof(codec));
 
   codec.mGMPApiVersion = kGMPVersion33;
   nsTArray<uint8_t> codecSpecific;
-  if (mConfig.mMimeType.EqualsLiteral("video/avc") ||
-      mConfig.mMimeType.EqualsLiteral("video/mp4")) {
+  if (MP4Decoder::IsH264(mConfig.mMimeType)) {
     codec.mCodecType = kGMPVideoCodecH264;
     codecSpecific.AppendElement(0); // mPacketizationMode.
     codecSpecific.AppendElements(mConfig.mExtraData->Elements(),
                                  mConfig.mExtraData->Length());
   } else if (VPXDecoder::IsVP8(mConfig.mMimeType)) {
     codec.mCodecType = kGMPVideoCodecVP8;
   } else if (VPXDecoder::IsVP9(mConfig.mMimeType)) {
     codec.mCodecType = kGMPVideoCodecVP9;
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -5,16 +5,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/TaskQueue.h"
 
 #include "nsThreadUtils.h"
 #include "ImageContainer.h"
 
 #include "MediaInfo.h"
+#include "VPXDecoder.h"
+#include "MP4Decoder.h"
 
 #include "FFmpegVideoDecoder.h"
 #include "FFmpegLog.h"
 #include "mozilla/PodOperations.h"
 
 #include "libavutil/pixfmt.h"
 #if LIBAVCODEC_VERSION_MAJOR < 54
 #define AVPixelFormat PixelFormat
@@ -333,32 +335,32 @@ FFmpegVideoDecoder<LIBAV_VER>::~FFmpegVi
     mLib->av_parser_close(mCodecParser);
     mCodecParser = nullptr;
   }
 }
 
 AVCodecID
 FFmpegVideoDecoder<LIBAV_VER>::GetCodecId(const nsACString& aMimeType)
 {
-  if (aMimeType.EqualsLiteral("video/avc") || aMimeType.EqualsLiteral("video/mp4")) {
+  if (MP4Decoder::IsH264(aMimeType)) {
     return AV_CODEC_ID_H264;
   }
 
   if (aMimeType.EqualsLiteral("video/x-vnd.on2.vp6")) {
     return AV_CODEC_ID_VP6F;
   }
 
 #if LIBAVCODEC_VERSION_MAJOR >= 54
-  if (aMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
+  if (VPXDecoder::IsVP8(aMimeType)) {
     return AV_CODEC_ID_VP8;
   }
 #endif
 
 #if LIBAVCODEC_VERSION_MAJOR >= 55
-  if (aMimeType.EqualsLiteral("video/webm; codecs=vp9")) {
+  if (VPXDecoder::IsVP9(aMimeType)) {
     return AV_CODEC_ID_VP9;
   }
 #endif
 
   return AV_CODEC_ID_NONE;
 }
 
 } // namespace mozilla
--- a/dom/media/platforms/omx/OmxPlatformLayer.cpp
+++ b/dom/media/platforms/omx/OmxPlatformLayer.cpp
@@ -8,16 +8,17 @@
 
 #include "OMX_VideoExt.h" // For VP8.
 
 #if defined(MOZ_WIDGET_GONK) && (ANDROID_VERSION == 20 || ANDROID_VERSION == 19)
 #define OMX_PLATFORM_GONK
 #include "GonkOmxPlatformLayer.h"
 #endif
 
+#include "VPXDecoder.h"
 
 #ifdef LOG
 #undef LOG
 #endif
 
 #define LOG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, ("OmxPlatformLayer -- %s: " arg, __func__, ##__VA_ARGS__))
 
 #define RETURN_IF_ERR(err)     \
@@ -273,17 +274,17 @@ OmxPlatformLayer::CompressionFormat()
 
   if (mInfo->mMimeType.EqualsLiteral("video/avc")) {
     return OMX_VIDEO_CodingAVC;
   } else if (mInfo->mMimeType.EqualsLiteral("video/mp4v-es") ||
        mInfo->mMimeType.EqualsLiteral("video/mp4")) {
     return OMX_VIDEO_CodingMPEG4;
   } else if (mInfo->mMimeType.EqualsLiteral("video/3gpp")) {
     return OMX_VIDEO_CodingH263;
-  } else if (mInfo->mMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
+  } else if (VPXDecoder::IsVP8(mInfo->mMimeType)) {
     return static_cast<OMX_VIDEO_CODINGTYPE>(OMX_VIDEO_CodingVP8);
   } else {
     MOZ_ASSERT_UNREACHABLE("Unsupported compression format");
     return OMX_VIDEO_CodingUnused;
   }
 }
 
 // Implementations for different platforms will be defined in their own files.
--- a/dom/media/platforms/wmf/WMFDecoderModule.cpp
+++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp
@@ -20,16 +20,18 @@
 #include "nsWindowsHelpers.h"
 #include "GfxDriverInfo.h"
 #include "gfxWindowsPlatform.h"
 #include "MediaInfo.h"
 #include "MediaPrefs.h"
 #include "prsystem.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/StaticMutex.h"
+#include "MP4Decoder.h"
+#include "VPXDecoder.h"
 
 namespace mozilla {
 
 static Atomic<bool> sDXVAEnabled(false);
 
 WMFDecoderModule::WMFDecoderModule()
   : mWMFInitialized(false)
 {
@@ -188,45 +190,41 @@ bool
 WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType,
                                    DecoderDoctorDiagnostics* aDiagnostics) const
 {
   if ((aMimeType.EqualsLiteral("audio/mp4a-latm") ||
        aMimeType.EqualsLiteral("audio/mp4")) &&
        WMFDecoderModule::HasAAC()) {
     return true;
   }
-  if ((aMimeType.EqualsLiteral("video/avc") ||
-       aMimeType.EqualsLiteral("video/mp4")) &&
-       WMFDecoderModule::HasH264()) {
+  if (MP4Decoder::IsH264(aMimeType) && WMFDecoderModule::HasH264()) {
     return true;
   }
   if (aMimeType.EqualsLiteral("audio/mpeg") &&
       CanCreateWMFDecoder<CLSID_CMP3DecMediaObject>()) {
     return true;
   }
   if (MediaPrefs::PDMWMFIntelDecoderEnabled() && sDXVAEnabled) {
-    if (aMimeType.EqualsLiteral("video/webm; codecs=vp8") &&
+    if (VPXDecoder::IsVP8(aMimeType) &&
         CanCreateWMFDecoder<CLSID_WebmMfVp8Dec>()) {
       return true;
     }
-    if (aMimeType.EqualsLiteral("video/webm; codecs=vp9") &&
+    if (VPXDecoder::IsVP9(aMimeType) &&
         CanCreateWMFDecoder<CLSID_WebmMfVp9Dec>()) {
       return true;
     }
   }
 
   // Some unsupported codec.
   return false;
 }
 
 PlatformDecoderModule::ConversionRequired
 WMFDecoderModule::DecoderNeedsConversion(const TrackInfo& aConfig) const
 {
-  if (aConfig.IsVideo() &&
-      (aConfig.mMimeType.EqualsLiteral("video/avc") ||
-       aConfig.mMimeType.EqualsLiteral("video/mp4"))) {
+  if (aConfig.IsVideo() && MP4Decoder::IsH264(aConfig.mMimeType)) {
     return kNeedAnnexB;
   } else {
     return kNeedNone;
   }
 }
 
 } // namespace mozilla
--- a/dom/media/platforms/wmf/WMFVideoMFTManager.cpp
+++ b/dom/media/platforms/wmf/WMFVideoMFTManager.cpp
@@ -25,16 +25,18 @@
 #include "gfx2DGlue.h"
 #include "gfxWindowsPlatform.h"
 #include "IMFYCbCrImage.h"
 #include "mozilla/WindowsVersion.h"
 #include "mozilla/Telemetry.h"
 #include "nsPrintfCString.h"
 #include "MediaTelemetryConstants.h"
 #include "GMPUtils.h" // For SplitAt. TODO: Move SplitAt to a central place.
+#include "MP4Decoder.h"
+#include "VPXDecoder.h"
 
 #define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 
 using mozilla::layers::Image;
 using mozilla::layers::IMFYCbCrImage;
 using mozilla::layers::LayerManager;
 using mozilla::layers::LayersBackend;
 
@@ -90,22 +92,21 @@ WMFVideoMFTManager::WMFVideoMFTManager(
   , mGotValidOutputAfterNullOutput(false)
   , mGotExcessiveNullOutput(false)
   // mVideoStride, mVideoWidth, mVideoHeight, mUseHwAccel are initialized in
   // Init().
 {
   MOZ_COUNT_CTOR(WMFVideoMFTManager);
 
   // Need additional checks/params to check vp8/vp9
-  if (aConfig.mMimeType.EqualsLiteral("video/mp4") ||
-      aConfig.mMimeType.EqualsLiteral("video/avc")) {
+  if (MP4Decoder::IsH264(aConfig.mMimeType)) {
     mStreamType = H264;
-  } else if (aConfig.mMimeType.EqualsLiteral("video/webm; codecs=vp8")) {
+  } else if (VPXDecoder::IsVP8(aConfig.mMimeType)) {
     mStreamType = VP8;
-  } else if (aConfig.mMimeType.EqualsLiteral("video/webm; codecs=vp9")) {
+  } else if (VPXDecoder::IsVP9(aConfig.mMimeType)) {
     mStreamType = VP9;
   } else {
     mStreamType = Unknown;
   }
 }
 
 WMFVideoMFTManager::~WMFVideoMFTManager()
 {
--- a/dom/media/platforms/wrappers/H264Converter.cpp
+++ b/dom/media/platforms/wrappers/H264Converter.cpp
@@ -236,17 +236,9 @@ H264Converter::UpdateConfigFromExtraData
     mCurrentConfig.mImage.width = spsdata.pic_width;
     mCurrentConfig.mImage.height = spsdata.pic_height;
     mCurrentConfig.mDisplay.width = spsdata.display_width;
     mCurrentConfig.mDisplay.height = spsdata.display_height;
   }
   mCurrentConfig.mExtraData = aExtraData;
 }
 
-/* static */
-bool
-H264Converter::IsH264(const TrackInfo& aConfig)
-{
-  return aConfig.mMimeType.EqualsLiteral("video/avc") ||
-    aConfig.mMimeType.EqualsLiteral("video/mp4");
-}
-
 } // namespace mozilla
--- a/dom/media/platforms/wrappers/H264Converter.h
+++ b/dom/media/platforms/wrappers/H264Converter.h
@@ -34,18 +34,16 @@ public:
   const char* GetDescriptionName() const override
   {
     if (mDecoder) {
       return mDecoder->GetDescriptionName();
     }
     return "H264Converter decoder (pending)";
   }
 
-  // Return true if mimetype is H.264.
-  static bool IsH264(const TrackInfo& aConfig);
   nsresult GetLastError() const { return mLastError; }
 
 private:
   // Will create the required MediaDataDecoder if need AVCC and we have a SPS NAL.
   // Returns NS_ERROR_FAILURE if error is permanent and can't be recovered and
   // will set mError accordingly.
   nsresult CreateDecoder(DecoderDoctorDiagnostics* aDiagnostics);
   nsresult CreateDecoderAndInit(MediaRawData* aSample);