1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gstreamer.DeviceMonitor;
26 
27 private import glib.ConstructionException;
28 private import glib.ListG;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gstreamer.Bus;
32 private import gstreamer.Caps;
33 private import gstreamer.ObjectGst;
34 private import gstreamerc.gstreamer;
35 public  import gstreamerc.gstreamertypes;
36 
37 
38 /**
39  * Applications should create a #GstDeviceMonitor when they want
40  * to probe, list and monitor devices of a specific type. The
41  * #GstDeviceMonitor will create the appropriate
42  * #GstDeviceProvider objects and manage them. It will then post
43  * messages on its #GstBus for devices that have been added and
44  * removed.
45  * 
46  * The device monitor will monitor all devices matching the filters that
47  * the application has set.
48  * 
49  * 
50  * The basic use pattern of a device monitor is as follows:
51  * |[
52  * static gboolean
53  * my_bus_func (GstBus * bus, GstMessage * message, gpointer user_data)
54  * {
55  * GstDevice *device;
56  * gchar *name;
57  * 
58  * switch (GST_MESSAGE_TYPE (message)) {
59  * case GST_MESSAGE_DEVICE_ADDED:
60  * gst_message_parse_device_added (message, &device);
61  * name = gst_device_get_display_name (device);
62  * g_print("Device added: %s\n", name);
63  * g_free (name);
64  * gst_object_unref (device);
65  * break;
66  * case GST_MESSAGE_DEVICE_REMOVED:
67  * gst_message_parse_device_removed (message, &device);
68  * name = gst_device_get_display_name (device);
69  * g_print("Device removed: %s\n", name);
70  * g_free (name);
71  * gst_object_unref (device);
72  * break;
73  * default:
74  * break;
75  * }
76  * 
77  * return G_SOURCE_CONTINUE;
78  * }
79  * 
80  * GstDeviceMonitor *
81  * setup_raw_video_source_device_monitor (void) {
82  * GstDeviceMonitor *monitor;
83  * GstBus *bus;
84  * GstCaps *caps;
85  * 
86  * monitor = gst_device_monitor_new ();
87  * 
88  * bus = gst_device_monitor_get_bus (monitor);
89  * gst_bus_add_watch (bus, my_bus_func, NULL);
90  * gst_object_unref (bus);
91  * 
92  * caps = gst_caps_new_empty_simple ("video/x-raw");
93  * gst_device_monitor_add_filter (monitor, "Video/Source", caps);
94  * gst_caps_unref (caps);
95  * 
96  * gst_device_monitor_start (monitor);
97  * 
98  * return monitor;
99  * }
100  * ]|
101  *
102  * Since: 1.4
103  */
104 public class DeviceMonitor : ObjectGst
105 {
106 	/** the main Gtk struct */
107 	protected GstDeviceMonitor* gstDeviceMonitor;
108 
109 	/** Get the main Gtk struct */
110 	public GstDeviceMonitor* getDeviceMonitorStruct()
111 	{
112 		return gstDeviceMonitor;
113 	}
114 
115 	/** the main Gtk struct as a void* */
116 	protected override void* getStruct()
117 	{
118 		return cast(void*)gstDeviceMonitor;
119 	}
120 
121 	protected override void setStruct(GObject* obj)
122 	{
123 		gstDeviceMonitor = cast(GstDeviceMonitor*)obj;
124 		super.setStruct(obj);
125 	}
126 
127 	/**
128 	 * Sets our main struct and passes it to the parent class.
129 	 */
130 	public this (GstDeviceMonitor* gstDeviceMonitor, bool ownedRef = false)
131 	{
132 		this.gstDeviceMonitor = gstDeviceMonitor;
133 		super(cast(GstObject*)gstDeviceMonitor, ownedRef);
134 	}
135 
136 
137 	/** */
138 	public static GType getType()
139 	{
140 		return gst_device_monitor_get_type();
141 	}
142 
143 	/**
144 	 * Create a new #GstDeviceMonitor
145 	 *
146 	 * Return: a new device monitor.
147 	 *
148 	 * Since: 1.4
149 	 *
150 	 * Throws: ConstructionException GTK+ fails to create the object.
151 	 */
152 	public this()
153 	{
154 		auto p = gst_device_monitor_new();
155 		
156 		if(p is null)
157 		{
158 			throw new ConstructionException("null returned by new");
159 		}
160 		
161 		this(cast(GstDeviceMonitor*) p, true);
162 	}
163 
164 	/**
165 	 * Adds a filter for which #GstDevice will be monitored, any device that matches
166 	 * all these classes and the #GstCaps will be returned.
167 	 *
168 	 * If this function is called multiple times to add more filters, each will be
169 	 * matched independently. That is, adding more filters will not further restrict
170 	 * what devices are matched.
171 	 *
172 	 * The #GstCaps supported by the device as returned by gst_device_get_caps() are
173 	 * not intersected with caps filters added using this function.
174 	 *
175 	 * Filters must be added before the #GstDeviceMonitor is started.
176 	 *
177 	 * Params:
178 	 *     classes = device classes to use as filter or %NULL for any class
179 	 *     caps = the #GstCaps to filter or %NULL for ANY
180 	 *
181 	 * Return: The id of the new filter or 0 if no provider matched the filter's
182 	 *     classes.
183 	 *
184 	 * Since: 1.4
185 	 */
186 	public uint addFilter(string classes, Caps caps)
187 	{
188 		return gst_device_monitor_add_filter(gstDeviceMonitor, Str.toStringz(classes), (caps is null) ? null : caps.getCapsStruct());
189 	}
190 
191 	/**
192 	 * Gets the #GstBus of this #GstDeviceMonitor
193 	 *
194 	 * Return: a #GstBus
195 	 *
196 	 * Since: 1.4
197 	 */
198 	public Bus getBus()
199 	{
200 		auto p = gst_device_monitor_get_bus(gstDeviceMonitor);
201 		
202 		if(p is null)
203 		{
204 			return null;
205 		}
206 		
207 		return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true);
208 	}
209 
210 	/**
211 	 * Gets a list of devices from all of the relevant monitors. This may actually
212 	 * probe the hardware if the monitor is not currently started.
213 	 *
214 	 * Return: a #GList of
215 	 *     #GstDevice
216 	 *
217 	 * Since: 1.4
218 	 */
219 	public ListG getDevices()
220 	{
221 		auto p = gst_device_monitor_get_devices(gstDeviceMonitor);
222 		
223 		if(p is null)
224 		{
225 			return null;
226 		}
227 		
228 		return new ListG(cast(GList*) p, true);
229 	}
230 
231 	/**
232 	 * Get a list of the currently selected device provider factories.
233 	 *
234 	 * This
235 	 *
236 	 * Return: A list of device provider factory names that are currently being
237 	 *     monitored by @monitor or %NULL when nothing is being monitored.
238 	 *
239 	 * Since: 1.6
240 	 */
241 	public string[] getProviders()
242 	{
243 		auto retStr = gst_device_monitor_get_providers(gstDeviceMonitor);
244 		
245 		scope(exit) Str.freeStringArray(retStr);
246 		return Str.toStringArray(retStr);
247 	}
248 
249 	/**
250 	 * Get if @monitor is curretly showing all devices, even those from hidden
251 	 * providers.
252 	 *
253 	 * Return: %TRUE when all devices will be shown.
254 	 *
255 	 * Since: 1.6
256 	 */
257 	public bool getShowAllDevices()
258 	{
259 		return gst_device_monitor_get_show_all_devices(gstDeviceMonitor) != 0;
260 	}
261 
262 	/**
263 	 * Removes a filter from the #GstDeviceMonitor using the id that was returned
264 	 * by gst_device_monitor_add_filter().
265 	 *
266 	 * Params:
267 	 *     filterId = the id of the filter
268 	 *
269 	 * Return: %TRUE of the filter id was valid, %FALSE otherwise
270 	 *
271 	 * Since: 1.4
272 	 */
273 	public bool removeFilter(uint filterId)
274 	{
275 		return gst_device_monitor_remove_filter(gstDeviceMonitor, filterId) != 0;
276 	}
277 
278 	/**
279 	 * Set if all devices should be visible, even those devices from hidden
280 	 * providers. Setting @show_all to true might show some devices multiple times.
281 	 *
282 	 * Params:
283 	 *     showAll = show all devices
284 	 *
285 	 * Since: 1.6
286 	 */
287 	public void setShowAllDevices(bool showAll)
288 	{
289 		gst_device_monitor_set_show_all_devices(gstDeviceMonitor, showAll);
290 	}
291 
292 	/**
293 	 * Starts monitoring the devices, one this has succeeded, the
294 	 * %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages
295 	 * will be emitted on the bus when the list of devices changes.
296 	 *
297 	 * Return: %TRUE if the device monitoring could be started
298 	 *
299 	 * Since: 1.4
300 	 */
301 	public bool start()
302 	{
303 		return gst_device_monitor_start(gstDeviceMonitor) != 0;
304 	}
305 
306 	/**
307 	 * Stops monitoring the devices.
308 	 *
309 	 * Since: 1.4
310 	 */
311 	public void stop()
312 	{
313 		gst_device_monitor_stop(gstDeviceMonitor);
314 	}
315 }