DeviceMonitor#
Added in version 1.4.
Superclasses: Object
, InitiallyUnowned
, Object
Applications should create a DeviceMonitor
when they want
to probe, list and monitor devices of a specific type. The
DeviceMonitor
will create the appropriate
DeviceProvider
objects and manage them. It will then post
messages on its Bus
for devices that have been added and
removed.
The device monitor will monitor all devices matching the filters that the application has set.
The basic use pattern of a device monitor is as follows:
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;
}
GstDeviceMonitor *
setup_raw_video_source_device_monitor (void) {
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);
gst_device_monitor_start (monitor);
return monitor;
}
Constructors#
- class DeviceMonitor
- classmethod new() DeviceMonitor #
Create a new
DeviceMonitor
Added in version 1.4.
Methods#
- class DeviceMonitor
- add_filter(classes: str | None = None, caps: Caps | None = None) int #
Adds a filter for which
Device
will be monitored, any device that matches all these classes and theCaps
will be returned.If this function is called multiple times to add more filters, each will be matched independently. That is, adding more filters will not further restrict what devices are matched.
The
Caps
supported by the device as returned byget_caps()
are not intersected with caps filters added using this function.Filters must be added before the
DeviceMonitor
is started.Added in version 1.4.
- Parameters:
classes – device classes to use as filter or
None
for any classcaps – the
Caps
to filter orNone
for ANY
- get_bus() Bus #
Gets the
Bus
of thisDeviceMonitor
Added in version 1.4.
- get_devices() list[Device] | None #
Gets a list of devices from all of the relevant monitors. This may actually probe the hardware if the monitor is not currently started.
Added in version 1.4.
- get_providers() list[str] #
Get a list of the currently selected device provider factories.
This
Added in version 1.6.
- get_show_all_devices() bool #
Get if
monitor
is currently showing all devices, even those from hidden providers.Added in version 1.6.
- remove_filter(filter_id: int) bool #
Removes a filter from the
DeviceMonitor
using the id that was returned byadd_filter()
.Added in version 1.4.
- Parameters:
filter_id – the id of the filter
- set_show_all_devices(show_all: bool) None #
Set if all devices should be visible, even those devices from hidden providers. Setting
show_all
to true might show some devices multiple times.Added in version 1.6.
- Parameters:
show_all – show all devices
- start() bool #
Starts monitoring the devices, one this has succeeded, the
DEVICE_ADDED
andDEVICE_REMOVED
messages will be emitted on the bus when the list of devices changes.Added in version 1.4.