Bug 1133633 - Part 1: Add logging reporting if we are using HW accelerated decode. r=rillian, a=lmandel
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 19 Feb 2015 15:37:08 +1300
changeset 250120 85e3bc280be6
parent 250119 e8a752491ccc
child 250121 1ba1e8df6e2f
push id4504
push userryanvm@gmail.com
push date2015-02-27 21:53 +0000
treeherdermozilla-beta@7bbbe05d19d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, lmandel
bugs1133633
milestone37.0
Bug 1133633 - Part 1: Add logging reporting if we are using HW accelerated decode. r=rillian, a=lmandel
dom/media/fmp4/apple/AppleDecoderModule.cpp
dom/media/fmp4/apple/AppleVTDecoder.cpp
dom/media/fmp4/apple/AppleVTFunctions.h
dom/media/fmp4/apple/AppleVTLinker.cpp
dom/media/fmp4/apple/AppleVTLinker.h
dom/media/fmp4/apple/VideoToolbox/VideoToolbox.h
--- a/dom/media/fmp4/apple/AppleDecoderModule.cpp
+++ b/dom/media/fmp4/apple/AppleDecoderModule.cpp
@@ -59,17 +59,17 @@ AppleDecoderModule::Init()
   // dlopen CoreMedia.framework if it's available.
   bool haveCoreMedia = AppleCMLinker::Link();
   // dlopen VideoToolbox.framework if it's available.
   // We must link both CM and VideoToolbox framework to allow for proper
   // paired Link/Unlink calls
   bool haveVideoToolbox = AppleVTLinker::Link();
   sIsVTAvailable = haveCoreMedia && haveVideoToolbox;
 
-  sIsVTHWAvailable = AppleVTLinker::skPropHWAccel != nullptr;
+  sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr;
 
   if (sIsVDAAvailable) {
     AppleVDALinker::Unlink();
   }
   if (sIsVTAvailable) {
     AppleVTLinker::Unlink();
     AppleCMLinker::Unlink();
   }
--- a/dom/media/fmp4/apple/AppleVTDecoder.cpp
+++ b/dom/media/fmp4/apple/AppleVTDecoder.cpp
@@ -300,16 +300,30 @@ AppleVTDecoder::InitializeSession()
                                     &cb,
                                     &mSession);
 
   if (rv != noErr) {
     NS_ERROR("Couldn't create decompression session!");
     return NS_ERROR_FAILURE;
   }
 
+  if (AppleVTLinker::skPropUsingHWAccel) {
+    CFBooleanRef isUsingHW = nullptr;
+    rv = VTSessionCopyProperty(mSession,
+                               AppleVTLinker::skPropUsingHWAccel,
+                               kCFAllocatorDefault,
+                               &isUsingHW);
+    if (rv != noErr) {
+      LOG("AppleVTDecoder: system doesn't support hardware acceleration");
+    }
+    LOG("AppleVTDecoder: %s hardware accelerated decoding",
+        (rv == noErr && isUsingHW == kCFBooleanTrue) ? "using" : "not using");
+  } else {
+    LOG("AppleVTDecoder: couldn't determine hardware acceleration status.");
+  }
   return NS_OK;
 }
 
 CFDictionaryRef
 AppleVTDecoder::CreateDecoderExtensions()
 {
   AutoCFRelease<CFDataRef> avc_data =
     CFDataCreate(kCFAllocatorDefault,
@@ -351,21 +365,21 @@ AppleVTDecoder::CreateDecoderExtensions(
                               ArrayLength(extensionKeys) - 1,
                             &kCFTypeDictionaryKeyCallBacks,
                             &kCFTypeDictionaryValueCallBacks);
 }
 
 CFDictionaryRef
 AppleVTDecoder::CreateDecoderSpecification()
 {
-  if (!AppleVTLinker::skPropHWAccel) {
+  if (!AppleVTLinker::skPropEnableHWAccel) {
     return nullptr;
   }
 
-  const void* specKeys[] = { AppleVTLinker::skPropHWAccel };
+  const void* specKeys[] = { AppleVTLinker::skPropEnableHWAccel };
   const void* specValues[] = { kCFBooleanTrue };
   static_assert(ArrayLength(specKeys) == ArrayLength(specValues),
                 "Non matching keys/values array size");
 
   return CFDictionaryCreate(kCFAllocatorDefault,
                             specKeys,
                             specValues,
                             ArrayLength(specKeys),
--- a/dom/media/fmp4/apple/AppleVTFunctions.h
+++ b/dom/media/fmp4/apple/AppleVTFunctions.h
@@ -5,8 +5,10 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Construct references to each of the VideoToolbox symbols we use.
 
 LINK_FUNC(VTDecompressionSessionCreate)
 LINK_FUNC(VTDecompressionSessionDecodeFrame)
 LINK_FUNC(VTDecompressionSessionInvalidate)
 LINK_FUNC(VTDecompressionSessionWaitForAsynchronousFrames)
+LINK_FUNC(VTSessionCopyProperty)
+LINK_FUNC(VTSessionCopySupportedPropertyDictionary)
--- a/dom/media/fmp4/apple/AppleVTLinker.cpp
+++ b/dom/media/fmp4/apple/AppleVTLinker.cpp
@@ -20,17 +20,18 @@ PRLogModuleInfo* GetAppleMediaLog();
 
 namespace mozilla {
 
 AppleVTLinker::LinkStatus
 AppleVTLinker::sLinkStatus = LinkStatus_INIT;
 
 void* AppleVTLinker::sLink = nullptr;
 nsrefcnt AppleVTLinker::sRefCount = 0;
-CFStringRef AppleVTLinker::skPropHWAccel = nullptr;
+CFStringRef AppleVTLinker::skPropEnableHWAccel = nullptr;
+CFStringRef AppleVTLinker::skPropUsingHWAccel = nullptr;
 
 #define LINK_FUNC(func) typeof(func) func;
 #include "AppleVTFunctions.h"
 #undef LINK_FUNC
 
 /* static */ bool
 AppleVTLinker::Link()
 {
@@ -64,18 +65,20 @@ AppleVTLinker::Link()
   if (!func) {                                                 \
     NS_WARNING("Couldn't load VideoToolbox function " #func ); \
     goto fail;                                                 \
   }
 #include "AppleVTFunctions.h"
 #undef LINK_FUNC
 
   // Will only resolve in 10.9 and later.
-  skPropHWAccel =
+  skPropEnableHWAccel =
     GetIOConst("kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder");
+  skPropUsingHWAccel =
+    GetIOConst("kVTDecompressionPropertyKey_UsingHardwareAcceleratedVideoDecoder");
 
   LOG("Loaded VideoToolbox framework.");
   sLinkStatus = LinkStatus_SUCCEEDED;
   return true;
 
 fail:
   Unlink();
 
@@ -92,17 +95,18 @@ AppleVTLinker::Unlink()
   // instances still need them.
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(sRefCount > 0, "Unbalanced Unlink()");
   --sRefCount;
   if (sLink && sRefCount < 1) {
     LOG("Unlinking VideoToolbox framework.");
     dlclose(sLink);
     sLink = nullptr;
-    skPropHWAccel = nullptr;
+    skPropEnableHWAccel = nullptr;
+    skPropUsingHWAccel = nullptr;
     sLinkStatus = LinkStatus_INIT;
   }
 }
 
 /* static */ CFStringRef
 AppleVTLinker::GetIOConst(const char* symbol)
 {
   CFStringRef* address = (CFStringRef*)dlsym(sLink, symbol);
--- a/dom/media/fmp4/apple/AppleVTLinker.h
+++ b/dom/media/fmp4/apple/AppleVTLinker.h
@@ -17,17 +17,18 @@ extern "C" {
 
 namespace mozilla {
 
 class AppleVTLinker
 {
 public:
   static bool Link();
   static void Unlink();
-  static CFStringRef skPropHWAccel;
+  static CFStringRef skPropEnableHWAccel;
+  static CFStringRef skPropUsingHWAccel;
 
 private:
   static void* sLink;
   static nsrefcnt sRefCount;
 
   static enum LinkStatus {
     LinkStatus_INIT = 0,
     LinkStatus_FAILED,
--- a/dom/media/fmp4/apple/VideoToolbox/VideoToolbox.h
+++ b/dom/media/fmp4/apple/VideoToolbox/VideoToolbox.h
@@ -21,16 +21,17 @@
 
 typedef uint32_t VTDecodeFrameFlags;
 typedef uint32_t VTDecodeInfoFlags;
 enum {
   kVTDecodeInfo_Asynchronous = 1UL << 0,
   kVTDecodeInfo_FrameDropped = 1UL << 1,
 };
 
+typedef CFTypeRef VTSessionRef;
 typedef struct OpaqueVTDecompressionSession* VTDecompressionSessionRef;
 typedef void (*VTDecompressionOutputCallback)(
     void*,
     void*,
     OSStatus,
     VTDecodeInfoFlags,
     CVImageBufferRef,
     CMTime,
@@ -65,9 +66,23 @@ VTDecompressionSessionWaitForAsynchronou
     VTDecompressionSessionRef
 );
 
 void
 VTDecompressionSessionInvalidate(
     VTDecompressionSessionRef
 );
 
+OSStatus
+VTSessionCopyProperty(
+    VTSessionRef,
+    CFStringRef,
+    CFAllocatorRef,
+    void*
+);
+
+OSStatus
+VTSessionCopySupportedPropertyDictionary(
+    VTSessionRef,
+    CFDictionaryRef*
+);
+
 #endif // mozilla_VideoToolbox_VideoToolbox_h