Bug 1259212 - WMFDecoderModule::Supports tries to create decoder - r?mattwoodrow draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 21 Oct 2016 17:51:35 +1100
changeset 428502 fdc791ab678ac0568a2d602b1d645c4b83a00f8f
parent 428501 50cee623f15e5ae552d1cb909a94d2e1c6650833
child 428503 5905ebd75f9529c92110290fc1d0cd9d88551f93
push id33314
push usergsquelart@mozilla.com
push dateMon, 24 Oct 2016 02:23:32 +0000
reviewersmattwoodrow
bugs1259212
milestone52.0a1
Bug 1259212 - WMFDecoderModule::Supports tries to create decoder - r?mattwoodrow If we are given any size or rate information, outright reject insanely-high values. This is actually used by YouTube to sense whether the browser reads these parameters, in which case YouTube will then probe for exact size&rate combinations. If we are given a size&rate, try to create a decoder with the relevant track informations, to see if the decoder really supports them. Note that the actual decoder check will be implemented in later patches. MozReview-Commit-ID: vlXlOj5Aw8
dom/media/platforms/wmf/WMFDecoderModule.cpp
--- a/dom/media/platforms/wmf/WMFDecoderModule.cpp
+++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp
@@ -7,19 +7,21 @@
 #include "WMF.h"
 #include "WMFDecoderModule.h"
 #include "WMFVideoMFTManager.h"
 #include "WMFAudioMFTManager.h"
 #include "MFTDecoder.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Services.h"
 #include "WMFMediaDataDecoder.h"
+#include "Layers.h"
 #include "nsAutoPtr.h"
 #include "nsIWindowsRegKey.h"
 #include "nsComponentManagerUtils.h"
+#include "nsContentUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIGfxInfo.h"
 #include "nsWindowsHelpers.h"
 #include "GfxDriverInfo.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "MediaInfo.h"
 #include "MediaPrefs.h"
 #include "prsystem.h"
@@ -211,29 +213,52 @@ WMFDecoderModule::Supports(const TrackIn
        WMFDecoderModule::HasAAC()) {
     return true;
   }
   if (MP4Decoder::IsH264(aTrackInfo.mMimeType) && WMFDecoderModule::HasH264()) {
     const VideoInfo* videoInfo = aTrackInfo.GetAsVideoInfo();
     MOZ_ASSERT(videoInfo);
     int32_t w = videoInfo->mImage.width;
     int32_t h = videoInfo->mImage.height;
+    uint32_t fr = videoInfo->mFramerate;
+    if (w >= 99999 || h >= 99999 || fr >= 9999) {
+      // Size/rate way too big.
+      // Also signals to YouTube that we can deal with these values, so that
+      // more precise size+rate combinations will be queried.
+      return false;
+    }
     // Check Windows format constraints, based on:
     // https://msdn.microsoft.com/en-us/library/windows/desktop/dd797815(v=vs.85).aspx
     if (IsWin8OrLater()) {
       // Windows >7 supports at most 4096x2304.
       if (w > 4096 || h > 2304) {
         return false;
       }
     } else {
       // Windows <=7 supports at most 1920x1088.
       if (w > 1920 || h > 1088) {
         return false;
       }
     }
+    if (w > 0 && h > 0 && fr > 0) {
+      // Got size&rate -> Try to create decoder with this track information.
+      // Some drivers can check if this configuration is not supported, in
+      // which case the decoder creation will fail.
+      RefPtr<LayerManager> layerManager =
+        nsContentUtils::LayerManagerForDocument(aDoc);
+      ShadowLayerForwarder* knowsCompositor = layerManager
+                                              ? layerManager->AsShadowForwarder()
+                                              : nullptr;
+      RefPtr<MediaDataDecoder> decoder =
+        const_cast<WMFDecoderModule*>(this)->
+        CreateVideoDecoder(CreateDecoderParams(aTrackInfo, knowsCompositor));
+      if (!decoder) {
+        return false;
+      }
+    }
     return true;
   }
   if (aTrackInfo.mMimeType.EqualsLiteral("audio/mpeg") &&
       CanCreateWMFDecoder<CLSID_CMP3DecMediaObject>()) {
     return true;
   }
   if (MediaPrefs::PDMWMFIntelDecoderEnabled() && sDXVAEnabled) {
     if (VPXDecoder::IsVP8(aTrackInfo.mMimeType) &&