1 /*
2 * Copyright (C) 2019 Mathieu Duponchelle <mathieu@centricular.com>
3 * Copyright (C) 2019 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 Free
17 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "gstdecklinkdeviceprovider.h"
25 #include "gstdecklink.h"
26
27 G_DEFINE_TYPE (GstDecklinkDeviceProvider, gst_decklink_device_provider,
28 GST_TYPE_DEVICE_PROVIDER);
29 GST_DEVICE_PROVIDER_REGISTER_DEFINE (decklinkdeviceprovider, "decklinkdeviceprovider",
30 GST_RANK_PRIMARY, GST_TYPE_DECKLINK_DEVICE_PROVIDER);
31
32 static void
gst_decklink_device_provider_init(GstDecklinkDeviceProvider * self)33 gst_decklink_device_provider_init (GstDecklinkDeviceProvider * self)
34 {
35 }
36
37 static GList *
gst_decklink_device_provider_probe(GstDeviceProvider * provider)38 gst_decklink_device_provider_probe (GstDeviceProvider * provider)
39 {
40 return gst_decklink_get_devices ();
41 }
42
43 static void
gst_decklink_device_provider_class_init(GstDecklinkDeviceProviderClass * klass)44 gst_decklink_device_provider_class_init (GstDecklinkDeviceProviderClass * klass)
45 {
46 GstDeviceProviderClass *dm_class = GST_DEVICE_PROVIDER_CLASS (klass);
47
48 dm_class->probe = GST_DEBUG_FUNCPTR (gst_decklink_device_provider_probe);
49
50 gst_device_provider_class_set_static_metadata (dm_class,
51 "Decklink Device Provider", "Hardware/Source/Sink/Audio/Video",
52 "Lists and provides Decklink devices",
53 "Sebastian Dröge <sebastian@centricular.com>");
54 }
55
56 G_DEFINE_TYPE (GstDecklinkDevice, gst_decklink_device, GST_TYPE_DEVICE);
57
58 static void
gst_decklink_device_init(GstDecklinkDevice * self)59 gst_decklink_device_init (GstDecklinkDevice * self)
60 {
61 }
62
63 static GstElement *
gst_decklink_device_create_element(GstDevice * device,const gchar * name)64 gst_decklink_device_create_element (GstDevice * device, const gchar * name)
65 {
66 GstDecklinkDevice *self = GST_DECKLINK_DEVICE (device);
67 GstElement *ret = NULL;
68
69 if (self->video && self->capture) {
70 ret = gst_element_factory_make ("decklinkvideosrc", name);
71 } else if (!self->video && self->capture) {
72 ret = gst_element_factory_make ("decklinkaudiosrc", name);
73 } else if (self->video && !self->capture) {
74 ret = gst_element_factory_make ("decklinkvideosink", name);
75 } else {
76 ret = gst_element_factory_make ("decklinkaudiosink", name);
77 }
78
79 if (ret) {
80 g_object_set (ret, "device-number", self->device_number, NULL);
81 }
82
83 return ret;
84 }
85
86 static void
gst_decklink_device_class_init(GstDecklinkDeviceClass * klass)87 gst_decklink_device_class_init (GstDecklinkDeviceClass * klass)
88 {
89 GstDeviceClass *gst_device_class = GST_DEVICE_CLASS (klass);
90
91 gst_device_class->create_element =
92 GST_DEBUG_FUNCPTR (gst_decklink_device_create_element);
93 }
94