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