1 /* GStreamer 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> 6 * 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. 11 * 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. 16 * 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. 21 */ 22 23 #ifndef _GST_DECKLINK_H_ 24 #define _GST_DECKLINK_H_ 25 26 #include <gst/gst.h> 27 #include <gst/video/video.h> 28 29 #include <stdint.h> 30 31 #ifdef G_OS_UNIX 32 #include "linux/DeckLinkAPI.h" 33 #endif 34 35 #ifdef G_OS_WIN32 36 #include "win/DeckLinkAPI.h" 37 38 #include <stdio.h> 39 #include <comutil.h> 40 41 #define bool BOOL 42 #define COMSTR_T BSTR 43 /* MinGW does not have comsuppw.lib, so no _com_util::ConvertBSTRToString */ 44 # ifdef __MINGW32__ 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); 47 # else 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__ */ 51 #else 52 #define COMSTR_T const char* 53 #define CONVERT_COM_STRING(s) 54 #define FREE_COM_STRING(s) 55 #define WINAPI 56 #endif /* G_OS_WIN32 */ 57 58 void decklink_element_init (GstPlugin * plugin); 59 60 typedef enum { 61 GST_DECKLINK_MODE_AUTO, 62 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, 68 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, 74 75 GST_DECKLINK_MODE_1080i50, 76 GST_DECKLINK_MODE_1080i5994, 77 GST_DECKLINK_MODE_1080i60, 78 79 GST_DECKLINK_MODE_1080p50, 80 GST_DECKLINK_MODE_1080p5994, 81 GST_DECKLINK_MODE_1080p60, 82 83 GST_DECKLINK_MODE_720p50, 84 GST_DECKLINK_MODE_720p5994, 85 GST_DECKLINK_MODE_720p60, 86 87 GST_DECKLINK_MODE_1556p2398, 88 GST_DECKLINK_MODE_1556p24, 89 GST_DECKLINK_MODE_1556p25, 90 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, 99 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, 108 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); 117 118 typedef enum { 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); 129 130 typedef enum { 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); 140 141 typedef enum { 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); 149 150 typedef enum { 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); 164 165 typedef enum { 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); 175 176 typedef enum { 177 GST_DECKLINK_TIMECODE_FORMAT_RP188VITC1, /*bmdTimecodeRP188VITC1 */ 178 GST_DECKLINK_TIMECODE_FORMAT_RP188VITC2, /*bmdTimecodeRP188VITC2 */ 179 GST_DECKLINK_TIMECODE_FORMAT_RP188LTC, /*bmdTimecodeRP188LTC */ 180 GST_DECKLINK_TIMECODE_FORMAT_RP188ANY, /*bmdTimecodeRP188Any */ 181 GST_DECKLINK_TIMECODE_FORMAT_VITC, /*bmdTimecodeVITC */ 182 GST_DECKLINK_TIMECODE_FORMAT_VITCFIELD2, /*bmdTimecodeVITCField2 */ 183 GST_DECKLINK_TIMECODE_FORMAT_SERIAL /* bmdTimecodeSerial */ 184 } GstDecklinkTimecodeFormat; 185 #define GST_TYPE_DECKLINK_TIMECODE_FORMAT (gst_decklink_timecode_format_get_type ()) 186 GType gst_decklink_timecode_format_get_type (void); 187 188 typedef enum 189 { 190 GST_DECKLINK_KEYER_MODE_OFF, 191 GST_DECKLINK_KEYER_MODE_INTERNAL, 192 GST_DECKLINK_KEYER_MODE_EXTERNAL 193 } GstDecklinkKeyerMode; 194 #define GST_TYPE_DECKLINK_KEYER_MODE (gst_decklink_keyer_mode_get_type ()) 195 GType gst_decklink_keyer_mode_get_type (void); 196 197 /* Enum BMDKeyerMode options of off, internal and external @@@ DJ @@@ */ 198 199 typedef uint32_t BMDKeyerMode; 200 enum _BMDKeyerMode 201 { 202 bmdKeyerModeOff = /* 'off' */ 0, 203 bmdKeyerModeInternal = /* 'int' */ 1, 204 bmdKeyerModeExternal = /* 'ext' */ 2 205 }; 206 207 const BMDPixelFormat gst_decklink_pixel_format_from_type (GstDecklinkVideoFormat t); 208 const gint gst_decklink_bpp_from_type (GstDecklinkVideoFormat t); 209 const GstDecklinkVideoFormat gst_decklink_type_from_video_format (GstVideoFormat f); 210 GstVideoFormat gst_decklink_video_format_from_type (BMDPixelFormat pf); 211 const BMDTimecodeFormat gst_decklink_timecode_format_from_enum (GstDecklinkTimecodeFormat f); 212 const GstDecklinkTimecodeFormat gst_decklink_timecode_format_to_enum (BMDTimecodeFormat f); 213 const BMDProfileID gst_decklink_profile_id_from_enum (GstDecklinkProfileId p); 214 const GstDecklinkProfileId gst_decklink_profile_id_to_enum (BMDProfileID p); 215 const BMDKeyerMode gst_decklink_keyer_mode_from_enum (GstDecklinkKeyerMode m); 216 const GstDecklinkKeyerMode gst_decklink_keyer_mode_to_enum (BMDKeyerMode m); 217 218 typedef struct _GstDecklinkMode GstDecklinkMode; 219 struct _GstDecklinkMode { 220 BMDDisplayMode mode; 221 int width; 222 int height; 223 int fps_n; 224 int fps_d; 225 gboolean interlaced; 226 int par_n; 227 int par_d; 228 gboolean tff; 229 const gchar *colorimetry; 230 }; 231 232 const GstDecklinkMode * gst_decklink_get_mode (GstDecklinkModeEnum e); 233 const GstDecklinkModeEnum gst_decklink_get_mode_enum_from_bmd (BMDDisplayMode mode); 234 const BMDVideoConnection gst_decklink_get_connection (GstDecklinkConnectionEnum e); 235 GstCaps * gst_decklink_mode_get_caps (GstDecklinkModeEnum e, BMDPixelFormat f, gboolean input); 236 GstCaps * gst_decklink_mode_get_template_caps (gboolean input); 237 238 typedef struct _GstDecklinkOutput GstDecklinkOutput; 239 struct _GstDecklinkOutput { 240 IDeckLink *device; 241 IDeckLinkOutput *output; 242 IDeckLinkProfileAttributes *attributes; 243 IDeckLinkKeyer *keyer; 244 245 gchar *hw_serial_number; 246 247 GstClock *clock; 248 GstClockTime clock_start_time, clock_last_time, clock_epoch; 249 GstClockTimeDiff clock_offset; 250 gboolean started; 251 gboolean clock_restart; 252 253 /* Everything below protected by mutex */ 254 GMutex lock; 255 GCond cond; 256 257 /* Set by the video source */ 258 /* Configured mode or NULL */ 259 const GstDecklinkMode *mode; 260 261 GstElement *audiosink; 262 gboolean audio_enabled; 263 GstElement *videosink; 264 gboolean video_enabled; 265 void (*start_scheduled_playback) (GstElement *videosink); 266 }; 267 268 typedef struct _GstDecklinkInput GstDecklinkInput; 269 struct _GstDecklinkInput { 270 IDeckLink *device; 271 IDeckLinkInput *input; 272 IDeckLinkConfiguration *config; 273 IDeckLinkProfileAttributes *attributes; 274 275 gchar *hw_serial_number; 276 277 /* Everything below protected by mutex */ 278 GMutex lock; 279 280 /* Set by the video source */ 281 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); 282 /* Configured mode or NULL */ 283 const GstDecklinkMode *mode; 284 BMDPixelFormat format; 285 286 /* Set by the audio source */ 287 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); 288 289 GstElement *audiosrc; 290 gboolean audio_enabled; 291 GstElement *videosrc; 292 gboolean video_enabled; 293 void (*start_streams) (GstElement *videosrc); 294 }; 295 296 GstDecklinkOutput * gst_decklink_acquire_nth_output (gint n, GstElement * sink, gboolean is_audio); 297 void gst_decklink_release_nth_output (gint n, GstElement * sink, gboolean is_audio); 298 299 GstDecklinkInput * gst_decklink_acquire_nth_input (gint n, GstElement * src, gboolean is_audio); 300 void gst_decklink_release_nth_input (gint n, GstElement * src, gboolean is_audio); 301 302 const GstDecklinkMode * gst_decklink_find_mode_for_caps (GstCaps * caps); 303 const GstDecklinkMode * gst_decklink_find_mode_and_format_for_caps (GstCaps * caps, BMDPixelFormat * format); 304 GstCaps * gst_decklink_mode_get_caps_all_formats (GstDecklinkModeEnum e, gboolean input); 305 GstCaps * gst_decklink_pixel_format_get_caps (BMDPixelFormat f, gboolean input); 306 307 #define GST_TYPE_DECKLINK_DEVICE gst_decklink_device_get_type() 308 #define GST_DECKLINK_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECKLINK_DEVICE,GstDecklinkDevice)) 309 310 typedef struct _GstDecklinkDevice GstDecklinkDevice; 311 typedef struct _GstDecklinkDeviceClass GstDecklinkDeviceClass; 312 313 struct _GstDecklinkDeviceClass 314 { 315 GstDeviceClass parent_class; 316 }; 317 318 struct _GstDecklinkDevice 319 { 320 GstDevice parent; 321 gboolean video; 322 gboolean capture; 323 guint device_number; 324 }; 325 326 GType gst_decklink_device_get_type (void); 327 328 GList * gst_decklink_get_devices (void); 329 330 #endif 331