FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
28 #include "libavutil/thread.h"
29 #include "decklink_common_c.h"
30 #if CONFIG_LIBKLVANC
31 #include "libklvanc/vanc.h"
32 #endif
33 
34 #ifdef _WIN32
35 #define DECKLINK_BOOL BOOL
36 #else
37 #define DECKLINK_BOOL bool
38 #endif
39 
40 #ifdef _WIN32
41 static char *dup_wchar_to_utf8(wchar_t *w)
42 {
43  char *s = NULL;
44  int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
45  s = (char *) av_malloc(l);
46  if (s)
47  WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
48  return s;
49 }
50 #define DECKLINK_STR OLECHAR *
51 #define DECKLINK_STRDUP dup_wchar_to_utf8
52 #define DECKLINK_FREE(s) SysFreeString(s)
53 #elif defined(__APPLE__)
54 static char *dup_cfstring_to_utf8(CFStringRef w)
55 {
56  char s[256];
57  CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
58  return av_strdup(s);
59 }
60 #define DECKLINK_STR const __CFString *
61 #define DECKLINK_STRDUP dup_cfstring_to_utf8
62 #define DECKLINK_FREE(s) CFRelease(s)
63 #else
64 #define DECKLINK_STR const char *
65 #define DECKLINK_STRDUP av_strdup
66 /* free() is needed for a string returned by the DeckLink SDL. */
67 #define DECKLINK_FREE(s) free((void *) s)
68 #endif
69 
72 
73 typedef struct AVPacketQueue {
76  unsigned long long size;
81  int64_t max_q_size;
83 
84 struct decklink_ctx {
85  /* DeckLink SDK interfaces */
86  IDeckLink *dl;
87  IDeckLinkOutput *dlo;
88  IDeckLinkInput *dli;
89  IDeckLinkConfiguration *cfg;
90  IDeckLinkAttributes *attr;
92 
93  /* DeckLink mode information */
94  BMDTimeValue bmd_tb_den;
95  BMDTimeValue bmd_tb_num;
96  BMDDisplayMode bmd_mode;
97  BMDVideoConnection video_input;
98  BMDAudioConnection audio_input;
99  BMDTimecodeFormat tc_format;
104 
105  /* Capture buffer queue */
107 
108  /* Streams present */
109  int audio;
110  int video;
111 
112  /* Status */
115  int64_t last_pts;
116  unsigned long frameCount;
117  unsigned int dropped;
122 
123  /* Options */
126  int64_t teletext_lines;
127  double preroll;
132  BMDPixelFormat raw_format;
133 
136 
141 
142 #if CONFIG_LIBKLVANC
143  struct klvanc_context_s *vanc_ctx;
144 #endif
145 
146  int channels;
148 };
149 
151 
152 #ifdef _WIN32
153 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
154 typedef unsigned long buffercount_type;
155 #else
156 typedef unsigned int buffercount_type;
157 #endif
158 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
159 #else
160 typedef uint32_t buffercount_type;
161 #endif
162 
163 static const BMDAudioConnection decklink_audio_connection_map[] = {
164  (BMDAudioConnection)0,
165  bmdAudioConnectionEmbedded,
166  bmdAudioConnectionAESEBU,
167  bmdAudioConnectionAnalog,
168  bmdAudioConnectionAnalogXLR,
169  bmdAudioConnectionAnalogRCA,
170  bmdAudioConnectionMicrophone,
171 };
172 
173 static const BMDVideoConnection decklink_video_connection_map[] = {
174  (BMDVideoConnection)0,
175  bmdVideoConnectionSDI,
176  bmdVideoConnectionHDMI,
177  bmdVideoConnectionOpticalSDI,
178  bmdVideoConnectionComponent,
179  bmdVideoConnectionComposite,
180  bmdVideoConnectionSVideo,
181 };
182 
183 static const BMDTimecodeFormat decklink_timecode_format_map[] = {
184  (BMDTimecodeFormat)0,
185  bmdTimecodeRP188VITC1,
186  bmdTimecodeRP188VITC2,
187  bmdTimecodeRP188LTC,
188  bmdTimecodeRP188Any,
189  bmdTimecodeVITC,
190  bmdTimecodeVITCField2,
191  bmdTimecodeSerial,
192 };
193 
195 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);
196 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
197 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
198 void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
201 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
202 
203 #endif /* AVDEVICE_DECKLINK_COMMON_H */
#define NULL
Definition: coverity.c:32
pthread_cond_t cond
Format I/O context.
Definition: avformat.h:1351
#define av_malloc(s)
pthread_mutex_t mutex
#define height
AVPacketList * last_pkt
static char * dup_wchar_to_utf8(wchar_t *w)
Definition: dshow.c:132
AVPacketList * first_pkt
unsigned long long size
#define width
uint8_t w
Definition: llviddspenc.c:38
#define s(width, name)
Definition: cbs_vp9.c:257
Stream structure.
Definition: avformat.h:874
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
AVFieldOrder
Definition: avcodec.h:1511
int64_t max_q_size
AVFormatContext * avctx
List of devices.
Definition: avdevice.h:460
_fmutex pthread_mutex_t
Definition: os2threads.h:49
const char * name
Definition: opengl_enc.c:103