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