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.Device;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gstreamer.Caps;
31 private import gstreamer.Element;
32 private import gstreamer.ObjectGst;
33 private import gstreamer.Structure;
34 private import gstreamerc.gstreamer;
35 public  import gstreamerc.gstreamertypes;
36 private import std.algorithm;
37 
38 
39 /**
40  * #GstDevice are objects representing a device, they contain
41  * relevant metadata about the device, such as its class and the #GstCaps
42  * representing the media types it can produce or handle.
43  * 
44  * #GstDevice are created by #GstDeviceProvider objects which can be
45  * aggregated by #GstDeviceMonitor objects.
46  *
47  * Since: 1.4
48  */
49 public class Device : ObjectGst
50 {
51 	/** the main Gtk struct */
52 	protected GstDevice* gstDevice;
53 
54 	/** Get the main Gtk struct */
55 	public GstDevice* getDeviceStruct(bool transferOwnership = false)
56 	{
57 		if (transferOwnership)
58 			ownedRef = false;
59 		return gstDevice;
60 	}
61 
62 	/** the main Gtk struct as a void* */
63 	protected override void* getStruct()
64 	{
65 		return cast(void*)gstDevice;
66 	}
67 
68 	protected override void setStruct(GObject* obj)
69 	{
70 		gstDevice = cast(GstDevice*)obj;
71 		super.setStruct(obj);
72 	}
73 
74 	/**
75 	 * Sets our main struct and passes it to the parent class.
76 	 */
77 	public this (GstDevice* gstDevice, bool ownedRef = false)
78 	{
79 		this.gstDevice = gstDevice;
80 		super(cast(GstObject*)gstDevice, ownedRef);
81 	}
82 
83 
84 	/** */
85 	public static GType getType()
86 	{
87 		return gst_device_get_type();
88 	}
89 
90 	/**
91 	 * Creates the element with all of the required parameters set to use
92 	 * this device.
93 	 *
94 	 * Params:
95 	 *     name = name of new element, or %NULL to automatically
96 	 *         create a unique name.
97 	 *
98 	 * Returns: a new #GstElement configured to use this device
99 	 *
100 	 * Since: 1.4
101 	 */
102 	public Element createElement(string name)
103 	{
104 		auto p = gst_device_create_element(gstDevice, Str.toStringz(name));
105 		
106 		if(p is null)
107 		{
108 			return null;
109 		}
110 		
111 		return ObjectG.getDObject!(Element)(cast(GstElement*) p, true);
112 	}
113 
114 	/**
115 	 * Getter for the #GstCaps that this device supports.
116 	 *
117 	 * Returns: The #GstCaps supported by this device. Unref with
118 	 *     gst_caps_unref() when done.
119 	 *
120 	 * Since: 1.4
121 	 */
122 	public Caps getCaps()
123 	{
124 		auto p = gst_device_get_caps(gstDevice);
125 		
126 		if(p is null)
127 		{
128 			return null;
129 		}
130 		
131 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p, true);
132 	}
133 
134 	/**
135 	 * Gets the "class" of a device. This is a "/" separated list of
136 	 * classes that represent this device. They are a subset of the
137 	 * classes of the #GstDeviceProvider that produced this device.
138 	 *
139 	 * Returns: The device class. Free with g_free() after use.
140 	 *
141 	 * Since: 1.4
142 	 */
143 	public string getDeviceClass()
144 	{
145 		auto retStr = gst_device_get_device_class(gstDevice);
146 		
147 		scope(exit) Str.freeString(retStr);
148 		return Str.toString(retStr);
149 	}
150 
151 	/**
152 	 * Gets the user-friendly name of the device.
153 	 *
154 	 * Returns: The device name. Free with g_free() after use.
155 	 *
156 	 * Since: 1.4
157 	 */
158 	public string getDisplayName()
159 	{
160 		auto retStr = gst_device_get_display_name(gstDevice);
161 		
162 		scope(exit) Str.freeString(retStr);
163 		return Str.toString(retStr);
164 	}
165 
166 	/**
167 	 * Gets the extra properties of a device.
168 	 *
169 	 * Returns: The extra properties or %NULL when there are none.
170 	 *     Free with gst_structure_free() after use.
171 	 *
172 	 * Since: 1.6
173 	 */
174 	public Structure getProperties()
175 	{
176 		auto p = gst_device_get_properties(gstDevice);
177 		
178 		if(p is null)
179 		{
180 			return null;
181 		}
182 		
183 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p, true);
184 	}
185 
186 	/**
187 	 * Check if @device matches all of the given classes
188 	 *
189 	 * Params:
190 	 *     classes = a "/"-separated list of device classes to match, only match if
191 	 *         all classes are matched
192 	 *
193 	 * Returns: %TRUE if @device matches.
194 	 *
195 	 * Since: 1.4
196 	 */
197 	public bool hasClasses(string classes)
198 	{
199 		return gst_device_has_classes(gstDevice, Str.toStringz(classes)) != 0;
200 	}
201 
202 	/**
203 	 * Check if @factory matches all of the given classes
204 	 *
205 	 * Params:
206 	 *     classes = a %NULL terminated array of classes
207 	 *         to match, only match if all classes are matched
208 	 *
209 	 * Returns: %TRUE if @device matches.
210 	 *
211 	 * Since: 1.4
212 	 */
213 	public bool hasClassesv(string[] classes)
214 	{
215 		return gst_device_has_classesv(gstDevice, Str.toStringzArray(classes)) != 0;
216 	}
217 
218 	/**
219 	 * Tries to reconfigure an existing element to use the device. If this
220 	 * function fails, then one must destroy the element and create a new one
221 	 * using gst_device_create_element().
222 	 *
223 	 * Note: This should only be implemented for elements can change their
224 	 * device in the PLAYING state.
225 	 *
226 	 * Params:
227 	 *     element = a #GstElement
228 	 *
229 	 * Returns: %TRUE if the element could be reconfigured to use this device,
230 	 *     %FALSE otherwise.
231 	 *
232 	 * Since: 1.4
233 	 */
234 	public bool reconfigureElement(Element element)
235 	{
236 		return gst_device_reconfigure_element(gstDevice, (element is null) ? null : element.getElementStruct()) != 0;
237 	}
238 
239 	protected class OnRemovedDelegateWrapper
240 	{
241 		static OnRemovedDelegateWrapper[] listeners;
242 		void delegate(Device) dlg;
243 		gulong handlerId;
244 		
245 		this(void delegate(Device) dlg)
246 		{
247 			this.dlg = dlg;
248 			this.listeners ~= this;
249 		}
250 		
251 		void remove(OnRemovedDelegateWrapper source)
252 		{
253 			foreach(index, wrapper; listeners)
254 			{
255 				if (wrapper.handlerId == source.handlerId)
256 				{
257 					listeners[index] = null;
258 					listeners = std.algorithm.remove(listeners, index);
259 					break;
260 				}
261 			}
262 		}
263 	}
264 
265 	/** */
266 	gulong addOnRemoved(void delegate(Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 	{
268 		auto wrapper = new OnRemovedDelegateWrapper(dlg);
269 		wrapper.handlerId = Signals.connectData(
270 			this,
271 			"removed",
272 			cast(GCallback)&callBackRemoved,
273 			cast(void*)wrapper,
274 			cast(GClosureNotify)&callBackRemovedDestroy,
275 			connectFlags);
276 		return wrapper.handlerId;
277 	}
278 	
279 	extern(C) static void callBackRemoved(GstDevice* deviceStruct, OnRemovedDelegateWrapper wrapper)
280 	{
281 		wrapper.dlg(wrapper.outer);
282 	}
283 	
284 	extern(C) static void callBackRemovedDestroy(OnRemovedDelegateWrapper wrapper, GClosure* closure)
285 	{
286 		wrapper.remove(wrapper);
287 	}
288 }