Bug 1425277 - p2: remove dynamic apple framework linkers. r=jya No need for own linkers anymore for CoreMedia and VideoToolbox are both available on our minimal supported version (10.9).
authorJohn Lin <jolin@mozilla.com>
Mon, 26 Nov 2018 18:27:32 +0000
changeset 507288 d1255f131fe48038f7b5167edad7cd3becc24958
parent 507287 725677ef4b8ede4401b7ffb71dd627be2a8ccea5
child 507289 4dd46901846aff3dd5c512cf21e05957a73ff6b0
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1425277
milestone65.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 1425277 - p2: remove dynamic apple framework linkers. r=jya No need for own linkers anymore for CoreMedia and VideoToolbox are both available on our minimal supported version (10.9). Differential Revision: https://phabricator.services.mozilla.com/D7558
dom/media/platforms/apple/AppleCMFunctions.h
dom/media/platforms/apple/AppleDecoderModule.cpp
dom/media/platforms/apple/AppleDecoderModule.cpp.rej
dom/media/platforms/apple/AppleDecoderModule.h
dom/media/platforms/apple/AppleVTDecoder.cpp
dom/media/platforms/apple/AppleVTDecoder.h
dom/media/platforms/apple/AppleVTFunctions.h
dom/media/platforms/moz.build
old-configure.in
deleted file mode 100644
--- a/dom/media/platforms/apple/AppleCMFunctions.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-// Construct references to each of the CoreMedia symbols we use.
-
-LINK_FUNC(VideoFormatDescriptionCreate)
-LINK_FUNC(BlockBufferCreateWithMemoryBlock)
-LINK_FUNC(SampleBufferCreate)
-LINK_FUNC(TimeMake)
--- a/dom/media/platforms/apple/AppleDecoderModule.cpp
+++ b/dom/media/platforms/apple/AppleDecoderModule.cpp
@@ -1,64 +1,48 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AppleATDecoder.h"
-#include "AppleCMLinker.h"
 #include "AppleDecoderModule.h"
 #include "AppleVTDecoder.h"
-#include "AppleVTLinker.h"
 #include "MacIOSurfaceImage.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Logging.h"
 #include "mozilla/gfx/gfxVars.h"
 
 namespace mozilla {
 
 bool AppleDecoderModule::sInitialized = false;
-bool AppleDecoderModule::sIsCoreMediaAvailable = false;
-bool AppleDecoderModule::sIsVTAvailable = false;
-bool AppleDecoderModule::sIsVTHWAvailable = false;
 bool AppleDecoderModule::sCanUseHardwareVideoDecoder = true;
 
 AppleDecoderModule::AppleDecoderModule() {}
 
 AppleDecoderModule::~AppleDecoderModule() {}
 
 /* static */
 void AppleDecoderModule::Init() {
   if (sInitialized) {
     return;
   }
 
   // Ensure IOSurface framework is loaded.
   MacIOSurfaceLib::LoadLibrary();
-  const bool loaded = MacIOSurfaceLib::isInit();
-
-  // dlopen CoreMedia.framework if it's available.
-  sIsCoreMediaAvailable = 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 = loaded && AppleVTLinker::Link();
-  sIsVTAvailable = sIsCoreMediaAvailable && haveVideoToolbox;
-
-  sIsVTHWAvailable = AppleVTLinker::skPropEnableHWAccel != nullptr;
 
   sCanUseHardwareVideoDecoder =
-      loaded && gfx::gfxVars::CanUseHardwareVideoDecoding();
+      MacIOSurfaceLib::isInit() && gfx::gfxVars::CanUseHardwareVideoDecoding();
 
   sInitialized = true;
 }
 
 nsresult AppleDecoderModule::Startup() {
-  if (!sInitialized || !sIsVTAvailable) {
+  if (!sInitialized) {
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 already_AddRefed<MediaDataDecoder> AppleDecoderModule::CreateVideoDecoder(
     const CreateDecoderParams& aParams) {
   RefPtr<MediaDataDecoder> decoder =
@@ -71,16 +55,15 @@ already_AddRefed<MediaDataDecoder> Apple
     const CreateDecoderParams& aParams) {
   RefPtr<MediaDataDecoder> decoder =
       new AppleATDecoder(aParams.AudioConfig(), aParams.mTaskQueue);
   return decoder.forget();
 }
 
 bool AppleDecoderModule::SupportsMimeType(
     const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const {
-  return (sIsCoreMediaAvailable &&
-          (aMimeType.EqualsLiteral("audio/mpeg") ||
-           aMimeType.EqualsLiteral("audio/mp4a-latm"))) ||
-         (sIsVTAvailable && (aMimeType.EqualsLiteral("video/mp4") ||
-                             aMimeType.EqualsLiteral("video/avc")));
+  return aMimeType.EqualsLiteral("audio/mpeg") ||
+         aMimeType.EqualsLiteral("audio/mp4a-latm") ||
+         aMimeType.EqualsLiteral("video/mp4") ||
+         aMimeType.EqualsLiteral("video/avc");
 }
 
 }  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/platforms/apple/AppleDecoderModule.cpp.rej
@@ -0,0 +1,12 @@
+diff a/dom/media/platforms/apple/AppleDecoderModule.cpp b/dom/media/platforms/apple/AppleDecoderModule.cpp	(rejected hunks)
+@@ -30,8 +30,8 @@ void AppleDecoderModule::Init() {
+   // Ensure IOSurface framework is loaded.
+   MacIOSurfaceLib::LoadLibrary();
+ 
+-  sCanUseHardwareVideoDecoder = MacIOSurfaceLib::isInit() &&
+-      gfx::gfxVars::CanUseHardwareVideoDecoding();
++  sCanUseHardwareVideoDecoder =
++      MacIOSurfaceLib::isInit() && gfx::gfxVars::CanUseHardwareVideoDecoding();
+ 
+   sInitialized = true;
+ }
--- a/dom/media/platforms/apple/AppleDecoderModule.h
+++ b/dom/media/platforms/apple/AppleDecoderModule.h
@@ -30,16 +30,13 @@ class AppleDecoderModule : public Platfo
                         DecoderDoctorDiagnostics* aDiagnostics) const override;
 
   static void Init();
 
   static bool sCanUseHardwareVideoDecoder;
 
  private:
   static bool sInitialized;
-  static bool sIsCoreMediaAvailable;
-  static bool sIsVTAvailable;
-  static bool sIsVTHWAvailable;
 };
 
 }  // namespace mozilla
 
 #endif  // mozilla_AppleDecoderModule_h
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -1,21 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#include <CoreFoundation/CFString.h>
+#include "AppleVTDecoder.h"
 
-#include "AppleVTDecoder.h"
-#include "AppleCMLinker.h"
 #include "AppleDecoderModule.h"
 #include "AppleUtils.h"
-#include "AppleVTLinker.h"
 #include "MacIOSurfaceImage.h"
 #include "MediaData.h"
 #include "mozilla/ArrayUtils.h"
 #include "H264.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Logging.h"
 #include "VideoUtils.h"
@@ -454,66 +451,63 @@ MediaResult AppleVTDecoder::InitializeSe
                                    outputConfiguration,  // Output video format.
                                    &cb, &mSession);
 
   if (rv != noErr) {
     return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                        RESULT_DETAIL("Couldn't create decompression session!"));
   }
 
-  if (AppleVTLinker::skPropUsingHWAccel) {
-    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",
-        mIsHardwareAccelerated ? "using" : "not using");
-  } else {
-    LOG("AppleVTDecoder: couldn't determine hardware acceleration status.");
+  CFBooleanRef isUsingHW = nullptr;
+  rv = VTSessionCopyProperty(
+      mSession,
+      kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder,
+      kCFAllocatorDefault, &isUsingHW);
+  if (rv != noErr) {
+    LOG("AppleVTDecoder: system doesn't support hardware acceleration");
   }
+  mIsHardwareAccelerated = rv == noErr && isUsingHW == kCFBooleanTrue;
+  LOG("AppleVTDecoder: %s hardware accelerated decoding",
+      mIsHardwareAccelerated ? "using" : "not using");
+
   return NS_OK;
 }
 
 CFDictionaryRef AppleVTDecoder::CreateDecoderExtensions() {
   AutoCFRelease<CFDataRef> avc_data = CFDataCreate(
       kCFAllocatorDefault, mExtraData->Elements(), mExtraData->Length());
 
   const void* atomsKey[] = {CFSTR("avcC")};
   const void* atomsValue[] = {avc_data};
   static_assert(ArrayLength(atomsKey) == ArrayLength(atomsValue),
                 "Non matching keys/values array size");
 
   AutoCFRelease<CFDictionaryRef> atoms = CFDictionaryCreate(
       kCFAllocatorDefault, atomsKey, atomsValue, ArrayLength(atomsKey),
       &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 
-  const void* extensionKeys[] = {kCVImageBufferChromaLocationBottomFieldKey,
-                                 kCVImageBufferChromaLocationTopFieldKey,
-                                 AppleCMLinker::skPropExtensionAtoms};
+  const void* extensionKeys[] = {
+      kCVImageBufferChromaLocationBottomFieldKey,
+      kCVImageBufferChromaLocationTopFieldKey,
+      kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms};
 
   const void* extensionValues[] = {kCVImageBufferChromaLocation_Left,
                                    kCVImageBufferChromaLocation_Left, atoms};
   static_assert(ArrayLength(extensionKeys) == ArrayLength(extensionValues),
                 "Non matching keys/values array size");
 
   return CFDictionaryCreate(kCFAllocatorDefault, extensionKeys, extensionValues,
                             ArrayLength(extensionKeys),
                             &kCFTypeDictionaryKeyCallBacks,
                             &kCFTypeDictionaryValueCallBacks);
 }
 
 CFDictionaryRef AppleVTDecoder::CreateDecoderSpecification() {
-  if (!AppleVTLinker::skPropEnableHWAccel) {
-    return nullptr;
-  }
-
-  const void* specKeys[] = {AppleVTLinker::skPropEnableHWAccel};
+  const void* specKeys[] = {
+      kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder};
   const void* specValues[1];
   if (AppleDecoderModule::sCanUseHardwareVideoDecoder) {
     specValues[0] = kCFBooleanTrue;
   } else {
     // This GPU is blacklisted for hardware decoding.
     specValues[0] = kCFBooleanFalse;
   }
   static_assert(ArrayLength(specKeys) == ArrayLength(specValues),
--- a/dom/media/platforms/apple/AppleVTDecoder.h
+++ b/dom/media/platforms/apple/AppleVTDecoder.h
@@ -2,24 +2,26 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_AppleVTDecoder_h
 #define mozilla_AppleVTDecoder_h
 
+#include <CoreFoundation/CFDictionary.h>  // For CFDictionaryRef
+#include <CoreMedia/CoreMedia.h>          // For CMVideoFormatDescriptionRef
+#include <VideoToolbox/VideoToolbox.h>    // For VTDecompressionSessionRef
+
 #include "PlatformDecoderModule.h"
 #include "mozilla/Atomics.h"
 #include "nsIThread.h"
 #include "ReorderQueue.h"
 #include "TimeUnits.h"
 
-#include "VideoToolbox/VideoToolbox.h"
-
 namespace mozilla {
 
 DDLoggedTypeDeclNameAndBase(AppleVTDecoder, MediaDataDecoder);
 
 class AppleVTDecoder : public MediaDataDecoder,
                        public DecoderDoctorLifeLogger<AppleVTDecoder> {
  public:
   AppleVTDecoder(const VideoInfo& aConfig, TaskQueue* aTaskQueue,
deleted file mode 100644
--- a/dom/media/platforms/apple/AppleVTFunctions.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * 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/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -84,23 +84,23 @@ if CONFIG['MOZ_OMX']:
     ]
 
 if CONFIG['MOZ_APPLEMEDIA']:
   EXPORTS += [
       'apple/AppleDecoderModule.h',
   ]
   UNIFIED_SOURCES += [
       'apple/AppleATDecoder.cpp',
-      'apple/AppleCMLinker.cpp',
       'apple/AppleDecoderModule.cpp',
       'apple/AppleVTDecoder.cpp',
-      'apple/AppleVTLinker.cpp',
   ]
   OS_LIBS += [
       '-framework AudioToolbox',
+      '-framework CoreMedia',
+      '-framework VideoToolbox',
   ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     EXPORTS += [
         'android/AndroidDecoderModule.h',
         'android/JavaCallbacksSupport.h',
--- a/old-configure.in
+++ b/old-configure.in
@@ -2270,17 +2270,17 @@ dnl ====================================
 dnl = Apple platform decoder support
 dnl ========================================================
 if test "$COMPILE_ENVIRONMENT"; then
 if test -n "$MOZ_APPLEMEDIA"; then
   # hack in frameworks for fmp4 - see bug 1029974
   # We load VideoToolbox and CoreMedia dynamically, so they don't appear here.
   LDFLAGS="$LDFLAGS -framework AudioToolbox"
   dnl Verify CoreMedia is available.
-  AC_CHECK_HEADER([CoreMedia/CoreMedia.h], [],
+  AC_CHECK_HEADERS([CoreMedia/CoreMedia.h VideoToolbox/VideoToolbox.h], [],
     [AC_MSG_ERROR([MacOS X 10.9 SDK or later is required])])
 fi
 fi # COMPILE_ENVIRONMENT
 
 dnl system libvpx Support
 dnl ========================================================
 MOZ_ARG_WITH_BOOL(system-libvpx,
 [  --with-system-libvpx    Use system libvpx (located with pkgconfig)],