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  * 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  * break;
71  * default:
72  * break;
73  * }
74  * 
75  * return G_SOURCE_CONTINUE;
76  * }
77  * 
78  * GstDeviceMonitor *
79  * setup_raw_video_source_device_monitor (void) {
80  * GstDeviceMonitor *monitor;
81  * GstBus *bus;
82  * GstCaps *caps;
83  * 
84  * monitor = gst_device_monitor_new ();
85  * 
86  * bus = gst_device_monitor_get_bus (monitor);
87  * gst_bus_add_watch (bus, my_bus_func, NULL);
88  * gst_object_unref (bus);
89  * 
90  * caps = gst_caps_new_empty_simple ("video/x-raw");
91  * gst_device_monitor_add_filter (monitor, "Video/Source", caps);
92  * gst_caps_unref (caps);
93  * 
94  * gst_device_monitor_start (monitor);
95  * 
96  * return monitor;
97  * }
98  * ]|
99  *
100  * Since: 1.4
101  */
102 public class DeviceMonitor : ObjectGst
103 {
104 	/** the main Gtk struct */
105 	protected GstDeviceMonitor* gstDeviceMonitor;
106 
107 	/** Get the main Gtk struct */
108 	public GstDeviceMonitor* getDeviceMonitorStruct()
109 	{
110 		return gstDeviceMonitor;
111 	}
112 
113 	/** the main Gtk struct as a void* */
114 	protected override void* getStruct()
115 	{
116 		return cast(void*)gstDeviceMonitor;
117 	}
118 
119 	protected override void setStruct(GObject* obj)
120 	{
121 		gstDeviceMonitor = cast(GstDeviceMonitor*)obj;
122 		super.setStruct(obj);
123 	}
124 
125 	/**
126 	 * Sets our main struct and passes it to the parent class.
127 	 */
128 	public this (GstDeviceMonitor* gstDeviceMonitor, bool ownedRef = false)
129 	{
130 		this.gstDeviceMonitor = gstDeviceMonitor;
131 		super(cast(GstObject*)gstDeviceMonitor, ownedRef);
132 	}
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 	 * Return: 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 classes and the #GstCaps will be returned.
166 	 *
167 	 * Filters must be added before the #GstDeviceMonitor is started.
168 	 *
169 	 * Params:
170 	 *     classes = device classes to use as filter or %NULL for any class
171 	 *     caps = the #GstCaps to filter or %NULL for ANY
172 	 *
173 	 * Return: The id of the new filter or 0 if no provider matched the filter's
174 	 *     classes.
175 	 *
176 	 * Since: 1.4
177 	 */
178 	public uint addFilter(string classes, Caps caps)
179 	{
180 		return gst_device_monitor_add_filter(gstDeviceMonitor, Str.toStringz(classes), (caps is null) ? null : caps.getCapsStruct());
181 	}
182 
183 	/**
184 	 * Gets the #GstBus of this #GstDeviceMonitor
185 	 *
186 	 * Return: a #GstBus
187 	 *
188 	 * Since: 1.4
189 	 */
190 	public Bus getBus()
191 	{
192 		auto p = gst_device_monitor_get_bus(gstDeviceMonitor);
193 		
194 		if(p is null)
195 		{
196 			return null;
197 		}
198 		
199 		return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true);
200 	}
201 
202 	/**
203 	 * Gets a list of devices from all of the relevant monitors. This may actually
204 	 * probe the hardware if the monitor is not currently started.
205 	 *
206 	 * Return: a #GList of
207 	 *     #GstDevice
208 	 *
209 	 * Since: 1.4
210 	 */
211 	public ListG getDevices()
212 	{
213 		auto p = gst_device_monitor_get_devices(gstDeviceMonitor);
214 		
215 		if(p is null)
216 		{
217 			return null;
218 		}
219 		
220 		return new ListG(cast(GList*) p);
221 	}
222 
223 	/**
224 	 * Get a list of the currently selected device provider factories.
225 	 *
226 	 * This
227 	 *
228 	 * Return: A list of device provider factory names that are currently being
229 	 *     monitored by @monitor or %NULL when nothing is being monitored.
230 	 *
231 	 * Since: 1.6
232 	 */
233 	public string[] getProviders()
234 	{
235 		return Str.toStringArray(gst_device_monitor_get_providers(gstDeviceMonitor));
236 	}
237 
238 	/**
239 	 * Get if @monitor is curretly showing all devices, even those from hidden
240 	 * providers.
241 	 *
242 	 * Return: %TRUE when all devices will be shown.
243 	 *
244 	 * Since: 1.6
245 	 */
246 	public bool getShowAllDevices()
247 	{
248 		return gst_device_monitor_get_show_all_devices(gstDeviceMonitor) != 0;
249 	}
250 
251 	/**
252 	 * Removes a filter from the #GstDeviceMonitor using the id that was returned
253 	 * by gst_device_monitor_add_filter().
254 	 *
255 	 * Params:
256 	 *     filterId = the id of the filter
257 	 *
258 	 * Return: %TRUE of the filter id was valid, %FALSE otherwise
259 	 *
260 	 * Since: 1.4
261 	 */
262 	public bool removeFilter(uint filterId)
263 	{
264 		return gst_device_monitor_remove_filter(gstDeviceMonitor, filterId) != 0;
265 	}
266 
267 	/**
268 	 * Set if all devices should be visible, even those devices from hidden
269 	 * providers. Setting @show_all to true might show some devices multiple times.
270 	 *
271 	 * Params:
272 	 *     showAll = show all devices
273 	 *
274 	 * Since: 1.6
275 	 */
276 	public void setShowAllDevices(bool showAll)
277 	{
278 		gst_device_monitor_set_show_all_devices(gstDeviceMonitor, showAll);
279 	}
280 
281 	/**
282 	 * Starts monitoring the devices, one this has succeeded, the
283 	 * %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages
284 	 * will be emitted on the bus when the list of devices changes.
285 	 *
286 	 * Return: %TRUE if the device monitoring could be started
287 	 *
288 	 * Since: 1.4
289 	 */
290 	public bool start()
291 	{
292 		return gst_device_monitor_start(gstDeviceMonitor) != 0;
293 	}
294 
295 	/**
296 	 * Stops monitoring the devices.
297 	 *
298 	 * Since: 1.4
299 	 */
300 	public void stop()
301 	{
302 		gst_device_monitor_stop(gstDeviceMonitor);
303 	}
304 }