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