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