1 /* -LICENSE-START-
2 ** Copyright (c) 2009 Blackmagic Design
3 **
4 ** Permission is hereby granted, free of charge, to any person or organization
5 ** obtaining a copy of the software and accompanying documentation covered by
6 ** this license (the "Software") to use, reproduce, display, distribute,
7 ** execute, and transmit the Software, and to prepare derivative works of the
8 ** Software, and to permit third-parties to whom the Software is furnished to
9 ** do so, all subject to the following:
10 **
11 ** The copyright notices in the Software and this entire statement, including
12 ** the above license grant, this restriction and the following disclaimer,
13 ** must be included in all copies of the Software, in whole or in part, and
14 ** all derivative works of the Software, unless such copies or derivative
15 ** works are solely in the form of machine-executable object code generated by
16 ** a source language processor.
17 **
18 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 ** FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21 ** SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22 ** FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23 ** ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 ** DEALINGS IN THE SOFTWARE.
25 ** -LICENSE-END-
26 */
27 /* DeckLinkAPIDispatch.cpp */
28
29 #include "DeckLinkAPI.h"
30 #include <pthread.h>
31
32 #if BLACKMAGIC_DECKLINK_API_MAGIC != 1
33 #error The DeckLink API version of DeckLinkAPIDispatch.cpp is not the same version as DeckLinkAPI.h
34 #endif
35
36 #define kDeckLinkAPI_BundlePath "/Library/Frameworks/DeckLinkAPI.framework"
37
38
39 typedef IDeckLinkIterator* (*CreateIteratorFunc)(void);
40 typedef IDeckLinkAPIInformation* (*CreateAPIInformationFunc)(void);
41 typedef IDeckLinkGLScreenPreviewHelper* (*CreateOpenGLScreenPreviewHelperFunc)(void);
42 typedef IDeckLinkCocoaScreenPreviewCallback* (*CreateCocoaScreenPreviewFunc)(void*);
43 typedef IDeckLinkVideoConversion* (*CreateVideoConversionInstanceFunc)(void);
44 typedef IDeckLinkDiscovery* (*CreateDeckLinkDiscoveryInstanceFunc)(void);
45
46 static pthread_once_t gDeckLinkOnceControl = PTHREAD_ONCE_INIT;
47 static CFBundleRef gDeckLinkAPIBundleRef = NULL;
48 static CreateIteratorFunc gCreateIteratorFunc = NULL;
49 static CreateAPIInformationFunc gCreateAPIInformationFunc = NULL;
50 static CreateOpenGLScreenPreviewHelperFunc gCreateOpenGLPreviewFunc = NULL;
51 static CreateCocoaScreenPreviewFunc gCreateCocoaPreviewFunc = NULL;
52 static CreateVideoConversionInstanceFunc gCreateVideoConversionFunc = NULL;
53 static CreateDeckLinkDiscoveryInstanceFunc gCreateDeckLinkDiscoveryFunc= NULL;
54
55
InitDeckLinkAPI(void)56 static void InitDeckLinkAPI (void)
57 {
58 CFURLRef bundleURL;
59
60 bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
61 if (bundleURL != NULL)
62 {
63 gDeckLinkAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
64 if (gDeckLinkAPIBundleRef != NULL)
65 {
66 gCreateIteratorFunc = (CreateIteratorFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkIteratorInstance_0002"));
67 gCreateAPIInformationFunc = (CreateAPIInformationFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkAPIInformationInstance_0001"));
68 gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateOpenGLScreenPreviewHelper_0001"));
69 gCreateCocoaPreviewFunc = (CreateCocoaScreenPreviewFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateCocoaScreenPreview_0001"));
70 gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateVideoConversionInstance_0001"));
71 gCreateDeckLinkDiscoveryFunc = (CreateDeckLinkDiscoveryInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkDiscoveryInstance_0001"));
72 }
73 CFRelease(bundleURL);
74 }
75 }
76
77 #if 0
78 bool IsDeckLinkAPIPresent (void)
79 {
80 // If the DeckLink API bundle was successfully loaded, return this knowledge to the caller
81 if (gDeckLinkAPIBundleRef != NULL)
82 return true;
83
84 return false;
85 }
86 #endif
87
CreateDeckLinkIteratorInstance(void)88 IDeckLinkIterator* CreateDeckLinkIteratorInstance (void)
89 {
90 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
91
92 if (gCreateIteratorFunc == NULL)
93 return NULL;
94
95 return gCreateIteratorFunc();
96 }
97
CreateDeckLinkAPIInformationInstance(void)98 IDeckLinkAPIInformation* CreateDeckLinkAPIInformationInstance (void)
99 {
100 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
101
102 if (gCreateAPIInformationFunc == NULL)
103 return NULL;
104
105 return gCreateAPIInformationFunc();
106 }
107
CreateOpenGLScreenPreviewHelper(void)108 IDeckLinkGLScreenPreviewHelper* CreateOpenGLScreenPreviewHelper (void)
109 {
110 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
111
112 if (gCreateOpenGLPreviewFunc == NULL)
113 return NULL;
114
115 return gCreateOpenGLPreviewFunc();
116 }
117
CreateCocoaScreenPreview(void * parentView)118 IDeckLinkCocoaScreenPreviewCallback* CreateCocoaScreenPreview (void* parentView)
119 {
120 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
121
122 if (gCreateCocoaPreviewFunc == NULL)
123 return NULL;
124
125 return gCreateCocoaPreviewFunc(parentView);
126 }
127
CreateVideoConversionInstance(void)128 IDeckLinkVideoConversion* CreateVideoConversionInstance (void)
129 {
130 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
131
132 if (gCreateVideoConversionFunc == NULL)
133 return NULL;
134
135 return gCreateVideoConversionFunc();
136 }
137
CreateDeckLinkDiscoveryInstance(void)138 IDeckLinkDiscovery* CreateDeckLinkDiscoveryInstance (void)
139 {
140 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
141
142 if (gCreateDeckLinkDiscoveryFunc == NULL)
143 return NULL;
144
145 return gCreateDeckLinkDiscoveryFunc();
146 }
147
148
149 #define kBMDStreamingAPI_BundlePath "/Library/Application Support/Blackmagic Design/Streaming/BMDStreamingAPI.bundle"
150
151 typedef IBMDStreamingDiscovery* (*CreateDiscoveryFunc)(void);
152 typedef IBMDStreamingH264NALParser* (*CreateNALParserFunc)(void);
153
154 static pthread_once_t gBMDStreamingOnceControl = PTHREAD_ONCE_INIT;
155 static CFBundleRef gBMDStreamingAPIBundleRef = NULL;
156 static CreateDiscoveryFunc gCreateDiscoveryFunc = NULL;
157 static CreateNALParserFunc gCreateNALParserFunc = NULL;
158
InitBMDStreamingAPI(void)159 void InitBMDStreamingAPI(void)
160 {
161 CFURLRef bundleURL;
162
163 bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kBMDStreamingAPI_BundlePath), kCFURLPOSIXPathStyle, true);
164 if (bundleURL != NULL)
165 {
166 gBMDStreamingAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
167 if (gBMDStreamingAPIBundleRef != NULL)
168 {
169 gCreateDiscoveryFunc = (CreateDiscoveryFunc)CFBundleGetFunctionPointerForName(gBMDStreamingAPIBundleRef, CFSTR("CreateBMDStreamingDiscoveryInstance_0001"));
170 gCreateNALParserFunc = (CreateNALParserFunc)CFBundleGetFunctionPointerForName(gBMDStreamingAPIBundleRef, CFSTR("CreateBMDStreamingH264NALParser_0001"));
171 }
172
173 CFRelease(bundleURL);
174 }
175 }
176
CreateBMDStreamingDiscoveryInstance()177 IBMDStreamingDiscovery* CreateBMDStreamingDiscoveryInstance()
178 {
179 pthread_once(&gBMDStreamingOnceControl, InitBMDStreamingAPI);
180
181 if (gCreateDiscoveryFunc == NULL)
182 return NULL;
183
184 return gCreateDiscoveryFunc();
185 }
186
CreateBMDStreamingH264NALParser()187 IBMDStreamingH264NALParser* CreateBMDStreamingH264NALParser()
188 {
189 pthread_once(&gBMDStreamingOnceControl, InitBMDStreamingAPI);
190
191 if (gCreateNALParserFunc == NULL)
192 return NULL;
193
194 return gCreateNALParserFunc();
195 }
196