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 	 * Removes a filter from the #GstDeviceMonitor using the id that was returned
225 	 * by gst_device_monitor_add_filter().
226 	 *
227 	 * Params:
228 	 *     filterId = the id of the filter
229 	 *
230 	 * Return: %TRUE of the filter id was valid, %FALSE otherwise
231 	 *
232 	 * Since: 1.4
233 	 */
234 	public bool removeFilter(uint filterId)
235 	{
236 		return gst_device_monitor_remove_filter(gstDeviceMonitor, filterId) != 0;
237 	}
238 
239 	/**
240 	 * Starts monitoring the devices, one this has succeeded, the
241 	 * %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages
242 	 * will be emitted on the bus when the list of devices changes.
243 	 *
244 	 * Return: %TRUE if the device monitoring could be started
245 	 *
246 	 * Since: 1.4
247 	 */
248 	public bool start()
249 	{
250 		return gst_device_monitor_start(gstDeviceMonitor) != 0;
251 	}
252 
253 	/**
254 	 * Stops monitoring the devices.
255 	 *
256 	 * Since: 1.4
257 	 */
258 	public void stop()
259 	{
260 		gst_device_monitor_stop(gstDeviceMonitor);
261 	}
262 }