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.

205 lines
5.9KB

  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. #if CONFIG_LIBKLVANC
  28. #include "libklvanc/vanc.h"
  29. #endif
  30. #ifdef _WIN32
  31. #define DECKLINK_BOOL BOOL
  32. #else
  33. #define DECKLINK_BOOL bool
  34. #endif
  35. #ifdef _WIN32
  36. static char *dup_wchar_to_utf8(wchar_t *w)
  37. {
  38. char *s = NULL;
  39. int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
  40. s = (char *) av_malloc(l);
  41. if (s)
  42. WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
  43. return s;
  44. }
  45. #define DECKLINK_STR OLECHAR *
  46. #define DECKLINK_STRDUP dup_wchar_to_utf8
  47. #define DECKLINK_FREE(s) SysFreeString(s)
  48. #elif defined(__APPLE__)
  49. static char *dup_cfstring_to_utf8(CFStringRef w)
  50. {
  51. char s[256];
  52. CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
  53. return av_strdup(s);
  54. }
  55. #define DECKLINK_STR const __CFString *
  56. #define DECKLINK_STRDUP dup_cfstring_to_utf8
  57. #define DECKLINK_FREE(s) CFRelease(s)
  58. #else
  59. #define DECKLINK_STR const char *
  60. #define DECKLINK_STRDUP av_strdup
  61. /* free() is needed for a string returned by the DeckLink SDL. */
  62. #define DECKLINK_FREE(s) free((void *) s)
  63. #endif
  64. class decklink_output_callback;
  65. class decklink_input_callback;
  66. typedef struct AVPacketQueue {
  67. AVPacketList *first_pkt, *last_pkt;
  68. int nb_packets;
  69. unsigned long long size;
  70. int abort_request;
  71. pthread_mutex_t mutex;
  72. pthread_cond_t cond;
  73. AVFormatContext *avctx;
  74. int64_t max_q_size;
  75. } AVPacketQueue;
  76. struct decklink_ctx {
  77. /* DeckLink SDK interfaces */
  78. IDeckLink *dl;
  79. IDeckLinkOutput *dlo;
  80. IDeckLinkInput *dli;
  81. IDeckLinkConfiguration *cfg;
  82. IDeckLinkAttributes *attr;
  83. decklink_output_callback *output_callback;
  84. /* DeckLink mode information */
  85. BMDTimeValue bmd_tb_den;
  86. BMDTimeValue bmd_tb_num;
  87. BMDDisplayMode bmd_mode;
  88. BMDVideoConnection video_input;
  89. BMDAudioConnection audio_input;
  90. BMDTimecodeFormat tc_format;
  91. int bmd_width;
  92. int bmd_height;
  93. int bmd_field_dominance;
  94. int supports_vanc;
  95. /* Capture buffer queue */
  96. AVPacketQueue queue;
  97. /* Streams present */
  98. int audio;
  99. int video;
  100. /* Status */
  101. int playback_started;
  102. int capture_started;
  103. int64_t last_pts;
  104. unsigned long frameCount;
  105. unsigned int dropped;
  106. AVStream *audio_st;
  107. AVStream *video_st;
  108. AVStream *teletext_st;
  109. uint16_t cdp_sequence_num;
  110. /* Options */
  111. int list_devices;
  112. int list_formats;
  113. int64_t teletext_lines;
  114. double preroll;
  115. int duplex_mode;
  116. DecklinkPtsSource audio_pts_source;
  117. DecklinkPtsSource video_pts_source;
  118. int draw_bars;
  119. BMDPixelFormat raw_format;
  120. int frames_preroll;
  121. int frames_buffer;
  122. pthread_mutex_t mutex;
  123. pthread_cond_t cond;
  124. int frames_buffer_available_spots;
  125. int autodetect;
  126. #if CONFIG_LIBKLVANC
  127. struct klvanc_context_s *vanc_ctx;
  128. #endif
  129. int channels;
  130. int audio_depth;
  131. };
  132. typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
  133. #ifdef _WIN32
  134. #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
  135. typedef unsigned long buffercount_type;
  136. #else
  137. typedef unsigned int buffercount_type;
  138. #endif
  139. IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
  140. #else
  141. typedef uint32_t buffercount_type;
  142. #endif
  143. static const BMDAudioConnection decklink_audio_connection_map[] = {
  144. (BMDAudioConnection)0,
  145. bmdAudioConnectionEmbedded,
  146. bmdAudioConnectionAESEBU,
  147. bmdAudioConnectionAnalog,
  148. bmdAudioConnectionAnalogXLR,
  149. bmdAudioConnectionAnalogRCA,
  150. bmdAudioConnectionMicrophone,
  151. };
  152. static const BMDVideoConnection decklink_video_connection_map[] = {
  153. (BMDVideoConnection)0,
  154. bmdVideoConnectionSDI,
  155. bmdVideoConnectionHDMI,
  156. bmdVideoConnectionOpticalSDI,
  157. bmdVideoConnectionComponent,
  158. bmdVideoConnectionComposite,
  159. bmdVideoConnectionSVideo,
  160. };
  161. static const BMDTimecodeFormat decklink_timecode_format_map[] = {
  162. (BMDTimecodeFormat)0,
  163. bmdTimecodeRP188VITC1,
  164. bmdTimecodeRP188VITC2,
  165. bmdTimecodeRP188LTC,
  166. bmdTimecodeRP188Any,
  167. bmdTimecodeVITC,
  168. bmdTimecodeVITCField2,
  169. bmdTimecodeSerial,
  170. };
  171. HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
  172. int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
  173. 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);
  174. int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
  175. int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
  176. void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
  177. int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
  178. void ff_decklink_cleanup(AVFormatContext *avctx);
  179. int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
  180. #endif /* AVDEVICE_DECKLINK_COMMON_H */