You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
5.7KB

  1. /*
  2. * Blackmagic DeckLink common code
  3. * Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
  4. * Copyright (c) 2017 Akamai Technologies, Inc.
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVDEVICE_DECKLINK_COMMON_H
  23. #define AVDEVICE_DECKLINK_COMMON_H
  24. #include <DeckLinkAPIVersion.h>
  25. #include "libavutil/thread.h"
  26. #include "decklink_common_c.h"
  27. #ifdef _WIN32
  28. #define DECKLINK_BOOL BOOL
  29. #else
  30. #define DECKLINK_BOOL bool
  31. #endif
  32. #ifdef _WIN32
  33. static char *dup_wchar_to_utf8(wchar_t *w)
  34. {
  35. char *s = NULL;
  36. int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
  37. s = (char *) av_malloc(l);
  38. if (s)
  39. WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
  40. return s;
  41. }
  42. #define DECKLINK_STR OLECHAR *
  43. #define DECKLINK_STRDUP dup_wchar_to_utf8
  44. #define DECKLINK_FREE(s) SysFreeString(s)
  45. #elif defined(__APPLE__)
  46. static char *dup_cfstring_to_utf8(CFStringRef w)
  47. {
  48. char s[256];
  49. CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
  50. return av_strdup(s);
  51. }
  52. #define DECKLINK_STR const __CFString *
  53. #define DECKLINK_STRDUP dup_cfstring_to_utf8
  54. #define DECKLINK_FREE(s) CFRelease(s)
  55. #else
  56. #define DECKLINK_STR const char *
  57. #define DECKLINK_STRDUP av_strdup
  58. /* free() is needed for a string returned by the DeckLink SDL. */
  59. #define DECKLINK_FREE(s) free((void *) s)
  60. #endif
  61. class decklink_output_callback;
  62. class decklink_input_callback;
  63. typedef struct AVPacketQueue {
  64. AVPacketList *first_pkt, *last_pkt;
  65. int nb_packets;
  66. unsigned long long size;
  67. int abort_request;
  68. pthread_mutex_t mutex;
  69. pthread_cond_t cond;
  70. AVFormatContext *avctx;
  71. int64_t max_q_size;
  72. } AVPacketQueue;
  73. struct decklink_ctx {
  74. /* DeckLink SDK interfaces */
  75. IDeckLink *dl;
  76. IDeckLinkOutput *dlo;
  77. IDeckLinkInput *dli;
  78. IDeckLinkConfiguration *cfg;
  79. IDeckLinkAttributes *attr;
  80. decklink_output_callback *output_callback;
  81. /* DeckLink mode information */
  82. BMDTimeValue bmd_tb_den;
  83. BMDTimeValue bmd_tb_num;
  84. BMDDisplayMode bmd_mode;
  85. BMDVideoConnection video_input;
  86. BMDAudioConnection audio_input;
  87. BMDTimecodeFormat tc_format;
  88. int bmd_width;
  89. int bmd_height;
  90. int bmd_field_dominance;
  91. /* Capture buffer queue */
  92. AVPacketQueue queue;
  93. /* Streams present */
  94. int audio;
  95. int video;
  96. /* Status */
  97. int playback_started;
  98. int capture_started;
  99. int64_t last_pts;
  100. unsigned long frameCount;
  101. unsigned int dropped;
  102. AVStream *audio_st;
  103. AVStream *video_st;
  104. AVStream *teletext_st;
  105. /* Options */
  106. int list_devices;
  107. int list_formats;
  108. int64_t teletext_lines;
  109. double preroll;
  110. int duplex_mode;
  111. DecklinkPtsSource audio_pts_source;
  112. DecklinkPtsSource video_pts_source;
  113. int draw_bars;
  114. int frames_preroll;
  115. int frames_buffer;
  116. pthread_mutex_t mutex;
  117. pthread_cond_t cond;
  118. int frames_buffer_available_spots;
  119. int autodetect;
  120. int channels;
  121. int audio_depth;
  122. };
  123. typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
  124. #ifdef _WIN32
  125. #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
  126. typedef unsigned long buffercount_type;
  127. #else
  128. typedef unsigned int buffercount_type;
  129. #endif
  130. IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
  131. #else
  132. typedef uint32_t buffercount_type;
  133. #endif
  134. static const BMDAudioConnection decklink_audio_connection_map[] = {
  135. (BMDAudioConnection)0,
  136. bmdAudioConnectionEmbedded,
  137. bmdAudioConnectionAESEBU,
  138. bmdAudioConnectionAnalog,
  139. bmdAudioConnectionAnalogXLR,
  140. bmdAudioConnectionAnalogRCA,
  141. bmdAudioConnectionMicrophone,
  142. };
  143. static const BMDVideoConnection decklink_video_connection_map[] = {
  144. (BMDVideoConnection)0,
  145. bmdVideoConnectionSDI,
  146. bmdVideoConnectionHDMI,
  147. bmdVideoConnectionOpticalSDI,
  148. bmdVideoConnectionComponent,
  149. bmdVideoConnectionComposite,
  150. bmdVideoConnectionSVideo,
  151. };
  152. static const BMDTimecodeFormat decklink_timecode_format_map[] = {
  153. (BMDTimecodeFormat)0,
  154. bmdTimecodeRP188VITC1,
  155. bmdTimecodeRP188VITC2,
  156. bmdTimecodeRP188LTC,
  157. bmdTimecodeRP188Any,
  158. bmdTimecodeVITC,
  159. bmdTimecodeVITCField2,
  160. bmdTimecodeSerial,
  161. };
  162. HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
  163. int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
  164. int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t direction = DIRECTION_OUT, int num = 0);
  165. int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
  166. int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
  167. void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
  168. int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
  169. void ff_decklink_cleanup(AVFormatContext *avctx);
  170. int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
  171. #endif /* AVDEVICE_DECKLINK_COMMON_H */