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