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- 26 */ 27 /* DeckLinkAPIDispatch.cpp */ 28 29 #include "DeckLinkAPI_v8_0.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 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); 43 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; 51 52 53 void InitDeckLinkAPI (void) 54 { 55 CFURLRef bundleURL; 56 57 bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true); 58 if (bundleURL != NULL) 59 { 60 gDeckLinkAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL); 61 if (gDeckLinkAPIBundleRef != NULL) 62 { 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")); 68 } 69 CFRelease(bundleURL); 70 } 71 } 72 73 bool IsDeckLinkAPIPresent (void) 74 { 75 // If the DeckLink API bundle was successfully loaded, return this knowledge to the caller 76 if (gDeckLinkAPIBundleRef != NULL) 77 return true; 78 79 return false; 80 } 81 82 IDeckLinkIterator_v8_0* CreateDeckLinkIteratorInstance (void) 83 { 84 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 85 86 if (gCreateIteratorFunc == NULL) 87 return NULL; 88 89 return gCreateIteratorFunc(); 90 } 91 92 IDeckLinkAPIInformation* CreateDeckLinkAPIInformationInstance (void) 93 { 94 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 95 96 if (gCreateAPIInformationFunc == NULL) 97 return NULL; 98 99 return gCreateAPIInformationFunc(); 100 } 101 102 IDeckLinkGLScreenPreviewHelper* CreateOpenGLScreenPreviewHelper (void) 103 { 104 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 105 106 if (gCreateOpenGLPreviewFunc == NULL) 107 return NULL; 108 109 return gCreateOpenGLPreviewFunc(); 110 } 111 112 IDeckLinkCocoaScreenPreviewCallback* CreateCocoaScreenPreview (void* parentView) 113 { 114 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 115 116 if (gCreateCocoaPreviewFunc == NULL) 117 return NULL; 118 119 return gCreateCocoaPreviewFunc(parentView); 120 } 121 122 IDeckLinkVideoConversion* CreateVideoConversionInstance (void) 123 { 124 pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI); 125 126 if (gCreateVideoConversionFunc == NULL) 127 return NULL; 128 129 return gCreateVideoConversionFunc(); 130 } 131 132