decklink: Fix indention
[platform/upstream/gstreamer.git] / sys / decklink / gstdecklink.cpp
1 /* GStreamer
2  * Copyright (C) 2011 David Schleef <ds@schleef.org>
3  * Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
18  * Boston, MA 02110-1335, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/gst.h>
26 #include "gstdecklink.h"
27 #include "gstdecklinkaudiosink.h"
28 #include "gstdecklinkvideosink.h"
29 #include "gstdecklinkaudiosrc.h"
30 #include "gstdecklinkvideosrc.h"
31
32 GST_DEBUG_CATEGORY_STATIC (gst_decklink_debug);
33 #define GST_CAT_DEFAULT gst_decklink_debug
34
35 GType
36 gst_decklink_mode_get_type (void)
37 {
38   static gsize id = 0;
39   static const GEnumValue modes[] = {
40     {GST_DECKLINK_MODE_NTSC, "ntsc", "NTSC SD 60i"},
41     {GST_DECKLINK_MODE_NTSC2398, "ntsc2398", "NTSC SD 60i (24 fps)"},
42     {GST_DECKLINK_MODE_PAL, "pal", "PAL SD 50i"},
43     {GST_DECKLINK_MODE_NTSC_P, "ntsc-p", "NTSC SD 60p"},
44     {GST_DECKLINK_MODE_PAL_P, "pal-p", "PAL SD 50p"},
45
46     {GST_DECKLINK_MODE_1080p2398, "1080p2398", "HD1080 23.98p"},
47     {GST_DECKLINK_MODE_1080p24, "1080p24", "HD1080 24p"},
48     {GST_DECKLINK_MODE_1080p25, "1080p25", "HD1080 25p"},
49     {GST_DECKLINK_MODE_1080p2997, "1080p2997", "HD1080 29.97p"},
50     {GST_DECKLINK_MODE_1080p30, "1080p30", "HD1080 30p"},
51
52     {GST_DECKLINK_MODE_1080i50, "1080i50", "HD1080 50i"},
53     {GST_DECKLINK_MODE_1080i5994, "1080i5994", "HD1080 59.94i"},
54     {GST_DECKLINK_MODE_1080i60, "1080i60", "HD1080 60i"},
55
56     {GST_DECKLINK_MODE_1080p50, "1080p50", "HD1080 50p"},
57     {GST_DECKLINK_MODE_1080p5994, "1080p5994", "HD1080 59.94p"},
58     {GST_DECKLINK_MODE_1080p60, "1080p60", "HD1080 60p"},
59
60     {GST_DECKLINK_MODE_720p50, "720p50", "HD720 50p"},
61     {GST_DECKLINK_MODE_720p5994, "720p5994", "HD720 59.94p"},
62     {GST_DECKLINK_MODE_720p60, "720p60", "HD720 60p"},
63
64     {GST_DECKLINK_MODE_2048p2398, "2048p2398", "2k 23.98p"},
65     {GST_DECKLINK_MODE_2048p24, "2048p24", "2k 24p"},
66     {GST_DECKLINK_MODE_2048p25, "2048p25", "2k 25p"},
67
68     {0, NULL, NULL}
69   };
70
71   if (g_once_init_enter (&id)) {
72     GType tmp = g_enum_register_static ("GstDecklinkModes", modes);
73     g_once_init_leave (&id, tmp);
74   }
75
76   return (GType) id;
77 }
78
79 GType
80 gst_decklink_connection_get_type (void)
81 {
82   static gsize id = 0;
83   static const GEnumValue connections[] = {
84     {GST_DECKLINK_CONNECTION_SDI, "sdi", "SDI"},
85     {GST_DECKLINK_CONNECTION_HDMI, "hdmi", "HDMI"},
86     {GST_DECKLINK_CONNECTION_OPTICAL_SDI, "optical-sdi", "Optical SDI"},
87     {GST_DECKLINK_CONNECTION_COMPONENT, "component", "Component"},
88     {GST_DECKLINK_CONNECTION_COMPOSITE, "composite", "Composite"},
89     {GST_DECKLINK_CONNECTION_SVIDEO, "svideo", "S-Video"},
90     {0, NULL, NULL}
91   };
92
93   if (g_once_init_enter (&id)) {
94     GType tmp = g_enum_register_static ("GstDecklinkConnection", connections);
95     g_once_init_leave (&id, tmp);
96   }
97
98   return (GType) id;
99 }
100
101 GType
102 gst_decklink_audio_connection_get_type (void)
103 {
104   static gsize id = 0;
105   static const GEnumValue connections[] = {
106     {GST_DECKLINK_AUDIO_CONNECTION_AUTO, "auto", "Automatic"},
107     {GST_DECKLINK_AUDIO_CONNECTION_EMBEDDED, "embedded",
108         "SDI/HDMI embedded audio"},
109     {GST_DECKLINK_AUDIO_CONNECTION_AES_EBU, "aes", "AES/EBU input"},
110     {GST_DECKLINK_AUDIO_CONNECTION_ANALOG, "analog", "Analog input"},
111     {0, NULL, NULL}
112   };
113
114   if (g_once_init_enter (&id)) {
115     GType tmp =
116         g_enum_register_static ("GstDecklinkAudioConnection", connections);
117     g_once_init_leave (&id, tmp);
118   }
119
120   return (GType) id;
121 }
122
123 #define NTSC 10, 11, false, false
124 #define PAL 12, 11, true, false
125 #define HD 1, 1, false, true
126
127 static const GstDecklinkMode modes[] = {
128   {bmdModeNTSC, 720, 486, 30000, 1001, true, NTSC},
129   {bmdModeNTSC2398, 720, 486, 24000, 1001, true, NTSC},
130   {bmdModePAL, 720, 576, 25, 1, true, PAL},
131   {bmdModeNTSCp, 720, 486, 30000, 1001, false, NTSC},
132   {bmdModePALp, 720, 576, 25, 1, false, PAL},
133
134   {bmdModeHD1080p2398, 1920, 1080, 24000, 1001, false, HD},
135   {bmdModeHD1080p24, 1920, 1080, 24, 1, false, HD},
136   {bmdModeHD1080p25, 1920, 1080, 25, 1, false, HD},
137   {bmdModeHD1080p2997, 1920, 1080, 30000, 1001, false, HD},
138   {bmdModeHD1080p30, 1920, 1080, 30, 1, false, HD},
139
140   {bmdModeHD1080i50, 1920, 1080, 50, 1, true, HD},
141   {bmdModeHD1080i5994, 1920, 1080, 60000, 1001, true, HD},
142   {bmdModeHD1080i6000, 1920, 1080, 60, 1, true, HD},
143
144   {bmdModeHD1080p50, 1920, 1080, 50, 1, false, HD},
145   {bmdModeHD1080p5994, 1920, 1080, 60000, 1001, false, HD},
146   {bmdModeHD1080p6000, 1920, 1080, 60, 1, false, HD},
147
148   {bmdModeHD720p50, 1280, 720, 50, 1, false, HD},
149   {bmdModeHD720p5994, 1280, 720, 60000, 1001, false, HD},
150   {bmdModeHD720p60, 1280, 720, 60, 1, false, HD},
151
152   {bmdMode2k2398, 2048, 1556, 24000, 1001, false, HD},
153   {bmdMode2k24, 2048, 1556, 24, 1, false, HD},
154   {bmdMode2k25, 2048, 1556, 25, 1, false, HD}
155
156 };
157
158 const GstDecklinkMode *
159 gst_decklink_get_mode (GstDecklinkModeEnum e)
160 {
161   return &modes[e];
162 }
163
164 static GstStructure *
165 gst_decklink_mode_get_structure (GstDecklinkModeEnum e)
166 {
167   const GstDecklinkMode *mode = &modes[e];
168
169   return gst_structure_new ("video/x-raw",
170       "format", G_TYPE_STRING, "UYVY",
171       "width", G_TYPE_INT, mode->width,
172       "height", G_TYPE_INT, mode->height,
173       "framerate", GST_TYPE_FRACTION, mode->fps_n, mode->fps_d,
174       "interlace-mode", G_TYPE_STRING,
175       mode->interlaced ? "interleaved" : "progressive", "pixel-aspect-ratio",
176       GST_TYPE_FRACTION, mode->par_n, mode->par_d, "colorimetry", G_TYPE_STRING,
177       mode->is_hdtv ? "bt709" : "bt601", "chroma-site", G_TYPE_STRING, "mpeg2",
178       NULL);
179 }
180
181 GstCaps *
182 gst_decklink_mode_get_caps (GstDecklinkModeEnum e)
183 {
184   GstCaps *caps;
185
186   caps = gst_caps_new_empty ();
187   gst_caps_append_structure (caps, gst_decklink_mode_get_structure (e));
188
189   return caps;
190 }
191
192 GstCaps *
193 gst_decklink_mode_get_template_caps (void)
194 {
195   int i;
196   GstCaps *caps;
197   GstStructure *s;
198
199   caps = gst_caps_new_empty ();
200   for (i = 0; i < (int) G_N_ELEMENTS (modes); i++) {
201     s = gst_decklink_mode_get_structure ((GstDecklinkModeEnum) i);
202     gst_caps_append_structure (caps, s);
203   }
204
205   return caps;
206 }
207
208 #define GST_TYPE_DECKLINK_CLOCK \
209   (gst_decklink_clock_get_type())
210 #define GST_DECKLINK_CLOCK(obj) \
211   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DECKLINK_CLOCK,GstDecklinkClock))
212 #define GST_DECKLINK_CLOCK_CLASS(klass) \
213   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DECKLINK_CLOCK,GstDecklinkClockClass))
214 #define GST_IS_Decklink_CLOCK(obj) \
215   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DECKLINK_CLOCK))
216 #define GST_IS_Decklink_CLOCK_CLASS(klass) \
217   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DECKLINK_CLOCK))
218 #define GST_DECKLINK_CLOCK_CAST(obj) \
219   ((GstDecklinkClock*)(obj))
220
221 typedef struct _GstDecklinkClock GstDecklinkClock;
222 typedef struct _GstDecklinkClockClass GstDecklinkClockClass;
223
224 struct _GstDecklinkClock
225 {
226   GstSystemClock clock;
227
228   IDeckLinkInput *input;
229   IDeckLinkOutput *output;
230 };
231
232 struct _GstDecklinkClockClass
233 {
234   GstSystemClockClass parent_class;
235 };
236
237 GType gst_decklink_clock_get_type (void);
238 static GstClock *gst_decklink_clock_new (const gchar * name);
239
240 typedef struct _Device Device;
241 struct _Device
242 {
243   GstDecklinkOutput output;
244   GstDecklinkInput input;
245 };
246
247 class GStreamerDecklinkInputCallback:public IDeckLinkInputCallback
248 {
249 private:
250   GstDecklinkInput * m_input;
251   GMutex m_mutex;
252   gint m_refcount;
253 public:
254     GStreamerDecklinkInputCallback (GstDecklinkInput * input)
255   : IDeckLinkInputCallback ()
256   {
257     m_input = input;
258     g_mutex_init (&m_mutex);
259   }
260
261   virtual ~ GStreamerDecklinkInputCallback ()
262   {
263     g_mutex_clear (&m_mutex);
264   }
265
266   virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID, LPVOID *)
267   {
268     return E_NOINTERFACE;
269   }
270
271   virtual ULONG STDMETHODCALLTYPE AddRef (void)
272   {
273     ULONG ret;
274
275     g_mutex_lock (&m_mutex);
276     m_refcount++;
277     ret = m_refcount;
278     g_mutex_unlock (&m_mutex);
279
280     return ret;
281   }
282
283   virtual ULONG STDMETHODCALLTYPE Release (void)
284   {
285     ULONG ret;
286
287     g_mutex_lock (&m_mutex);
288     m_refcount--;
289     ret = m_refcount;
290     g_mutex_unlock (&m_mutex);
291
292
293     if (ret == 0) {
294       delete this;
295     }
296
297     return ret;
298   }
299
300   virtual HRESULT STDMETHODCALLTYPE
301       VideoInputFormatChanged (BMDVideoInputFormatChangedEvents,
302       IDeckLinkDisplayMode *, BMDDetectedVideoInputFormatFlags)
303   {
304     GST_FIXME ("Video input format change not supported yet");
305     return S_OK;
306   }
307
308   virtual HRESULT STDMETHODCALLTYPE
309       VideoInputFrameArrived (IDeckLinkVideoInputFrame * video_frame,
310       IDeckLinkAudioInputPacket * audio_packet)
311   {
312     GstClockTime clock_time = gst_clock_get_time (m_input->clock);
313
314     g_mutex_lock (&m_input->lock);
315     if (m_input->got_video_frame) {
316       GstClockTime capture_time = clock_time -
317           gst_element_get_base_time (m_input->videosrc);
318       m_input->got_video_frame (m_input->videosrc, video_frame, capture_time);
319     }
320
321     if (m_input->got_audio_packet) {
322       GstClockTime capture_time = clock_time -
323           gst_element_get_base_time (m_input->audiosrc);
324       m_input->got_audio_packet (m_input->audiosrc, audio_packet, capture_time);
325     }
326
327     g_mutex_unlock (&m_input->lock);
328     return S_OK;
329   }
330 };
331
332 #ifdef _MSC_VER
333 /* FIXME: We currently never deinit this */
334
335 static GMutex com_init_lock;
336 static GMutex com_deinit_lock;
337 static GCond com_init_cond;
338 static GCond com_deinit_cond;
339 static GCond com_deinited_cond;
340 static gboolean com_initialized = FALSE;
341
342 /* COM initialization/uninitialization thread */
343 static gpointer
344 gst_decklink_com_thread (gpointer data)
345 {
346   HRESULT res;
347
348   g_mutex_lock (&com_init_lock);
349
350   /* Initialize COM with a MTA for this process. This thread will
351    * be the first one to enter the apartement and the last one to leave
352    * it, unitializing COM properly */
353
354   res = CoInitializeEx (0, COINIT_MULTITHREADED);
355   if (res == S_FALSE)
356     GST_WARNING ("COM has been already initialized in the same process");
357   else if (res == RPC_E_CHANGED_MODE)
358     GST_WARNING ("The concurrency model of COM has changed.");
359   else
360     GST_INFO ("COM intialized succesfully");
361
362   com_initialized = TRUE;
363
364   /* Signal other threads waiting on this condition that COM was initialized */
365   g_cond_signal (&com_init_cond);
366
367   g_mutex_unlock (&com_init_lock);
368
369   /* Wait until the unitialize condition is met to leave the COM apartement */
370   g_mutex_lock (&com_deinit_lock);
371   g_cond_wait (&com_deinit_cond, &com_deinit_lock);
372
373   CoUninitialize ();
374   GST_INFO ("COM unintialized succesfully");
375   com_initialized = FALSE;
376   g_cond_signal (&com_deinited_cond);
377   g_mutex_unlock (&com_deinit_lock);
378
379   return NULL;
380 }
381 #endif /* _MSC_VER */
382
383 static GOnce devices_once = G_ONCE_INIT;
384 static int n_devices;
385 static Device devices[10];
386
387 static gpointer
388 init_devices (gpointer data)
389 {
390   IDeckLinkIterator *iterator;
391   IDeckLink *decklink = NULL;
392   HRESULT ret;
393   int i;
394
395 #ifdef _MSC_VER
396   // Start COM thread for Windows
397
398   g_mutex_lock (&com_init_lock);
399
400   /* create the COM initialization thread */
401   g_thread_create ((GThreadFunc) gst_decklink_com_thread, NULL, FALSE, NULL);
402
403   /* wait until the COM thread signals that COM has been initialized */
404   g_cond_wait (&com_init_cond, &com_init_lock);
405   g_mutex_unlock (&com_init_lock);
406 #endif /* _MSC_VER */
407
408   iterator = CreateDeckLinkIteratorInstance ();
409   if (iterator == NULL) {
410     GST_ERROR ("no driver");
411     return NULL;
412   }
413
414   i = 0;
415   ret = iterator->Next (&decklink);
416   while (ret == S_OK) {
417     ret = decklink->QueryInterface (IID_IDeckLinkInput,
418         (void **) &devices[i].input.input);
419     if (ret != S_OK) {
420       GST_WARNING ("selected device does not have input interface");
421     } else {
422       devices[i].input.device = decklink;
423       devices[i].input.clock = gst_decklink_clock_new ("GstDecklinkInputClock");
424       GST_DECKLINK_CLOCK_CAST (devices[i].input.clock)->input =
425           devices[i].input.input;
426       devices[i].input.
427           input->SetCallback (new GStreamerDecklinkInputCallback (&devices[i].
428               input));
429     }
430
431     ret = decklink->QueryInterface (IID_IDeckLinkOutput,
432         (void **) &devices[i].output.output);
433     if (ret != S_OK) {
434       GST_WARNING ("selected device does not have output interface");
435     } else {
436       devices[i].output.device = decklink;
437       devices[i].output.clock =
438           gst_decklink_clock_new ("GstDecklinkOutputClock");
439       GST_DECKLINK_CLOCK_CAST (devices[i].output.clock)->output =
440           devices[i].output.output;
441     }
442
443     ret = decklink->QueryInterface (IID_IDeckLinkConfiguration,
444         (void **) &devices[i].input.config);
445     if (ret != S_OK) {
446       GST_WARNING ("selected device does not have config interface");
447     }
448
449     ret = iterator->Next (&decklink);
450     i++;
451
452     if (i == 10) {
453       GST_WARNING ("this hardware has more then 10 devices");
454       break;
455     }
456   }
457
458   n_devices = i;
459
460   iterator->Release ();
461
462   return NULL;
463 }
464
465 GstDecklinkOutput *
466 gst_decklink_acquire_nth_output (gint n, GstElement * sink, gboolean is_audio)
467 {
468   GstDecklinkOutput *output;
469
470   g_once (&devices_once, init_devices, NULL);
471
472   if (n >= n_devices)
473     return NULL;
474
475   output = &devices[n].output;
476   if (!output->output) {
477     GST_ERROR ("Device %d has no output", n);
478     return NULL;
479   }
480
481   g_mutex_lock (&output->lock);
482   if (is_audio && !output->audiosink) {
483     output->audiosink = GST_ELEMENT_CAST (gst_object_ref (sink));
484     g_mutex_unlock (&output->lock);
485     return output;
486   } else if (!output->videosink) {
487     output->videosink = GST_ELEMENT_CAST (gst_object_ref (sink));
488     g_mutex_unlock (&output->lock);
489     return output;
490   }
491   g_mutex_unlock (&output->lock);
492
493   GST_ERROR ("Output device %d (audio: %d) in use already", n, is_audio);
494   return NULL;
495 }
496
497 void
498 gst_decklink_release_nth_output (gint n, GstElement * sink, gboolean is_audio)
499 {
500   GstDecklinkOutput *output;
501
502   if (n >= n_devices)
503     return;
504
505   output = &devices[n].output;
506   g_assert (output->output);
507
508   g_mutex_lock (&output->lock);
509   if (is_audio) {
510     g_assert (output->audiosink == sink);
511     gst_object_unref (sink);
512     output->audiosink = NULL;
513   } else {
514     g_assert (output->videosink == sink);
515     gst_object_unref (sink);
516     output->videosink = NULL;
517   }
518   g_mutex_unlock (&output->lock);
519 }
520
521 void
522 gst_decklink_output_set_audio_clock (GstDecklinkOutput * output,
523     GstClock * clock)
524 {
525   g_mutex_lock (&output->lock);
526   if (output->audio_clock)
527     gst_object_unref (output->audio_clock);
528   output->audio_clock = clock;
529   if (clock)
530     gst_object_ref (clock);
531   g_mutex_unlock (&output->lock);
532 }
533
534
535 GstClock *
536 gst_decklink_output_get_audio_clock (GstDecklinkOutput * output)
537 {
538   GstClock *ret = NULL;
539
540   g_mutex_lock (&output->lock);
541   if (output->audio_clock)
542     ret = GST_CLOCK_CAST (gst_object_ref (output->audio_clock));
543   g_mutex_unlock (&output->lock);
544
545   return ret;
546 }
547
548 GstDecklinkInput *
549 gst_decklink_acquire_nth_input (gint n, GstElement * src, gboolean is_audio)
550 {
551   GstDecklinkInput *input;
552
553   g_once (&devices_once, init_devices, NULL);
554
555   if (n >= n_devices)
556     return NULL;
557
558   input = &devices[n].input;
559   if (!input->input) {
560     GST_ERROR ("Device %d has no input", n);
561     return NULL;
562   }
563
564   g_mutex_lock (&input->lock);
565   if (is_audio && !input->audiosrc) {
566     input->audiosrc = GST_ELEMENT_CAST (gst_object_ref (src));
567     g_mutex_unlock (&input->lock);
568     return input;
569   } else if (!input->videosrc) {
570     input->videosrc = GST_ELEMENT_CAST (gst_object_ref (src));
571     g_mutex_unlock (&input->lock);
572     return input;
573   }
574   g_mutex_unlock (&input->lock);
575
576   GST_ERROR ("Input device %d (audio: %d) in use already", n, is_audio);
577   return NULL;
578 }
579
580 void
581 gst_decklink_release_nth_input (gint n, GstElement * src, gboolean is_audio)
582 {
583   GstDecklinkInput *input;
584
585   if (n >= n_devices)
586     return;
587
588   input = &devices[n].input;
589   g_assert (input->input);
590
591   g_mutex_lock (&input->lock);
592   if (is_audio) {
593     g_assert (input->audiosrc == src);
594     gst_object_unref (src);
595     input->audiosrc = NULL;
596   } else {
597     g_assert (input->videosrc == src);
598     gst_object_unref (src);
599     input->videosrc = NULL;
600   }
601   g_mutex_unlock (&input->lock);
602 }
603
604 G_DEFINE_TYPE (GstDecklinkClock, gst_decklink_clock, GST_TYPE_SYSTEM_CLOCK);
605
606 static GstClockTime gst_decklink_clock_get_internal_time (GstClock * clock);
607
608 static void
609 gst_decklink_clock_class_init (GstDecklinkClockClass * klass)
610 {
611   GstClockClass *clock_class = (GstClockClass *) klass;
612
613   clock_class->get_internal_time = gst_decklink_clock_get_internal_time;
614 }
615
616 static void
617 gst_decklink_clock_init (GstDecklinkClock * clock)
618 {
619   GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
620 }
621
622 static GstClock *
623 gst_decklink_clock_new (const gchar * name)
624 {
625   GstDecklinkClock *self =
626       GST_DECKLINK_CLOCK (g_object_new (GST_TYPE_DECKLINK_CLOCK, "name", name,
627           "clock-type", GST_CLOCK_TYPE_OTHER, NULL));
628
629   return GST_CLOCK_CAST (self);
630 }
631
632 static GstClockTime
633 gst_decklink_clock_get_internal_time (GstClock * clock)
634 {
635   GstDecklinkClock *self = GST_DECKLINK_CLOCK (clock);
636   GstClockTime result;
637   BMDTimeValue time;
638   HRESULT ret;
639
640   GST_OBJECT_LOCK (clock);
641   if (self->input != NULL) {
642     ret =
643         self->input->GetHardwareReferenceClock (GST_SECOND, &time, NULL, NULL);
644     if (ret == S_OK && time >= 0)
645       result = time;
646     else
647       result = GST_CLOCK_TIME_NONE;
648   } else if (self->output != NULL) {
649     ret =
650         self->output->GetHardwareReferenceClock (GST_SECOND, &time, NULL, NULL);
651     if (ret == S_OK && time >= 0)
652       result = time;
653     else
654       result = GST_CLOCK_TIME_NONE;
655   } else {
656     result = GST_CLOCK_TIME_NONE;
657   }
658   GST_OBJECT_UNLOCK (clock);
659   GST_LOG_OBJECT (clock, "result %" GST_TIME_FORMAT, GST_TIME_ARGS (result));
660
661   return result;
662 }
663
664 static gboolean
665 plugin_init (GstPlugin * plugin)
666 {
667   GST_DEBUG_CATEGORY_INIT (gst_decklink_debug, "decklink", 0,
668       "debug category for decklink plugin");
669
670   gst_element_register (plugin, "decklinkaudiosink", GST_RANK_NONE,
671       GST_TYPE_DECKLINK_AUDIO_SINK);
672   gst_element_register (plugin, "decklinkvideosink", GST_RANK_NONE,
673       GST_TYPE_DECKLINK_VIDEO_SINK);
674   gst_element_register (plugin, "decklinkaudiosrc", GST_RANK_NONE,
675       GST_TYPE_DECKLINK_AUDIO_SRC);
676   gst_element_register (plugin, "decklinkvideosrc", GST_RANK_NONE,
677       GST_TYPE_DECKLINK_VIDEO_SRC);
678   return TRUE;
679 }
680
681 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
682     GST_VERSION_MINOR,
683     decklink,
684     "Blackmagic Decklink plugin",
685     plugin_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)