-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevice-provider.c
More file actions
65 lines (54 loc) · 1.66 KB
/
device-provider.c
File metadata and controls
65 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <gst/gst.h>
#include <stdio.h>
#include <string.h>
static gboolean
my_bus_func (GstBus * bus, GstMessage * message, gpointer user_data)
{
GstDevice *device;
gchar *name;
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_DEVICE_ADDED:
gst_message_parse_device_added (message, &device);
name = gst_device_get_display_name (device);
g_print("Device added: %s\n", name);
g_free (name);
gst_object_unref (device);
break;
case GST_MESSAGE_DEVICE_REMOVED:
gst_message_parse_device_removed (message, &device);
name = gst_device_get_display_name (device);
g_print("Device removed: %s\n", name);
g_free (name);
gst_object_unref (device);
break;
default:
break;
}
return G_SOURCE_CONTINUE;
}
int main()
{
GstDeviceMonitor *monitor;
GstBus *bus;
GstCaps *caps;
monitor = gst_device_monitor_new();
bus = gst_device_monitor_get_bus (monitor);
gst_bus_add_watch (bus, my_bus_func, NULL);
gst_object_unref(bus);
caps = gst_caps_new_empty_simple ("video/x-raw");
gst_device_monitor_add_filter (monitor, "Video/Source", caps);
gst_caps_unref (caps);
if(gst_device_monitor_start(monitor))
printf("Monitor started\n");
else
printf("Monitor failed to start\n");
return 0;
g_autofree GList *devices = gst_device_monitor_get_devices(monitor);
for (int i = 0; i < g_list_length(devices); i++)
{
GstDevice *device = g_list_nth_data(devices, i);
printf("device: %s", gst_device_get_display_name(device));
}
gst_device_monitor_stop(monitor);
return 0;
}