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 "win/DeckLinkAPI.h"
39 /* MinGW does not have comsuppw.lib, so no _com_util::ConvertBSTRToString */
41 # 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
42 # define FREE_COM_STRING(s) free(s);
43 # define CONVERT_TO_COM_STRING(s) G_STMT_START { char * _s = (char *)s; s = (BSTR) malloc(100); mbstowcs(s, _s, 100); g_free(_s); } G_STMT_END
45 # define CONVERT_COM_STRING(s) G_STMT_START { BSTR _s = (BSTR)s; s = _com_util::ConvertBSTRToString(_s); ::SysFreeString(_s); } G_STMT_END
46 # define FREE_COM_STRING(s) G_STMT_START { delete[] s; } G_STMT_END
47 # define CONVERT_TO_COM_STRING(s) G_STMT_START { char * _s = (char *)s; s = _com_util::ConvertStringToBSTR(_s); g_free(_s); } G_STMT_END
48 # endif /* __MINGW32__ */
49 #elif defined(__APPLE__)
50 #include "osx/DeckLinkAPI.h"
52 #define COMSTR_T CFStringRef
53 #define CONVERT_COM_STRING(s) G_STMT_START { CFStringRef _s = (CFStringRef)s; s = (char*) malloc(100); CFStringGetCString(_s, s, 100, kCFStringEncodingUTF8); CFRelease(_s); } G_STMT_END
54 #define FREE_COM_STRING(s) free(s);
55 #define CONVERT_TO_COM_STRING(s) G_STMT_START { char * _s = (char *)s; s = CFStringCreateWithCString(kCFAllocatorDefault, _s, kCFStringEncodingUTF8); g_free(_s); } G_STMT_END
58 #include "linux/DeckLinkAPI.h"
60 #define COMSTR_T const char*
61 #define CONVERT_COM_STRING(s)
62 #define CONVERT_TO_COM_STRING(s)
63 /* While this is a const char*, the string still has to be freed */
64 #define FREE_COM_STRING(s) free(s);
66 #endif /* G_OS_WIN32 */
68 void decklink_element_init (GstPlugin * plugin);
71 GST_DECKLINK_MODE_AUTO,
73 GST_DECKLINK_MODE_NTSC,
74 GST_DECKLINK_MODE_NTSC2398,
75 GST_DECKLINK_MODE_PAL,
76 GST_DECKLINK_MODE_NTSC_P,
77 GST_DECKLINK_MODE_PAL_P,
79 GST_DECKLINK_MODE_1080p2398,
80 GST_DECKLINK_MODE_1080p24,
81 GST_DECKLINK_MODE_1080p25,
82 GST_DECKLINK_MODE_1080p2997,
83 GST_DECKLINK_MODE_1080p30,
85 GST_DECKLINK_MODE_1080i50,
86 GST_DECKLINK_MODE_1080i5994,
87 GST_DECKLINK_MODE_1080i60,
89 GST_DECKLINK_MODE_1080p50,
90 GST_DECKLINK_MODE_1080p5994,
91 GST_DECKLINK_MODE_1080p60,
93 GST_DECKLINK_MODE_720p50,
94 GST_DECKLINK_MODE_720p5994,
95 GST_DECKLINK_MODE_720p60,
97 GST_DECKLINK_MODE_1556p2398,
98 GST_DECKLINK_MODE_1556p24,
99 GST_DECKLINK_MODE_1556p25,
101 GST_DECKLINK_MODE_2KDCI2398,
102 GST_DECKLINK_MODE_2KDCI24,
103 GST_DECKLINK_MODE_2KDCI25,
104 GST_DECKLINK_MODE_2KDCI2997,
105 GST_DECKLINK_MODE_2KDCI30,
106 GST_DECKLINK_MODE_2KDCI50,
107 GST_DECKLINK_MODE_2KDCI5994,
108 GST_DECKLINK_MODE_2KDCI60,
110 GST_DECKLINK_MODE_2160p2398,
111 GST_DECKLINK_MODE_2160p24,
112 GST_DECKLINK_MODE_2160p25,
113 GST_DECKLINK_MODE_2160p2997,
114 GST_DECKLINK_MODE_2160p30,
115 GST_DECKLINK_MODE_2160p50,
116 GST_DECKLINK_MODE_2160p5994,
117 GST_DECKLINK_MODE_2160p60,
119 GST_DECKLINK_MODE_NTSC_WIDESCREEN,
120 GST_DECKLINK_MODE_NTSC2398_WIDESCREEN,
121 GST_DECKLINK_MODE_PAL_WIDESCREEN,
122 GST_DECKLINK_MODE_NTSC_P_WIDESCREEN,
123 GST_DECKLINK_MODE_PAL_P_WIDESCREEN,
126 * GstDecklinkModes::4kdcip2398:
130 GST_DECKLINK_MODE_4Kp2398,
132 * GstDecklinkModes::4kdcip24:
136 GST_DECKLINK_MODE_4Kp24,
138 * GstDecklinkModes::4kdcip25:
142 GST_DECKLINK_MODE_4Kp25,
144 * GstDecklinkModes::4kdcip2997:
148 GST_DECKLINK_MODE_4Kp2997,
150 * GstDecklinkModes::4kdcip30:
154 GST_DECKLINK_MODE_4Kp30,
156 * GstDecklinkModes::4kdcip50:
160 GST_DECKLINK_MODE_4Kp50,
162 * GstDecklinkModes::4kdcip5994:
166 GST_DECKLINK_MODE_4Kp5994,
168 * GstDecklinkModes::4kdcip60:
172 GST_DECKLINK_MODE_4Kp60,
175 * GstDecklinkModes::8kp2398:
179 GST_DECKLINK_MODE_4320p2398,
181 * GstDecklinkModes::8kp24:
185 GST_DECKLINK_MODE_4320p24,
187 * GstDecklinkModes::8kp25:
191 GST_DECKLINK_MODE_4320p25,
193 * GstDecklinkModes::8kp2997:
197 GST_DECKLINK_MODE_4320p2997,
199 * GstDecklinkModes::8kp30:
203 GST_DECKLINK_MODE_4320p30,
205 * GstDecklinkModes::8kp50:
209 GST_DECKLINK_MODE_4320p50,
211 * GstDecklinkModes::8kp5994:
215 GST_DECKLINK_MODE_4320p5994,
217 * GstDecklinkModes::8kp60:
221 GST_DECKLINK_MODE_4320p60,
224 * GstDecklinkModes::8kdcip2398:
228 GST_DECKLINK_MODE_8Kp2398,
230 * GstDecklinkModes::8kdcip24:
234 GST_DECKLINK_MODE_8Kp24,
236 * GstDecklinkModes::8kdcip25:
240 GST_DECKLINK_MODE_8Kp25,
242 * GstDecklinkModes::8kdcip2997:
246 GST_DECKLINK_MODE_8Kp2997,
248 * GstDecklinkModes::8kdcip30:
252 GST_DECKLINK_MODE_8Kp30,
254 * GstDecklinkModes::8kdcip50:
258 GST_DECKLINK_MODE_8Kp50,
260 * GstDecklinkModes::8kdcip5994:
264 GST_DECKLINK_MODE_8Kp5994,
266 * GstDecklinkModes::8kdcip60:
270 GST_DECKLINK_MODE_8Kp60
271 } GstDecklinkModeEnum;
272 #define GST_TYPE_DECKLINK_MODE (gst_decklink_mode_get_type ())
273 GType gst_decklink_mode_get_type (void);
276 GST_DECKLINK_CONNECTION_AUTO,
277 GST_DECKLINK_CONNECTION_SDI,
278 GST_DECKLINK_CONNECTION_HDMI,
279 GST_DECKLINK_CONNECTION_OPTICAL_SDI,
280 GST_DECKLINK_CONNECTION_COMPONENT,
281 GST_DECKLINK_CONNECTION_COMPOSITE,
282 GST_DECKLINK_CONNECTION_SVIDEO
283 } GstDecklinkConnectionEnum;
284 #define GST_TYPE_DECKLINK_CONNECTION (gst_decklink_connection_get_type ())
285 GType gst_decklink_connection_get_type (void);
288 GST_DECKLINK_AUDIO_CONNECTION_AUTO,
289 GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED,
290 GST_DECKLINK_AUDIO_CONNECTION_AES_EBU,
291 GST_DECKLINK_AUDIO_CONNECTION_ANALOG,
292 GST_DECKLINK_AUDIO_CONNECTION_ANALOG_XLR,
293 GST_DECKLINK_AUDIO_CONNECTION_ANALOG_RCA
294 } GstDecklinkAudioConnectionEnum;
295 #define GST_TYPE_DECKLINK_AUDIO_CONNECTION (gst_decklink_audio_connection_get_type ())
296 GType gst_decklink_audio_connection_get_type (void);
299 GST_DECKLINK_AUDIO_CHANNELS_MAX = 0,
300 GST_DECKLINK_AUDIO_CHANNELS_2 = 2,
301 GST_DECKLINK_AUDIO_CHANNELS_8 = 8,
302 GST_DECKLINK_AUDIO_CHANNELS_16 = 16
303 } GstDecklinkAudioChannelsEnum;
304 #define GST_TYPE_DECKLINK_AUDIO_CHANNELS (gst_decklink_audio_channels_get_type ())
305 GType gst_decklink_audio_channels_get_type (void);
308 GST_DECKLINK_VIDEO_FORMAT_AUTO,
309 GST_DECKLINK_VIDEO_FORMAT_8BIT_YUV, /* bmdFormat8BitYUV */
310 GST_DECKLINK_VIDEO_FORMAT_10BIT_YUV, /* bmdFormat10BitYUV */
311 GST_DECKLINK_VIDEO_FORMAT_8BIT_ARGB, /* bmdFormat8BitARGB */
312 GST_DECKLINK_VIDEO_FORMAT_8BIT_BGRA, /* bmdFormat8BitBGRA */
315 * GstDecklinkVideoFormat::10bit-rgb:
319 GST_DECKLINK_VIDEO_FORMAT_10BIT_RGB, /* bmdFormat10BitRGB */
320 /* Not yet supported */
322 GST_DECKLINK_VIDEO_FORMAT_12BIT_RGB, /* bmdFormat12BitRGB */
323 GST_DECKLINK_VIDEO_FORMAT_12BIT_RGBLE, /* bmdFormat12BitRGBLE */
324 GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBXLE, /* bmdFormat10BitRGBXLE */
325 GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBX, /* bmdFormat10BitRGBX */
327 } GstDecklinkVideoFormat;
328 #define GST_TYPE_DECKLINK_VIDEO_FORMAT (gst_decklink_video_format_get_type ())
329 GType gst_decklink_video_format_get_type (void);
332 GST_DECKLINK_PROFILE_ID_DEFAULT,
333 GST_DECKLINK_PROFILE_ID_ONE_SUB_DEVICE_FULL_DUPLEX, /* bmdProfileOneSubDeviceFullDuplex */
334 GST_DECKLINK_PROFILE_ID_ONE_SUB_DEVICE_HALF_DUPLEX, /* bmdProfileOneSubDeviceHalfDuplex */
335 GST_DECKLINK_PROFILE_ID_TWO_SUB_DEVICES_FULL_DUPLEX, /* bmdProfileTwoSubDevicesFullDuplex */
336 GST_DECKLINK_PROFILE_ID_TWO_SUB_DEVICES_HALF_DUPLEX, /* bmdProfileTwoSubDevicesHalfDuplex */
337 GST_DECKLINK_PROFILE_ID_FOUR_SUB_DEVICES_HALF_DUPLEX, /* bmdProfileFourSubDevicesHalfDuplex */
338 } GstDecklinkProfileId;
339 #define GST_TYPE_DECKLINK_PROFILE_ID (gst_decklink_profile_id_get_type ())
340 GType gst_decklink_profile_id_get_type (void);
343 GST_DECKLINK_MAPPING_FORMAT_DEFAULT,
344 GST_DECKLINK_MAPPING_FORMAT_LEVEL_A, /* bmdDeckLinkConfigSMPTELevelAOutput = true */
345 GST_DECKLINK_MAPPING_FORMAT_LEVEL_B, /* bmdDeckLinkConfigSMPTELevelAOutput = false */
346 } GstDecklinkMappingFormat;
347 #define GST_TYPE_DECKLINK_MAPPING_FORMAT (gst_decklink_mapping_format_get_type ())
348 GType gst_decklink_mapping_format_get_type (void);
351 GST_DECKLINK_TIMECODE_FORMAT_RP188VITC1, /*bmdTimecodeRP188VITC1 */
352 GST_DECKLINK_TIMECODE_FORMAT_RP188VITC2, /*bmdTimecodeRP188VITC2 */
353 GST_DECKLINK_TIMECODE_FORMAT_RP188LTC, /*bmdTimecodeRP188LTC */
354 GST_DECKLINK_TIMECODE_FORMAT_RP188ANY, /*bmdTimecodeRP188Any */
355 GST_DECKLINK_TIMECODE_FORMAT_VITC, /*bmdTimecodeVITC */
356 GST_DECKLINK_TIMECODE_FORMAT_VITCFIELD2, /*bmdTimecodeVITCField2 */
357 GST_DECKLINK_TIMECODE_FORMAT_SERIAL /* bmdTimecodeSerial */
358 } GstDecklinkTimecodeFormat;
359 #define GST_TYPE_DECKLINK_TIMECODE_FORMAT (gst_decklink_timecode_format_get_type ())
360 GType gst_decklink_timecode_format_get_type (void);
364 GST_DECKLINK_KEYER_MODE_OFF,
365 GST_DECKLINK_KEYER_MODE_INTERNAL,
366 GST_DECKLINK_KEYER_MODE_EXTERNAL
367 } GstDecklinkKeyerMode;
368 #define GST_TYPE_DECKLINK_KEYER_MODE (gst_decklink_keyer_mode_get_type ())
369 GType gst_decklink_keyer_mode_get_type (void);
371 /* Enum BMDKeyerMode options of off, internal and external @@@ DJ @@@ */
373 typedef uint32_t BMDKeyerMode;
376 bmdKeyerModeOff = /* 'off' */ 0,
377 bmdKeyerModeInternal = /* 'int' */ 1,
378 bmdKeyerModeExternal = /* 'ext' */ 2
381 const BMDPixelFormat gst_decklink_pixel_format_from_type (GstDecklinkVideoFormat t);
382 const gint gst_decklink_bpp_from_type (GstDecklinkVideoFormat t);
383 const GstDecklinkVideoFormat gst_decklink_type_from_video_format (GstVideoFormat f);
384 GstVideoFormat gst_decklink_video_format_from_type (BMDPixelFormat pf);
385 const BMDTimecodeFormat gst_decklink_timecode_format_from_enum (GstDecklinkTimecodeFormat f);
386 const GstDecklinkTimecodeFormat gst_decklink_timecode_format_to_enum (BMDTimecodeFormat f);
387 const BMDProfileID gst_decklink_profile_id_from_enum (GstDecklinkProfileId p);
388 const GstDecklinkProfileId gst_decklink_profile_id_to_enum (BMDProfileID p);
389 const BMDKeyerMode gst_decklink_keyer_mode_from_enum (GstDecklinkKeyerMode m);
390 const GstDecklinkKeyerMode gst_decklink_keyer_mode_to_enum (BMDKeyerMode m);
392 typedef struct _GstDecklinkMode GstDecklinkMode;
393 struct _GstDecklinkMode {
403 const gchar *colorimetry;
406 const GstDecklinkMode * gst_decklink_get_mode (GstDecklinkModeEnum e);
407 const GstDecklinkModeEnum gst_decklink_get_mode_enum_from_bmd (BMDDisplayMode mode);
408 const BMDVideoConnection gst_decklink_get_connection (GstDecklinkConnectionEnum e);
409 GstCaps * gst_decklink_mode_get_caps (GstDecklinkModeEnum e, BMDPixelFormat f, gboolean input);
410 GstCaps * gst_decklink_mode_get_template_caps (gboolean input);
412 typedef struct _GstDecklinkOutput GstDecklinkOutput;
413 struct _GstDecklinkOutput {
415 IDeckLinkOutput *output;
416 IDeckLinkProfileAttributes *attributes;
417 IDeckLinkKeyer *keyer;
419 gchar *hw_serial_number;
420 gint64 persistent_id;
423 GstClockTime clock_start_time, clock_last_time, clock_epoch;
424 GstClockTimeDiff clock_offset;
426 gboolean clock_restart;
428 /* Everything below protected by mutex */
432 /* Set by the video source */
433 /* Configured mode or NULL */
434 const GstDecklinkMode *mode;
436 GstElement *audiosink;
437 gboolean audio_enabled;
438 GstElement *videosink;
439 gboolean video_enabled;
440 void (*start_scheduled_playback) (GstElement *videosink);
443 typedef struct _GstDecklinkInput GstDecklinkInput;
444 struct _GstDecklinkInput {
446 IDeckLinkInput *input;
447 IDeckLinkConfiguration *config;
448 IDeckLinkProfileAttributes *attributes;
450 gchar *hw_serial_number;
451 gint64 persistent_id;
453 /* Everything below protected by mutex */
456 /* Set by the video source */
457 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);
458 /* Configured mode or NULL */
459 const GstDecklinkMode *mode;
460 BMDPixelFormat format;
461 gboolean auto_format;
463 /* Set by the audio source */
464 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);
466 GstElement *audiosrc;
467 gboolean audio_enabled;
468 GstElement *videosrc;
469 gboolean video_enabled;
470 void (*start_streams) (GstElement *videosrc);
473 GstDecklinkOutput * gst_decklink_acquire_nth_output (gint n, gint64 persistent_id, GstElement * sink, gboolean is_audio);
474 void gst_decklink_release_nth_output (gint n, gint64 persistent_id, GstElement * sink, gboolean is_audio);
476 GstDecklinkInput * gst_decklink_acquire_nth_input (gint n, gint64 persistent_id, GstElement * src, gboolean is_audio);
477 void gst_decklink_release_nth_input (gint n, gint64 persistent_id, GstElement * src, gboolean is_audio);
479 const GstDecklinkMode * gst_decklink_find_mode_for_caps (GstCaps * caps);
480 const GstDecklinkMode * gst_decklink_find_mode_and_format_for_caps (GstCaps * caps, BMDPixelFormat * format);
481 GstCaps * gst_decklink_mode_get_caps_all_formats (GstDecklinkModeEnum e, gboolean input);
482 GstCaps * gst_decklink_pixel_format_get_caps (BMDPixelFormat f, gboolean input);
484 #define GST_TYPE_DECKLINK_DEVICE gst_decklink_device_get_type()
485 #define GST_DECKLINK_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECKLINK_DEVICE,GstDecklinkDevice))
487 typedef struct _GstDecklinkDevice GstDecklinkDevice;
488 typedef struct _GstDecklinkDeviceClass GstDecklinkDeviceClass;
490 struct _GstDecklinkDeviceClass
492 GstDeviceClass parent_class;
495 struct _GstDecklinkDevice
500 gint64 persistent_id;
503 GType gst_decklink_device_get_type (void);
505 GList * gst_decklink_get_devices (void);