2 * Blackmagic DeckLink common code
3 * Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
4 * Copyright (c) 2017 Akamai Technologies, Inc.
6 * This file is part of FFmpeg.
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.
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.
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
23 #ifndef AVDEVICE_DECKLINK_COMMON_H
24 #define AVDEVICE_DECKLINK_COMMON_H
26 #include <DeckLinkAPIVersion.h>
28 #include "libavutil/thread.h"
29 #include "decklink_common_c.h"
31 #include "libklvanc/vanc.h"
35 #define DECKLINK_BOOL BOOL
37 #define DECKLINK_BOOL bool
41 static char *dup_wchar_to_utf8(wchar_t *w)
44 int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
45 s = (char *) av_malloc(l);
47 WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
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)
57 CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
60 #define DECKLINK_STR const __CFString *
61 #define DECKLINK_STRDUP dup_cfstring_to_utf8
62 #define DECKLINK_FREE(s) CFRelease(s)
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)
70 class decklink_output_callback;
71 class decklink_input_callback;
73 typedef struct AVPacketQueue {
74 AVPacketList *first_pkt, *last_pkt;
76 unsigned long long size;
78 pthread_mutex_t mutex;
80 AVFormatContext *avctx;
85 /* DeckLink SDK interfaces */
89 IDeckLinkConfiguration *cfg;
90 IDeckLinkAttributes *attr;
91 decklink_output_callback *output_callback;
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;
102 int bmd_field_dominance;
105 /* Capture buffer queue */
108 /* Streams present */
113 int playback_started;
116 unsigned long frameCount;
117 unsigned int dropped;
120 AVStream *teletext_st;
121 uint16_t cdp_sequence_num;
126 int64_t teletext_lines;
129 DecklinkPtsSource audio_pts_source;
130 DecklinkPtsSource video_pts_source;
132 BMDPixelFormat raw_format;
137 pthread_mutex_t mutex;
139 int frames_buffer_available_spots;
143 struct klvanc_context_s *vanc_ctx;
150 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
153 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
154 typedef unsigned long buffercount_type;
156 typedef unsigned int buffercount_type;
158 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
160 typedef uint32_t buffercount_type;
163 static const BMDAudioConnection decklink_audio_connection_map[] = {
164 (BMDAudioConnection)0,
165 bmdAudioConnectionEmbedded,
166 bmdAudioConnectionAESEBU,
167 bmdAudioConnectionAnalog,
168 bmdAudioConnectionAnalogXLR,
169 bmdAudioConnectionAnalogRCA,
170 bmdAudioConnectionMicrophone,
173 static const BMDVideoConnection decklink_video_connection_map[] = {
174 (BMDVideoConnection)0,
175 bmdVideoConnectionSDI,
176 bmdVideoConnectionHDMI,
177 bmdVideoConnectionOpticalSDI,
178 bmdVideoConnectionComponent,
179 bmdVideoConnectionComposite,
180 bmdVideoConnectionSVideo,
183 static const BMDTimecodeFormat decklink_timecode_format_map[] = {
184 (BMDTimecodeFormat)0,
185 bmdTimecodeRP188VITC1,
186 bmdTimecodeRP188VITC2,
190 bmdTimecodeVITCField2,
194 int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
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);
199 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
200 void ff_decklink_cleanup(AVFormatContext *avctx);
201 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
203 #endif /* AVDEVICE_DECKLINK_COMMON_H */