Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / third_party / decklink / mac / include / DeckLinkAPIDispatch_v8_0.cpp
blobcd6857aa9bcd4c5a37c0db7450584b73bff4c073
1 /* -LICENSE-START-
2 ** Copyright (c) 2011 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-
27 /* DeckLinkAPIDispatch.cpp */
29 #include "DeckLinkAPI_v8_0.h"
30 #include <pthread.h>
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
36 #define kDeckLinkAPI_BundlePath "/Library/Frameworks/DeckLinkAPI.framework"
38 typedef IDeckLinkIterator_v8_0* (*CreateIteratorFunc)(void);
39 typedef IDeckLinkAPIInformation* (*CreateAPIInformationFunc)(void);
40 typedef IDeckLinkGLScreenPreviewHelper* (*CreateOpenGLScreenPreviewHelperFunc)(void);
41 typedef IDeckLinkCocoaScreenPreviewCallback* (*CreateCocoaScreenPreviewFunc)(void*);
42 typedef IDeckLinkVideoConversion* (*CreateVideoConversionInstanceFunc)(void);
44 static pthread_once_t gDeckLinkOnceControl = PTHREAD_ONCE_INIT;
45 static CFBundleRef gDeckLinkAPIBundleRef = NULL;
46 static CreateIteratorFunc gCreateIteratorFunc = NULL;
47 static CreateAPIInformationFunc gCreateAPIInformationFunc = NULL;
48 static CreateOpenGLScreenPreviewHelperFunc gCreateOpenGLPreviewFunc = NULL;
49 static CreateCocoaScreenPreviewFunc gCreateCocoaPreviewFunc = NULL;
50 static CreateVideoConversionInstanceFunc gCreateVideoConversionFunc = NULL;
53 void InitDeckLinkAPI (void)
55 CFURLRef bundleURL;
57 bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
58 if (bundleURL != NULL)
60 gDeckLinkAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
61 if (gDeckLinkAPIBundleRef != NULL)
63 gCreateIteratorFunc = (CreateIteratorFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkIteratorInstance_0001"));
64 gCreateAPIInformationFunc = (CreateAPIInformationFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkAPIInformationInstance_0001"));
65 gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateOpenGLScreenPreviewHelper_0001"));
66 gCreateCocoaPreviewFunc = (CreateCocoaScreenPreviewFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateCocoaScreenPreview_0001"));
67 gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateVideoConversionInstance_0001"));
69 CFRelease(bundleURL);
73 bool IsDeckLinkAPIPresent (void)
75 // If the DeckLink API bundle was successfully loaded, return this knowledge to the caller
76 if (gDeckLinkAPIBundleRef != NULL)
77 return true;
79 return false;
82 IDeckLinkIterator_v8_0* CreateDeckLinkIteratorInstance (void)
84 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
86 if (gCreateIteratorFunc == NULL)
87 return NULL;
89 return gCreateIteratorFunc();
92 IDeckLinkAPIInformation* CreateDeckLinkAPIInformationInstance (void)
94 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
96 if (gCreateAPIInformationFunc == NULL)
97 return NULL;
99 return gCreateAPIInformationFunc();
102 IDeckLinkGLScreenPreviewHelper* CreateOpenGLScreenPreviewHelper (void)
104 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
106 if (gCreateOpenGLPreviewFunc == NULL)
107 return NULL;
109 return gCreateOpenGLPreviewFunc();
112 IDeckLinkCocoaScreenPreviewCallback* CreateCocoaScreenPreview (void* parentView)
114 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
116 if (gCreateCocoaPreviewFunc == NULL)
117 return NULL;
119 return gCreateCocoaPreviewFunc(parentView);
122 IDeckLinkVideoConversion* CreateVideoConversionInstance (void)
124 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
126 if (gCreateVideoConversionFunc == NULL)
127 return NULL;
129 return gCreateVideoConversionFunc();