OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <dlfcn.h> | |
6 | |
7 #include "base/memory/singleton.h" | |
8 #include "content/common/gpu/media/vt_support.h" | |
9 | |
10 namespace content { | |
11 | |
12 // static | |
13 VTSupport* VTSupport::GetInstance() { | |
14 VTSupport* vt_support = Singleton<VTSupport>::get(); | |
15 if (vt_support->Initialized()) | |
16 return vt_support; | |
17 return NULL; | |
18 } | |
19 | |
20 VTSupport::VTSupport() | |
21 : cm_handle_(NULL), | |
22 initialized_(false) { | |
23 cm_handle_ = dlopen( | |
24 "/System/Library/Frameworks/CoreMedia.framework/CoreMedia", | |
25 RTLD_LAZY | RTLD_LOCAL); | |
26 // TODO(sandersd): Attempt fallback to private framework. | |
27 vt_handle_ = dlopen( | |
28 "/System/Library/Frameworks/VideoToolbox.framework/VideoToolbox", | |
29 RTLD_LAZY | RTLD_LOCAL); | |
mcasas
2014/06/19 12:04:23
First create the Bundle and then dlopen() it:
NSB
| |
30 if (!cm_handle_ || !vt_handle_) | |
31 return; | |
32 | |
33 CMBlockBufferCreateWithMemoryBlock = | |
34 reinterpret_cast<CMBlockBufferCreateWithMemoryBlockPtr>( | |
35 dlsym(cm_handle_, "CMBlockBufferCreateWithMemoryBlock")); | |
mcasas
2014/06/19 12:04:24
CHECK(CMBlockBufferCreateWithMemoryBlock) << dlerr
| |
36 CMFormatDescriptionGetExtensions = | |
37 reinterpret_cast<CMFormatDescriptionGetExtensionsPtr>( | |
38 dlsym(cm_handle_, "CMFormatDescriptionGetExtensions")); | |
39 CMSampleBufferCreate = | |
40 reinterpret_cast<CMSampleBufferCreatePtr>( | |
41 dlsym(cm_handle_, "CMSampleBufferCreate")); | |
42 // TODO(sandersd): Make CreateFromH264 optional. | |
43 CMVideoFormatDescriptionCreateFromH264ParameterSets = | |
44 reinterpret_cast<CMVideoFormatDescriptionCreateFromH264ParameterSetsPtr>( | |
45 dlsym(cm_handle_, | |
46 "CMVideoFormatDescriptionCreateFromH264ParameterSets")); | |
47 | |
48 VTDecompressionSessionDecodeFrame = | |
49 reinterpret_cast<VTDecompressionSessionDecodeFramePtr>( | |
50 dlsym(vt_handle_, "VTDecompressionSessionDecodeFrame")); | |
51 VTDecompressionSessionCreate = | |
52 reinterpret_cast<VTDecompressionSessionCreatePtr>( | |
53 dlsym(vt_handle_, "VTDecompressionSessionCreate")); | |
54 | |
55 if (!CMBlockBufferCreateWithMemoryBlock || | |
56 !CMFormatDescriptionGetExtensions || | |
57 !CMSampleBufferCreate || | |
58 !CMVideoFormatDescriptionCreateFromH264ParameterSets || | |
59 !VTDecompressionSessionDecodeFrame || | |
60 !VTDecompressionSessionCreate) { | |
61 CloseLibraryHandles(); | |
62 return; | |
63 } | |
64 | |
65 initialized_ = true; | |
66 } | |
67 | |
68 VTSupport::~VTSupport() { | |
69 CloseLibraryHandles(); | |
70 } | |
71 | |
72 bool VTSupport::Initialized() { | |
73 return initialized_; | |
74 } | |
75 | |
76 void VTSupport::CloseLibraryHandles() { | |
77 if (cm_handle_) { | |
78 dlclose(cm_handle_); | |
79 cm_handle_ = NULL; | |
80 } | |
81 if (vt_handle_) { | |
82 dlclose(vt_handle_); | |
83 vt_handle_ = NULL; | |
84 } | |
85 } | |
86 | |
87 } // namespace content | |
OLD | NEW |