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