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 gstreamer.c.functions;
35 public  import gstreamer.c.types;
36 public  import gstreamerc.gstreamertypes;
37 
38 
39 /**
40  * Applications should create a #GstDeviceMonitor when they want
41  * to probe, list and monitor devices of a specific type. The
42  * #GstDeviceMonitor will create the appropriate
43  * #GstDeviceProvider objects and manage them. It will then post
44  * messages on its #GstBus for devices that have been added and
45  * removed.
46  * 
47  * The device monitor will monitor all devices matching the filters that
48  * the application has set.
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(bool transferOwnership = false)
111 	{
112 		if (transferOwnership)
113 			ownedRef = false;
114 		return gstDeviceMonitor;
115 	}
116 
117 	/** the main Gtk struct as a void* */
118 	protected override void* getStruct()
119 	{
120 		return cast(void*)gstDeviceMonitor;
121 	}
122 
123 	protected override void setStruct(GObject* obj)
124 	{
125 		gstDeviceMonitor = cast(GstDeviceMonitor*)obj;
126 		super.setStruct(obj);
127 	}
128 
129 	/**
130 	 * Sets our main struct and passes it to the parent class.
131 	 */
132 	public this (GstDeviceMonitor* gstDeviceMonitor, bool ownedRef = false)
133 	{
134 		this.gstDeviceMonitor = gstDeviceMonitor;
135 		super(cast(GstObject*)gstDeviceMonitor, ownedRef);
136 	}
137 
138 
139 	/** */
140 	public static GType getType()
141 	{
142 		return gst_device_monitor_get_type();
143 	}
144 
145 	/**
146 	 * Create a new #GstDeviceMonitor
147 	 *
148 	 * Returns: a new device monitor.
149 	 *
150 	 * Since: 1.4
151 	 *
152 	 * Throws: ConstructionException GTK+ fails to create the object.
153 	 */
154 	public this()
155 	{
156 		auto p = gst_device_monitor_new();
157 
158 		if(p is null)
159 		{
160 			throw new ConstructionException("null returned by new");
161 		}
162 
163 		this(cast(GstDeviceMonitor*) p, true);
164 	}
165 
166 	/**
167 	 * Adds a filter for which #GstDevice will be monitored, any device that matches
168 	 * all these classes and the #GstCaps will be returned.
169 	 *
170 	 * If this function is called multiple times to add more filters, each will be
171 	 * matched independently. That is, adding more filters will not further restrict
172 	 * what devices are matched.
173 	 *
174 	 * The #GstCaps supported by the device as returned by gst_device_get_caps() are
175 	 * not intersected with caps filters added using this function.
176 	 *
177 	 * Filters must be added before the #GstDeviceMonitor is started.
178 	 *
179 	 * Params:
180 	 *     classes = device classes to use as filter or %NULL for any class
181 	 *     caps = the #GstCaps to filter or %NULL for ANY
182 	 *
183 	 * Returns: The id of the new filter or 0 if no provider matched the filter's
184 	 *     classes.
185 	 *
186 	 * Since: 1.4
187 	 */
188 	public uint addFilter(string classes, Caps caps)
189 	{
190 		return gst_device_monitor_add_filter(gstDeviceMonitor, Str.toStringz(classes), (caps is null) ? null : caps.getCapsStruct());
191 	}
192 
193 	/**
194 	 * Gets the #GstBus of this #GstDeviceMonitor
195 	 *
196 	 * Returns: a #GstBus
197 	 *
198 	 * Since: 1.4
199 	 */
200 	public Bus getBus()
201 	{
202 		auto p = gst_device_monitor_get_bus(gstDeviceMonitor);
203 
204 		if(p is null)
205 		{
206 			return null;
207 		}
208 
209 		return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true);
210 	}
211 
212 	/**
213 	 * Gets a list of devices from all of the relevant monitors. This may actually
214 	 * probe the hardware if the monitor is not currently started.
215 	 *
216 	 * Returns: a #GList of
217 	 *     #GstDevice
218 	 *
219 	 * Since: 1.4
220 	 */
221 	public ListG getDevices()
222 	{
223 		auto p = gst_device_monitor_get_devices(gstDeviceMonitor);
224 
225 		if(p is null)
226 		{
227 			return null;
228 		}
229 
230 		return new ListG(cast(GList*) p, true);
231 	}
232 
233 	/**
234 	 * Get a list of the currently selected device provider factories.
235 	 *
236 	 * This
237 	 *
238 	 * Returns: A list of device provider factory names that are currently being
239 	 *     monitored by @monitor or %NULL when nothing is being monitored.
240 	 *
241 	 * Since: 1.6
242 	 */
243 	public string[] getProviders()
244 	{
245 		auto retStr = gst_device_monitor_get_providers(gstDeviceMonitor);
246 
247 		scope(exit) Str.freeStringArray(retStr);
248 		return Str.toStringArray(retStr);
249 	}
250 
251 	/**
252 	 * Get if @monitor is curretly showing all devices, even those from hidden
253 	 * providers.
254 	 *
255 	 * Returns: %TRUE when all devices will be shown.
256 	 *
257 	 * Since: 1.6
258 	 */
259 	public bool getShowAllDevices()
260 	{
261 		return gst_device_monitor_get_show_all_devices(gstDeviceMonitor) != 0;
262 	}
263 
264 	/**
265 	 * Removes a filter from the #GstDeviceMonitor using the id that was returned
266 	 * by gst_device_monitor_add_filter().
267 	 *
268 	 * Params:
269 	 *     filterId = the id of the filter
270 	 *
271 	 * Returns: %TRUE of the filter id was valid, %FALSE otherwise
272 	 *
273 	 * Since: 1.4
274 	 */
275 	public bool removeFilter(uint filterId)
276 	{
277 		return gst_device_monitor_remove_filter(gstDeviceMonitor, filterId) != 0;
278 	}
279 
280 	/**
281 	 * Set if all devices should be visible, even those devices from hidden
282 	 * providers. Setting @show_all to true might show some devices multiple times.
283 	 *
284 	 * Params:
285 	 *     showAll = show all devices
286 	 *
287 	 * Since: 1.6
288 	 */
289 	public void setShowAllDevices(bool showAll)
290 	{
291 		gst_device_monitor_set_show_all_devices(gstDeviceMonitor, showAll);
292 	}
293 
294 	/**
295 	 * Starts monitoring the devices, one this has succeeded, the
296 	 * %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages
297 	 * will be emitted on the bus when the list of devices changes.
298 	 *
299 	 * Returns: %TRUE if the device monitoring could be started
300 	 *
301 	 * Since: 1.4
302 	 */
303 	public bool start()
304 	{
305 		return gst_device_monitor_start(gstDeviceMonitor) != 0;
306 	}
307 
308 	/**
309 	 * Stops monitoring the devices.
310 	 *
311 	 * Since: 1.4
312 	 */
313 	public void stop()
314 	{
315 		gst_device_monitor_stop(gstDeviceMonitor);
316 	}
317 }