Class DeviceMonitor

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class DeviceMonitor extends GstObject

Applications should create a GstDeviceMonitor when they want to probe, list and monitor devices of a specific type. The GstDeviceMonitor will create the appropriate GstDeviceProvider objects and manage them. It will then post messages on its GstBus 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;
  }
Since:
1.4
  • Constructor Details

    • DeviceMonitor

      public DeviceMonitor(MemorySegment address)
      Create a DeviceMonitor instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • DeviceMonitor

      public DeviceMonitor()
      Create a new DeviceMonitor.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the DeviceMonitor class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected DeviceMonitor asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GstObject
      Returns:
      the instance as if it were its parent type
    • addFilter

      public int addFilter(@Nullable String classes, @Nullable Caps caps)

      Adds a filter for which GstDevice will be monitored, any device that matches all these classes and the GstCaps 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 GstCaps supported by the device as returned by gst_device_get_caps() are not intersected with caps filters added using this function.

      Filters must be added before the GstDeviceMonitor is started.

      Parameters:
      classes - device classes to use as filter or null for any class
      caps - the GstCaps to filter or null for ANY
      Returns:
      The id of the new filter or 0 if no provider matched the filter's classes.
      Since:
      1.4
    • getBus

      public Bus getBus()
      Gets the GstBus of this GstDeviceMonitor
      Returns:
      a GstBus
      Since:
      1.4
    • getDevices

      public @Nullable List<Device> getDevices()
      Gets a list of devices from all of the relevant monitors. This may actually probe the hardware if the monitor is not currently started.
      Returns:
      a GList of GstDevice
      Since:
      1.4
    • getProviders

      public String[] getProviders()

      Get a list of the currently selected device provider factories.

      This

      Returns:
      A list of device provider factory names that are currently being monitored by this DeviceMonitor or null when nothing is being monitored.
      Since:
      1.6
    • getShowAllDevices

      public boolean getShowAllDevices()
      Get if this DeviceMonitor is currently showing all devices, even those from hidden providers.
      Returns:
      true when all devices will be shown.
      Since:
      1.6
    • removeFilter

      public boolean removeFilter(int filterId)
      Removes a filter from the GstDeviceMonitor using the id that was returned by gst_device_monitor_add_filter().
      Parameters:
      filterId - the id of the filter
      Returns:
      true of the filter id was valid, false otherwise
      Since:
      1.4
    • setShowAllDevices

      public void setShowAllDevices(boolean showAll)
      Set if all devices should be visible, even those devices from hidden providers. Setting showAll to true might show some devices multiple times.
      Parameters:
      showAll - show all devices
      Since:
      1.6
    • start

      public boolean start()
      Starts monitoring the devices, one this has succeeded, the MessageType.DEVICE_ADDED and MessageType.DEVICE_REMOVED messages will be emitted on the bus when the list of devices changes.
      Returns:
      true if the device monitoring could be started, i.e. at least a single device provider was started successfully.
      Since:
      1.4
    • stop

      public void stop()
      Stops monitoring the devices.
      Since:
      1.4
    • builder

      public static DeviceMonitor.Builder<? extends DeviceMonitor.Builder> builder()
      A DeviceMonitor.Builder object constructs a DeviceMonitor with the specified properties. Use the various set...() methods to set properties, and finish construction with DeviceMonitor.Builder.build().
      Returns:
      the builder object