decklink_common.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. class decklink_output_callback;
  28. class decklink_input_callback;
  29. typedef struct AVPacketQueue {
  30. AVPacketList *first_pkt, *last_pkt;
  31. int nb_packets;
  32. unsigned long long size;
  33. int abort_request;
  34. pthread_mutex_t mutex;
  35. pthread_cond_t cond;
  36. AVFormatContext *avctx;
  37. int64_t max_q_size;
  38. } AVPacketQueue;
  39. struct decklink_ctx {
  40. /* DeckLink SDK interfaces */
  41. IDeckLink *dl;
  42. IDeckLinkOutput *dlo;
  43. IDeckLinkInput *dli;
  44. IDeckLinkConfiguration *cfg;
  45. IDeckLinkAttributes *attr;
  46. decklink_output_callback *output_callback;
  47. decklink_input_callback *input_callback;
  48. /* DeckLink mode information */
  49. BMDTimeValue bmd_tb_den;
  50. BMDTimeValue bmd_tb_num;
  51. BMDDisplayMode bmd_mode;
  52. BMDVideoConnection video_input;
  53. BMDAudioConnection audio_input;
  54. int bmd_width;
  55. int bmd_height;
  56. int bmd_field_dominance;
  57. /* Capture buffer queue */
  58. AVPacketQueue queue;
  59. /* Streams present */
  60. int audio;
  61. int video;
  62. /* Status */
  63. int playback_started;
  64. int capture_started;
  65. int64_t last_pts;
  66. unsigned long frameCount;
  67. unsigned int dropped;
  68. AVStream *audio_st;
  69. AVStream *video_st;
  70. AVStream *teletext_st;
  71. /* Options */
  72. int list_devices;
  73. int list_formats;
  74. int64_t teletext_lines;
  75. double preroll;
  76. int duplex_mode;
  77. DecklinkPtsSource audio_pts_source;
  78. DecklinkPtsSource video_pts_source;
  79. int draw_bars;
  80. int frames_preroll;
  81. int frames_buffer;
  82. pthread_mutex_t mutex;
  83. pthread_cond_t cond;
  84. int frames_buffer_available_spots;
  85. int channels;
  86. };
  87. typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
  88. #ifdef _WIN32
  89. #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
  90. typedef unsigned long buffercount_type;
  91. #else
  92. typedef unsigned int buffercount_type;
  93. #endif
  94. IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
  95. #else
  96. typedef uint32_t buffercount_type;
  97. #endif
  98. static const BMDAudioConnection decklink_audio_connection_map[] = {
  99. (BMDAudioConnection)0,
  100. bmdAudioConnectionEmbedded,
  101. bmdAudioConnectionAESEBU,
  102. bmdAudioConnectionAnalog,
  103. bmdAudioConnectionAnalogXLR,
  104. bmdAudioConnectionAnalogRCA,
  105. bmdAudioConnectionMicrophone,
  106. };
  107. static const BMDVideoConnection decklink_video_connection_map[] = {
  108. (BMDVideoConnection)0,
  109. bmdVideoConnectionSDI,
  110. bmdVideoConnectionHDMI,
  111. bmdVideoConnectionOpticalSDI,
  112. bmdVideoConnectionComponent,
  113. bmdVideoConnectionComposite,
  114. bmdVideoConnectionSVideo,
  115. };
  116. HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
  117. 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);
  118. int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
  119. int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
  120. void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
  121. int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
  122. void ff_decklink_cleanup(AVFormatContext *avctx);
  123. int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
  124. #endif /* AVDEVICE_DECKLINK_COMMON_H */