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>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
19 * Boston, MA 02110-1335, USA.
27 #include "gstdecklink.h"
28 #include "gstdecklinkaudiosink.h"
29 #include "gstdecklinkvideosink.h"
30 #include "gstdecklinkaudiosrc.h"
31 #include "gstdecklinkvideosrc.h"
33 GST_DEBUG_CATEGORY_STATIC (gst_decklink_debug);
34 #define GST_CAT_DEFAULT gst_decklink_debug
37 gst_decklink_mode_get_type (void)
40 static const GEnumValue modes[] = {
41 {GST_DECKLINK_MODE_AUTO, "Automatic detection", "auto"},
43 {GST_DECKLINK_MODE_NTSC, "NTSC SD 60i", "ntsc"},
44 {GST_DECKLINK_MODE_NTSC2398, "NTSC SD 60i (24 fps)", "ntsc2398"},
45 {GST_DECKLINK_MODE_PAL, "PAL SD 50i", "pal"},
46 {GST_DECKLINK_MODE_NTSC_P, "NTSC SD 60p", "ntsc-p"},
47 {GST_DECKLINK_MODE_PAL_P, "PAL SD 50p", "pal-p"},
49 {GST_DECKLINK_MODE_1080p2398, "HD1080 23.98p", "1080p2398"},
50 {GST_DECKLINK_MODE_1080p24, "HD1080 24p", "1080p24"},
51 {GST_DECKLINK_MODE_1080p25, "HD1080 25p", "1080p25"},
52 {GST_DECKLINK_MODE_1080p2997, "HD1080 29.97p", "1080p2997"},
53 {GST_DECKLINK_MODE_1080p30, "HD1080 30p", "1080p30"},
55 {GST_DECKLINK_MODE_1080i50, "HD1080 50i", "1080i50"},
56 {GST_DECKLINK_MODE_1080i5994, "HD1080 59.94i", "1080i5994"},
57 {GST_DECKLINK_MODE_1080i60, "HD1080 60i", "1080i60"},
59 {GST_DECKLINK_MODE_1080p50, "HD1080 50p", "1080p50"},
60 {GST_DECKLINK_MODE_1080p5994, "HD1080 59.94p", "1080p5994"},
61 {GST_DECKLINK_MODE_1080p60, "HD1080 60p", "1080p60"},
63 {GST_DECKLINK_MODE_720p50, "HD720 50p", "720p50"},
64 {GST_DECKLINK_MODE_720p5994, "HD720 59.94p", "720p5994"},
65 {GST_DECKLINK_MODE_720p60, "HD720 60p", "720p60"},
67 {GST_DECKLINK_MODE_1556p2398, "2k 23.98p", "1556p2398"},
68 {GST_DECKLINK_MODE_1556p24, "2k 24p", "1556p24"},
69 {GST_DECKLINK_MODE_1556p25, "2k 25p", "1556p25"},
71 {GST_DECKLINK_MODE_2160p2398, "4k 23.98p", "2160p2398"},
72 {GST_DECKLINK_MODE_2160p24, "4k 24p", "2160p24"},
73 {GST_DECKLINK_MODE_2160p25, "4k 25p", "2160p25"},
74 {GST_DECKLINK_MODE_2160p2997, "4k 29.97p", "2160p2997"},
75 {GST_DECKLINK_MODE_2160p30, "4k 30p", "2160p30"},
76 {GST_DECKLINK_MODE_2160p50, "4k 50p", "2160p50"},
77 {GST_DECKLINK_MODE_2160p5994, "4k 59.94p", "2160p5994"},
78 {GST_DECKLINK_MODE_2160p60, "4k 60p", "2160p60"},
83 if (g_once_init_enter (&id)) {
84 GType tmp = g_enum_register_static ("GstDecklinkModes", modes);
85 g_once_init_leave (&id, tmp);
92 gst_decklink_connection_get_type (void)
95 static const GEnumValue connections[] = {
96 {GST_DECKLINK_CONNECTION_AUTO, "Auto", "auto"},
97 {GST_DECKLINK_CONNECTION_SDI, "SDI", "sdi"},
98 {GST_DECKLINK_CONNECTION_HDMI, "HDMI", "hdmi"},
99 {GST_DECKLINK_CONNECTION_OPTICAL_SDI, "Optical SDI", "optical-sdi"},
100 {GST_DECKLINK_CONNECTION_COMPONENT, "Component", "component"},
101 {GST_DECKLINK_CONNECTION_COMPOSITE, "Composite", "composite"},
102 {GST_DECKLINK_CONNECTION_SVIDEO, "S-Video", "svideo"},
106 if (g_once_init_enter (&id)) {
107 GType tmp = g_enum_register_static ("GstDecklinkConnection", connections);
108 g_once_init_leave (&id, tmp);
115 gst_decklink_video_format_get_type (void)
118 static const GEnumValue types[] = {
119 {GST_DECKLINK_VIDEO_FORMAT_AUTO, "Auto", "auto"},
120 {GST_DECKLINK_VIDEO_FORMAT_8BIT_YUV, "bmdFormat8BitYUV", "8bit-yuv"},
121 {GST_DECKLINK_VIDEO_FORMAT_10BIT_YUV, "bmdFormat10BitYUV", "10bit-yuv"},
122 {GST_DECKLINK_VIDEO_FORMAT_8BIT_ARGB, "bmdFormat8BitARGB", "8bit-argb"},
123 {GST_DECKLINK_VIDEO_FORMAT_8BIT_BGRA, "bmdFormat8BitBGRA", "8bit-bgra"},
124 /* Not yet supported:
125 {GST_DECKLINK_VIDEO_FORMAT_10BIT_RGB, "bmdFormat10BitRGB", "10bit-rgb"},
126 {GST_DECKLINK_VIDEO_FORMAT_12BIT_RGB, "bmdFormat12BitRGB", "12bit-rgb"},
127 {GST_DECKLINK_VIDEO_FORMAT_12BIT_RGBLE, "bmdFormat12BitRGBLE", "12bit-rgble"},
128 {GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBXLE, "bmdFormat10BitRGBXLE", "10bit-rgbxle"},
129 {GST_DECKLINK_VIDEO_FORMAT_10BIT_RGBX, "bmdFormat10BitRGBX", "10bit-rgbx"},
134 if (g_once_init_enter (&id)) {
135 GType tmp = g_enum_register_static ("GstDecklinkVideoFormat", types);
136 g_once_init_leave (&id, tmp);
143 gst_decklink_timecode_format_get_type (void)
146 static const GEnumValue timecodeformats[] = {
147 {GST_DECKLINK_TIMECODE_FORMAT_RP188VITC1, "bmdTimecodeRP188VITC1",
149 {GST_DECKLINK_TIMECODE_FORMAT_RP188VITC2, "bmdTimecodeRP188VITC2",
151 {GST_DECKLINK_TIMECODE_FORMAT_RP188LTC, "bmdTimecodeRP188LTC", "rp188ltc"},
152 {GST_DECKLINK_TIMECODE_FORMAT_RP188ANY, "bmdTimecodeRP188Any", "rp188any"},
153 {GST_DECKLINK_TIMECODE_FORMAT_VITC, "bmdTimecodeVITC", "vitc"},
154 {GST_DECKLINK_TIMECODE_FORMAT_VITCFIELD2, "bmdTimecodeVITCField2",
156 {GST_DECKLINK_TIMECODE_FORMAT_SERIAL, "bmdTimecodeSerial", "serial"},
160 if (g_once_init_enter (&id)) {
162 g_enum_register_static ("GstDecklinkTimecodeFormat", timecodeformats);
163 g_once_init_leave (&id, tmp);
170 gst_decklink_keyer_mode_get_type (void)
173 static const GEnumValue keyermodes[] = {
174 {GST_DECKLINK_KEYER_MODE_OFF, "Off", "off"},
175 {GST_DECKLINK_KEYER_MODE_INTERNAL, "Internal", "internal"},
176 {GST_DECKLINK_KEYER_MODE_EXTERNAL, "External", "external"},
180 if (g_once_init_enter (&id)) {
181 GType tmp = g_enum_register_static ("GstDecklinkKeyerMode", keyermodes);
182 g_once_init_leave (&id, tmp);
189 gst_decklink_audio_connection_get_type (void)
192 static const GEnumValue connections[] = {
193 {GST_DECKLINK_AUDIO_CONNECTION_AUTO, "Automatic", "auto"},
194 {GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED, "SDI/HDMI embedded audio",
196 {GST_DECKLINK_AUDIO_CONNECTION_AES_EBU, "AES/EBU input", "aes"},
197 {GST_DECKLINK_AUDIO_CONNECTION_ANALOG, "Analog input", "analog"},
198 {GST_DECKLINK_AUDIO_CONNECTION_ANALOG_XLR, "Analog input (XLR)",
200 {GST_DECKLINK_AUDIO_CONNECTION_ANALOG_RCA, "Analog input (RCA)",
205 if (g_once_init_enter (&id)) {
207 g_enum_register_static ("GstDecklinkAudioConnection", connections);
208 g_once_init_leave (&id, tmp);
215 gst_decklink_audio_channels_get_type (void)
218 static const GEnumValue connections[] = {
219 {GST_DECKLINK_AUDIO_CHANNELS_2, "2 Channels", "2"},
220 {GST_DECKLINK_AUDIO_CHANNELS_8, "8 Channels", "8"},
221 {GST_DECKLINK_AUDIO_CHANNELS_16, "16 Channels", "16"},
222 {GST_DECKLINK_AUDIO_CHANNELS_MAX, "Maximum channels supported", "max"},
226 if (g_once_init_enter (&id)) {
228 g_enum_register_static ("GstDecklinkAudioChannels", connections);
229 g_once_init_leave (&id, tmp);
235 #define NTSC 10, 11, false, "bt601"
236 #define PAL 12, 11, true, "bt601"
237 #define HD 1, 1, true, "bt709"
238 #define UHD 1, 1, true, "bt2020"
240 static const GstDecklinkMode modes[] = {
241 {bmdModeNTSC, 720, 486, 30000, 1001, true, NTSC}, // default is ntsc
243 {bmdModeNTSC, 720, 486, 30000, 1001, true, NTSC},
244 {bmdModeNTSC2398, 720, 486, 24000, 1001, true, NTSC},
245 {bmdModePAL, 720, 576, 25, 1, true, PAL},
246 {bmdModeNTSCp, 720, 486, 30000, 1001, false, NTSC},
247 {bmdModePALp, 720, 576, 25, 1, false, PAL},
249 {bmdModeHD1080p2398, 1920, 1080, 24000, 1001, false, HD},
250 {bmdModeHD1080p24, 1920, 1080, 24, 1, false, HD},
251 {bmdModeHD1080p25, 1920, 1080, 25, 1, false, HD},
252 {bmdModeHD1080p2997, 1920, 1080, 30000, 1001, false, HD},
253 {bmdModeHD1080p30, 1920, 1080, 30, 1, false, HD},
255 {bmdModeHD1080i50, 1920, 1080, 25, 1, true, HD},
256 {bmdModeHD1080i5994, 1920, 1080, 30000, 1001, true, HD},
257 {bmdModeHD1080i6000, 1920, 1080, 30, 1, true, HD},
259 {bmdModeHD1080p50, 1920, 1080, 50, 1, false, HD},
260 {bmdModeHD1080p5994, 1920, 1080, 60000, 1001, false, HD},
261 {bmdModeHD1080p6000, 1920, 1080, 60, 1, false, HD},
263 {bmdModeHD720p50, 1280, 720, 50, 1, false, HD},
264 {bmdModeHD720p5994, 1280, 720, 60000, 1001, false, HD},
265 {bmdModeHD720p60, 1280, 720, 60, 1, false, HD},
267 {bmdMode2k2398, 2048, 1556, 24000, 1001, false, HD},
268 {bmdMode2k24, 2048, 1556, 24, 1, false, HD},
269 {bmdMode2k25, 2048, 1556, 25, 1, false, HD},
271 {bmdMode4K2160p2398, 3840, 2160, 24000, 1001, false, UHD},
272 {bmdMode4K2160p24, 3840, 2160, 24, 1, false, UHD},
273 {bmdMode4K2160p25, 3840, 2160, 25, 1, false, UHD},
274 {bmdMode4K2160p2997, 3840, 2160, 30000, 1001, false, UHD},
275 {bmdMode4K2160p30, 3840, 2160, 30, 1, false, UHD},
276 {bmdMode4K2160p50, 3840, 2160, 50, 1, false, UHD},
277 {bmdMode4K2160p5994, 3840, 2160, 60000, 1001, false, UHD},
278 {bmdMode4K2160p60, 3840, 2160, 60, 1, false, UHD}
283 BMDPixelFormat format;
285 GstVideoFormat vformat;
288 {bmdFormat8BitYUV, 2, GST_VIDEO_FORMAT_UYVY}, /* auto */
289 {bmdFormat8BitYUV, 2, GST_VIDEO_FORMAT_UYVY},
290 {bmdFormat10BitYUV, 4, GST_VIDEO_FORMAT_v210},
291 {bmdFormat8BitARGB, 4, GST_VIDEO_FORMAT_ARGB},
292 {bmdFormat8BitBGRA, 4, GST_VIDEO_FORMAT_BGRA},
294 {bmdFormat10BitRGB, FIXME, FIXME},
295 {bmdFormat12BitRGB, FIXME, FIXME},
296 {bmdFormat12BitRGBLE, FIXME, FIXME},
297 {bmdFormat10BitRGBXLE, FIXME, FIXME},
298 {bmdFormat10BitRGBX, FIXME, FIXME} */
304 BMDTimecodeFormat format;
305 GstDecklinkTimecodeFormat gstformat;
308 {bmdTimecodeRP188VITC1, GST_DECKLINK_TIMECODE_FORMAT_RP188VITC1},
309 {bmdTimecodeRP188VITC2, GST_DECKLINK_TIMECODE_FORMAT_RP188VITC2},
310 {bmdTimecodeRP188LTC, GST_DECKLINK_TIMECODE_FORMAT_RP188LTC},
311 {bmdTimecodeRP188Any, GST_DECKLINK_TIMECODE_FORMAT_RP188ANY},
312 {bmdTimecodeVITC, GST_DECKLINK_TIMECODE_FORMAT_VITC},
313 {bmdTimecodeVITCField2, GST_DECKLINK_TIMECODE_FORMAT_VITCFIELD2},
314 {bmdTimecodeSerial, GST_DECKLINK_TIMECODE_FORMAT_SERIAL}
320 BMDKeyerMode keymode;
321 GstDecklinkKeyerMode gstkeymode;
324 {bmdKeyerModeOff, GST_DECKLINK_KEYER_MODE_OFF},
325 {bmdKeyerModeInternal, GST_DECKLINK_KEYER_MODE_INTERNAL},
326 {bmdKeyerModeExternal, GST_DECKLINK_KEYER_MODE_EXTERNAL}
330 const GstDecklinkMode *
331 gst_decklink_get_mode (GstDecklinkModeEnum e)
333 if (e < GST_DECKLINK_MODE_AUTO || e > GST_DECKLINK_MODE_2160p60)
338 const GstDecklinkModeEnum
339 gst_decklink_get_mode_enum_from_bmd (BMDDisplayMode mode)
341 GstDecklinkModeEnum displayMode = GST_DECKLINK_MODE_NTSC;
344 displayMode = GST_DECKLINK_MODE_NTSC;
346 case bmdModeNTSC2398:
347 displayMode = GST_DECKLINK_MODE_NTSC2398;
350 displayMode = GST_DECKLINK_MODE_PAL;
353 displayMode = GST_DECKLINK_MODE_NTSC_P;
356 displayMode = GST_DECKLINK_MODE_PAL_P;
358 case bmdModeHD1080p2398:
359 displayMode = GST_DECKLINK_MODE_1080p2398;
361 case bmdModeHD1080p24:
362 displayMode = GST_DECKLINK_MODE_1080p24;
364 case bmdModeHD1080p25:
365 displayMode = GST_DECKLINK_MODE_1080p25;
367 case bmdModeHD1080p2997:
368 displayMode = GST_DECKLINK_MODE_1080p2997;
370 case bmdModeHD1080p30:
371 displayMode = GST_DECKLINK_MODE_1080p30;
373 case bmdModeHD1080i50:
374 displayMode = GST_DECKLINK_MODE_1080i50;
376 case bmdModeHD1080i5994:
377 displayMode = GST_DECKLINK_MODE_1080i5994;
379 case bmdModeHD1080i6000:
380 displayMode = GST_DECKLINK_MODE_1080i60;
382 case bmdModeHD1080p50:
383 displayMode = GST_DECKLINK_MODE_1080p50;
385 case bmdModeHD1080p5994:
386 displayMode = GST_DECKLINK_MODE_1080p5994;
388 case bmdModeHD1080p6000:
389 displayMode = GST_DECKLINK_MODE_1080p60;
391 case bmdModeHD720p50:
392 displayMode = GST_DECKLINK_MODE_720p50;
394 case bmdModeHD720p5994:
395 displayMode = GST_DECKLINK_MODE_720p5994;
397 case bmdModeHD720p60:
398 displayMode = GST_DECKLINK_MODE_720p60;
401 displayMode = GST_DECKLINK_MODE_1556p2398;
404 displayMode = GST_DECKLINK_MODE_1556p24;
407 displayMode = GST_DECKLINK_MODE_1556p25;
409 case bmdMode4K2160p2398:
410 displayMode = GST_DECKLINK_MODE_2160p2398;
412 case bmdMode4K2160p24:
413 displayMode = GST_DECKLINK_MODE_2160p24;
415 case bmdMode4K2160p25:
416 displayMode = GST_DECKLINK_MODE_2160p25;
418 case bmdMode4K2160p2997:
419 displayMode = GST_DECKLINK_MODE_2160p2997;
421 case bmdMode4K2160p30:
422 displayMode = GST_DECKLINK_MODE_2160p30;
424 case bmdMode4K2160p50:
425 displayMode = GST_DECKLINK_MODE_2160p50;
427 case bmdMode4K2160p5994:
428 displayMode = GST_DECKLINK_MODE_2160p5994;
430 case bmdMode4K2160p60:
431 displayMode = GST_DECKLINK_MODE_2160p60;
434 g_assert_not_reached ();
441 gst_decklink_pixel_format_from_type (GstDecklinkVideoFormat t)
443 return formats[t].format;
447 gst_decklink_bpp_from_type (GstDecklinkVideoFormat t)
449 return formats[t].bpp;
452 const GstDecklinkVideoFormat
453 gst_decklink_type_from_video_format (GstVideoFormat f)
457 for (i = 1; i < G_N_ELEMENTS (formats); i++) {
458 if (formats[i].vformat == f)
459 return (GstDecklinkVideoFormat) i;
461 g_assert_not_reached ();
462 return GST_DECKLINK_VIDEO_FORMAT_AUTO;
465 const BMDTimecodeFormat
466 gst_decklink_timecode_format_from_enum (GstDecklinkTimecodeFormat f)
468 return tcformats[f].format;
471 const GstDecklinkTimecodeFormat
472 gst_decklink_timecode_format_to_enum (BMDTimecodeFormat f)
476 for (i = 0; i < G_N_ELEMENTS (tcformats); i++) {
477 if (tcformats[i].format == f)
478 return (GstDecklinkTimecodeFormat) i;
480 g_assert_not_reached ();
481 return GST_DECKLINK_TIMECODE_FORMAT_RP188ANY;
485 gst_decklink_keyer_mode_from_enum (GstDecklinkKeyerMode m)
487 return kmodes[m].keymode;
490 const GstDecklinkKeyerMode
491 gst_decklink_keyer_mode_to_enum (BMDKeyerMode m)
495 for (i = 0; i < G_N_ELEMENTS (kmodes); i++) {
496 if (kmodes[i].keymode == m)
497 return (GstDecklinkKeyerMode) i;
499 g_assert_not_reached ();
500 return GST_DECKLINK_KEYER_MODE_OFF;
503 static const BMDVideoConnection connections[] = {
504 (BMDVideoConnection) 0, /* auto */
505 bmdVideoConnectionSDI,
506 bmdVideoConnectionHDMI,
507 bmdVideoConnectionOpticalSDI,
508 bmdVideoConnectionComponent,
509 bmdVideoConnectionComposite,
510 bmdVideoConnectionSVideo
513 const BMDVideoConnection
514 gst_decklink_get_connection (GstDecklinkConnectionEnum e)
516 g_return_val_if_fail (e != GST_DECKLINK_CONNECTION_AUTO,
517 bmdVideoConnectionSDI);
519 if (e <= GST_DECKLINK_CONNECTION_AUTO || e > GST_DECKLINK_CONNECTION_SVIDEO)
520 e = GST_DECKLINK_CONNECTION_SDI;
522 return connections[e];
526 gst_decklink_caps_get_pixel_format (GstCaps * caps, BMDPixelFormat * format)
531 if (gst_video_info_from_caps (&vinfo, caps) == FALSE) {
532 GST_ERROR ("Could not get video info from caps: %" GST_PTR_FORMAT, caps);
536 f = vinfo.finfo->format;
537 return gst_decklink_type_from_video_format (f);
540 static GstStructure *
541 gst_decklink_mode_get_structure (GstDecklinkModeEnum e, BMDPixelFormat f,
544 const GstDecklinkMode *mode = &modes[e];
545 GstStructure *s = gst_structure_new ("video/x-raw",
546 "width", G_TYPE_INT, mode->width,
547 "height", G_TYPE_INT, mode->height,
548 "pixel-aspect-ratio", GST_TYPE_FRACTION, mode->par_n, mode->par_d,
549 "interlace-mode", G_TYPE_STRING,
550 mode->interlaced ? "interleaved" : "progressive",
551 "framerate", GST_TYPE_FRACTION, mode->fps_n, mode->fps_d, NULL);
553 if (input && mode->interlaced) {
555 gst_structure_set (s, "field-order", G_TYPE_STRING, "top-field-first",
558 gst_structure_set (s, "field-order", G_TYPE_STRING, "bottom-field-first",
563 case bmdFormat8BitYUV: /* '2vuy' */
564 gst_structure_set (s, "format", G_TYPE_STRING, "UYVY",
565 "colorimetry", G_TYPE_STRING, mode->colorimetry,
566 "chroma-site", G_TYPE_STRING, "mpeg2", NULL);
568 case bmdFormat10BitYUV: /* 'v210' */
569 gst_structure_set (s, "format", G_TYPE_STRING, "v210", NULL);
571 case bmdFormat8BitARGB: /* 'ARGB' */
572 gst_structure_set (s, "format", G_TYPE_STRING, "ARGB", NULL);
574 case bmdFormat8BitBGRA: /* 'BGRA' */
575 gst_structure_set (s, "format", G_TYPE_STRING, "BGRA", NULL);
577 case bmdFormat10BitRGB: /* 'r210' Big-endian RGB 10-bit per component with SMPTE video levels (64-960). Packed as 2:10:10:10 */
578 case bmdFormat12BitRGB: /* 'R12B' Big-endian RGB 12-bit per component with full range (0-4095). Packed as 12-bit per component */
579 case bmdFormat12BitRGBLE: /* 'R12L' Little-endian RGB 12-bit per component with full range (0-4095). Packed as 12-bit per component */
580 case bmdFormat10BitRGBXLE: /* 'R10l' Little-endian 10-bit RGB with SMPTE video levels (64-940) */
581 case bmdFormat10BitRGBX: /* 'R10b' Big-endian 10-bit RGB with SMPTE video levels (64-940) */
583 GST_WARNING ("format not supported %d", f);
584 gst_structure_free (s);
593 gst_decklink_mode_get_caps (GstDecklinkModeEnum e, BMDPixelFormat f,
598 caps = gst_caps_new_empty ();
600 gst_caps_merge_structure (caps, gst_decklink_mode_get_structure (e, f,
607 gst_decklink_mode_get_caps_all_formats (GstDecklinkModeEnum e, gboolean input)
612 caps = gst_caps_new_empty ();
613 for (i = 1; i < G_N_ELEMENTS (formats); i++)
615 gst_caps_merge_structure (caps, gst_decklink_mode_get_structure (e,
616 formats[i].format, input));
622 gst_decklink_pixel_format_get_caps (BMDPixelFormat f, gboolean input)
628 caps = gst_caps_new_empty ();
629 for (i = 1; i < (int) G_N_ELEMENTS (modes); i++) {
630 s = gst_decklink_mode_get_structure ((GstDecklinkModeEnum) i, f, input);
631 caps = gst_caps_merge_structure (caps, s);
638 gst_decklink_mode_get_template_caps (gboolean input)
643 caps = gst_caps_new_empty ();
644 for (i = 1; i < (int) G_N_ELEMENTS (modes); i++)
646 gst_caps_merge (caps,
647 gst_decklink_mode_get_caps_all_formats ((GstDecklinkModeEnum) i,
653 const GstDecklinkMode *
654 gst_decklink_find_mode_and_format_for_caps (GstCaps * caps,
655 BMDPixelFormat * format)
660 g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
661 if (!gst_decklink_caps_get_pixel_format (caps, format))
664 for (i = 1; i < (int) G_N_ELEMENTS (modes); i++) {
666 gst_decklink_mode_get_caps ((GstDecklinkModeEnum) i, *format, FALSE);
667 if (gst_caps_can_intersect (caps, mode_caps)) {
668 gst_caps_unref (mode_caps);
669 return gst_decklink_get_mode ((GstDecklinkModeEnum) i);
671 gst_caps_unref (mode_caps);
677 const GstDecklinkMode *
678 gst_decklink_find_mode_for_caps (GstCaps * caps)
680 BMDPixelFormat format;
682 return gst_decklink_find_mode_and_format_for_caps (caps, &format);
685 #define GST_TYPE_DECKLINK_CLOCK \
686 (gst_decklink_clock_get_type())
687 #define GST_DECKLINK_CLOCK(obj) \
688 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECKLINK_CLOCK,GstDecklinkClock))
689 #define GST_DECKLINK_CLOCK_CLASS(klass) \
690 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DECKLINK_CLOCK,GstDecklinkClockClass))
691 #define GST_IS_Decklink_CLOCK(obj) \
692 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DECKLINK_CLOCK))
693 #define GST_IS_Decklink_CLOCK_CLASS(klass) \
694 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DECKLINK_CLOCK))
695 #define GST_DECKLINK_CLOCK_CAST(obj) \
696 ((GstDecklinkClock*)(obj))
698 typedef struct _GstDecklinkClock GstDecklinkClock;
699 typedef struct _GstDecklinkClockClass GstDecklinkClockClass;
701 struct _GstDecklinkClock
703 GstSystemClock clock;
705 GstDecklinkOutput *output;
708 struct _GstDecklinkClockClass
710 GstSystemClockClass parent_class;
713 GType gst_decklink_clock_get_type (void);
714 static GstClock *gst_decklink_clock_new (const gchar * name);
716 typedef struct _Device Device;
719 GstDecklinkOutput output;
720 GstDecklinkInput input;
723 class GStreamerDecklinkInputCallback:public IDeckLinkInputCallback
726 GstDecklinkInput * m_input;
730 GStreamerDecklinkInputCallback (GstDecklinkInput * input)
731 : IDeckLinkInputCallback (), m_refcount (1)
734 g_mutex_init (&m_mutex);
737 virtual ~ GStreamerDecklinkInputCallback ()
739 g_mutex_clear (&m_mutex);
742 virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID, LPVOID *)
744 return E_NOINTERFACE;
747 virtual ULONG STDMETHODCALLTYPE AddRef (void)
751 g_mutex_lock (&m_mutex);
754 g_mutex_unlock (&m_mutex);
759 virtual ULONG STDMETHODCALLTYPE Release (void)
763 g_mutex_lock (&m_mutex);
766 g_mutex_unlock (&m_mutex);
776 virtual HRESULT STDMETHODCALLTYPE
777 VideoInputFormatChanged (BMDVideoInputFormatChangedEvents,
778 IDeckLinkDisplayMode * mode, BMDDetectedVideoInputFormatFlags formatFlags)
780 BMDPixelFormat pixelFormat = bmdFormat8BitYUV;
782 GST_INFO ("Video input format changed");
784 if (formatFlags & bmdDetectedVideoInputRGB444)
785 pixelFormat = bmdFormat8BitARGB;
787 g_mutex_lock (&m_input->lock);
788 m_input->input->PauseStreams ();
789 m_input->input->EnableVideoInput (mode->GetDisplayMode (),
790 pixelFormat, bmdVideoInputEnableFormatDetection);
791 m_input->input->FlushStreams ();
792 m_input->input->StartStreams ();
794 gst_decklink_get_mode (gst_decklink_get_mode_enum_from_bmd
795 (mode->GetDisplayMode ()));
796 m_input->format = pixelFormat;
797 g_mutex_unlock (&m_input->lock);
802 virtual HRESULT STDMETHODCALLTYPE
803 VideoInputFrameArrived (IDeckLinkVideoInputFrame * video_frame,
804 IDeckLinkAudioInputPacket * audio_packet)
806 GstElement *videosrc = NULL, *audiosrc = NULL;
807 void (*got_video_frame) (GstElement * videosrc,
808 IDeckLinkVideoInputFrame * frame, GstDecklinkModeEnum mode,
809 GstClockTime capture_time, GstClockTime stream_time,
810 GstClockTime stream_duration, GstClockTime hardware_time,
811 GstClockTime hardware_duration, IDeckLinkTimecode * dtc,
812 gboolean no_signal) = NULL;
813 void (*got_audio_packet) (GstElement * videosrc,
814 IDeckLinkAudioInputPacket * packet, GstClockTime capture_time,
815 GstClockTime stream_time, GstClockTime stream_duration,
816 GstClockTime hardware_time, GstClockTime hardware_duration,
817 gboolean no_signal) = NULL;
818 GstDecklinkModeEnum mode;
819 GstClockTime capture_time = GST_CLOCK_TIME_NONE;
820 GstClockTime base_time = 0;
821 gboolean no_signal = FALSE;
822 GstClock *clock = NULL;
824 BMDTimeValue stream_time = GST_CLOCK_TIME_NONE;
825 BMDTimeValue stream_duration = GST_CLOCK_TIME_NONE;
826 BMDTimeValue hardware_time = GST_CLOCK_TIME_NONE;
827 BMDTimeValue hardware_duration = GST_CLOCK_TIME_NONE;
829 g_mutex_lock (&m_input->lock);
830 if (m_input->videosrc) {
831 videosrc = GST_ELEMENT_CAST (gst_object_ref (m_input->videosrc));
832 clock = gst_element_get_clock (videosrc);
833 base_time = gst_element_get_base_time (videosrc);
834 got_video_frame = m_input->got_video_frame;
836 mode = gst_decklink_get_mode_enum_from_bmd (m_input->mode->mode);
838 if (m_input->audiosrc) {
839 audiosrc = GST_ELEMENT_CAST (gst_object_ref (m_input->audiosrc));
841 clock = gst_element_get_clock (GST_ELEMENT_CAST (audiosrc));
842 base_time = gst_element_get_base_time (audiosrc);
844 got_audio_packet = m_input->got_audio_packet;
846 g_mutex_unlock (&m_input->lock);
849 capture_time = gst_clock_get_time (clock);
850 if (capture_time > base_time)
851 capture_time -= base_time;
859 flags = video_frame->GetFlags ();
860 if (flags & bmdFrameHasNoInputSource) {
865 if (got_video_frame && videosrc && video_frame) {
866 IDeckLinkTimecode *dtc = 0;
869 video_frame->GetStreamTime (&stream_time, &stream_duration,
872 GST_ERROR ("Failed to get stream time: 0x%08lx", (unsigned long) res);
873 stream_time = GST_CLOCK_TIME_NONE;
874 stream_duration = GST_CLOCK_TIME_NONE;
878 video_frame->GetHardwareReferenceTimestamp (GST_SECOND,
879 &hardware_time, &hardware_duration);
881 GST_ERROR ("Failed to get hardware time: 0x%08lx", (unsigned long) res);
882 hardware_time = GST_CLOCK_TIME_NONE;
883 hardware_duration = GST_CLOCK_TIME_NONE;
886 if (m_input->videosrc) {
887 /* FIXME: Avoid circularity between gstdecklink.cpp and
888 * gstdecklinkvideosrc.cpp */
891 GetTimecode (GST_DECKLINK_VIDEO_SRC (videosrc)->timecode_format,
895 GST_DEBUG_OBJECT (videosrc, "Failed to get timecode: 0x%08lx",
896 (unsigned long) res);
901 /* passing dtc reference */
902 got_video_frame (videosrc, video_frame, mode, capture_time,
903 stream_time, stream_duration, hardware_time, hardware_duration, dtc,
907 if (got_audio_packet && audiosrc && audio_packet) {
908 m_input->got_audio_packet (audiosrc, audio_packet, capture_time,
909 stream_time, stream_duration, hardware_time, hardware_duration,
913 GST_DEBUG ("Received no audio packet at %" GST_TIME_FORMAT,
914 GST_TIME_ARGS (capture_time));
917 gst_object_replace ((GstObject **) & videosrc, NULL);
918 gst_object_replace ((GstObject **) & audiosrc, NULL);
919 gst_object_replace ((GstObject **) & clock, NULL);
925 class GStreamerDecklinkMemoryAllocator:public IDeckLinkMemoryAllocator
929 uint32_t m_lastBufferSize;
930 uint32_t m_nonEmptyCalls;
931 GstQueueArray *m_buffers;
934 void _clearBufferPool ()
941 while ((buf = (uint8_t *) gst_queue_array_pop_head (m_buffers)))
946 GStreamerDecklinkMemoryAllocator ()
947 : IDeckLinkMemoryAllocator (),
948 m_lastBufferSize (0),
949 m_nonEmptyCalls (0), m_buffers (NULL), m_refcount (1)
951 g_mutex_init (&m_mutex);
953 m_buffers = gst_queue_array_new (60);
956 virtual ~ GStreamerDecklinkMemoryAllocator () {
959 gst_queue_array_free (m_buffers);
961 g_mutex_clear (&m_mutex);
964 virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID, LPVOID *)
966 return E_NOINTERFACE;
969 virtual ULONG STDMETHODCALLTYPE AddRef (void)
973 g_mutex_lock (&m_mutex);
976 g_mutex_unlock (&m_mutex);
981 virtual ULONG STDMETHODCALLTYPE Release (void)
985 g_mutex_lock (&m_mutex);
988 g_mutex_unlock (&m_mutex);
998 virtual HRESULT STDMETHODCALLTYPE
999 AllocateBuffer (uint32_t bufferSize, void **allocatedBuffer)
1003 g_mutex_lock (&m_mutex);
1005 /* If buffer size changed since last call, empty buffer pool */
1006 if (bufferSize != m_lastBufferSize) {
1007 _clearBufferPool ();
1008 m_lastBufferSize = bufferSize;
1011 /* Look if there is a free buffer in the pool */
1012 if (!(buf = (uint8_t *) gst_queue_array_pop_head (m_buffers))) {
1013 /* If not, alloc a new one */
1014 buf = (uint8_t *) g_malloc (bufferSize + 128);
1015 *((uint32_t *) buf) = bufferSize;
1018 *allocatedBuffer = (void *) buf;
1020 /* If there are still unused buffers in the pool
1021 * remove one of them every fifth call */
1022 if (gst_queue_array_get_length (m_buffers) > 0) {
1023 if (++m_nonEmptyCalls >= 5) {
1024 buf = (uint8_t *) gst_queue_array_pop_head (m_buffers) - 128;
1026 m_nonEmptyCalls = 0;
1029 m_nonEmptyCalls = 0;
1032 g_mutex_unlock (&m_mutex);
1037 virtual HRESULT STDMETHODCALLTYPE ReleaseBuffer (void *buffer)
1039 g_mutex_lock (&m_mutex);
1041 /* Put the buffer back to the pool if size matches with current pool */
1042 uint32_t size = *(uint32_t *) ((uint8_t *) buffer - 128);
1043 if (size == m_lastBufferSize) {
1044 gst_queue_array_push_tail (m_buffers, buffer);
1046 g_free (((uint8_t *) buffer) - 128);
1049 g_mutex_unlock (&m_mutex);
1054 virtual HRESULT STDMETHODCALLTYPE Commit ()
1059 virtual HRESULT STDMETHODCALLTYPE Decommit ()
1061 /* Clear all remaining pools */
1062 _clearBufferPool ();
1069 /* FIXME: We currently never deinit this */
1071 static GMutex com_init_lock;
1072 static GMutex com_deinit_lock;
1073 static GCond com_init_cond;
1074 static GCond com_deinit_cond;
1075 static GCond com_deinited_cond;
1076 static gboolean com_initialized = FALSE;
1078 /* COM initialization/uninitialization thread */
1080 gst_decklink_com_thread (gpointer data)
1084 g_mutex_lock (&com_init_lock);
1086 /* Initialize COM with a MTA for this process. This thread will
1087 * be the first one to enter the apartement and the last one to leave
1088 * it, unitializing COM properly */
1090 res = CoInitializeEx (0, COINIT_MULTITHREADED);
1092 GST_WARNING ("COM has been already initialized in the same process");
1093 else if (res == RPC_E_CHANGED_MODE)
1094 GST_WARNING ("The concurrency model of COM has changed.");
1096 GST_INFO ("COM intialized succesfully");
1098 com_initialized = TRUE;
1100 /* Signal other threads waiting on this condition that COM was initialized */
1101 g_cond_signal (&com_init_cond);
1103 g_mutex_unlock (&com_init_lock);
1105 /* Wait until the unitialize condition is met to leave the COM apartement */
1106 g_mutex_lock (&com_deinit_lock);
1107 g_cond_wait (&com_deinit_cond, &com_deinit_lock);
1110 GST_INFO ("COM unintialized succesfully");
1111 com_initialized = FALSE;
1112 g_cond_signal (&com_deinited_cond);
1113 g_mutex_unlock (&com_deinit_lock);
1117 #endif /* G_OS_WIN32 */
1119 static GOnce devices_once = G_ONCE_INIT;
1120 static GPtrArray *devices; /* array of Device */
1123 init_devices (gpointer data)
1125 IDeckLinkIterator *iterator;
1126 IDeckLink *decklink = NULL;
1131 // Start COM thread for Windows
1133 g_mutex_lock (&com_init_lock);
1135 /* create the COM initialization thread */
1136 g_thread_create ((GThreadFunc) gst_decklink_com_thread, NULL, FALSE, NULL);
1138 /* wait until the COM thread signals that COM has been initialized */
1139 g_cond_wait (&com_init_cond, &com_init_lock);
1140 g_mutex_unlock (&com_init_lock);
1141 #endif /* G_OS_WIN32 */
1143 iterator = CreateDeckLinkIteratorInstance ();
1144 if (iterator == NULL) {
1145 GST_ERROR ("no driver");
1149 devices = g_ptr_array_new ();
1152 ret = iterator->Next (&decklink);
1153 while (ret == S_OK) {
1156 dev = g_new0 (Device, 1);
1158 g_mutex_init (&dev->input.lock);
1159 g_mutex_init (&dev->output.lock);
1160 g_cond_init (&dev->output.cond);
1162 ret = decklink->QueryInterface (IID_IDeckLinkInput,
1163 (void **) &dev->input.input);
1165 GST_WARNING ("selected device does not have input interface: 0x%08lx",
1166 (unsigned long) ret);
1168 IDeckLinkDisplayModeIterator *mode_iter;
1170 dev->input.device = decklink;
1172 SetCallback (new GStreamerDecklinkInputCallback (&dev->input));
1174 if ((ret = dev->input.input->GetDisplayModeIterator (&mode_iter)) == S_OK) {
1175 IDeckLinkDisplayMode *mode;
1177 GST_DEBUG ("Input %d supports:", i);
1178 while ((ret = mode_iter->Next (&mode)) == S_OK) {
1181 mode->GetName ((COMSTR_T *) & name);
1182 CONVERT_COM_STRING (name);
1183 GST_DEBUG (" %s mode: 0x%08x width: %ld height: %ld"
1184 " fields: 0x%08x flags: 0x%08x", name,
1185 (int) mode->GetDisplayMode (), mode->GetWidth (),
1186 mode->GetHeight (), (int) mode->GetFieldDominance (),
1187 (int) mode->GetFlags ());
1188 FREE_COM_STRING (name);
1191 mode_iter->Release ();
1196 ret = decklink->QueryInterface (IID_IDeckLinkOutput,
1197 (void **) &dev->output.output);
1199 GST_WARNING ("selected device does not have output interface: 0x%08lx",
1200 (unsigned long) ret);
1202 IDeckLinkDisplayModeIterator *mode_iter;
1204 dev->output.device = decklink;
1205 dev->output.clock = gst_decklink_clock_new ("GstDecklinkOutputClock");
1206 GST_DECKLINK_CLOCK_CAST (dev->output.clock)->output = &dev->output;
1209 dev->output.output->GetDisplayModeIterator (&mode_iter)) ==
1211 IDeckLinkDisplayMode *mode;
1213 GST_DEBUG ("Output %d supports:", i);
1214 while ((ret = mode_iter->Next (&mode)) == S_OK) {
1217 mode->GetName ((COMSTR_T *) & name);
1218 CONVERT_COM_STRING (name);
1219 GST_DEBUG (" %s mode: 0x%08x width: %ld height: %ld"
1220 " fields: 0x%08x flags: 0x%08x", name,
1221 (int) mode->GetDisplayMode (), mode->GetWidth (),
1222 mode->GetHeight (), (int) mode->GetFieldDominance (),
1223 (int) mode->GetFlags ());
1224 FREE_COM_STRING (name);
1227 mode_iter->Release ();
1232 ret = decklink->QueryInterface (IID_IDeckLinkConfiguration,
1233 (void **) &dev->input.config);
1235 GST_WARNING ("selected device does not have config interface: 0x%08lx",
1236 (unsigned long) ret);
1238 char *serial_number;
1242 config->GetString (bmdDeckLinkConfigDeviceInformationSerialNumber,
1243 (COMSTR_T *) & serial_number);
1245 CONVERT_COM_STRING (serial_number);
1246 dev->output.hw_serial_number = g_strdup (serial_number);
1247 dev->input.hw_serial_number = g_strdup (serial_number);
1248 GST_DEBUG ("device %d has serial number %s", i, serial_number);
1249 FREE_COM_STRING (serial_number);
1253 ret = decklink->QueryInterface (IID_IDeckLinkAttributes,
1254 (void **) &dev->input.attributes);
1255 dev->output.attributes = dev->input.attributes;
1257 GST_WARNING ("selected device does not have attributes interface: "
1258 "0x%08lx", (unsigned long) ret);
1261 ret = decklink->QueryInterface (IID_IDeckLinkKeyer,
1262 (void **) &dev->output.keyer);
1264 g_ptr_array_add (devices, dev);
1266 /* We only warn of failure to obtain the keyer interface if the keyer
1267 * is enabled by keyer_mode
1270 ret = iterator->Next (&decklink);
1274 GST_INFO ("Detected %u devices", devices->len);
1276 iterator->Release ();
1282 gst_decklink_acquire_nth_output (gint n, GstElement * sink, gboolean is_audio)
1284 GstDecklinkOutput *output;
1287 g_once (&devices_once, init_devices, NULL);
1289 if (devices == NULL)
1292 if (n < 0 || (guint) n >= devices->len)
1295 device = (Device *) g_ptr_array_index (devices, n);
1296 output = &device->output;
1297 if (!output->output) {
1298 GST_ERROR ("Device %d has no output", n);
1302 g_mutex_lock (&output->lock);
1303 if (is_audio && !output->audiosink) {
1304 output->audiosink = GST_ELEMENT_CAST (gst_object_ref (sink));
1305 g_mutex_unlock (&output->lock);
1307 } else if (!output->videosink) {
1308 output->videosink = GST_ELEMENT_CAST (gst_object_ref (sink));
1309 g_mutex_unlock (&output->lock);
1312 g_mutex_unlock (&output->lock);
1314 GST_ERROR ("Output device %d (audio: %d) in use already", n, is_audio);
1319 gst_decklink_release_nth_output (gint n, GstElement * sink, gboolean is_audio)
1321 GstDecklinkOutput *output;
1324 if (devices == NULL)
1327 if (n < 0 || (guint) n >= devices->len)
1330 device = (Device *) g_ptr_array_index (devices, n);
1331 output = &device->output;
1332 g_assert (output->output);
1334 g_mutex_lock (&output->lock);
1336 g_assert (output->audiosink == sink);
1337 gst_object_unref (sink);
1338 output->audiosink = NULL;
1340 g_assert (output->videosink == sink);
1341 gst_object_unref (sink);
1342 output->videosink = NULL;
1344 g_mutex_unlock (&output->lock);
1348 gst_decklink_acquire_nth_input (gint n, GstElement * src, gboolean is_audio)
1350 GstDecklinkInput *input;
1353 g_once (&devices_once, init_devices, NULL);
1355 if (devices == NULL)
1358 if (n < 0 || (guint) n >= devices->len)
1361 device = (Device *) g_ptr_array_index (devices, n);
1362 input = &device->input;
1363 if (!input->input) {
1364 GST_ERROR ("Device %d has no input", n);
1368 g_mutex_lock (&input->lock);
1369 input->input->SetVideoInputFrameMemoryAllocator (new
1370 GStreamerDecklinkMemoryAllocator);
1371 if (is_audio && !input->audiosrc) {
1372 input->audiosrc = GST_ELEMENT_CAST (gst_object_ref (src));
1373 g_mutex_unlock (&input->lock);
1375 } else if (!input->videosrc) {
1376 input->videosrc = GST_ELEMENT_CAST (gst_object_ref (src));
1377 g_mutex_unlock (&input->lock);
1380 g_mutex_unlock (&input->lock);
1382 GST_ERROR ("Input device %d (audio: %d) in use already", n, is_audio);
1387 gst_decklink_release_nth_input (gint n, GstElement * src, gboolean is_audio)
1389 GstDecklinkInput *input;
1392 if (devices == NULL)
1395 if (n < 0 || (guint) n >= devices->len)
1398 device = (Device *) g_ptr_array_index (devices, n);
1400 input = &device->input;
1401 g_assert (input->input);
1403 g_mutex_lock (&input->lock);
1405 g_assert (input->audiosrc == src);
1406 gst_object_unref (src);
1407 input->audiosrc = NULL;
1409 g_assert (input->videosrc == src);
1410 gst_object_unref (src);
1411 input->videosrc = NULL;
1413 g_mutex_unlock (&input->lock);
1416 G_DEFINE_TYPE (GstDecklinkClock, gst_decklink_clock, GST_TYPE_SYSTEM_CLOCK);
1418 static GstClockTime gst_decklink_clock_get_internal_time (GstClock * clock);
1421 gst_decklink_clock_class_init (GstDecklinkClockClass * klass)
1423 GstClockClass *clock_class = (GstClockClass *) klass;
1425 clock_class->get_internal_time = gst_decklink_clock_get_internal_time;
1429 gst_decklink_clock_init (GstDecklinkClock * clock)
1431 GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
1435 gst_decklink_clock_new (const gchar * name)
1437 GstDecklinkClock *self =
1438 GST_DECKLINK_CLOCK (g_object_new (GST_TYPE_DECKLINK_CLOCK, "name", name,
1439 "clock-type", GST_CLOCK_TYPE_OTHER, NULL));
1441 gst_object_ref_sink (self);
1443 return GST_CLOCK_CAST (self);
1447 gst_decklink_clock_get_internal_time (GstClock * clock)
1449 GstDecklinkClock *self = GST_DECKLINK_CLOCK (clock);
1450 GstClockTime result, start_time, last_time;
1451 GstClockTimeDiff offset;
1455 g_mutex_lock (&self->output->lock);
1456 start_time = self->output->clock_start_time;
1457 offset = self->output->clock_offset;
1458 last_time = self->output->clock_last_time;
1460 if (!self->output->started) {
1465 self->output->output->GetHardwareReferenceClock (GST_SECOND, &time,
1467 if (ret == S_OK && time >= 0) {
1470 if (start_time == GST_CLOCK_TIME_NONE)
1471 start_time = self->output->clock_start_time = result;
1473 if (result > start_time)
1474 result -= start_time;
1478 if (self->output->clock_restart) {
1479 self->output->clock_offset = result - last_time;
1480 offset = self->output->clock_offset;
1481 self->output->clock_restart = FALSE;
1483 result = MAX (last_time, result);
1485 result = MAX (last_time, result);
1490 self->output->clock_last_time = result;
1492 result += self->output->clock_epoch;
1493 g_mutex_unlock (&self->output->lock);
1495 GST_LOG_OBJECT (clock,
1496 "result %" GST_TIME_FORMAT " time %" GST_TIME_FORMAT " last time %"
1497 GST_TIME_FORMAT " offset %" GST_TIME_FORMAT " start time %"
1498 GST_TIME_FORMAT " (ret: 0x%08lx)", GST_TIME_ARGS (result),
1499 GST_TIME_ARGS (time), GST_TIME_ARGS (last_time), GST_TIME_ARGS (offset),
1500 GST_TIME_ARGS (start_time), (unsigned long) ret);
1506 plugin_init (GstPlugin * plugin)
1508 GST_DEBUG_CATEGORY_INIT (gst_decklink_debug, "decklink", 0,
1509 "debug category for decklink plugin");
1511 gst_element_register (plugin, "decklinkaudiosink", GST_RANK_NONE,
1512 GST_TYPE_DECKLINK_AUDIO_SINK);
1513 gst_element_register (plugin, "decklinkvideosink", GST_RANK_NONE,
1514 GST_TYPE_DECKLINK_VIDEO_SINK);
1515 gst_element_register (plugin, "decklinkaudiosrc", GST_RANK_NONE,
1516 GST_TYPE_DECKLINK_AUDIO_SRC);
1517 gst_element_register (plugin, "decklinkvideosrc", GST_RANK_NONE,
1518 GST_TYPE_DECKLINK_VIDEO_SRC);
1522 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1525 "Blackmagic Decklink plugin",
1526 plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)