2 * Copyright (C) 2011 David Schleef <ds@schleef.org>
3 * Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
4 * Copyright (C) 2015 Florian Langlois <florian.langlois@fr.thalesgroup.com>
5 * Copyright (C) 2020 Sohonet <dev@sohonet.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #ifndef _GST_DECKLINK_H_
24 #define _GST_DECKLINK_H_
27 #include <gst/video/video.h>
32 #include "linux/DeckLinkAPI.h"
36 #include "win/DeckLinkAPI.h"
43 /* MinGW does not have comsuppw.lib, so no _com_util::ConvertBSTRToString */
45 # define CONVERT_COM_STRING(s) G_STMT_START { BSTR _s = (BSTR)s; s = (char*) malloc(100); wcstombs(s, _s, 100); ::SysFreeString(_s); } G_STMT_END
46 # define FREE_COM_STRING(s) free(s);
48 # define CONVERT_COM_STRING(s) G_STMT_START { BSTR _s = (BSTR)s; s = _com_util::ConvertBSTRToString(_s); ::SysFreeString(_s); } G_STMT_END
49 # define FREE_COM_STRING(s) G_STMT_START { delete[] s; } G_STMT_END
50 # endif /* __MINGW32__ */
52 #define COMSTR_T const char*
53 #define CONVERT_COM_STRING(s)
54 #define FREE_COM_STRING(s)
56 #endif /* G_OS_WIN32 */
58 void decklink_element_init (GstPlugin * plugin);
61 GST_DECKLINK_MODE_AUTO,
63 GST_DECKLINK_MODE_NTSC,
64 GST_DECKLINK_MODE_NTSC2398,
65 GST_DECKLINK_MODE_PAL,
66 GST_DECKLINK_MODE_NTSC_P,
67 GST_DECKLINK_MODE_PAL_P,
69 GST_DECKLINK_MODE_1080p2398,
70 GST_DECKLINK_MODE_1080p24,
71 GST_DECKLINK_MODE_1080p25,
72 GST_DECKLINK_MODE_1080p2997,
73 GST_DECKLINK_MODE_1080p30,
75 GST_DECKLINK_MODE_1080i50,
76 GST_DECKLINK_MODE_1080i5994,
77 GST_DECKLINK_MODE_1080i60,
79 GST_DECKLINK_MODE_1080p50,
80 GST_DECKLINK_MODE_1080p5994,
81 GST_DECKLINK_MODE_1080p60,
83 GST_DECKLINK_MODE_720p50,
84 GST_DECKLINK_MODE_720p5994,
85 GST_DECKLINK_MODE_720p60,
87 GST_DECKLINK_MODE_1556p2398,
88 GST_DECKLINK_MODE_1556p24,
89 GST_DECKLINK_MODE_1556p25,
91 GST_DECKLINK_MODE_2KDCI2398,
92 GST_DECKLINK_MODE_2KDCI24,
93 GST_DECKLINK_MODE_2KDCI25,
94 GST_DECKLINK_MODE_2KDCI2997,
95 GST_DECKLINK_MODE_2KDCI30,
96 GST_DECKLINK_MODE_2KDCI50,
97 GST_DECKLINK_MODE_2KDCI5994,
98 GST_DECKLINK_MODE_2KDCI60,
100 GST_DECKLINK_MODE_2160p2398,
101 GST_DECKLINK_MODE_2160p24,
102 GST_DECKLINK_MODE_2160p25,
103 GST_DECKLINK_MODE_2160p2997,
104 GST_DECKLINK_MODE_2160p30,
105 GST_DECKLINK_MODE_2160p50,
106 GST_DECKLINK_MODE_2160p5994,
107 GST_DECKLINK_MODE_2160p60,
109 GST_DECKLINK_MODE_NTSC_WIDESCREEN,
110 GST_DECKLINK_MODE_NTSC2398_WIDESCREEN,
111 GST_DECKLINK_MODE_PAL_WIDESCREEN,
112 GST_DECKLINK_MODE_NTSC_P_WIDESCREEN,
113 GST_DECKLINK_MODE_PAL_P_WIDESCREEN
114 } GstDecklinkModeEnum;
115 #define GST_TYPE_DECKLINK_MODE (gst_decklink_mode_get_type ())
116 GType gst_decklink_mode_get_type (void);
119 GST_DECKLINK_CONNECTION_AUTO,
120 GST_DECKLINK_CONNECTION_SDI,
121 GST_DECKLINK_CONNECTION_HDMI,
122 GST_DECKLINK_CONNECTION_OPTICAL_SDI,
123 GST_DECKLINK_CONNECTION_COMPONENT,
124 GST_DECKLINK_CONNECTION_COMPOSITE,
125 GST_DECKLINK_CONNECTION_SVIDEO
126 } GstDecklinkConnectionEnum;
127 #define GST_TYPE_DECKLINK_CONNECTION (gst_decklink_connection_get_type ())
128 GType gst_decklink_connection_get_type (void);
131 GST_DECKLINK_AUDIO_CONNECTION_AUTO,
132 GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED,
133 GST_DECKLINK_AUDIO_CONNECTION_AES_EBU,
134 GST_DECKLINK_AUDIO_CONNECTION_ANALOG,
135 GST_DECKLINK_AUDIO_CONNECTION_ANALOG_XLR,
136 GST_DECKLINK_AUDIO_CONNECTION_ANALOG_RCA
137 } GstDecklinkAudioConnectionEnum;
138 #define GST_TYPE_DECKLINK_AUDIO_CONNECTION (gst_decklink_audio_connection_get_type ())
139 GType gst_decklink_audio_connection_get_type (void);
142 GST_DECKLINK_AUDIO_CHANNELS_MAX = 0,
143 GST_DECKLINK_AUDIO_CHANNELS_2 = 2,
144 GST_DECKLINK_AUDIO_CHANNELS_8 = 8,
145 GST_DECKLINK_AUDIO_CHANNELS_16 = 16
146 } GstDecklinkAudioChannelsEnum;
147 #define GST_TYPE_DECKLINK_AUDIO_CHANNELS (gst_decklink_audio_channels_get_type ())
148 GType gst_decklink_audio_channels_get_type (void);
151 GST_DECKLINK_VIDEO_FORMAT_AUTO,
152 GST_DECKLINK_VIDEO_FORMAT_8BIT_YUV, /* bmdFormat8BitYUV */
153 GST_DECKLINK_VIDEO_FORMAT_10BIT_YUV, /* bmdFormat10BitYUV */
154 GST_DECKLINK_VIDEO_FORMAT_8BIT_ARGB, /* bmdFormat8BitARGB */
155 GST_DECKLINK_VIDEO_FORMAT_8BIT_BGRA, /* bmdFormat8BitBGRA */
156 GST_DECKLINK_VIDEO_FORMAT_10BIT_RGB, /* bmdFormat10BitRGB */
157 GST_DECKLINK_VIDEO_FORMAT_12BIT_RGB, /* bmdFormat12BitRGB */
158 GST_DECKLINK_VIDEO_FORMAT_12BIT_RGBLE, /* bmdFormat12BitRGBLE */
159 GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBXLE, /* bmdFormat10BitRGBXLE */
160 GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBX, /* bmdFormat10BitRGBX */
161 } GstDecklinkVideoFormat;
162 #define GST_TYPE_DECKLINK_VIDEO_FORMAT (gst_decklink_video_format_get_type ())
163 GType gst_decklink_video_format_get_type (void);
166 GST_DECKLINK_PROFILE_ID_DEFAULT,
167 GST_DECKLINK_PROFILE_ID_ONE_SUB_DEVICE_FULL_DUPLEX, /* bmdProfileOneSubDeviceFullDuplex */
168 GST_DECKLINK_PROFILE_ID_ONE_SUB_DEVICE_HALF_DUPLEX, /* bmdProfileOneSubDeviceHalfDuplex */
169 GST_DECKLINK_PROFILE_ID_TWO_SUB_DEVICES_FULL_DUPLEX, /* bmdProfileTwoSubDevicesFullDuplex */
170 GST_DECKLINK_PROFILE_ID_TWO_SUB_DEVICES_HALF_DUPLEX, /* bmdProfileTwoSubDevicesHalfDuplex */
171 GST_DECKLINK_PROFILE_ID_FOUR_SUB_DEVICES_HALF_DUPLEX, /* bmdProfileFourSubDevicesHalfDuplex */
172 } GstDecklinkProfileId;
173 #define GST_TYPE_DECKLINK_PROFILE_ID (gst_decklink_profile_id_get_type ())
174 GType gst_decklink_profile_id_get_type (void);
177 GST_DECKLINK_MAPPING_FORMAT_DEFAULT,
178 GST_DECKLINK_MAPPING_FORMAT_LEVEL_A, /* bmdDeckLinkConfigSMPTELevelAOutput = true */
179 GST_DECKLINK_MAPPING_FORMAT_LEVEL_B, /* bmdDeckLinkConfigSMPTELevelAOutput = false */
180 } GstDecklinkMappingFormat;
181 #define GST_TYPE_DECKLINK_MAPPING_FORMAT (gst_decklink_mapping_format_get_type ())
182 GType gst_decklink_mapping_format_get_type (void);
185 GST_DECKLINK_TIMECODE_FORMAT_RP188VITC1, /*bmdTimecodeRP188VITC1 */
186 GST_DECKLINK_TIMECODE_FORMAT_RP188VITC2, /*bmdTimecodeRP188VITC2 */
187 GST_DECKLINK_TIMECODE_FORMAT_RP188LTC, /*bmdTimecodeRP188LTC */
188 GST_DECKLINK_TIMECODE_FORMAT_RP188ANY, /*bmdTimecodeRP188Any */
189 GST_DECKLINK_TIMECODE_FORMAT_VITC, /*bmdTimecodeVITC */
190 GST_DECKLINK_TIMECODE_FORMAT_VITCFIELD2, /*bmdTimecodeVITCField2 */
191 GST_DECKLINK_TIMECODE_FORMAT_SERIAL /* bmdTimecodeSerial */
192 } GstDecklinkTimecodeFormat;
193 #define GST_TYPE_DECKLINK_TIMECODE_FORMAT (gst_decklink_timecode_format_get_type ())
194 GType gst_decklink_timecode_format_get_type (void);
198 GST_DECKLINK_KEYER_MODE_OFF,
199 GST_DECKLINK_KEYER_MODE_INTERNAL,
200 GST_DECKLINK_KEYER_MODE_EXTERNAL
201 } GstDecklinkKeyerMode;
202 #define GST_TYPE_DECKLINK_KEYER_MODE (gst_decklink_keyer_mode_get_type ())
203 GType gst_decklink_keyer_mode_get_type (void);
205 /* Enum BMDKeyerMode options of off, internal and external @@@ DJ @@@ */
207 typedef uint32_t BMDKeyerMode;
210 bmdKeyerModeOff = /* 'off' */ 0,
211 bmdKeyerModeInternal = /* 'int' */ 1,
212 bmdKeyerModeExternal = /* 'ext' */ 2
215 const BMDPixelFormat gst_decklink_pixel_format_from_type (GstDecklinkVideoFormat t);
216 const gint gst_decklink_bpp_from_type (GstDecklinkVideoFormat t);
217 const GstDecklinkVideoFormat gst_decklink_type_from_video_format (GstVideoFormat f);
218 GstVideoFormat gst_decklink_video_format_from_type (BMDPixelFormat pf);
219 const BMDTimecodeFormat gst_decklink_timecode_format_from_enum (GstDecklinkTimecodeFormat f);
220 const GstDecklinkTimecodeFormat gst_decklink_timecode_format_to_enum (BMDTimecodeFormat f);
221 const BMDProfileID gst_decklink_profile_id_from_enum (GstDecklinkProfileId p);
222 const GstDecklinkProfileId gst_decklink_profile_id_to_enum (BMDProfileID p);
223 const BMDKeyerMode gst_decklink_keyer_mode_from_enum (GstDecklinkKeyerMode m);
224 const GstDecklinkKeyerMode gst_decklink_keyer_mode_to_enum (BMDKeyerMode m);
226 typedef struct _GstDecklinkMode GstDecklinkMode;
227 struct _GstDecklinkMode {
237 const gchar *colorimetry;
240 const GstDecklinkMode * gst_decklink_get_mode (GstDecklinkModeEnum e);
241 const GstDecklinkModeEnum gst_decklink_get_mode_enum_from_bmd (BMDDisplayMode mode);
242 const BMDVideoConnection gst_decklink_get_connection (GstDecklinkConnectionEnum e);
243 GstCaps * gst_decklink_mode_get_caps (GstDecklinkModeEnum e, BMDPixelFormat f, gboolean input);
244 GstCaps * gst_decklink_mode_get_template_caps (gboolean input);
246 typedef struct _GstDecklinkOutput GstDecklinkOutput;
247 struct _GstDecklinkOutput {
249 IDeckLinkOutput *output;
250 IDeckLinkProfileAttributes *attributes;
251 IDeckLinkKeyer *keyer;
253 gchar *hw_serial_number;
256 GstClockTime clock_start_time, clock_last_time, clock_epoch;
257 GstClockTimeDiff clock_offset;
259 gboolean clock_restart;
261 /* Everything below protected by mutex */
265 /* Set by the video source */
266 /* Configured mode or NULL */
267 const GstDecklinkMode *mode;
269 GstElement *audiosink;
270 gboolean audio_enabled;
271 GstElement *videosink;
272 gboolean video_enabled;
273 void (*start_scheduled_playback) (GstElement *videosink);
276 typedef struct _GstDecklinkInput GstDecklinkInput;
277 struct _GstDecklinkInput {
279 IDeckLinkInput *input;
280 IDeckLinkConfiguration *config;
281 IDeckLinkProfileAttributes *attributes;
283 gchar *hw_serial_number;
285 /* Everything below protected by mutex */
288 /* Set by the video source */
289 void (*got_video_frame) (GstElement *videosrc, IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode, GstClockTime capture_time, GstClockTime stream_time, GstClockTime stream_duration, GstClockTime hardware_time, GstClockTime hardware_duration, IDeckLinkTimecode *dtc, gboolean no_signal);
290 /* Configured mode or NULL */
291 const GstDecklinkMode *mode;
292 BMDPixelFormat format;
294 /* Set by the audio source */
295 void (*got_audio_packet) (GstElement *videosrc, IDeckLinkAudioInputPacket * packet, GstClockTime capture_time, GstClockTime stream_time, GstClockTime stream_duration, GstClockTime hardware_time, GstClockTime hardware_duration, gboolean no_signal);
297 GstElement *audiosrc;
298 gboolean audio_enabled;
299 GstElement *videosrc;
300 gboolean video_enabled;
301 void (*start_streams) (GstElement *videosrc);
304 GstDecklinkOutput * gst_decklink_acquire_nth_output (gint n, GstElement * sink, gboolean is_audio);
305 void gst_decklink_release_nth_output (gint n, GstElement * sink, gboolean is_audio);
307 GstDecklinkInput * gst_decklink_acquire_nth_input (gint n, GstElement * src, gboolean is_audio);
308 void gst_decklink_release_nth_input (gint n, GstElement * src, gboolean is_audio);
310 const GstDecklinkMode * gst_decklink_find_mode_for_caps (GstCaps * caps);
311 const GstDecklinkMode * gst_decklink_find_mode_and_format_for_caps (GstCaps * caps, BMDPixelFormat * format);
312 GstCaps * gst_decklink_mode_get_caps_all_formats (GstDecklinkModeEnum e, gboolean input);
313 GstCaps * gst_decklink_pixel_format_get_caps (BMDPixelFormat f, gboolean input);
315 #define GST_TYPE_DECKLINK_DEVICE gst_decklink_device_get_type()
316 #define GST_DECKLINK_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECKLINK_DEVICE,GstDecklinkDevice))
318 typedef struct _GstDecklinkDevice GstDecklinkDevice;
319 typedef struct _GstDecklinkDeviceClass GstDecklinkDeviceClass;
321 struct _GstDecklinkDeviceClass
323 GstDeviceClass parent_class;
326 struct _GstDecklinkDevice
334 GType gst_decklink_device_get_type (void);
336 GList * gst_decklink_get_devices (void);