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