Bug 944088 - Make MP4Reader::Init() assume mLayersBackendType=LAYERS_NONE if it doesn't have a decoder owner. r=kinetik
authorChris Pearce <cpearce@mozilla.com>
Thu, 28 Nov 2013 11:12:22 +1300
changeset 173467 499c81cdff30765f7a563c61faff15e56650119d
parent 173466 234a044ca9425ea538eaec00cbb64d333529657d
child 173468 49a6738fa2500300aca5b7ffd0afc32c9dcc3d75
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)
reviewerskinetik
bugs944088
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 944088 - Make MP4Reader::Init() assume mLayersBackendType=LAYERS_NONE if it doesn't have a decoder owner. r=kinetik This ensures that if the MP4Reader fails to get a decoder owner, we don't abort the media load, but instead we will assume that we don't have an advanced layers backend, and so fallback to software decoding on Windows.
content/media/fmp4/MP4Reader.cpp
content/media/fmp4/MP4Reader.h
--- a/content/media/fmp4/MP4Reader.cpp
+++ b/content/media/fmp4/MP4Reader.cpp
@@ -88,42 +88,53 @@ MP4Reader::MP4Reader(AbstractMediaDecode
   MOZ_COUNT_CTOR(MP4Reader);
 }
 
 MP4Reader::~MP4Reader()
 {
   MOZ_COUNT_DTOR(MP4Reader);
 }
 
+void
+MP4Reader::InitLayersBackendType()
+{
+  if (!IsVideoContentType(mDecoder->GetResource()->GetContentType())) {
+    // Not playing video, we don't care about the layers backend type.
+    return;
+  }
+  // Extract the layer manager backend type so that platform decoders
+  // can determine whether it's worthwhile using hardware accelerated
+  // video decoding.
+  MediaDecoderOwner* owner = mDecoder->GetOwner();
+  if (!owner) {
+    NS_WARNING("MP4Reader without a decoder owner, can't get HWAccel");
+    return;
+  }
+
+  dom::HTMLMediaElement* element = owner->GetMediaElement();
+  NS_ENSURE_TRUE_VOID(element);
+
+  nsRefPtr<LayerManager> layerManager =
+    nsContentUtils::LayerManagerForDocument(element->OwnerDoc());
+  NS_ENSURE_TRUE_VOID(layerManager);
+
+  mLayersBackendType = layerManager->GetBackendType();
+}
+
 nsresult
 MP4Reader::Init(MediaDecoderReader* aCloneDonor)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
   mMP4Stream = new MP4Stream(mDecoder->GetResource());
   mDemuxer = new MP4Demuxer(mMP4Stream);
 
   mPlatform = PlatformDecoderModule::Create();
   NS_ENSURE_TRUE(mPlatform, NS_ERROR_FAILURE);
 
-  if (IsVideoContentType(mDecoder->GetResource()->GetContentType())) {
-    // Extract the layer manager backend type so that platform decoders
-    // can determine whether it's worthwhile using hardware accelerated
-    // video decoding.
-    MediaDecoderOwner* owner = mDecoder->GetOwner();
-    NS_ENSURE_TRUE(owner, NS_ERROR_FAILURE);
-
-    dom::HTMLMediaElement* element = owner->GetMediaElement();
-    NS_ENSURE_TRUE(element, NS_ERROR_FAILURE);
-
-    nsRefPtr<LayerManager> layerManager =
-      nsContentUtils::LayerManagerForDocument(element->OwnerDoc());
-    NS_ENSURE_TRUE(layerManager, NS_ERROR_FAILURE);
-
-    mLayersBackendType = layerManager->GetBackendType();
-  }
+  InitLayersBackendType();
 
   return NS_OK;
 }
 
 nsresult
 MP4Reader::ReadMetadata(MediaInfo* aInfo,
                         MetadataTags** aTags)
 {
--- a/content/media/fmp4/MP4Reader.h
+++ b/content/media/fmp4/MP4Reader.h
@@ -48,16 +48,18 @@ public:
                         int64_t aStartTime,
                         int64_t aEndTime,
                         int64_t aCurrentTime) MOZ_OVERRIDE;
 
   virtual void OnDecodeThreadStart() MOZ_OVERRIDE;
   virtual void OnDecodeThreadFinish() MOZ_OVERRIDE;
 
 private:
+  // Initializes mLayersBackendType if possible.
+  void InitLayersBackendType();
 
   MP4SampleQueue& SampleQueue(mp4_demuxer::TrackType aTrack);
 
   // Blocks until the demuxer produces an sample of specified type.
   // Returns nullptr on error on EOS. Caller must delete sample.
   mp4_demuxer::MP4Sample* PopSample(mp4_demuxer::TrackType aTrack);
 
   bool Decode(mp4_demuxer::TrackType aTrack,