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  * The basic use pattern of a device monitor is as follows:
50  * |[
51  * static gboolean
52  * my_bus_func (GstBus * bus, GstMessage * message, gpointer user_data)
53  * {
54  * GstDevice *device;
55  * gchar *name;
56  * 
57  * switch (GST_MESSAGE_TYPE (message)) {
58  * case GST_MESSAGE_DEVICE_ADDED:
59  * gst_message_parse_device_added (message, &device);
60  * name = gst_device_get_display_name (device);
61  * g_print("Device added: %s\n", name);
62  * g_free (name);
63  * gst_object_unref (device);
64  * break;
65  * case GST_MESSAGE_DEVICE_REMOVED:
66  * gst_message_parse_device_removed (message, &device);
67  * name = gst_device_get_display_name (device);
68  * g_print("Device removed: %s\n", name);
69  * g_free (name);
70  * gst_object_unref (device);
71  * break;
72  * default:
73  * break;
74  * }
75  * 
76  * return G_SOURCE_CONTINUE;
77  * }
78  * 
79  * GstDeviceMonitor *
80  * setup_raw_video_source_device_monitor (void) {
81  * GstDeviceMonitor *monitor;
82  * GstBus *bus;
83  * GstCaps *caps;
84  * 
85  * monitor = gst_device_monitor_new ();
86  * 
87  * bus = gst_device_monitor_get_bus (monitor);
88  * gst_bus_add_watch (bus, my_bus_func, NULL);
89  * gst_object_unref (bus);
90  * 
91  * caps = gst_caps_new_empty_simple ("video/x-raw");
92  * gst_device_monitor_add_filter (monitor, "Video/Source", caps);
93  * gst_caps_unref (caps);
94  * 
95  * gst_device_monitor_start (monitor);
96  * 
97  * return monitor;
98  * }
99  * ]|
100  *
101  * Since: 1.4
102  */
103 public class DeviceMonitor : ObjectGst
104 {
105 	/** the main Gtk struct */
106 	protected GstDeviceMonitor* gstDeviceMonitor;
107 
108 	/** Get the main Gtk struct */
109 	public GstDeviceMonitor* getDeviceMonitorStruct(bool transferOwnership = false)
110 	{
111 		if (transferOwnership)
112 			ownedRef = false;
113 		return gstDeviceMonitor;
114 	}
115 
116 	/** the main Gtk struct as a void* */
117 	protected override void* getStruct()
118 	{
119 		return cast(void*)gstDeviceMonitor;
120 	}
121 
122 	protected override void setStruct(GObject* obj)
123 	{
124 		gstDeviceMonitor = cast(GstDeviceMonitor*)obj;
125 		super.setStruct(obj);
126 	}
127 
128 	/**
129 	 * Sets our main struct and passes it to the parent class.
130 	 */
131 	public this (GstDeviceMonitor* gstDeviceMonitor, bool ownedRef = false)
132 	{
133 		this.gstDeviceMonitor = gstDeviceMonitor;
134 		super(cast(GstObject*)gstDeviceMonitor, ownedRef);
135 	}
136 
137 
138 	/** */
139 	public static GType getType()
140 	{
141 		return gst_device_monitor_get_type();
142 	}
143 
144 	/**
145 	 * Create a new #GstDeviceMonitor
146 	 *
147 	 * Returns: a new device monitor.
148 	 *
149 	 * Since: 1.4
150 	 *
151 	 * Throws: ConstructionException GTK+ fails to create the object.
152 	 */
153 	public this()
154 	{
155 		auto p = gst_device_monitor_new();
156 		
157 		if(p is null)
158 		{
159 			throw new ConstructionException("null returned by new");
160 		}
161 		
162 		this(cast(GstDeviceMonitor*) p, true);
163 	}
164 
165 	/**
166 	 * Adds a filter for which #GstDevice will be monitored, any device that matches
167 	 * all these classes and the #GstCaps will be returned.
168 	 *
169 	 * If this function is called multiple times to add more filters, each will be
170 	 * matched independently. That is, adding more filters will not further restrict
171 	 * what devices are matched.
172 	 *
173 	 * The #GstCaps supported by the device as returned by gst_device_get_caps() are
174 	 * not intersected with caps filters added using this function.
175 	 *
176 	 * Filters must be added before the #GstDeviceMonitor is started.
177 	 *
178 	 * Params:
179 	 *     classes = device classes to use as filter or %NULL for any class
180 	 *     caps = the #GstCaps to filter or %NULL for ANY
181 	 *
182 	 * Returns: The id of the new filter or 0 if no provider matched the filter's
183 	 *     classes.
184 	 *
185 	 * Since: 1.4
186 	 */
187 	public uint addFilter(string classes, Caps caps)
188 	{
189 		return gst_device_monitor_add_filter(gstDeviceMonitor, Str.toStringz(classes), (caps is null) ? null : caps.getCapsStruct());
190 	}
191 
192 	/**
193 	 * Gets the #GstBus of this #GstDeviceMonitor
194 	 *
195 	 * Returns: a #GstBus
196 	 *
197 	 * Since: 1.4
198 	 */
199 	public Bus getBus()
200 	{
201 		auto p = gst_device_monitor_get_bus(gstDeviceMonitor);
202 		
203 		if(p is null)
204 		{
205 			return null;
206 		}
207 		
208 		return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true);
209 	}
210 
211 	/**
212 	 * Gets a list of devices from all of the relevant monitors. This may actually
213 	 * probe the hardware if the monitor is not currently started.
214 	 *
215 	 * Returns: a #GList of
216 	 *     #GstDevice
217 	 *
218 	 * Since: 1.4
219 	 */
220 	public ListG getDevices()
221 	{
222 		auto p = gst_device_monitor_get_devices(gstDeviceMonitor);
223 		
224 		if(p is null)
225 		{
226 			return null;
227 		}
228 		
229 		return new ListG(cast(GList*) p, true);
230 	}
231 
232 	/**
233 	 * Get a list of the currently selected device provider factories.
234 	 *
235 	 * This
236 	 *
237 	 * Returns: A list of device provider factory names that are currently being
238 	 *     monitored by @monitor or %NULL when nothing is being monitored.
239 	 *
240 	 * Since: 1.6
241 	 */
242 	public string[] getProviders()
243 	{
244 		auto retStr = gst_device_monitor_get_providers(gstDeviceMonitor);
245 		
246 		scope(exit) Str.freeStringArray(retStr);
247 		return Str.toStringArray(retStr);
248 	}
249 
250 	/**
251 	 * Get if @monitor is curretly showing all devices, even those from hidden
252 	 * providers.
253 	 *
254 	 * Returns: %TRUE when all devices will be shown.
255 	 *
256 	 * Since: 1.6
257 	 */
258 	public bool getShowAllDevices()
259 	{
260 		return gst_device_monitor_get_show_all_devices(gstDeviceMonitor) != 0;
261 	}
262 
263 	/**
264 	 * Removes a filter from the #GstDeviceMonitor using the id that was returned
265 	 * by gst_device_monitor_add_filter().
266 	 *
267 	 * Params:
268 	 *     filterId = the id of the filter
269 	 *
270 	 * Returns: %TRUE of the filter id was valid, %FALSE otherwise
271 	 *
272 	 * Since: 1.4
273 	 */
274 	public bool removeFilter(uint filterId)
275 	{
276 		return gst_device_monitor_remove_filter(gstDeviceMonitor, filterId) != 0;
277 	}
278 
279 	/**
280 	 * Set if all devices should be visible, even those devices from hidden
281 	 * providers. Setting @show_all to true might show some devices multiple times.
282 	 *
283 	 * Params:
284 	 *     showAll = show all devices
285 	 *
286 	 * Since: 1.6
287 	 */
288 	public void setShowAllDevices(bool showAll)
289 	{
290 		gst_device_monitor_set_show_all_devices(gstDeviceMonitor, showAll);
291 	}
292 
293 	/**
294 	 * Starts monitoring the devices, one this has succeeded, the
295 	 * %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages
296 	 * will be emitted on the bus when the list of devices changes.
297 	 *
298 	 * Returns: %TRUE if the device monitoring could be started
299 	 *
300 	 * Since: 1.4
301 	 */
302 	public bool start()
303 	{
304 		return gst_device_monitor_start(gstDeviceMonitor) != 0;
305 	}
306 
307 	/**
308 	 * Stops monitoring the devices.
309 	 *
310 	 * Since: 1.4
311 	 */
312 	public void stop()
313 	{
314 		gst_device_monitor_stop(gstDeviceMonitor);
315 	}
316 }