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