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 gst.base.BaseTransform;
26 
27 private import gobject.ObjectG;
28 private import gst.base.c.functions;
29 public  import gst.base.c.types;
30 private import gstreamer.AllocationParams;
31 private import gstreamer.Allocator;
32 private import gstreamer.BufferPool;
33 private import gstreamer.Caps;
34 private import gstreamer.Element;
35 
36 
37 /**
38  * This base class is for filter elements that process data. Elements
39  * that are suitable for implementation using #GstBaseTransform are ones
40  * where the size and caps of the output is known entirely from the input
41  * caps and buffer sizes. These include elements that directly transform
42  * one buffer into another, modify the contents of a buffer in-place, as
43  * well as elements that collate multiple input buffers into one output buffer,
44  * or that expand one input buffer into multiple output buffers. See below
45  * for more concrete use cases.
46  * 
47  * It provides for:
48  * 
49  * * one sinkpad and one srcpad
50  * * Possible formats on sink and source pad implemented
51  * with custom transform_caps function. By default uses
52  * same format on sink and source.
53  * 
54  * * Handles state changes
55  * * Does flushing
56  * * Push mode
57  * * Pull mode if the sub-class transform can operate on arbitrary data
58  * 
59  * # Use Cases
60  * 
61  * ## Passthrough mode
62  * 
63  * * Element has no interest in modifying the buffer. It may want to inspect it,
64  * in which case the element should have a transform_ip function. If there
65  * is no transform_ip function in passthrough mode, the buffer is pushed
66  * intact.
67  * 
68  * * The #GstBaseTransformClass.passthrough_on_same_caps variable
69  * will automatically set/unset passthrough based on whether the
70  * element negotiates the same caps on both pads.
71  * 
72  * * #GstBaseTransformClass.passthrough_on_same_caps on an element that
73  * doesn't implement a transform_caps function is useful for elements that
74  * only inspect data (such as level)
75  * 
76  * * Example elements
77  * 
78  * * Level
79  * * Videoscale, audioconvert, videoconvert, audioresample in certain modes.
80  * 
81  * ## Modifications in-place - input buffer and output buffer are the same thing.
82  * 
83  * * The element must implement a transform_ip function.
84  * * Output buffer size must <= input buffer size
85  * * If the always_in_place flag is set, non-writable buffers will be copied
86  * and passed to the transform_ip function, otherwise a new buffer will be
87  * created and the transform function called.
88  * 
89  * * Incoming writable buffers will be passed to the transform_ip function
90  * immediately.
91  * * only implementing transform_ip and not transform implies always_in_place = %TRUE
92  * 
93  * * Example elements:
94  * * Volume
95  * * Audioconvert in certain modes (signed/unsigned conversion)
96  * * videoconvert in certain modes (endianness swapping)
97  * 
98  * ## Modifications only to the caps/metadata of a buffer
99  * 
100  * * The element does not require writable data, but non-writable buffers
101  * should be subbuffered so that the meta-information can be replaced.
102  * 
103  * * Elements wishing to operate in this mode should replace the
104  * prepare_output_buffer method to create subbuffers of the input buffer
105  * and set always_in_place to %TRUE
106  * 
107  * * Example elements
108  * * Capsfilter when setting caps on outgoing buffers that have
109  * none.
110  * * identity when it is going to re-timestamp buffers by
111  * datarate.
112  * 
113  * ## Normal mode
114  * * always_in_place flag is not set, or there is no transform_ip function
115  * * Element will receive an input buffer and output buffer to operate on.
116  * * Output buffer is allocated by calling the prepare_output_buffer function.
117  * * Example elements:
118  * * Videoscale, videoconvert, audioconvert when doing
119  * scaling/conversions
120  * 
121  * ## Special output buffer allocations
122  * * Elements which need to do special allocation of their output buffers
123  * beyond allocating output buffers via the negotiated allocator or
124  * buffer pool should implement the prepare_output_buffer method.
125  * 
126  * * Example elements:
127  * * efence
128  * 
129  * # Sub-class settable flags on GstBaseTransform
130  * 
131  * * passthrough
132  * 
133  * * Implies that in the current configuration, the sub-class is not interested in modifying the buffers.
134  * * Elements which are always in passthrough mode whenever the same caps has been negotiated on both pads can set the class variable passthrough_on_same_caps to have this behaviour automatically.
135  * 
136  * * always_in_place
137  * * Determines whether a non-writable buffer will be copied before passing
138  * to the transform_ip function.
139  * 
140  * * Implied %TRUE if no transform function is implemented.
141  * * Implied %FALSE if ONLY transform function is implemented.
142  */
143 public class BaseTransform : Element
144 {
145 	/** the main Gtk struct */
146 	protected GstBaseTransform* gstBaseTransform;
147 
148 	/** Get the main Gtk struct */
149 	public GstBaseTransform* getBaseTransformStruct(bool transferOwnership = false)
150 	{
151 		if (transferOwnership)
152 			ownedRef = false;
153 		return gstBaseTransform;
154 	}
155 
156 	/** the main Gtk struct as a void* */
157 	protected override void* getStruct()
158 	{
159 		return cast(void*)gstBaseTransform;
160 	}
161 
162 	protected override void setStruct(GObject* obj)
163 	{
164 		gstBaseTransform = cast(GstBaseTransform*)obj;
165 		super.setStruct(obj);
166 	}
167 
168 	/**
169 	 * Sets our main struct and passes it to the parent class.
170 	 */
171 	public this (GstBaseTransform* gstBaseTransform, bool ownedRef = false)
172 	{
173 		this.gstBaseTransform = gstBaseTransform;
174 		super(cast(GstElement*)gstBaseTransform, ownedRef);
175 	}
176 
177 
178 	/** */
179 	public static GType getType()
180 	{
181 		return gst_base_transform_get_type();
182 	}
183 
184 	/**
185 	 * Lets #GstBaseTransform sub-classes to know the memory @allocator
186 	 * used by the base class and its @params.
187 	 *
188 	 * Unref the @allocator after use it.
189 	 *
190 	 * Params:
191 	 *     allocator = the #GstAllocator
192 	 *         used
193 	 *     params = the
194 	 *         #GstAllocationParams of @allocator
195 	 */
196 	public void getAllocator(out Allocator allocator, out AllocationParams params)
197 	{
198 		GstAllocator* outallocator = null;
199 		GstAllocationParams* outparams = gMalloc!GstAllocationParams();
200 
201 		gst_base_transform_get_allocator(gstBaseTransform, &outallocator, outparams);
202 
203 		allocator = ObjectG.getDObject!(Allocator)(outallocator);
204 		params = ObjectG.getDObject!(AllocationParams)(outparams, true);
205 	}
206 
207 	/**
208 	 * Returns: the instance of the #GstBufferPool used
209 	 *     by @trans; free it after use it
210 	 */
211 	public BufferPool getBufferPool()
212 	{
213 		auto p = gst_base_transform_get_buffer_pool(gstBaseTransform);
214 
215 		if(p is null)
216 		{
217 			return null;
218 		}
219 
220 		return ObjectG.getDObject!(BufferPool)(cast(GstBufferPool*) p, true);
221 	}
222 
223 	/**
224 	 * See if @trans is configured as a in_place transform.
225 	 *
226 	 * Returns: %TRUE is the transform is configured in in_place mode.
227 	 *
228 	 *     MT safe.
229 	 */
230 	public bool isInPlace()
231 	{
232 		return gst_base_transform_is_in_place(gstBaseTransform) != 0;
233 	}
234 
235 	/**
236 	 * See if @trans is configured as a passthrough transform.
237 	 *
238 	 * Returns: %TRUE is the transform is configured in passthrough mode.
239 	 *
240 	 *     MT safe.
241 	 */
242 	public bool isPassthrough()
243 	{
244 		return gst_base_transform_is_passthrough(gstBaseTransform) != 0;
245 	}
246 
247 	/**
248 	 * Queries if the transform will handle QoS.
249 	 *
250 	 * Returns: %TRUE if QoS is enabled.
251 	 *
252 	 *     MT safe.
253 	 */
254 	public bool isQosEnabled()
255 	{
256 		return gst_base_transform_is_qos_enabled(gstBaseTransform) != 0;
257 	}
258 
259 	/**
260 	 * Instructs @trans to request renegotiation upstream. This function is
261 	 * typically called after properties on the transform were set that
262 	 * influence the input format.
263 	 */
264 	public void reconfigureSink()
265 	{
266 		gst_base_transform_reconfigure_sink(gstBaseTransform);
267 	}
268 
269 	/**
270 	 * Instructs @trans to renegotiate a new downstream transform on the next
271 	 * buffer. This function is typically called after properties on the transform
272 	 * were set that influence the output format.
273 	 */
274 	public void reconfigureSrc()
275 	{
276 		gst_base_transform_reconfigure_src(gstBaseTransform);
277 	}
278 
279 	/**
280 	 * If @gap_aware is %FALSE (the default), output buffers will have the
281 	 * %GST_BUFFER_FLAG_GAP flag unset.
282 	 *
283 	 * If set to %TRUE, the element must handle output buffers with this flag set
284 	 * correctly, i.e. it can assume that the buffer contains neutral data but must
285 	 * unset the flag if the output is no neutral data.
286 	 *
287 	 * MT safe.
288 	 *
289 	 * Params:
290 	 *     gapAware = New state
291 	 */
292 	public void setGapAware(bool gapAware)
293 	{
294 		gst_base_transform_set_gap_aware(gstBaseTransform, gapAware);
295 	}
296 
297 	/**
298 	 * Determines whether a non-writable buffer will be copied before passing
299 	 * to the transform_ip function.
300 	 *
301 	 * * Always %TRUE if no transform function is implemented.
302 	 * * Always %FALSE if ONLY transform function is implemented.
303 	 *
304 	 * MT safe.
305 	 *
306 	 * Params:
307 	 *     inPlace = Boolean value indicating that we would like to operate
308 	 *         on in_place buffers.
309 	 */
310 	public void setInPlace(bool inPlace)
311 	{
312 		gst_base_transform_set_in_place(gstBaseTransform, inPlace);
313 	}
314 
315 	/**
316 	 * Set passthrough mode for this filter by default. This is mostly
317 	 * useful for filters that do not care about negotiation.
318 	 *
319 	 * Always %TRUE for filters which don't implement either a transform
320 	 * or transform_ip method.
321 	 *
322 	 * MT safe.
323 	 *
324 	 * Params:
325 	 *     passthrough = boolean indicating passthrough mode.
326 	 */
327 	public void setPassthrough(bool passthrough)
328 	{
329 		gst_base_transform_set_passthrough(gstBaseTransform, passthrough);
330 	}
331 
332 	/**
333 	 * If @prefer_passthrough is %TRUE (the default), @trans will check and
334 	 * prefer passthrough caps from the list of caps returned by the
335 	 * transform_caps vmethod.
336 	 *
337 	 * If set to %FALSE, the element must order the caps returned from the
338 	 * transform_caps function in such a way that the preferred format is
339 	 * first in the list. This can be interesting for transforms that can do
340 	 * passthrough transforms but prefer to do something else, like a
341 	 * capsfilter.
342 	 *
343 	 * MT safe.
344 	 *
345 	 * Params:
346 	 *     preferPassthrough = New state
347 	 *
348 	 * Since: 1.0.1
349 	 */
350 	public void setPreferPassthrough(bool preferPassthrough)
351 	{
352 		gst_base_transform_set_prefer_passthrough(gstBaseTransform, preferPassthrough);
353 	}
354 
355 	/**
356 	 * Enable or disable QoS handling in the transform.
357 	 *
358 	 * MT safe.
359 	 *
360 	 * Params:
361 	 *     enabled = new state
362 	 */
363 	public void setQosEnabled(bool enabled)
364 	{
365 		gst_base_transform_set_qos_enabled(gstBaseTransform, enabled);
366 	}
367 
368 	/**
369 	 * Set the QoS parameters in the transform. This function is called internally
370 	 * when a QOS event is received but subclasses can provide custom information
371 	 * when needed.
372 	 *
373 	 * MT safe.
374 	 *
375 	 * Params:
376 	 *     proportion = the proportion
377 	 *     diff = the diff against the clock
378 	 *     timestamp = the timestamp of the buffer generating the QoS expressed in
379 	 *         running_time.
380 	 */
381 	public void updateQos(double proportion, GstClockTimeDiff diff, GstClockTime timestamp)
382 	{
383 		gst_base_transform_update_qos(gstBaseTransform, proportion, diff, timestamp);
384 	}
385 
386 	/**
387 	 * Updates the srcpad caps and send the caps downstream. This function
388 	 * can be used by subclasses when they have already negotiated their caps
389 	 * but found a change in them (or computed new informations). This way,
390 	 * they can notify downstream about that change without loosing any
391 	 * buffer.
392 	 *
393 	 * Params:
394 	 *     updatedCaps = An updated version of the srcpad caps to be pushed
395 	 *         downstream
396 	 *
397 	 * Returns: %TRUE if the caps could be send downstream %FALSE otherwise
398 	 *
399 	 * Since: 1.6
400 	 */
401 	public bool updateSrcCaps(Caps updatedCaps)
402 	{
403 		return gst_base_transform_update_src_caps(gstBaseTransform, (updatedCaps is null) ? null : updatedCaps.getCapsStruct()) != 0;
404 	}
405 }