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  * |[
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()
95 	{
96 		return gstTypeFindFactory;
97 	}
98 
99 	/** the main Gtk struct as a void* */
100 	protected override void* getStruct()
101 	{
102 		return cast(void*)gstTypeFindFactory;
103 	}
104 
105 	protected override void setStruct(GObject* obj)
106 	{
107 		gstTypeFindFactory = cast(GstTypeFindFactory*)obj;
108 		super.setStruct(obj);
109 	}
110 
111 	/**
112 	 * Sets our main struct and passes it to the parent class.
113 	 */
114 	public this (GstTypeFindFactory* gstTypeFindFactory, bool ownedRef = false)
115 	{
116 		this.gstTypeFindFactory = gstTypeFindFactory;
117 		super(cast(GstPluginFeature*)gstTypeFindFactory, ownedRef);
118 	}
119 
120 	/**
121 	 */
122 
123 	public static GType getType()
124 	{
125 		return gst_type_find_factory_get_type();
126 	}
127 
128 	/**
129 	 * Gets the list of all registered typefind factories. You must free the
130 	 * list using gst_plugin_feature_list_free().
131 	 *
132 	 * The returned factories are sorted by highest rank first, and then by
133 	 * factory name.
134 	 *
135 	 * Free-function: gst_plugin_feature_list_free
136 	 *
137 	 * Return: the list of all
138 	 *     registered #GstTypeFindFactory.
139 	 */
140 	public static ListG getList()
141 	{
142 		auto p = gst_type_find_factory_get_list();
143 		
144 		if(p is null)
145 		{
146 			return null;
147 		}
148 		
149 		return new ListG(cast(GList*) p);
150 	}
151 
152 	/**
153 	 * Calls the #GstTypeFindFunction associated with this factory.
154 	 *
155 	 * Params:
156 	 *     find = a properly setup #GstTypeFind entry. The get_data
157 	 *         and suggest_type members must be set.
158 	 */
159 	public void callFunction(TypeFind find)
160 	{
161 		gst_type_find_factory_call_function(gstTypeFindFactory, (find is null) ? null : find.getTypeFindStruct());
162 	}
163 
164 	/**
165 	 * Gets the #GstCaps associated with a typefind factory.
166 	 *
167 	 * Return: the #GstCaps associated with this factory
168 	 */
169 	public Caps getCaps()
170 	{
171 		auto p = gst_type_find_factory_get_caps(gstTypeFindFactory);
172 		
173 		if(p is null)
174 		{
175 			return null;
176 		}
177 		
178 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p);
179 	}
180 
181 	/**
182 	 * Gets the extensions associated with a #GstTypeFindFactory. The returned
183 	 * array should not be changed. If you need to change stuff in it, you should
184 	 * copy it using g_strdupv().  This function may return %NULL to indicate
185 	 * a 0-length list.
186 	 *
187 	 * Return: a %NULL-terminated array of extensions associated with this factory
188 	 */
189 	public string[] getExtensions()
190 	{
191 		return Str.toStringArray(gst_type_find_factory_get_extensions(gstTypeFindFactory));
192 	}
193 
194 	/**
195 	 * Check whether the factory has a typefind function. Typefind factories
196 	 * without typefind functions are a last-effort fallback mechanism to
197 	 * e.g. assume a certain media type based on the file extension.
198 	 *
199 	 * Return: %TRUE if the factory has a typefind functions set, otherwise %FALSE
200 	 */
201 	public bool hasFunction()
202 	{
203 		return gst_type_find_factory_has_function(gstTypeFindFactory) != 0;
204 	}
205 }