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