DeckLinkAPIDispatch_v10_8.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #include "DeckLinkAPI.h"
  29. #include <pthread.h>
  30. #if BLACKMAGIC_DECKLINK_API_MAGIC != 1
  31. #error The DeckLink API version of DeckLinkAPIDispatch.cpp is not the same version as DeckLinkAPI.h
  32. #endif
  33. #define kDeckLinkAPI_BundlePath "/Library/Frameworks/DeckLinkAPI.framework"
  34. typedef IDeckLinkIterator* (*CreateIteratorFunc)(void);
  35. typedef IDeckLinkAPIInformation* (*CreateAPIInformationFunc)(void);
  36. typedef IDeckLinkGLScreenPreviewHelper* (*CreateOpenGLScreenPreviewHelperFunc)(void);
  37. typedef IDeckLinkCocoaScreenPreviewCallback* (*CreateCocoaScreenPreviewFunc)(void*);
  38. typedef IDeckLinkVideoConversion* (*CreateVideoConversionInstanceFunc)(void);
  39. typedef IDeckLinkDiscovery* (*CreateDeckLinkDiscoveryInstanceFunc)(void);
  40. static pthread_once_t gDeckLinkOnceControl = PTHREAD_ONCE_INIT;
  41. static CFBundleRef gDeckLinkAPIBundleRef = NULL;
  42. static CreateIteratorFunc gCreateIteratorFunc = NULL;
  43. static CreateAPIInformationFunc gCreateAPIInformationFunc = NULL;
  44. static CreateOpenGLScreenPreviewHelperFunc gCreateOpenGLPreviewFunc = NULL;
  45. static CreateCocoaScreenPreviewFunc gCreateCocoaPreviewFunc = NULL;
  46. static CreateVideoConversionInstanceFunc gCreateVideoConversionFunc = NULL;
  47. static CreateDeckLinkDiscoveryInstanceFunc gCreateDeckLinkDiscoveryFunc = NULL;
  48. void InitDeckLinkAPI(void)
  49. {
  50. CFURLRef bundleURL;
  51. bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
  52. if (bundleURL != NULL)
  53. {
  54. gDeckLinkAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
  55. if (gDeckLinkAPIBundleRef != NULL)
  56. {
  57. gCreateIteratorFunc = (CreateIteratorFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkIteratorInstance_0002"));
  58. gCreateAPIInformationFunc = (CreateAPIInformationFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkAPIInformationInstance_0001"));
  59. gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateOpenGLScreenPreviewHelper_0001"));
  60. gCreateCocoaPreviewFunc = (CreateCocoaScreenPreviewFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateCocoaScreenPreview_0001"));
  61. gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateVideoConversionInstance_0001"));
  62. gCreateDeckLinkDiscoveryFunc = (CreateDeckLinkDiscoveryInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkDiscoveryInstance_0001"));
  63. }
  64. CFRelease(bundleURL);
  65. }
  66. }
  67. bool IsDeckLinkAPIPresent(void)
  68. {
  69. // If the DeckLink API bundle was successfully loaded, return this knowledge to the caller
  70. if (gDeckLinkAPIBundleRef != NULL)
  71. return true;
  72. return false;
  73. }
  74. IDeckLinkIterator* CreateDeckLinkIteratorInstance(void)
  75. {
  76. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  77. if (gCreateIteratorFunc == NULL)
  78. return NULL;
  79. return gCreateIteratorFunc();
  80. }
  81. IDeckLinkAPIInformation* CreateDeckLinkAPIInformationInstance(void)
  82. {
  83. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  84. if (gCreateAPIInformationFunc == NULL)
  85. return NULL;
  86. return gCreateAPIInformationFunc();
  87. }
  88. IDeckLinkGLScreenPreviewHelper* CreateOpenGLScreenPreviewHelper(void)
  89. {
  90. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  91. if (gCreateOpenGLPreviewFunc == NULL)
  92. return NULL;
  93. return gCreateOpenGLPreviewFunc();
  94. }
  95. IDeckLinkCocoaScreenPreviewCallback* CreateCocoaScreenPreview(void* parentView)
  96. {
  97. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  98. if (gCreateCocoaPreviewFunc == NULL)
  99. return NULL;
  100. return gCreateCocoaPreviewFunc(parentView);
  101. }
  102. IDeckLinkVideoConversion* CreateVideoConversionInstance(void)
  103. {
  104. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  105. if (gCreateVideoConversionFunc == NULL)
  106. return NULL;
  107. return gCreateVideoConversionFunc();
  108. }
  109. IDeckLinkDiscovery* CreateDeckLinkDiscoveryInstance(void)
  110. {
  111. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  112. if (gCreateDeckLinkDiscoveryFunc == NULL)
  113. return NULL;
  114. return gCreateDeckLinkDiscoveryFunc();
  115. }
  116. #define kBMDStreamingAPI_BundlePath "/Library/Application Support/Blackmagic Design/Streaming/BMDStreamingAPI.bundle"
  117. typedef IBMDStreamingDiscovery* (*CreateDiscoveryFunc)(void);
  118. typedef IBMDStreamingH264NALParser* (*CreateNALParserFunc)(void);
  119. static pthread_once_t gBMDStreamingOnceControl = PTHREAD_ONCE_INIT;
  120. static CFBundleRef gBMDStreamingAPIBundleRef = NULL;
  121. static CreateDiscoveryFunc gCreateDiscoveryFunc = NULL;
  122. static CreateNALParserFunc gCreateNALParserFunc = NULL;
  123. void InitBMDStreamingAPI(void)
  124. {
  125. CFURLRef bundleURL;
  126. bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kBMDStreamingAPI_BundlePath), kCFURLPOSIXPathStyle, true);
  127. if (bundleURL != NULL)
  128. {
  129. gBMDStreamingAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
  130. if (gBMDStreamingAPIBundleRef != NULL)
  131. {
  132. gCreateDiscoveryFunc = (CreateDiscoveryFunc)CFBundleGetFunctionPointerForName(gBMDStreamingAPIBundleRef, CFSTR("CreateBMDStreamingDiscoveryInstance_0001"));
  133. gCreateNALParserFunc = (CreateNALParserFunc)CFBundleGetFunctionPointerForName(gBMDStreamingAPIBundleRef, CFSTR("CreateBMDStreamingH264NALParser_0001"));
  134. }
  135. CFRelease(bundleURL);
  136. }
  137. }
  138. IBMDStreamingDiscovery* CreateBMDStreamingDiscoveryInstance()
  139. {
  140. pthread_once(&gBMDStreamingOnceControl, InitBMDStreamingAPI);
  141. if (gCreateDiscoveryFunc == NULL)
  142. return NULL;
  143. return gCreateDiscoveryFunc();
  144. }
  145. IBMDStreamingH264NALParser* CreateBMDStreamingH264NALParser()
  146. {
  147. pthread_once(&gBMDStreamingOnceControl, InitBMDStreamingAPI);
  148. if (gCreateNALParserFunc == NULL)
  149. return NULL;
  150. return gCreateNALParserFunc();
  151. }