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