DeckLinkAPIDispatch_v10_8.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include <stdio.h>
  28. #include <pthread.h>
  29. #include <dlfcn.h>
  30. #include "DeckLinkAPI.h"
  31. #define kDeckLinkAPI_Name "libDeckLinkAPI.so"
  32. #define KDeckLinkPreviewAPI_Name "libDeckLinkPreviewAPI.so"
  33. typedef IDeckLinkIterator* (*CreateIteratorFunc)(void);
  34. typedef IDeckLinkAPIInformation* (*CreateAPIInformationFunc)(void);
  35. typedef IDeckLinkGLScreenPreviewHelper* (*CreateOpenGLScreenPreviewHelperFunc)(void);
  36. typedef IDeckLinkVideoConversion* (*CreateVideoConversionInstanceFunc)(void);
  37. typedef IDeckLinkDiscovery* (*CreateDeckLinkDiscoveryInstanceFunc)(void);
  38. static pthread_once_t gDeckLinkOnceControl = PTHREAD_ONCE_INIT;
  39. static pthread_once_t gPreviewOnceControl = PTHREAD_ONCE_INIT;
  40. static bool gLoadedDeckLinkAPI = false;
  41. static CreateIteratorFunc gCreateIteratorFunc = NULL;
  42. static CreateAPIInformationFunc gCreateAPIInformationFunc = NULL;
  43. static CreateOpenGLScreenPreviewHelperFunc gCreateOpenGLPreviewFunc = NULL;
  44. static CreateVideoConversionInstanceFunc gCreateVideoConversionFunc = NULL;
  45. static CreateDeckLinkDiscoveryInstanceFunc gCreateDeckLinkDiscoveryFunc = NULL;
  46. static void InitDeckLinkAPI(void)
  47. {
  48. void *libraryHandle;
  49. libraryHandle = dlopen(kDeckLinkAPI_Name, RTLD_NOW | RTLD_GLOBAL);
  50. if (!libraryHandle)
  51. {
  52. fprintf(stderr, "%s\n", dlerror());
  53. return;
  54. }
  55. gLoadedDeckLinkAPI = true;
  56. gCreateIteratorFunc = (CreateIteratorFunc)dlsym(libraryHandle, "CreateDeckLinkIteratorInstance_0002");
  57. if (!gCreateIteratorFunc)
  58. fprintf(stderr, "%s\n", dlerror());
  59. gCreateAPIInformationFunc = (CreateAPIInformationFunc)dlsym(libraryHandle, "CreateDeckLinkAPIInformationInstance_0001");
  60. if (!gCreateAPIInformationFunc)
  61. fprintf(stderr, "%s\n", dlerror());
  62. gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)dlsym(libraryHandle, "CreateVideoConversionInstance_0001");
  63. if (!gCreateVideoConversionFunc)
  64. fprintf(stderr, "%s\n", dlerror());
  65. gCreateDeckLinkDiscoveryFunc = (CreateDeckLinkDiscoveryInstanceFunc)dlsym(libraryHandle, "CreateDeckLinkDiscoveryInstance_0001");
  66. if (!gCreateDeckLinkDiscoveryFunc)
  67. fprintf(stderr, "%s\n", dlerror());
  68. }
  69. static void InitDeckLinkPreviewAPI(void)
  70. {
  71. void *libraryHandle;
  72. libraryHandle = dlopen(KDeckLinkPreviewAPI_Name, RTLD_NOW | RTLD_GLOBAL);
  73. if (!libraryHandle)
  74. {
  75. fprintf(stderr, "%s\n", dlerror());
  76. return;
  77. }
  78. gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)dlsym(libraryHandle, "CreateOpenGLScreenPreviewHelper_0001");
  79. if (!gCreateOpenGLPreviewFunc)
  80. fprintf(stderr, "%s\n", dlerror());
  81. }
  82. bool IsDeckLinkAPIPresent(void)
  83. {
  84. // If the DeckLink API dynamic library was successfully loaded, return this knowledge to the caller
  85. return gLoadedDeckLinkAPI;
  86. }
  87. IDeckLinkIterator* CreateDeckLinkIteratorInstance(void)
  88. {
  89. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  90. if (gCreateIteratorFunc == NULL)
  91. return NULL;
  92. return gCreateIteratorFunc();
  93. }
  94. IDeckLinkAPIInformation* CreateDeckLinkAPIInformationInstance(void)
  95. {
  96. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  97. if (gCreateAPIInformationFunc == NULL)
  98. return NULL;
  99. return gCreateAPIInformationFunc();
  100. }
  101. IDeckLinkGLScreenPreviewHelper* CreateOpenGLScreenPreviewHelper(void)
  102. {
  103. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  104. pthread_once(&gPreviewOnceControl, InitDeckLinkPreviewAPI);
  105. if (gCreateOpenGLPreviewFunc == NULL)
  106. return NULL;
  107. return gCreateOpenGLPreviewFunc();
  108. }
  109. IDeckLinkVideoConversion* CreateVideoConversionInstance(void)
  110. {
  111. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  112. if (gCreateVideoConversionFunc == NULL)
  113. return NULL;
  114. return gCreateVideoConversionFunc();
  115. }
  116. IDeckLinkDiscovery* CreateDeckLinkDiscoveryInstance(void)
  117. {
  118. pthread_once(&gDeckLinkOnceControl, InitDeckLinkAPI);
  119. if (gCreateDeckLinkDiscoveryFunc == NULL)
  120. return NULL;
  121. return gCreateDeckLinkDiscoveryFunc();
  122. }