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.TypeFindFactory;
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.PluginFeature;
32 private import gstreamer.TypeFind;
33 private import gstreamerc.gstreamer;
34 public  import gstreamerc.gstreamertypes;
35 
36 
37 /**
38  * These functions allow querying informations about registered typefind
39  * functions. How to create and register these functions is described in
40  * the section <link linkend="gstreamer-Writing-typefind-functions">
41  * "Writing typefind functions"</link>.
42  * 
43  * The following example shows how to write a very simple typefinder that
44  * identifies the given data. You can get quite a bit more complicated than
45  * that though.
46  * |[<!-- language="C" -->
47  * typedef struct {
48  * guint8 *data;
49  * guint size;
50  * guint probability;
51  * GstCaps *data;
52  * } MyTypeFind;
53  * static void
54  * my_peek (gpointer data, gint64 offset, guint size)
55  * {
56  * MyTypeFind *find = (MyTypeFind *) data;
57  * if (offset &gt;= 0 &amp;&amp; offset + size &lt;= find->size) {
58  * return find->data + offset;
59  * }
60  * return NULL;
61  * }
62  * static void
63  * my_suggest (gpointer data, guint probability, GstCaps *caps)
64  * {
65  * MyTypeFind *find = (MyTypeFind *) data;
66  * if (probability &gt; find->probability) {
67  * find->probability = probability;
68  * gst_caps_replace (&amp;find->caps, caps);
69  * }
70  * }
71  * static GstCaps *
72  * find_type (guint8 *data, guint size)
73  * {
74  * GList *walk, *type_list;
75  * MyTypeFind find = {data, size, 0, NULL};
76  * GstTypeFind gst_find = {my_peek, my_suggest, &amp;find, };
77  * walk = type_list = gst_type_find_factory_get_list ();
78  * while (walk) {
79  * GstTypeFindFactory *factory = GST_TYPE_FIND_FACTORY (walk->data);
80  * walk = g_list_next (walk)
81  * gst_type_find_factory_call_function (factory, &amp;gst_find);
82  * }
83  * g_list_free (type_list);
84  * return find.caps;
85  * };
86  * ]|
87  */
88 public class TypeFindFactory : PluginFeature
89 {
90 	/** the main Gtk struct */
91 	protected GstTypeFindFactory* gstTypeFindFactory;
92 
93 	/** Get the main Gtk struct */
94 	public GstTypeFindFactory* getTypeFindFactoryStruct(bool transferOwnership = false)
95 	{
96 		if (transferOwnership)
97 			ownedRef = false;
98 		return gstTypeFindFactory;
99 	}
100 
101 	/** the main Gtk struct as a void* */
102 	protected override void* getStruct()
103 	{
104 		return cast(void*)gstTypeFindFactory;
105 	}
106 
107 	protected override void setStruct(GObject* obj)
108 	{
109 		gstTypeFindFactory = cast(GstTypeFindFactory*)obj;
110 		super.setStruct(obj);
111 	}
112 
113 	/**
114 	 * Sets our main struct and passes it to the parent class.
115 	 */
116 	public this (GstTypeFindFactory* gstTypeFindFactory, bool ownedRef = false)
117 	{
118 		this.gstTypeFindFactory = gstTypeFindFactory;
119 		super(cast(GstPluginFeature*)gstTypeFindFactory, ownedRef);
120 	}
121 
122 
123 	/** */
124 	public static GType getType()
125 	{
126 		return gst_type_find_factory_get_type();
127 	}
128 
129 	/**
130 	 * Gets the list of all registered typefind factories. You must free the
131 	 * list using gst_plugin_feature_list_free().
132 	 *
133 	 * The returned factories are sorted by highest rank first, and then by
134 	 * factory name.
135 	 *
136 	 * Free-function: gst_plugin_feature_list_free
137 	 *
138 	 * Returns: the list of all
139 	 *     registered #GstTypeFindFactory.
140 	 */
141 	public static ListG getList()
142 	{
143 		auto p = gst_type_find_factory_get_list();
144 		
145 		if(p is null)
146 		{
147 			return null;
148 		}
149 		
150 		return new ListG(cast(GList*) p, true);
151 	}
152 
153 	/**
154 	 * Calls the #GstTypeFindFunction associated with this factory.
155 	 *
156 	 * Params:
157 	 *     find = a properly setup #GstTypeFind entry. The get_data
158 	 *         and suggest_type members must be set.
159 	 */
160 	public void callFunction(TypeFind find)
161 	{
162 		gst_type_find_factory_call_function(gstTypeFindFactory, (find is null) ? null : find.getTypeFindStruct());
163 	}
164 
165 	/**
166 	 * Gets the #GstCaps associated with a typefind factory.
167 	 *
168 	 * Returns: the #GstCaps associated with this factory
169 	 */
170 	public Caps getCaps()
171 	{
172 		auto p = gst_type_find_factory_get_caps(gstTypeFindFactory);
173 		
174 		if(p is null)
175 		{
176 			return null;
177 		}
178 		
179 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
180 	}
181 
182 	/**
183 	 * Gets the extensions associated with a #GstTypeFindFactory. The returned
184 	 * array should not be changed. If you need to change stuff in it, you should
185 	 * copy it using g_strdupv().  This function may return %NULL to indicate
186 	 * a 0-length list.
187 	 *
188 	 * Returns: a %NULL-terminated array of extensions associated with this factory
189 	 */
190 	public string[] getExtensions()
191 	{
192 		return Str.toStringArray(gst_type_find_factory_get_extensions(gstTypeFindFactory));
193 	}
194 
195 	/**
196 	 * Check whether the factory has a typefind function. Typefind factories
197 	 * without typefind functions are a last-effort fallback mechanism to
198 	 * e.g. assume a certain media type based on the file extension.
199 	 *
200 	 * Returns: %TRUE if the factory has a typefind functions set, otherwise %FALSE
201 	 */
202 	public bool hasFunction()
203 	{
204 		return gst_type_find_factory_has_function(gstTypeFindFactory) != 0;
205 	}
206 }