Bug 945645 - Only init WMF video decoding if we have a video container. r=padenot, a=bajaj
authorChris Pearce <cpearce@mozilla.com>
Tue, 07 Jan 2014 14:36:12 +1300
changeset 175634 c0cb72104db65edd3acb7e73bcf9abdb2b9117c5
parent 175633 617552f36f090497afe041e670f0e7d085a5f800
child 175635 fe978d81ac30c365a13e999a2370064f196cb436
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, bajaj
bugs945645
milestone28.0a2
Bug 945645 - Only init WMF video decoding if we have a video container. r=padenot, a=bajaj
content/media/wmf/WMFReader.cpp
--- a/content/media/wmf/WMFReader.cpp
+++ b/content/media/wmf/WMFReader.cpp
@@ -100,16 +100,17 @@ WMFReader::OnDecodeThreadFinish()
 }
 
 bool
 WMFReader::InitializeDXVA()
 {
   if (!Preferences::GetBool("media.windows-media-foundation.use-dxva", false)) {
     return false;
   }
+  MOZ_ASSERT(mDecoder->GetImageContainer());
 
   // Extract the layer manager backend type so that we can determine
   // whether it's worthwhile using DXVA. If we're not running with a D3D
   // layer manager then the readback of decoded video frames from GPU to
   // CPU memory grinds painting to a halt, and makes playback performance
   // *worse*.
   MediaDecoderOwner* owner = mDecoder->GetOwner();
   NS_ENSURE_TRUE(owner, false);
@@ -146,17 +147,18 @@ WMFReader::Init(MediaDecoderReader* aClo
 
   mSourceReaderCallback = new WMFSourceReaderCallback();
 
   // Must be created on main thread.
   mByteStream = new WMFByteStream(mDecoder->GetResource(), mSourceReaderCallback);
   rv = mByteStream->Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (IsVideoContentType(mDecoder->GetResource()->GetContentType())) {
+  if (mDecoder->GetImageContainer() != nullptr &&
+      IsVideoContentType(mDecoder->GetResource()->GetContentType())) {
     mUseHwAccel = InitializeDXVA();
   } else {
     mUseHwAccel = false;
   }
 
   return NS_OK;
 }
 
@@ -340,16 +342,21 @@ WMFReader::ConfigureVideoDecoder()
 
   // Determine if we have video.
   if (!mSourceReader ||
       !SourceReaderHasStream(mSourceReader, MF_SOURCE_READER_FIRST_VIDEO_STREAM)) {
     // No stream, no error.
     return S_OK;
   }
 
+  if (!mDecoder->GetImageContainer()) {
+    // We can't display the video, so don't bother to decode; disable the stream.
+    return mSourceReader->SetStreamSelection(MF_SOURCE_READER_FIRST_VIDEO_STREAM, FALSE);
+  }
+
   static const GUID MP4VideoTypes[] = {
     MFVideoFormat_H264
   };
   HRESULT hr = ConfigureSourceReaderStream(mSourceReader,
                                            MF_SOURCE_READER_FIRST_VIDEO_STREAM,
                                            mUseHwAccel ? MFVideoFormat_NV12 : MFVideoFormat_YV12,
                                            MP4VideoTypes,
                                            NS_ARRAY_LENGTH(MP4VideoTypes));