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