FFmpeg
decklink_common.h
Go to the documentation of this file.
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 
23 #ifndef AVDEVICE_DECKLINK_COMMON_H
24 #define AVDEVICE_DECKLINK_COMMON_H
25 
26 #include <DeckLinkAPIVersion.h>
27 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0b000000
28 #define IID_IDeckLinkProfileAttributes IID_IDeckLinkAttributes
29 #define IDeckLinkProfileAttributes IDeckLinkAttributes
30 #endif
31 
32 extern "C" {
33 #include "libavutil/mem.h"
35 #include "libavfilter/ccfifo.h"
36 }
37 #include "libavutil/thread.h"
38 #include "decklink_common_c.h"
39 #if CONFIG_LIBKLVANC
40 #include "libklvanc/vanc.h"
41 #endif
42 
43 #ifdef _WIN32
44 #define DECKLINK_BOOL BOOL
45 #else
46 #define DECKLINK_BOOL bool
47 #endif
48 
49 #ifdef _WIN32
50 static char *dup_wchar_to_utf8(wchar_t *w)
51 {
52  char *s = NULL;
53  int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
54  s = (char *) av_malloc(l);
55  if (s)
56  WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
57  return s;
58 }
59 #define DECKLINK_STR OLECHAR *
60 #define DECKLINK_STRDUP dup_wchar_to_utf8
61 #define DECKLINK_FREE(s) SysFreeString(s)
62 #elif defined(__APPLE__)
63 static char *dup_cfstring_to_utf8(CFStringRef w)
64 {
65  char s[256];
66  CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
67  return av_strdup(s);
68 }
69 #define DECKLINK_STR const __CFString *
70 #define DECKLINK_STRDUP dup_cfstring_to_utf8
71 #define DECKLINK_FREE(s) CFRelease(s)
72 #else
73 #define DECKLINK_STR const char *
74 #define DECKLINK_STRDUP av_strdup
75 /* free() is needed for a string returned by the DeckLink SDL. */
76 #define DECKLINK_FREE(s) free((void *) s)
77 #endif
78 
81 
82 typedef struct DecklinkPacketQueue {
85  unsigned long long size;
90  int64_t max_q_size;
92 
93 struct decklink_ctx {
94  /* DeckLink SDK interfaces */
95  IDeckLink *dl;
96  IDeckLinkOutput *dlo;
97  IDeckLinkInput *dli;
98  IDeckLinkConfiguration *cfg;
101 
102  /* DeckLink mode information */
103  BMDTimeValue bmd_tb_den;
104  BMDTimeValue bmd_tb_num;
105  BMDDisplayMode bmd_mode;
106  BMDVideoConnection video_input;
107  BMDAudioConnection audio_input;
108  BMDTimecodeFormat tc_format;
113 
114  /* Capture buffer queue */
116 
117  CCFifo cc_fifo; ///< closed captions
118 
119  /* Output VANC queue */
121 
122  /* Streams present */
123  int audio;
124  int video;
125 
126  /* Status */
128  int64_t first_pts;
129  int64_t last_pts;
130  unsigned long frameCount;
131  unsigned int dropped;
137 
138  /* Options */
142  int64_t teletext_lines;
143  double preroll;
145  BMDLinkConfiguration link;
149  BMDPixelFormat raw_format;
150 
153 
158 
159 #if CONFIG_LIBKLVANC
160  struct klvanc_context_s *vanc_ctx;
161 #endif
162 
163  int channels;
165  unsigned long tc_seen; // used with option wait_for_tc
166 };
167 
169 
170 static const BMDPixelFormat decklink_raw_format_map[] = {
171  (BMDPixelFormat)0,
172  bmdFormat8BitYUV,
173  bmdFormat10BitYUV,
174  bmdFormat8BitARGB,
175  bmdFormat8BitBGRA,
176  bmdFormat10BitRGB,
177 };
178 
179 static const BMDAudioConnection decklink_audio_connection_map[] = {
180  (BMDAudioConnection)0,
181  bmdAudioConnectionEmbedded,
182  bmdAudioConnectionAESEBU,
183  bmdAudioConnectionAnalog,
184  bmdAudioConnectionAnalogXLR,
185  bmdAudioConnectionAnalogRCA,
186  bmdAudioConnectionMicrophone,
187 };
188 
189 static const BMDVideoConnection decklink_video_connection_map[] = {
190  (BMDVideoConnection)0,
191  bmdVideoConnectionSDI,
192  bmdVideoConnectionHDMI,
193  bmdVideoConnectionOpticalSDI,
194  bmdVideoConnectionComponent,
195  bmdVideoConnectionComposite,
196  bmdVideoConnectionSVideo,
197 };
198 
199 static const BMDTimecodeFormat decklink_timecode_format_map[] = {
200  (BMDTimecodeFormat)0,
201  bmdTimecodeRP188VITC1,
202  bmdTimecodeRP188VITC2,
203  bmdTimecodeRP188LTC,
204  bmdTimecodeRP188Any,
205  bmdTimecodeVITC,
206  bmdTimecodeVITCField2,
207  bmdTimecodeSerial,
208 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
209  bmdTimecodeRP188HighFrameRate,
210 #else
211  (BMDTimecodeFormat)0,
212 #endif
213 };
214 
215 static const BMDLinkConfiguration decklink_link_conf_map[] = {
216  (BMDLinkConfiguration)0,
217  bmdLinkConfigurationSingleLink,
218  bmdLinkConfigurationDualLink,
219  bmdLinkConfigurationQuadLink
220 };
221 
222 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
223 static const BMDProfileID decklink_profile_id_map[] = {
224  (BMDProfileID)0,
225  bmdProfileTwoSubDevicesHalfDuplex,
226  bmdProfileOneSubDeviceFullDuplex,
227  bmdProfileOneSubDeviceHalfDuplex,
228  bmdProfileTwoSubDevicesFullDuplex,
229  bmdProfileFourSubDevicesHalfDuplex,
230 };
231 #endif
232 
234 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);
236 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
237 void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
240 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
241 
242 void ff_decklink_packet_queue_init(AVFormatContext *avctx, DecklinkPacketQueue *q, int64_t queue_size);
249 
250 #endif /* AVDEVICE_DECKLINK_COMMON_H */
pthread_mutex_t
_fmutex pthread_mutex_t
Definition: os2threads.h:53
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
DecklinkPacketQueue::abort_request
int abort_request
Definition: decklink_common.h:86
AVFieldOrder
AVFieldOrder
Definition: defs.h:199
thread.h
w
uint8_t w
Definition: llviddspenc.c:38
PacketList
Definition: packet_internal.h:33
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
pkt
AVPacket * pkt
Definition: movenc.c:60
width
#define width
DecklinkPacketQueue::cond
pthread_cond_t cond
Definition: decklink_common.h:88
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
DecklinkPacketQueue::nb_packets
int nb_packets
Definition: decklink_common.h:84
NULL
#define NULL
Definition: coverity.c:32
DecklinkPacketQueue::avctx
AVFormatContext * avctx
Definition: decklink_common.h:89
CCFifo
Definition: ccfifo.h:40
DecklinkPacketQueue::pkt_list
PacketList pkt_list
Definition: decklink_common.h:83
DecklinkPacketQueue
Definition: decklink_common.h:82
DecklinkPacketQueue::size
unsigned long long size
Definition: decklink_common.h:85
height
#define height
dup_wchar_to_utf8
static char * dup_wchar_to_utf8(wchar_t *w)
Definition: dshow.c:313
pthread_cond_t
Definition: os2threads.h:58
AVStream
Stream structure.
Definition: avformat.h:743
AVDeviceInfoList
List of devices.
Definition: avdevice.h:343
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
mem.h
packet_internal.h
AVPacket
This structure stores compressed data.
Definition: packet.h:497
DecklinkPacketQueue::max_q_size
int64_t max_q_size
Definition: decklink_common.h:90
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
ccfifo.h
DecklinkPacketQueue::mutex
pthread_mutex_t mutex
Definition: decklink_common.h:87