FFmpeg
Loading...
Searching...
No Matches
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#if BLACKMAGIC_DECKLINK_API_VERSION < 0x0e030000
33#define IDeckLinkInput_v14_2_1 IDeckLinkInput
34#define IDeckLinkInputCallback_v14_2_1 IDeckLinkInputCallback
35#define IDeckLinkMemoryAllocator_v14_2_1 IDeckLinkMemoryAllocator
36#define IDeckLinkOutput_v14_2_1 IDeckLinkOutput
37#define IDeckLinkVideoFrame_v14_2_1 IDeckLinkVideoFrame
38#define IDeckLinkVideoInputFrame_v14_2_1 IDeckLinkVideoInputFrame
39#define IDeckLinkVideoOutputCallback_v14_2_1 IDeckLinkVideoOutputCallback
40#define IID_IDeckLinkInput_v14_2_1 IID_IDeckLinkInput
41#define IID_IDeckLinkInputCallback_v14_2_1 IID_IDeckLinkInputCallback
42#define IID_IDeckLinkMemoryAllocator_v14_2_1 IID_IDeckLinkMemoryAllocator
43#define IID_IDeckLinkOutput_v14_2_1 IID_IDeckLinkOutput
44#define IID_IDeckLinkVideoFrame_v14_2_1 IID_IDeckLinkVideoFrame
45#define IID_IDeckLinkVideoInputFrame_v14_2_1 IID_IDeckLinkVideoInputFrame
46#define IID_IDeckLinkVideoOutputCallback_v14_2_1 IID_IDeckLinkVideoOutputCallback
47#endif
48
49extern "C" {
50#include "libavutil/mem.h"
52#include "libavfilter/ccfifo.h"
53}
54#include "libavutil/thread.h"
55#include "decklink_common_c.h"
56#if CONFIG_LIBKLVANC
57#include "libklvanc/vanc.h"
58#endif
59
60#ifdef _WIN32
61#define DECKLINK_BOOL BOOL
62#else
63#define DECKLINK_BOOL bool
64#endif
65
66#ifdef _WIN32
67static char *dup_wchar_to_utf8(wchar_t *w)
68{
69 char *s = NULL;
70 int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
71 s = (char *) av_malloc(l);
72 if (s)
73 WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
74 return s;
75}
76#define DECKLINK_STR OLECHAR *
77#define DECKLINK_STRDUP dup_wchar_to_utf8
78#define DECKLINK_FREE(s) SysFreeString(s)
79#elif defined(__APPLE__)
80static char *dup_cfstring_to_utf8(CFStringRef w)
81{
82 char s[256];
83 CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
84 return av_strdup(s);
85}
86#define DECKLINK_STR const __CFString *
87#define DECKLINK_STRDUP dup_cfstring_to_utf8
88#define DECKLINK_FREE(s) CFRelease(s)
89#else
90#define DECKLINK_STR const char *
91#define DECKLINK_STRDUP av_strdup
92/* free() is needed for a string returned by the DeckLink SDL. */
93#define DECKLINK_FREE(s) free((void *) s)
94#endif
95
96#ifdef _WIN32
97#include <guiddef.h> // REFIID, IsEqualIID()
98#define DECKLINK_IsEqualIID IsEqualIID
99#else
100static inline bool DECKLINK_IsEqualIID(const REFIID& riid1, const REFIID& riid2)
101{
102 return memcmp(&riid1, &riid2, sizeof(REFIID)) == 0;
103}
104#endif
105
106#ifdef __APPLE__
107/* The macOS SDK only provides IUnknownUUID. */
108#define IID_IUnknown CFUUIDGetUUIDBytes(IUnknownUUID)
109#endif
110
113
124
126 /* DeckLink SDK interfaces */
127 IDeckLink *dl;
130 IDeckLinkConfiguration *cfg;
133
134 /* DeckLink mode information */
135 BMDTimeValue bmd_tb_den;
136 BMDTimeValue bmd_tb_num;
137 BMDDisplayMode bmd_mode;
138 BMDVideoConnection video_input;
139 BMDAudioConnection audio_input;
140 BMDTimecodeFormat tc_format;
145
146 /* Capture buffer queue */
148
149 CCFifo cc_fifo; ///< closed captions
150
151 /* Output VANC queue */
153
154 /* Streams present */
155 int audio;
156 int video;
157
158 /* Status */
162 unsigned long frameCount;
163 unsigned int dropped;
169
170 /* Options */
175 double preroll;
177 BMDLinkConfiguration link;
181 BMDPixelFormat raw_format;
183
186
191
192#if CONFIG_LIBKLVANC
193 struct klvanc_context_s *vanc_ctx;
194#endif
195
198 unsigned long tc_seen; // used with option wait_for_tc
199};
200
202
203static const BMDPixelFormat decklink_raw_format_map[] = {
204 (BMDPixelFormat)0,
205 bmdFormat8BitYUV,
206 bmdFormat10BitYUV,
207 bmdFormat8BitARGB,
208 bmdFormat8BitBGRA,
209 bmdFormat10BitRGB,
210};
211
212static const BMDAudioConnection decklink_audio_connection_map[] = {
213 (BMDAudioConnection)0,
214 bmdAudioConnectionEmbedded,
215 bmdAudioConnectionAESEBU,
216 bmdAudioConnectionAnalog,
217 bmdAudioConnectionAnalogXLR,
218 bmdAudioConnectionAnalogRCA,
219 bmdAudioConnectionMicrophone,
220};
221
222static const BMDVideoConnection decklink_video_connection_map[] = {
223 (BMDVideoConnection)0,
224 bmdVideoConnectionSDI,
225 bmdVideoConnectionHDMI,
226 bmdVideoConnectionOpticalSDI,
227 bmdVideoConnectionComponent,
228 bmdVideoConnectionComposite,
229 bmdVideoConnectionSVideo,
230};
231
232static const BMDTimecodeFormat decklink_timecode_format_map[] = {
233 (BMDTimecodeFormat)0,
234 bmdTimecodeRP188VITC1,
235 bmdTimecodeRP188VITC2,
236 bmdTimecodeRP188LTC,
237 bmdTimecodeRP188Any,
238 bmdTimecodeVITC,
239 bmdTimecodeVITCField2,
240 bmdTimecodeSerial,
241#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
242 bmdTimecodeRP188HighFrameRate,
243#else
244 (BMDTimecodeFormat)0,
245#endif
246};
247
248static const BMDLinkConfiguration decklink_link_conf_map[] = {
249 (BMDLinkConfiguration)0,
250 bmdLinkConfigurationSingleLink,
251 bmdLinkConfigurationDualLink,
252 bmdLinkConfigurationQuadLink
253};
254
255#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
256static const BMDProfileID decklink_profile_id_map[] = {
257 (BMDProfileID)0,
258 bmdProfileTwoSubDevicesHalfDuplex,
259 bmdProfileOneSubDeviceFullDuplex,
260 bmdProfileOneSubDeviceHalfDuplex,
261 bmdProfileTwoSubDevicesFullDuplex,
262 bmdProfileFourSubDevicesHalfDuplex,
263};
264#endif
265
267int 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);
269int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
270void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
273int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
274
282
283#endif /* AVDEVICE_DECKLINK_COMMON_H */
#define s(width, name)
Definition cbs_vp9.c:198
CC FIFO Buffer.
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static int16_t block[64]
Definition dct.c:125
AVFieldOrder
Definition defs.h:227
static AVPacket * pkt
static char * dup_wchar_to_utf8(wchar_t *w)
Definition dshow.c:313
uint8_t w
Definition llvidencdsp.c:39
Memory handling functions.
#define av_strdup(s)
Definition ops_static.c:55
#define av_malloc(s)
Definition ops_static.c:52
_fmutex pthread_mutex_t
Definition os2threads.h:53
const char * name
Definition qsvenc.c:142
List of devices.
Definition avdevice.h:343
Format I/O context.
Definition avformat.h:1401
This structure stores compressed data.
Definition packet.h:587
Stream structure.
Definition avformat.h:768
pthread_mutex_t mutex
unsigned long long size
AVFormatContext * avctx
#define height
Definition dsp.h:99
#define width
Definition dsp.h:99