Skip to content

Commit a071fe2

Browse files
Update and document org.freedesktop.gstreamer.device package.
1 parent 440a91e commit a071fe2

File tree

5 files changed

+330
-84
lines changed

5 files changed

+330
-84
lines changed

src/org/freedesktop/gstreamer/device/Device.java

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2017 Neil C Smith
3+
* Copyright (c) 2019 Neil C Smith
44
* Copyright (c) 2015 Andres Colubri <[email protected]>
55
* Copyright (C) 2013 Olivier Crete <[email protected]>
66
*
@@ -30,51 +30,114 @@
3030
import static org.freedesktop.gstreamer.lowlevel.GstDeviceAPI.GSTDEVICE_API;
3131

3232
/**
33-
*
34-
* @author andres
33+
* Devices are objects representing a device, they contain relevant metadata
34+
* about the device, such as its class and the GstCaps representing the media
35+
* types it can produce or handle.
36+
* <p>
37+
* See upstream documentation at
38+
* <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/gstreamer-GstDevice.html"
39+
* >https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/gstreamer-GstDevice.html</a>
40+
* <p>
41+
* Device objects are created by {@link DeviceProvider} objects, which can be
42+
* aggregated by {@link DeviceMonitor} objects.
3543
*/
3644
public class Device extends GstObject {
3745

3846
public static final String GTYPE_NAME = "GstDevice";
3947

40-
public Device(Initializer init) {
48+
Device(Initializer init) {
4149
super(init);
4250
}
4351

52+
/**
53+
* Creates the element with all of the required parameters set to use this
54+
* device.
55+
*
56+
* @param name name of new element, or NULL to automatically create a unique
57+
* name
58+
* @return a new {@link Element} configured to use this device.
59+
*/
4460
public Element createElement(String name) {
4561
return GSTDEVICE_API.gst_device_create_element(this, name);
4662
}
4763

64+
/**
65+
* Get the {@link Caps} that this device supports.
66+
*
67+
* @return The Caps supported by this device.
68+
*/
4869
public Caps getCaps() {
4970
return GSTDEVICE_API.gst_device_get_caps(this);
5071
}
5172

73+
/**
74+
* Gets the "class" of a device. This is a "/" separated list of classes
75+
* that represent this device. They are a subset of the classes of the
76+
* {@link DeviceProvider} that produced this device.
77+
*
78+
* @return class the device class
79+
*/
5280
public String getDeviceClass() {
5381
Pointer ptr = GSTDEVICE_API.gst_device_get_device_class(this);
5482
String ret = ptr.getString(0);
5583
GLIB_API.g_free(ptr);
5684
return ret;
5785
}
5886

87+
/**
88+
* Gets the user-friendly name of the device.
89+
*
90+
* @return name of the device
91+
*/
5992
public String getDisplayName() {
6093
Pointer ptr = GSTDEVICE_API.gst_device_get_display_name(this);
6194
String ret = ptr.getString(0);
6295
GLIB_API.g_free(ptr);
6396
return ret;
6497
}
6598

99+
/**
100+
* Check if device matches all of the given classes.
101+
*
102+
* @param classes a "/"-separated list of device classes to match, only
103+
* match if all classes are matched
104+
* @return true if device matches
105+
*/
66106
public boolean hasClasses(String classes) {
67107
return GSTDEVICE_API.gst_device_has_classes(this, classes);
68108
}
69109

110+
/**
111+
* Check if device matches all of the given classes.
112+
*
113+
* @param classes an array of classes to match, only match if all classes
114+
* are matched.
115+
* @return true if device matches
116+
*/
70117
public boolean hasClasses(String[] classes) {
71118
return GSTDEVICE_API.gst_device_has_classesv(this, classes);
72119
}
73120

121+
/**
122+
* Tries to reconfigure an existing element to use the device. If this
123+
* function fails, then one must destroy the element and create a new one
124+
* using {@link #createElement(java.lang.String) }
125+
* <p>
126+
* Note: This should only be implemented for elements can change their
127+
* device in the PLAYING state.
128+
*
129+
* @param element the element to be configured
130+
* @return true if the element could be reconfigured to use this device
131+
*/
74132
public boolean reconfigureElement(Element element) {
75133
return GSTDEVICE_API.gst_device_reconfigure_element(this, element);
76134
}
77135

136+
/**
137+
* Gets the extra properties of a device.
138+
*
139+
* @return The extra properties or NULL when there are none.
140+
*/
78141
public Structure getProperties() {
79142
return GSTDEVICE_API.gst_device_get_properties(this);
80143
}

src/org/freedesktop/gstreamer/device/DeviceMonitor.java

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
*
3-
* Copyright (c) 2017 Neil C Smith
3+
* Copyright (c) 2019 Neil C Smith
44
* Copyright (c) 2015 Andres Colubri <[email protected]>
55
* Copyright (C) 2013 Olivier Crete <[email protected]>
66
*
@@ -30,44 +30,102 @@
3030
import static org.freedesktop.gstreamer.lowlevel.GstDeviceMonitorAPI.GSTDEVICEMONITOR_API;
3131

3232
/**
33-
*
34-
* @author andres
33+
* A device monitor and prober
34+
* <p>
35+
* See upstream documentation at
36+
* <a href="https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/gstreamer-GstDeviceMonitor.html"
37+
* >https://gstreamer.freedesktop.org/data/doc/gstreamer/stable/gstreamer/html/gstreamer-GstDeviceMonitor.html</a>
38+
* <p>
39+
* Applications should create a DeviceMonitor when they want to probe, list and
40+
* monitor devices of a specific type. The DeviceMonitor will create the
41+
* appropriate {@link DeviceProvider} objects and manage them. It will then post
42+
* messages on its {@link Bus} for devices that have been added and removed.
43+
* <p>
44+
* The device monitor will monitor all devices matching the filters that the
45+
* application has set.
3546
*/
3647
public class DeviceMonitor extends GstObject {
3748

3849
public static final String GTYPE_NAME = "GstDeviceMonitor";
3950

40-
public DeviceMonitor(Initializer init) {
41-
super(init);
51+
public DeviceMonitor() {
52+
super(initializer(GSTDEVICEMONITOR_API.ptr_gst_device_monitor_new(), false, true));
4253
}
4354

44-
static public DeviceMonitor createNew() {
45-
return GSTDEVICEMONITOR_API.gst_device_monitor_new();
55+
DeviceMonitor(Initializer init) {
56+
super(init);
4657
}
4758

59+
/**
60+
* Get the {@link Bus} for this DeviceMonitor
61+
*
62+
* @return bus
63+
*/
4864
public Bus getBus() {
4965
return GSTDEVICEMONITOR_API.gst_device_monitor_get_bus(this);
5066
}
5167

68+
/**
69+
* Adds a filter for which devices will be monitored, any device that
70+
* matches all these classes and the {@link Caps} will be returned.
71+
* <p>
72+
* If this function is called multiple times to add more filters, each will
73+
* be matched independently. That is, adding more filters will not further
74+
* restrict what devices are matched.
75+
* <p>
76+
* The GstCaps supported by the device as returned by gst_device_get_caps()
77+
* are not intersected with caps filters added using this function.
78+
* <p>
79+
* Filters must be added before the GstDeviceMonitor is started.
80+
*
81+
* @param classes device classes to use as filter or NULL for any class.
82+
* @param caps the GstCaps to filter or NULL for ANY.
83+
* @return id the id of the new filter or 0 if no provider matched the
84+
* filter's classes.
85+
*/
5286
public int addFilter(String classes, Caps caps) {
5387
return GSTDEVICEMONITOR_API.gst_device_monitor_add_filter(this, classes, caps);
5488
}
5589

90+
/**
91+
* Remove a filter from the DeviceMonitor using the id that was returned
92+
* from {@link #addFilter(java.lang.String, org.freedesktop.gstreamer.Caps)
93+
* }
94+
*
95+
* @param filterId of filter to remove
96+
* @return true if the filter id was valid and the filter was removed
97+
*/
5698
public boolean removeFilter(int filterId) {
5799
return GSTDEVICEMONITOR_API.gst_device_monitor_remove_filter(this, filterId);
58100
}
59101

102+
/**
103+
* Starts monitoring the devices, once this has succeeded, the
104+
* GST_MESSAGE_DEVICE_ADDED and GST_MESSAGE_DEVICE_REMOVED messages will be
105+
* emitted on the bus when the list of devices changes.
106+
*
107+
* @return true if the device monitoring could be started
108+
*/
60109
public boolean start() {
61110
return GSTDEVICEMONITOR_API.gst_device_monitor_start(this);
62111
}
63112

113+
/**
114+
* Stop monitoring devices.
115+
*/
64116
public void stop() {
65117
GSTDEVICEMONITOR_API.gst_device_monitor_stop(this);
66118
}
67119

120+
/**
121+
* Gets a list of devices from all of the relevant monitors. This may
122+
* actually probe the hardware if the monitor is not currently started.
123+
*
124+
* @return list of {@link Device}
125+
*/
68126
public List<Device> getDevices() {
69127
GList glist = GSTDEVICEMONITOR_API.gst_device_monitor_get_devices(this);
70-
List<Device> list = new ArrayList<Device>();
128+
List<Device> list = new ArrayList<>();
71129

72130
GList next = glist;
73131
while (next != null) {

0 commit comments

Comments
 (0)