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.ElementFactory;
26 
27 private import glib.ListG;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gstreamer.Caps;
31 private import gstreamer.Element;
32 private import gstreamer.PluginFeature;
33 private import gstreamerc.gstreamer;
34 public  import gstreamerc.gstreamertypes;
35 
36 
37 /**
38  * #GstElementFactory is used to create instances of elements. A
39  * GstElementFactory can be added to a #GstPlugin as it is also a
40  * #GstPluginFeature.
41  * 
42  * Use the gst_element_factory_find() and gst_element_factory_create()
43  * functions to create element instances or use gst_element_factory_make() as a
44  * convenient shortcut.
45  * 
46  * The following code example shows you how to create a GstFileSrc element.
47  * 
48  * <example>
49  * <title>Using an element factory</title>
50  * <programlisting language="c">
51  * #include &lt;gst/gst.h&gt;
52  * 
53  * GstElement *src;
54  * GstElementFactory *srcfactory;
55  * 
56  * gst_init (&amp;argc, &amp;argv);
57  * 
58  * srcfactory = gst_element_factory_find ("filesrc");
59  * g_return_if_fail (srcfactory != NULL);
60  * src = gst_element_factory_create (srcfactory, "src");
61  * g_return_if_fail (src != NULL);
62  * ...
63  * </programlisting>
64  * </example>
65  */
66 public class ElementFactory : PluginFeature
67 {
68 	/** the main Gtk struct */
69 	protected GstElementFactory* gstElementFactory;
70 
71 	/** Get the main Gtk struct */
72 	public GstElementFactory* getElementFactoryStruct()
73 	{
74 		return gstElementFactory;
75 	}
76 
77 	/** the main Gtk struct as a void* */
78 	protected override void* getStruct()
79 	{
80 		return cast(void*)gstElementFactory;
81 	}
82 
83 	protected override void setStruct(GObject* obj)
84 	{
85 		gstElementFactory = cast(GstElementFactory*)obj;
86 		super.setStruct(obj);
87 	}
88 
89 	/**
90 	 * Sets our main struct and passes it to the parent class.
91 	 */
92 	public this (GstElementFactory* gstElementFactory, bool ownedRef = false)
93 	{
94 		this.gstElementFactory = gstElementFactory;
95 		super(cast(GstPluginFeature*)gstElementFactory, ownedRef);
96 	}
97 
98 	/**
99 	 * Create a new element of the type defined by the given element factory.
100 	 * The element will receive a guaranteed unique name,
101 	 * consisting of the element factory name and a number.
102 	 * Params:
103 	 *  factoryname = a named factory to instantiate
104 	 * Returns:
105 	 *  new GstElement or NULL if unable to create element
106 	 */
107 	public static Element make( string factoryname )
108 	{
109 		// GstElement* gst_element_factory_make (const gchar *factoryname,  const gchar *name);
110 		auto p = gst_element_factory_make(Str.toStringz(factoryname), null );
111 		
112 		if(p is null)
113 		{
114 			return null;
115 		}
116 		
117 		return new Element( p );
118 	}
119 
120 	/**
121 	 */
122 
123 	/** */
124 	public static GType getType()
125 	{
126 		return gst_element_factory_get_type();
127 	}
128 
129 	/**
130 	 * Search for an element factory of the given name. Refs the returned
131 	 * element factory; caller is responsible for unreffing.
132 	 *
133 	 * Params:
134 	 *     name = name of factory to find
135 	 *
136 	 * Return: #GstElementFactory if found,
137 	 *     %NULL otherwise
138 	 */
139 	public static ElementFactory find(string name)
140 	{
141 		auto p = gst_element_factory_find(Str.toStringz(name));
142 		
143 		if(p is null)
144 		{
145 			return null;
146 		}
147 		
148 		return ObjectG.getDObject!(ElementFactory)(cast(GstElementFactory*) p, true);
149 	}
150 
151 	/**
152 	 * Filter out all the elementfactories in @list that can handle @caps in
153 	 * the given direction.
154 	 *
155 	 * If @subsetonly is %TRUE, then only the elements whose pads templates
156 	 * are a complete superset of @caps will be returned. Else any element
157 	 * whose pad templates caps can intersect with @caps will be returned.
158 	 *
159 	 * Params:
160 	 *     list = a #GList of
161 	 *         #GstElementFactory to filter
162 	 *     caps = a #GstCaps
163 	 *     direction = a #GstPadDirection to filter on
164 	 *     subsetonly = whether to filter on caps subsets or not.
165 	 *
166 	 * Return: a #GList of
167 	 *     #GstElementFactory elements that match the given requisites.
168 	 *     Use #gst_plugin_feature_list_free after usage.
169 	 */
170 	public static ListG listFilter(ListG list, Caps caps, GstPadDirection direction, bool subsetonly)
171 	{
172 		auto p = gst_element_factory_list_filter((list is null) ? null : list.getListGStruct(), (caps is null) ? null : caps.getCapsStruct(), direction, subsetonly);
173 		
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 		
179 		return new ListG(cast(GList*) p, true);
180 	}
181 
182 	/**
183 	 * Get a list of factories that match the given @type. Only elements
184 	 * with a rank greater or equal to @minrank will be returned.
185 	 * The list of factories is returned by decreasing rank.
186 	 *
187 	 * Params:
188 	 *     type = a #GstElementFactoryListType
189 	 *     minrank = Minimum rank
190 	 *
191 	 * Return: a #GList of
192 	 *     #GstElementFactory elements. Use gst_plugin_feature_list_free() after
193 	 *     usage.
194 	 */
195 	public static ListG listGetElements(GstElementFactoryListType type, GstRank minrank)
196 	{
197 		auto p = gst_element_factory_list_get_elements(type, minrank);
198 		
199 		if(p is null)
200 		{
201 			return null;
202 		}
203 		
204 		return new ListG(cast(GList*) p, true);
205 	}
206 
207 	/**
208 	 * Create a new element of the type defined by the given element factory.
209 	 * If name is %NULL, then the element will receive a guaranteed unique name,
210 	 * consisting of the element factory name and a number.
211 	 * If name is given, it will be given the name supplied.
212 	 *
213 	 * Params:
214 	 *     factoryname = a named factory to instantiate
215 	 *     name = name of new element, or %NULL to automatically create
216 	 *         a unique name
217 	 *
218 	 * Return: new #GstElement or %NULL
219 	 *     if unable to create element
220 	 */
221 	public static Element make(string factoryname, string name)
222 	{
223 		auto p = gst_element_factory_make(Str.toStringz(factoryname), Str.toStringz(name));
224 		
225 		if(p is null)
226 		{
227 			return null;
228 		}
229 		
230 		return ObjectG.getDObject!(Element)(cast(GstElement*) p);
231 	}
232 
233 	/**
234 	 * Checks if the factory can sink all possible capabilities.
235 	 *
236 	 * Params:
237 	 *     caps = the caps to check
238 	 *
239 	 * Return: %TRUE if the caps are fully compatible.
240 	 */
241 	public bool canSinkAllCaps(Caps caps)
242 	{
243 		return gst_element_factory_can_sink_all_caps(gstElementFactory, (caps is null) ? null : caps.getCapsStruct()) != 0;
244 	}
245 
246 	/**
247 	 * Checks if the factory can sink any possible capability.
248 	 *
249 	 * Params:
250 	 *     caps = the caps to check
251 	 *
252 	 * Return: %TRUE if the caps have a common subset.
253 	 */
254 	public bool canSinkAnyCaps(Caps caps)
255 	{
256 		return gst_element_factory_can_sink_any_caps(gstElementFactory, (caps is null) ? null : caps.getCapsStruct()) != 0;
257 	}
258 
259 	/**
260 	 * Checks if the factory can src all possible capabilities.
261 	 *
262 	 * Params:
263 	 *     caps = the caps to check
264 	 *
265 	 * Return: %TRUE if the caps are fully compatible.
266 	 */
267 	public bool canSrcAllCaps(Caps caps)
268 	{
269 		return gst_element_factory_can_src_all_caps(gstElementFactory, (caps is null) ? null : caps.getCapsStruct()) != 0;
270 	}
271 
272 	/**
273 	 * Checks if the factory can src any possible capability.
274 	 *
275 	 * Params:
276 	 *     caps = the caps to check
277 	 *
278 	 * Return: %TRUE if the caps have a common subset.
279 	 */
280 	public bool canSrcAnyCaps(Caps caps)
281 	{
282 		return gst_element_factory_can_src_any_caps(gstElementFactory, (caps is null) ? null : caps.getCapsStruct()) != 0;
283 	}
284 
285 	/**
286 	 * Create a new element of the type defined by the given elementfactory.
287 	 * It will be given the name supplied, since all elements require a name as
288 	 * their first argument.
289 	 *
290 	 * Params:
291 	 *     name = name of new element, or %NULL to automatically create
292 	 *         a unique name
293 	 *
294 	 * Return: new #GstElement or %NULL
295 	 *     if the element couldn't be created
296 	 */
297 	public Element create(string name)
298 	{
299 		auto p = gst_element_factory_create(gstElementFactory, Str.toStringz(name));
300 		
301 		if(p is null)
302 		{
303 			return null;
304 		}
305 		
306 		return ObjectG.getDObject!(Element)(cast(GstElement*) p);
307 	}
308 
309 	/**
310 	 * Get the #GType for elements managed by this factory. The type can
311 	 * only be retrieved if the element factory is loaded, which can be
312 	 * assured with gst_plugin_feature_load().
313 	 *
314 	 * Return: the #GType for elements managed by this factory or 0 if
315 	 *     the factory is not loaded.
316 	 */
317 	public GType getElementType()
318 	{
319 		return gst_element_factory_get_element_type(gstElementFactory);
320 	}
321 
322 	/**
323 	 * Get the metadata on @factory with @key.
324 	 *
325 	 * Params:
326 	 *     key = a key
327 	 *
328 	 * Return: the metadata with @key on @factory or %NULL
329 	 *     when there was no metadata with the given @key.
330 	 */
331 	public string getMetadata(string key)
332 	{
333 		return Str.toString(gst_element_factory_get_metadata(gstElementFactory, Str.toStringz(key)));
334 	}
335 
336 	/**
337 	 * Get the available keys for the metadata on @factory.
338 	 *
339 	 * Return: a %NULL-terminated array of key strings, or %NULL when there is no
340 	 *     metadata. Free with g_strfreev() when no longer needed.
341 	 */
342 	public string[] getMetadataKeys()
343 	{
344 		auto retStr = gst_element_factory_get_metadata_keys(gstElementFactory);
345 		
346 		scope(exit) Str.freeStringArray(retStr);
347 		return Str.toStringArray(retStr);
348 	}
349 
350 	/**
351 	 * Gets the number of pad_templates in this factory.
352 	 *
353 	 * Return: the number of pad_templates
354 	 */
355 	public uint getNumPadTemplates()
356 	{
357 		return gst_element_factory_get_num_pad_templates(gstElementFactory);
358 	}
359 
360 	/**
361 	 * Gets the #GList of #GstStaticPadTemplate for this factory.
362 	 *
363 	 * Return: the
364 	 *     static pad templates
365 	 */
366 	public ListG getStaticPadTemplates()
367 	{
368 		auto p = gst_element_factory_get_static_pad_templates(gstElementFactory);
369 		
370 		if(p is null)
371 		{
372 			return null;
373 		}
374 		
375 		return new ListG(cast(GList*) p);
376 	}
377 
378 	/**
379 	 * Gets a %NULL-terminated array of protocols this element supports or %NULL if
380 	 * no protocols are supported. You may not change the contents of the returned
381 	 * array, as it is still owned by the element factory. Use g_strdupv() to
382 	 * make a copy of the protocol string array if you need to.
383 	 *
384 	 * Return: the supported protocols
385 	 *     or %NULL
386 	 */
387 	public string[] getUriProtocols()
388 	{
389 		return Str.toStringArray(gst_element_factory_get_uri_protocols(gstElementFactory));
390 	}
391 
392 	/**
393 	 * Gets the type of URIs the element supports or #GST_URI_UNKNOWN if none.
394 	 *
395 	 * Return: type of URIs this element supports
396 	 */
397 	public GstURIType getUriType()
398 	{
399 		return gst_element_factory_get_uri_type(gstElementFactory);
400 	}
401 
402 	/**
403 	 * Check if @factory implements the interface with name @interfacename.
404 	 *
405 	 * Params:
406 	 *     interfacename = an interface name
407 	 *
408 	 * Return: %TRUE when @factory implement the interface.
409 	 */
410 	public bool hasInterface(string interfacename)
411 	{
412 		return gst_element_factory_has_interface(gstElementFactory, Str.toStringz(interfacename)) != 0;
413 	}
414 
415 	/**
416 	 * Check if @factory is of the given types.
417 	 *
418 	 * Params:
419 	 *     type = a #GstElementFactoryListType
420 	 *
421 	 * Return: %TRUE if @factory is of @type.
422 	 */
423 	public bool listIsType(GstElementFactoryListType type)
424 	{
425 		return gst_element_factory_list_is_type(gstElementFactory, type) != 0;
426 	}
427 }