decklink_common.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Blackmagic DeckLink common code
  3. * Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVDEVICE_DECKLINK_COMMON_H
  22. #define AVDEVICE_DECKLINK_COMMON_H
  23. #include <DeckLinkAPIVersion.h>
  24. #include "decklink_common_c.h"
  25. class decklink_output_callback;
  26. class decklink_input_callback;
  27. typedef struct AVPacketQueue {
  28. AVPacketList *first_pkt, *last_pkt;
  29. int nb_packets;
  30. unsigned long long size;
  31. int abort_request;
  32. pthread_mutex_t mutex;
  33. pthread_cond_t cond;
  34. AVFormatContext *avctx;
  35. } AVPacketQueue;
  36. struct decklink_ctx {
  37. /* DeckLink SDK interfaces */
  38. IDeckLink *dl;
  39. IDeckLinkOutput *dlo;
  40. IDeckLinkInput *dli;
  41. IDeckLinkConfiguration *cfg;
  42. IDeckLinkAttributes *attr;
  43. decklink_output_callback *output_callback;
  44. decklink_input_callback *input_callback;
  45. /* DeckLink mode information */
  46. BMDTimeValue bmd_tb_den;
  47. BMDTimeValue bmd_tb_num;
  48. BMDDisplayMode bmd_mode;
  49. BMDVideoConnection video_input;
  50. BMDAudioConnection audio_input;
  51. int bmd_width;
  52. int bmd_height;
  53. int bmd_field_dominance;
  54. /* Capture buffer queue */
  55. AVPacketQueue queue;
  56. /* Streams present */
  57. int audio;
  58. int video;
  59. /* Status */
  60. int playback_started;
  61. int capture_started;
  62. int64_t last_pts;
  63. unsigned long frameCount;
  64. unsigned int dropped;
  65. AVStream *audio_st;
  66. AVStream *video_st;
  67. AVStream *teletext_st;
  68. /* Options */
  69. int list_devices;
  70. int list_formats;
  71. int64_t teletext_lines;
  72. double preroll;
  73. int duplex_mode;
  74. DecklinkPtsSource audio_pts_source;
  75. DecklinkPtsSource video_pts_source;
  76. int draw_bars;
  77. int frames_preroll;
  78. int frames_buffer;
  79. sem_t semaphore;
  80. int channels;
  81. };
  82. typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
  83. #ifdef _WIN32
  84. #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
  85. typedef unsigned long buffercount_type;
  86. #else
  87. typedef unsigned int buffercount_type;
  88. #endif
  89. IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
  90. #else
  91. typedef uint32_t buffercount_type;
  92. #endif
  93. static const BMDAudioConnection decklink_audio_connection_map[] = {
  94. (BMDAudioConnection)0,
  95. bmdAudioConnectionEmbedded,
  96. bmdAudioConnectionAESEBU,
  97. bmdAudioConnectionAnalog,
  98. bmdAudioConnectionAnalogXLR,
  99. bmdAudioConnectionAnalogRCA,
  100. bmdAudioConnectionMicrophone,
  101. };
  102. static const BMDVideoConnection decklink_video_connection_map[] = {
  103. (BMDVideoConnection)0,
  104. bmdVideoConnectionSDI,
  105. bmdVideoConnectionHDMI,
  106. bmdVideoConnectionOpticalSDI,
  107. bmdVideoConnectionComponent,
  108. bmdVideoConnectionComposite,
  109. bmdVideoConnectionSVideo,
  110. };
  111. HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
  112. int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, decklink_direction_t direction = DIRECTION_OUT, int num = 0);
  113. int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
  114. int ff_decklink_list_devices(AVFormatContext *avctx);
  115. int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
  116. void ff_decklink_cleanup(AVFormatContext *avctx);
  117. int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
  118. #endif /* AVDEVICE_DECKLINK_COMMON_H */