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"
32 #define DECKLINK_BOOL BOOL
34 #define DECKLINK_BOOL bool
38 static char *dup_wchar_to_utf8(wchar_t *w)
41 int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
42 s = (char *) av_malloc(l);
44 WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
47 #define DECKLINK_STR OLECHAR *
48 #define DECKLINK_STRDUP dup_wchar_to_utf8
49 #define DECKLINK_FREE(s) SysFreeString(s)
50 #elif defined(__APPLE__)
51 static char *dup_cfstring_to_utf8(CFStringRef w)
54 CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
57 #define DECKLINK_STR const __CFString *
58 #define DECKLINK_STRDUP dup_cfstring_to_utf8
59 #define DECKLINK_FREE(s) CFRelease(s)
61 #define DECKLINK_STR const char *
62 #define DECKLINK_STRDUP av_strdup
63 /* free() is needed for a string returned by the DeckLink SDL. */
64 #define DECKLINK_FREE(s) free((void *) s)
67 class decklink_output_callback;
68 class decklink_input_callback;
70 typedef struct AVPacketQueue {
71 AVPacketList *first_pkt, *last_pkt;
73 unsigned long long size;
75 pthread_mutex_t mutex;
77 AVFormatContext *avctx;
82 /* DeckLink SDK interfaces */
86 IDeckLinkConfiguration *cfg;
87 IDeckLinkAttributes *attr;
88 decklink_output_callback *output_callback;
90 /* DeckLink mode information */
91 BMDTimeValue bmd_tb_den;
92 BMDTimeValue bmd_tb_num;
93 BMDDisplayMode bmd_mode;
94 BMDVideoConnection video_input;
95 BMDAudioConnection audio_input;
98 int bmd_field_dominance;
100 /* Capture buffer queue */
103 /* Streams present */
108 int playback_started;
111 unsigned long frameCount;
112 unsigned int dropped;
115 AVStream *teletext_st;
120 int64_t teletext_lines;
123 DecklinkPtsSource audio_pts_source;
124 DecklinkPtsSource video_pts_source;
130 pthread_mutex_t mutex;
132 int frames_buffer_available_spots;
139 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
142 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
143 typedef unsigned long buffercount_type;
145 typedef unsigned int buffercount_type;
147 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
149 typedef uint32_t buffercount_type;
152 static const BMDAudioConnection decklink_audio_connection_map[] = {
153 (BMDAudioConnection)0,
154 bmdAudioConnectionEmbedded,
155 bmdAudioConnectionAESEBU,
156 bmdAudioConnectionAnalog,
157 bmdAudioConnectionAnalogXLR,
158 bmdAudioConnectionAnalogRCA,
159 bmdAudioConnectionMicrophone,
162 static const BMDVideoConnection decklink_video_connection_map[] = {
163 (BMDVideoConnection)0,
164 bmdVideoConnectionSDI,
165 bmdVideoConnectionHDMI,
166 bmdVideoConnectionOpticalSDI,
167 bmdVideoConnectionComponent,
168 bmdVideoConnectionComposite,
169 bmdVideoConnectionSVideo,
172 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
173 int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
174 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);
175 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
176 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
177 void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
178 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
179 void ff_decklink_cleanup(AVFormatContext *avctx);
180 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
182 #endif /* AVDEVICE_DECKLINK_COMMON_H */