Bug 1176218 - p13. Reject Resolutions that are too big for Windows' decoder - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 07 Oct 2016 15:51:34 +1100
changeset 317122 4429c8701a840b4b08c28507e909a429d37916d5
parent 317121 82be75a8428869b9c80db58a8789cab7bc1c01cf
child 317123 52bba388b92a30b8c5ca203336561f02861ba3c2
push id20681
push userphilringnalda@gmail.com
push dateSat, 08 Oct 2016 23:57:20 +0000
treeherderfx-team@7a7ba250bb2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1176218
milestone52.0a1
Bug 1176218 - p13. Reject Resolutions that are too big for Windows' decoder - r=jya The WMFDecoderModule can override Supports(TrackInfo) to reject resolutions that we know are too big for the platform decoder. MozReview-Commit-ID: dU905wjZcJ
dom/media/platforms/wmf/WMFDecoderModule.cpp
dom/media/platforms/wmf/WMFDecoderModule.h
--- a/dom/media/platforms/wmf/WMFDecoderModule.cpp
+++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp
@@ -20,16 +20,17 @@
 #include "nsWindowsHelpers.h"
 #include "GfxDriverInfo.h"
 #include "mozilla/gfx/gfxVars.h"
 #include "MediaInfo.h"
 #include "MediaPrefs.h"
 #include "prsystem.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/StaticMutex.h"
+#include "mozilla/WindowsVersion.h"
 #include "MP4Decoder.h"
 #include "VPXDecoder.h"
 
 namespace mozilla {
 
 static Atomic<bool> sDXVAEnabled(false);
 
 WMFDecoderModule::WMFDecoderModule()
@@ -188,34 +189,60 @@ WMFDecoderModule::HasAAC()
 {
   return CanCreateWMFDecoder<CLSID_CMSAACDecMFT>();
 }
 
 bool
 WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType,
                                    DecoderDoctorDiagnostics* aDiagnostics) const
 {
-  if ((aMimeType.EqualsLiteral("audio/mp4a-latm") ||
-       aMimeType.EqualsLiteral("audio/mp4")) &&
+  UniquePtr<TrackInfo> trackInfo = CreateTrackInfoWithMIMEType(aMimeType);
+  if (!trackInfo) {
+    return false;
+  }
+  return Supports(*trackInfo, aDiagnostics);
+}
+
+bool
+WMFDecoderModule::Supports(const TrackInfo& aTrackInfo,
+                           DecoderDoctorDiagnostics* aDiagnostics) const
+{
+  if ((aTrackInfo.mMimeType.EqualsLiteral("audio/mp4a-latm") ||
+       aTrackInfo.mMimeType.EqualsLiteral("audio/mp4")) &&
        WMFDecoderModule::HasAAC()) {
     return true;
   }
-  if (MP4Decoder::IsH264(aMimeType) && WMFDecoderModule::HasH264()) {
+  if (MP4Decoder::IsH264(aTrackInfo.mMimeType) && WMFDecoderModule::HasH264()) {
+    const VideoInfo* videoInfo = aTrackInfo.GetAsVideoInfo();
+    MOZ_ASSERT(videoInfo);
+    // 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 (videoInfo->mImage.width > 4096 || videoInfo->mImage.height > 2304) {
+        return false;
+      }
+    } else {
+      // Windows <=7 supports at most 1920x1088.
+      if (videoInfo->mImage.width > 1920 || videoInfo->mImage.height > 1088) {
+        return false;
+      }
+    }
     return true;
   }
-  if (aMimeType.EqualsLiteral("audio/mpeg") &&
+  if (aTrackInfo.mMimeType.EqualsLiteral("audio/mpeg") &&
       CanCreateWMFDecoder<CLSID_CMP3DecMediaObject>()) {
     return true;
   }
   if (MediaPrefs::PDMWMFIntelDecoderEnabled() && sDXVAEnabled) {
-    if (VPXDecoder::IsVP8(aMimeType) &&
+    if (VPXDecoder::IsVP8(aTrackInfo.mMimeType) &&
         CanCreateWMFDecoder<CLSID_WebmMfVp8Dec>()) {
       return true;
     }
-    if (VPXDecoder::IsVP9(aMimeType) &&
+    if (VPXDecoder::IsVP9(aTrackInfo.mMimeType) &&
         CanCreateWMFDecoder<CLSID_WebmMfVp9Dec>()) {
       return true;
     }
   }
 
   // Some unsupported codec.
   return false;
 }
--- a/dom/media/platforms/wmf/WMFDecoderModule.h
+++ b/dom/media/platforms/wmf/WMFDecoderModule.h
@@ -22,16 +22,18 @@ public:
   already_AddRefed<MediaDataDecoder>
   CreateVideoDecoder(const CreateDecoderParams& aParams) override;
 
   already_AddRefed<MediaDataDecoder>
   CreateAudioDecoder(const CreateDecoderParams& aParams) override;
 
   bool SupportsMimeType(const nsACString& aMimeType,
                         DecoderDoctorDiagnostics* aDiagnostics) const override;
+  bool Supports(const TrackInfo& aTrackInfo,
+                DecoderDoctorDiagnostics* aDiagnostics) const override;
 
   ConversionRequired
   DecoderNeedsConversion(const TrackInfo& aConfig) const override;
 
   // Called on main thread.
   static void Init();
 
   // Called from any thread, must call init first