Bug 1128380: Add IsHardwareAccelerated implementation for AVCC and mac decoder. r=cpearce
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 09 Mar 2015 14:17:27 +1100
changeset 232491 8cdf05d1d04dcbc322b282ee53d56e70d05ecdba
parent 232490 3bd19a1cf4b419351c62670c3215be27cc9ef962
child 232492 9506fff39d1cdcf3fe3539ca8bc74d32d07ba006
push id28384
push usercbook@mozilla.com
push dateMon, 09 Mar 2015 12:46:25 +0000
treeherdermozilla-central@23f1f0369df5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1128380
milestone39.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 1128380: Add IsHardwareAccelerated implementation for AVCC and mac decoder. r=cpearce
dom/media/fmp4/AVCCDecoderModule.cpp
dom/media/fmp4/apple/AppleVDADecoder.h
dom/media/fmp4/apple/AppleVTDecoder.cpp
dom/media/fmp4/apple/AppleVTDecoder.h
--- a/dom/media/fmp4/AVCCDecoderModule.cpp
+++ b/dom/media/fmp4/AVCCDecoderModule.cpp
@@ -30,16 +30,17 @@ public:
   virtual nsresult Flush() MOZ_OVERRIDE;
   virtual nsresult Drain() MOZ_OVERRIDE;
   virtual nsresult Shutdown() MOZ_OVERRIDE;
   virtual bool IsWaitingMediaResources() MOZ_OVERRIDE;
   virtual bool IsDormantNeeded() MOZ_OVERRIDE;
   virtual void AllocateMediaResources() MOZ_OVERRIDE;
   virtual void ReleaseMediaResources() MOZ_OVERRIDE;
   virtual void ReleaseDecoder() MOZ_OVERRIDE;
+  virtual bool IsHardwareAccelerated() const MOZ_OVERRIDE;
 
 private:
   // Will create the required MediaDataDecoder if we have a AVC SPS.
   // Returns NS_ERROR_FAILURE if error is permanent and can't be recovered and
   // will set mError accordingly.
   nsresult CreateDecoder();
   nsresult CreateDecoderAndInit(mp4_demuxer::MP4Sample* aSample);
 
@@ -206,16 +207,25 @@ AVCCMediaDataDecoder::CreateDecoderAndIn
   }
   mCurrentConfig.extra_data = extra_data;
 
   nsresult rv = CreateDecoder();
   NS_ENSURE_SUCCESS(rv, rv);
   return Init();
 }
 
+bool
+AVCCMediaDataDecoder::IsHardwareAccelerated() const
+{
+  if (mDecoder) {
+    return mDecoder->IsHardwareAccelerated();
+  }
+  return MediaDataDecoder::IsHardwareAccelerated();
+}
+
 // AVCCDecoderModule
 
 AVCCDecoderModule::AVCCDecoderModule(PlatformDecoderModule* aPDM)
 : mPDM(aPDM)
 {
   MOZ_ASSERT(aPDM);
 }
 
--- a/dom/media/fmp4/apple/AppleVDADecoder.h
+++ b/dom/media/fmp4/apple/AppleVDADecoder.h
@@ -70,16 +70,20 @@ public:
                   MediaDataDecoderCallback* aCallback,
                   layers::ImageContainer* aImageContainer);
   virtual ~AppleVDADecoder();
   virtual nsresult Init() MOZ_OVERRIDE;
   virtual nsresult Input(mp4_demuxer::MP4Sample* aSample) MOZ_OVERRIDE;
   virtual nsresult Flush() MOZ_OVERRIDE;
   virtual nsresult Drain() MOZ_OVERRIDE;
   virtual nsresult Shutdown() MOZ_OVERRIDE;
+  virtual bool IsHardwareAccelerated() const MOZ_OVERRIDE
+  {
+    return true;
+  }
 
   nsresult OutputFrame(CVPixelBufferRef aImage,
                        nsAutoPtr<AppleFrameRef> aFrameRef);
 
  protected:
   AppleFrameRef* CreateAppleFrameRef(const mp4_demuxer::MP4Sample* aSample);
   void DrainReorderedFrames();
   void ClearReorderedFrames();
--- a/dom/media/fmp4/apple/AppleVTDecoder.cpp
+++ b/dom/media/fmp4/apple/AppleVTDecoder.cpp
@@ -36,16 +36,17 @@ namespace mozilla {
 
 AppleVTDecoder::AppleVTDecoder(const mp4_demuxer::VideoDecoderConfig& aConfig,
                                FlushableMediaTaskQueue* aVideoTaskQueue,
                                MediaDataDecoderCallback* aCallback,
                                layers::ImageContainer* aImageContainer)
   : AppleVDADecoder(aConfig, aVideoTaskQueue, aCallback, aImageContainer)
   , mFormat(nullptr)
   , mSession(nullptr)
+  , mIsHardwareAccelerated(false)
 {
   MOZ_COUNT_CTOR(AppleVTDecoder);
   // TODO: Verify aConfig.mime_type.
   LOG("Creating AppleVTDecoder for %dx%d h.264 video",
       mConfig.image_width,
       mConfig.image_height
      );
 }
@@ -309,18 +310,19 @@ AppleVTDecoder::InitializeSession()
     CFBooleanRef isUsingHW = nullptr;
     rv = VTSessionCopyProperty(mSession,
                                AppleVTLinker::skPropUsingHWAccel,
                                kCFAllocatorDefault,
                                &isUsingHW);
     if (rv != noErr) {
       LOG("AppleVTDecoder: system doesn't support hardware acceleration");
     }
+    mIsHardwareAccelerated = rv == noErr && isUsingHW == kCFBooleanTrue;
     LOG("AppleVTDecoder: %s hardware accelerated decoding",
-        (rv == noErr && isUsingHW == kCFBooleanTrue) ? "using" : "not using");
+        mIsHardwareAccelerated ? "using" : "not using");
   } else {
     LOG("AppleVTDecoder: couldn't determine hardware acceleration status.");
   }
   return NS_OK;
 }
 
 CFDictionaryRef
 AppleVTDecoder::CreateDecoderExtensions()
--- a/dom/media/fmp4/apple/AppleVTDecoder.h
+++ b/dom/media/fmp4/apple/AppleVTDecoder.h
@@ -20,25 +20,30 @@ public:
                  MediaDataDecoderCallback* aCallback,
                  layers::ImageContainer* aImageContainer);
   virtual ~AppleVTDecoder();
   virtual nsresult Init() MOZ_OVERRIDE;
   virtual nsresult Input(mp4_demuxer::MP4Sample* aSample) MOZ_OVERRIDE;
   virtual nsresult Flush() MOZ_OVERRIDE;
   virtual nsresult Drain() MOZ_OVERRIDE;
   virtual nsresult Shutdown() MOZ_OVERRIDE;
+  virtual bool IsHardwareAccelerated() const MOZ_OVERRIDE
+  {
+    return mIsHardwareAccelerated;
+  }
 
 private:
   CMVideoFormatDescriptionRef mFormat;
   VTDecompressionSessionRef mSession;
 
   // Method to pass a frame to VideoToolbox for decoding.
   nsresult SubmitFrame(mp4_demuxer::MP4Sample* aSample);
   // Method to set up the decompression session.
   nsresult InitializeSession();
   nsresult WaitForAsynchronousFrames();
   CFDictionaryRef CreateDecoderSpecification();
   CFDictionaryRef CreateDecoderExtensions();
+  bool mIsHardwareAccelerated;
 };
 
 } // namespace mozilla
 
 #endif // mozilla_AppleVTDecoder_h