Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: content/common/gpu/media/vt_support.cc

Issue 340933002: Add VTSupport for dynamically linking VideoToolbox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/vt_support.cc
diff --git a/content/common/gpu/media/vt_support.cc b/content/common/gpu/media/vt_support.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ef889293e15bc8483315cbfe1f20a33abad7cdc
--- /dev/null
+++ b/content/common/gpu/media/vt_support.cc
@@ -0,0 +1,87 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <dlfcn.h>
+
+#include "base/memory/singleton.h"
+#include "content/common/gpu/media/vt_support.h"
+
+namespace content {
+
+// static
+VTSupport* VTSupport::GetInstance() {
+ VTSupport* vt_support = Singleton<VTSupport>::get();
+ if (vt_support->Initialized())
+ return vt_support;
+ return NULL;
+}
+
+VTSupport::VTSupport()
+ : cm_handle_(NULL),
+ initialized_(false) {
+ cm_handle_ = dlopen(
+ "/System/Library/Frameworks/CoreMedia.framework/CoreMedia",
+ RTLD_LAZY | RTLD_LOCAL);
+ // TODO(sandersd): Attempt fallback to private framework.
+ vt_handle_ = dlopen(
+ "/System/Library/Frameworks/VideoToolbox.framework/VideoToolbox",
+ RTLD_LAZY | RTLD_LOCAL);
mcasas 2014/06/19 12:04:23 First create the Bundle and then dlopen() it: NSB
+ if (!cm_handle_ || !vt_handle_)
+ return;
+
+ CMBlockBufferCreateWithMemoryBlock =
+ reinterpret_cast<CMBlockBufferCreateWithMemoryBlockPtr>(
+ dlsym(cm_handle_, "CMBlockBufferCreateWithMemoryBlock"));
mcasas 2014/06/19 12:04:24 CHECK(CMBlockBufferCreateWithMemoryBlock) << dlerr
+ CMFormatDescriptionGetExtensions =
+ reinterpret_cast<CMFormatDescriptionGetExtensionsPtr>(
+ dlsym(cm_handle_, "CMFormatDescriptionGetExtensions"));
+ CMSampleBufferCreate =
+ reinterpret_cast<CMSampleBufferCreatePtr>(
+ dlsym(cm_handle_, "CMSampleBufferCreate"));
+ // TODO(sandersd): Make CreateFromH264 optional.
+ CMVideoFormatDescriptionCreateFromH264ParameterSets =
+ reinterpret_cast<CMVideoFormatDescriptionCreateFromH264ParameterSetsPtr>(
+ dlsym(cm_handle_,
+ "CMVideoFormatDescriptionCreateFromH264ParameterSets"));
+
+ VTDecompressionSessionDecodeFrame =
+ reinterpret_cast<VTDecompressionSessionDecodeFramePtr>(
+ dlsym(vt_handle_, "VTDecompressionSessionDecodeFrame"));
+ VTDecompressionSessionCreate =
+ reinterpret_cast<VTDecompressionSessionCreatePtr>(
+ dlsym(vt_handle_, "VTDecompressionSessionCreate"));
+
+ if (!CMBlockBufferCreateWithMemoryBlock ||
+ !CMFormatDescriptionGetExtensions ||
+ !CMSampleBufferCreate ||
+ !CMVideoFormatDescriptionCreateFromH264ParameterSets ||
+ !VTDecompressionSessionDecodeFrame ||
+ !VTDecompressionSessionCreate) {
+ CloseLibraryHandles();
+ return;
+ }
+
+ initialized_ = true;
+}
+
+VTSupport::~VTSupport() {
+ CloseLibraryHandles();
+}
+
+bool VTSupport::Initialized() {
+ return initialized_;
+}
+
+void VTSupport::CloseLibraryHandles() {
+ if (cm_handle_) {
+ dlclose(cm_handle_);
+ cm_handle_ = NULL;
+ }
+ if (vt_handle_) {
+ dlclose(vt_handle_);
+ vt_handle_ = NULL;
+ }
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698