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.Plugin;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.ListG;
30 private import glib.Str;
31 private import gobject.ObjectG;
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 
38 
39 /**
40  * GStreamer is extensible, so #GstElement instances can be loaded at runtime.
41  * A plugin system can provide one or more of the basic
42  * <application>GStreamer</application> #GstPluginFeature subclasses.
43  * 
44  * A plugin should export a symbol <symbol>gst_plugin_desc</symbol> that is a
45  * struct of type #GstPluginDesc.
46  * the plugin loader will check the version of the core library the plugin was
47  * linked against and will create a new #GstPlugin. It will then call the
48  * #GstPluginInitFunc function that was provided in the
49  * <symbol>gst_plugin_desc</symbol>.
50  * 
51  * Once you have a handle to a #GstPlugin (e.g. from the #GstRegistry), you
52  * can add any object that subclasses #GstPluginFeature.
53  * 
54  * Usually plugins are always automatically loaded so you don't need to call
55  * gst_plugin_load() explicitly to bring it into memory. There are options to
56  * statically link plugins to an app or even use GStreamer without a plugin
57  * repository in which case gst_plugin_load() can be needed to bring the plugin
58  * into memory.
59  */
60 public class Plugin : ObjectGst
61 {
62 	/** the main Gtk struct */
63 	protected GstPlugin* gstPlugin;
64 
65 	/** Get the main Gtk struct */
66 	public GstPlugin* getPluginStruct(bool transferOwnership = false)
67 	{
68 		if (transferOwnership)
69 			ownedRef = false;
70 		return gstPlugin;
71 	}
72 
73 	/** the main Gtk struct as a void* */
74 	protected override void* getStruct()
75 	{
76 		return cast(void*)gstPlugin;
77 	}
78 
79 	protected override void setStruct(GObject* obj)
80 	{
81 		gstPlugin = cast(GstPlugin*)obj;
82 		super.setStruct(obj);
83 	}
84 
85 	/**
86 	 * Sets our main struct and passes it to the parent class.
87 	 */
88 	public this (GstPlugin* gstPlugin, bool ownedRef = false)
89 	{
90 		this.gstPlugin = gstPlugin;
91 		super(cast(GstObject*)gstPlugin, ownedRef);
92 	}
93 
94 
95 	/** */
96 	public static GType getType()
97 	{
98 		return gst_plugin_get_type();
99 	}
100 
101 	/**
102 	 * Unrefs each member of @list, then frees the list.
103 	 *
104 	 * Params:
105 	 *     list = list of #GstPlugin
106 	 */
107 	public static void listFree(ListG list)
108 	{
109 		gst_plugin_list_free((list is null) ? null : list.getListGStruct());
110 	}
111 
112 	/**
113 	 * Load the named plugin. Refs the plugin.
114 	 *
115 	 * Params:
116 	 *     name = name of plugin to load
117 	 *
118 	 * Returns: a reference to a loaded plugin, or %NULL on error.
119 	 */
120 	public static Plugin loadByName(string name)
121 	{
122 		auto p = gst_plugin_load_by_name(Str.toStringz(name));
123 
124 		if(p is null)
125 		{
126 			return null;
127 		}
128 
129 		return ObjectG.getDObject!(Plugin)(cast(GstPlugin*) p, true);
130 	}
131 
132 	/**
133 	 * Loads the given plugin and refs it.  Caller needs to unref after use.
134 	 *
135 	 * Params:
136 	 *     filename = the plugin filename to load
137 	 *
138 	 * Returns: a reference to the existing loaded GstPlugin, a
139 	 *     reference to the newly-loaded GstPlugin, or %NULL if an error occurred.
140 	 *
141 	 * Throws: GException on failure.
142 	 */
143 	public static Plugin loadFile(string filename)
144 	{
145 		GError* err = null;
146 
147 		auto p = gst_plugin_load_file(Str.toStringz(filename), &err);
148 
149 		if (err !is null)
150 		{
151 			throw new GException( new ErrorG(err) );
152 		}
153 
154 		if(p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(Plugin)(cast(GstPlugin*) p, true);
160 	}
161 
162 	/**
163 	 * Registers a static plugin, ie. a plugin which is private to an application
164 	 * or library and contained within the application or library (as opposed to
165 	 * being shipped as a separate module file).
166 	 *
167 	 * You must make sure that GStreamer has been initialised (with gst_init() or
168 	 * via gst_init_get_option_group()) before calling this function.
169 	 *
170 	 * Params:
171 	 *     majorVersion = the major version number of the GStreamer core that the
172 	 *         plugin was compiled for, you can just use GST_VERSION_MAJOR here
173 	 *     minorVersion = the minor version number of the GStreamer core that the
174 	 *         plugin was compiled for, you can just use GST_VERSION_MINOR here
175 	 *     name = a unique name of the plugin (ideally prefixed with an application- or
176 	 *         library-specific namespace prefix in order to avoid name conflicts in
177 	 *         case a similar plugin with the same name ever gets added to GStreamer)
178 	 *     description = description of the plugin
179 	 *     initFunc = pointer to the init function of this plugin.
180 	 *     versio = version string of the plugin
181 	 *     license = effective license of plugin. Must be one of the approved licenses
182 	 *         (see #GstPluginDesc above) or the plugin will not be registered.
183 	 *     source = source module plugin belongs to
184 	 *     p = shipped package plugin belongs to
185 	 *     origin = URL to provider of plugin
186 	 *
187 	 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
188 	 */
189 	public static bool registerStatic(int majorVersion, int minorVersion, string name, string description, GstPluginInitFunc initFunc, string versio, string license, string source, string p, string origin)
190 	{
191 		return gst_plugin_register_static(majorVersion, minorVersion, Str.toStringz(name), Str.toStringz(description), initFunc, Str.toStringz(versio), Str.toStringz(license), Str.toStringz(source), Str.toStringz(p), Str.toStringz(origin)) != 0;
192 	}
193 
194 	/**
195 	 * Registers a static plugin, ie. a plugin which is private to an application
196 	 * or library and contained within the application or library (as opposed to
197 	 * being shipped as a separate module file) with a #GstPluginInitFullFunc
198 	 * which allows user data to be passed to the callback function (useful
199 	 * for bindings).
200 	 *
201 	 * You must make sure that GStreamer has been initialised (with gst_init() or
202 	 * via gst_init_get_option_group()) before calling this function.
203 	 *
204 	 * Params:
205 	 *     majorVersion = the major version number of the GStreamer core that the
206 	 *         plugin was compiled for, you can just use GST_VERSION_MAJOR here
207 	 *     minorVersion = the minor version number of the GStreamer core that the
208 	 *         plugin was compiled for, you can just use GST_VERSION_MINOR here
209 	 *     name = a unique name of the plugin (ideally prefixed with an application- or
210 	 *         library-specific namespace prefix in order to avoid name conflicts in
211 	 *         case a similar plugin with the same name ever gets added to GStreamer)
212 	 *     description = description of the plugin
213 	 *     initFullFunc = pointer to the init function with user data
214 	 *         of this plugin.
215 	 *     versio = version string of the plugin
216 	 *     license = effective license of plugin. Must be one of the approved licenses
217 	 *         (see #GstPluginDesc above) or the plugin will not be registered.
218 	 *     source = source module plugin belongs to
219 	 *     p = shipped package plugin belongs to
220 	 *     origin = URL to provider of plugin
221 	 *     userData = gpointer to user data
222 	 *
223 	 * Returns: %TRUE if the plugin was registered correctly, otherwise %FALSE.
224 	 */
225 	public static bool registerStaticFull(int majorVersion, int minorVersion, string name, string description, GstPluginInitFullFunc initFullFunc, string versio, string license, string source, string p, string origin, void* userData)
226 	{
227 		return gst_plugin_register_static_full(majorVersion, minorVersion, Str.toStringz(name), Str.toStringz(description), initFullFunc, Str.toStringz(versio), Str.toStringz(license), Str.toStringz(source), Str.toStringz(p), Str.toStringz(origin), userData) != 0;
228 	}
229 
230 	/**
231 	 * Make GStreamer aware of external dependencies which affect the feature
232 	 * set of this plugin (ie. the elements or typefinders associated with it).
233 	 *
234 	 * GStreamer will re-inspect plugins with external dependencies whenever any
235 	 * of the external dependencies change. This is useful for plugins which wrap
236 	 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
237 	 * library and makes visualisations available as GStreamer elements, or a
238 	 * codec loader which exposes elements and/or caps dependent on what external
239 	 * codec libraries are currently installed.
240 	 *
241 	 * Params:
242 	 *     envVars = %NULL-terminated array of environment variables affecting the
243 	 *         feature set of the plugin (e.g. an environment variable containing
244 	 *         paths where to look for additional modules/plugins of a library),
245 	 *         or %NULL. Environment variable names may be followed by a path component
246 	 *         which will be added to the content of the environment variable, e.g.
247 	 *         "HOME/.mystuff/plugins".
248 	 *     paths = %NULL-terminated array of directories/paths where dependent files
249 	 *         may be, or %NULL.
250 	 *     names = %NULL-terminated array of file names (or file name suffixes,
251 	 *         depending on @flags) to be used in combination with the paths from
252 	 *         @paths and/or the paths extracted from the environment variables in
253 	 *         @env_vars, or %NULL.
254 	 *     flags = optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
255 	 */
256 	public void addDependency(string[] envVars, string[] paths, string[] names, GstPluginDependencyFlags flags)
257 	{
258 		gst_plugin_add_dependency(gstPlugin, Str.toStringzArray(envVars), Str.toStringzArray(paths), Str.toStringzArray(names), flags);
259 	}
260 
261 	/**
262 	 * Make GStreamer aware of external dependencies which affect the feature
263 	 * set of this plugin (ie. the elements or typefinders associated with it).
264 	 *
265 	 * GStreamer will re-inspect plugins with external dependencies whenever any
266 	 * of the external dependencies change. This is useful for plugins which wrap
267 	 * other plugin systems, e.g. a plugin which wraps a plugin-based visualisation
268 	 * library and makes visualisations available as GStreamer elements, or a
269 	 * codec loader which exposes elements and/or caps dependent on what external
270 	 * codec libraries are currently installed.
271 	 *
272 	 * Convenience wrapper function for gst_plugin_add_dependency() which
273 	 * takes simple strings as arguments instead of string arrays, with multiple
274 	 * arguments separated by predefined delimiters (see above).
275 	 *
276 	 * Params:
277 	 *     envVars = one or more environment variables (separated by ':', ';' or ','),
278 	 *         or %NULL. Environment variable names may be followed by a path component
279 	 *         which will be added to the content of the environment variable, e.g.
280 	 *         "HOME/.mystuff/plugins:MYSTUFF_PLUGINS_PATH"
281 	 *     paths = one ore more directory paths (separated by ':' or ';' or ','),
282 	 *         or %NULL. Example: "/usr/lib/mystuff/plugins"
283 	 *     names = one or more file names or file name suffixes (separated by commas),
284 	 *         or %NULL
285 	 *     flags = optional flags, or #GST_PLUGIN_DEPENDENCY_FLAG_NONE
286 	 */
287 	public void addDependencySimple(string envVars, string paths, string names, GstPluginDependencyFlags flags)
288 	{
289 		gst_plugin_add_dependency_simple(gstPlugin, Str.toStringz(envVars), Str.toStringz(paths), Str.toStringz(names), flags);
290 	}
291 
292 	/**
293 	 * Gets the plugin specific data cache. If it is %NULL there is no cached data
294 	 * stored. This is the case when the registry is getting rebuilt.
295 	 *
296 	 * Returns: The cached data as a
297 	 *     #GstStructure or %NULL.
298 	 */
299 	public Structure getCacheData()
300 	{
301 		auto p = gst_plugin_get_cache_data(gstPlugin);
302 
303 		if(p is null)
304 		{
305 			return null;
306 		}
307 
308 		return ObjectG.getDObject!(Structure)(cast(GstStructure*) p);
309 	}
310 
311 	/**
312 	 * Get the long descriptive name of the plugin
313 	 *
314 	 * Returns: the long name of the plugin
315 	 */
316 	public string getDescription()
317 	{
318 		return Str.toString(gst_plugin_get_description(gstPlugin));
319 	}
320 
321 	/**
322 	 * get the filename of the plugin
323 	 *
324 	 * Returns: the filename of the plugin
325 	 */
326 	public string getFilename()
327 	{
328 		return Str.toString(gst_plugin_get_filename(gstPlugin));
329 	}
330 
331 	/**
332 	 * get the license of the plugin
333 	 *
334 	 * Returns: the license of the plugin
335 	 */
336 	public string getLicense()
337 	{
338 		return Str.toString(gst_plugin_get_license(gstPlugin));
339 	}
340 
341 	/**
342 	 * Get the short name of the plugin
343 	 *
344 	 * Returns: the name of the plugin
345 	 */
346 	public override string getName()
347 	{
348 		return Str.toString(gst_plugin_get_name(gstPlugin));
349 	}
350 
351 	/**
352 	 * get the URL where the plugin comes from
353 	 *
354 	 * Returns: the origin of the plugin
355 	 */
356 	public string getOrigin()
357 	{
358 		return Str.toString(gst_plugin_get_origin(gstPlugin));
359 	}
360 
361 	/**
362 	 * get the package the plugin belongs to.
363 	 *
364 	 * Returns: the package of the plugin
365 	 */
366 	public string getPackage()
367 	{
368 		return Str.toString(gst_plugin_get_package(gstPlugin));
369 	}
370 
371 	/**
372 	 * Get the release date (and possibly time) in form of a string, if available.
373 	 *
374 	 * For normal GStreamer plugin releases this will usually just be a date in
375 	 * the form of "YYYY-MM-DD", while pre-releases and builds from git may contain
376 	 * a time component after the date as well, in which case the string will be
377 	 * formatted like "YYYY-MM-DDTHH:MMZ" (e.g. "2012-04-30T09:30Z").
378 	 *
379 	 * There may be plugins that do not have a valid release date set on them.
380 	 *
381 	 * Returns: the date string of the plugin, or %NULL if not
382 	 *     available.
383 	 */
384 	public string getReleaseDateString()
385 	{
386 		return Str.toString(gst_plugin_get_release_date_string(gstPlugin));
387 	}
388 
389 	/**
390 	 * get the source module the plugin belongs to.
391 	 *
392 	 * Returns: the source of the plugin
393 	 */
394 	public string getSource()
395 	{
396 		return Str.toString(gst_plugin_get_source(gstPlugin));
397 	}
398 
399 	/**
400 	 * get the version of the plugin
401 	 *
402 	 * Returns: the version of the plugin
403 	 */
404 	public string getVersion()
405 	{
406 		return Str.toString(gst_plugin_get_version(gstPlugin));
407 	}
408 
409 	/**
410 	 * queries if the plugin is loaded into memory
411 	 *
412 	 * Returns: %TRUE is loaded, %FALSE otherwise
413 	 */
414 	public bool isLoaded()
415 	{
416 		return gst_plugin_is_loaded(gstPlugin) != 0;
417 	}
418 
419 	/**
420 	 * Loads @plugin. Note that the *return value* is the loaded plugin; @plugin is
421 	 * untouched. The normal use pattern of this function goes like this:
422 	 *
423 	 * |[
424 	 * GstPlugin *loaded_plugin;
425 	 * loaded_plugin = gst_plugin_load (plugin);
426 	 * // presumably, we're no longer interested in the potentially-unloaded plugin
427 	 * gst_object_unref (plugin);
428 	 * plugin = loaded_plugin;
429 	 * ]|
430 	 *
431 	 * Returns: a reference to a loaded plugin, or %NULL on error.
432 	 */
433 	public Plugin load()
434 	{
435 		auto p = gst_plugin_load(gstPlugin);
436 
437 		if(p is null)
438 		{
439 			return null;
440 		}
441 
442 		return ObjectG.getDObject!(Plugin)(cast(GstPlugin*) p, true);
443 	}
444 
445 	/**
446 	 * Adds plugin specific data to cache. Passes the ownership of the structure to
447 	 * the @plugin.
448 	 *
449 	 * The cache is flushed every time the registry is rebuilt.
450 	 *
451 	 * Params:
452 	 *     cacheData = a structure containing the data to cache
453 	 */
454 	public void setCacheData(Structure cacheData)
455 	{
456 		gst_plugin_set_cache_data(gstPlugin, (cacheData is null) ? null : cacheData.getStructureStruct(true));
457 	}
458 
459 	/**
460 	 * Get the error quark.
461 	 *
462 	 * Returns: The error quark used in GError messages
463 	 */
464 	public static GQuark pluginErrorQuark()
465 	{
466 		return gst_plugin_error_quark();
467 	}
468 }