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