]> git.sesse.net Git - ffmpeg/blob - libavdevice/decklink_common.h
Merge commit 'f8060865f3e1a16c62e0d337ef0979b6ee4ba457'
[ffmpeg] / libavdevice / decklink_common.h
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
31 #ifdef _WIN32
32 #define DECKLINK_BOOL BOOL
33 #else
34 #define DECKLINK_BOOL bool
35 #endif
36
37 #ifdef _WIN32
38 static char *dup_wchar_to_utf8(wchar_t *w)
39 {
40     char *s = NULL;
41     int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
42     s = (char *) av_malloc(l);
43     if (s)
44         WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
45     return s;
46 }
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)
52 {
53     char s[256];
54     CFStringGetCString(w, s, 255, kCFStringEncodingUTF8);
55     return av_strdup(s);
56 }
57 #define DECKLINK_STR    const __CFString *
58 #define DECKLINK_STRDUP dup_cfstring_to_utf8
59 #define DECKLINK_FREE(s) CFRelease(s)
60 #else
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)
65 #endif
66
67 class decklink_output_callback;
68 class decklink_input_callback;
69
70 typedef struct AVPacketQueue {
71     AVPacketList *first_pkt, *last_pkt;
72     int nb_packets;
73     unsigned long long size;
74     int abort_request;
75     pthread_mutex_t mutex;
76     pthread_cond_t cond;
77     AVFormatContext *avctx;
78     int64_t max_q_size;
79 } AVPacketQueue;
80
81 struct decklink_ctx {
82     /* DeckLink SDK interfaces */
83     IDeckLink *dl;
84     IDeckLinkOutput *dlo;
85     IDeckLinkInput *dli;
86     IDeckLinkConfiguration *cfg;
87     IDeckLinkAttributes *attr;
88     decklink_output_callback *output_callback;
89
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;
96     BMDTimecodeFormat tc_format;
97     int bmd_width;
98     int bmd_height;
99     int bmd_field_dominance;
100
101     /* Capture buffer queue */
102     AVPacketQueue queue;
103
104     /* Streams present */
105     int audio;
106     int video;
107
108     /* Status */
109     int playback_started;
110     int capture_started;
111     int64_t last_pts;
112     unsigned long frameCount;
113     unsigned int dropped;
114     AVStream *audio_st;
115     AVStream *video_st;
116     AVStream *teletext_st;
117
118     /* Options */
119     int list_devices;
120     int list_formats;
121     int64_t teletext_lines;
122     double preroll;
123     int duplex_mode;
124     DecklinkPtsSource audio_pts_source;
125     DecklinkPtsSource video_pts_source;
126     int draw_bars;
127
128     int frames_preroll;
129     int frames_buffer;
130
131     pthread_mutex_t mutex;
132     pthread_cond_t cond;
133     int frames_buffer_available_spots;
134     int autodetect;
135
136     int channels;
137     int audio_depth;
138 };
139
140 typedef enum { DIRECTION_IN, DIRECTION_OUT} decklink_direction_t;
141
142 #ifdef _WIN32
143 #if BLACKMAGIC_DECKLINK_API_VERSION < 0x0a040000
144 typedef unsigned long buffercount_type;
145 #else
146 typedef unsigned int buffercount_type;
147 #endif
148 IDeckLinkIterator *CreateDeckLinkIteratorInstance(void);
149 #else
150 typedef uint32_t buffercount_type;
151 #endif
152
153 static const BMDAudioConnection decklink_audio_connection_map[] = {
154     (BMDAudioConnection)0,
155     bmdAudioConnectionEmbedded,
156     bmdAudioConnectionAESEBU,
157     bmdAudioConnectionAnalog,
158     bmdAudioConnectionAnalogXLR,
159     bmdAudioConnectionAnalogRCA,
160     bmdAudioConnectionMicrophone,
161 };
162
163 static const BMDVideoConnection decklink_video_connection_map[] = {
164     (BMDVideoConnection)0,
165     bmdVideoConnectionSDI,
166     bmdVideoConnectionHDMI,
167     bmdVideoConnectionOpticalSDI,
168     bmdVideoConnectionComponent,
169     bmdVideoConnectionComposite,
170     bmdVideoConnectionSVideo,
171 };
172
173 static const BMDTimecodeFormat decklink_timecode_format_map[] = {
174     (BMDTimecodeFormat)0,
175     bmdTimecodeRP188VITC1,
176     bmdTimecodeRP188VITC2,
177     bmdTimecodeRP188LTC,
178     bmdTimecodeRP188Any,
179     bmdTimecodeVITC,
180     bmdTimecodeVITCField2,
181     bmdTimecodeSerial,
182 };
183
184 HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName);
185 int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction);
186 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);
187 int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);
188 int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs);
189 void ff_decklink_list_devices_legacy(AVFormatContext *avctx, int show_inputs, int show_outputs);
190 int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT);
191 void ff_decklink_cleanup(AVFormatContext *avctx);
192 int ff_decklink_init_device(AVFormatContext *avctx, const char* name);
193
194 #endif /* AVDEVICE_DECKLINK_COMMON_H */