DeckLinkAPIDispatch_v8_0.cpp 4.6 KB

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