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 to know the memory @allocator
181 	 * used by the base class and its @params.
182 	 *
183 	 * Unref the @allocator after use it.
184 	 *
185 	 * Params:
186 	 *     allocator = the #GstAllocator
187 	 *         used
188 	 *     params = the
189 	 *         #GstAllocationParams of @allocator
190 	 */
191 	public void getAllocator(out Allocator allocator, out AllocationParams params)
192 	{
193 		GstAllocator* outallocator = null;
194 		GstAllocationParams* outparams = sliceNew!GstAllocationParams();
195 
196 		gst_base_transform_get_allocator(gstBaseTransform, &outallocator, outparams);
197 
198 		allocator = ObjectG.getDObject!(Allocator)(outallocator);
199 		params = ObjectG.getDObject!(AllocationParams)(outparams, true);
200 	}
201 
202 	/**
203 	 * Returns: the instance of the #GstBufferPool used
204 	 *     by @trans; free it after use it
205 	 */
206 	public BufferPool getBufferPool()
207 	{
208 		auto p = gst_base_transform_get_buffer_pool(gstBaseTransform);
209 
210 		if(p is null)
211 		{
212 			return null;
213 		}
214 
215 		return ObjectG.getDObject!(BufferPool)(cast(GstBufferPool*) p, true);
216 	}
217 
218 	/**
219 	 * See if @trans is configured as a in_place transform.
220 	 *
221 	 * Returns: %TRUE is the transform is configured in in_place mode.
222 	 *
223 	 *     MT safe.
224 	 */
225 	public bool isInPlace()
226 	{
227 		return gst_base_transform_is_in_place(gstBaseTransform) != 0;
228 	}
229 
230 	/**
231 	 * See if @trans is configured as a passthrough transform.
232 	 *
233 	 * Returns: %TRUE is the transform is configured in passthrough mode.
234 	 *
235 	 *     MT safe.
236 	 */
237 	public bool isPassthrough()
238 	{
239 		return gst_base_transform_is_passthrough(gstBaseTransform) != 0;
240 	}
241 
242 	/**
243 	 * Queries if the transform will handle QoS.
244 	 *
245 	 * Returns: %TRUE if QoS is enabled.
246 	 *
247 	 *     MT safe.
248 	 */
249 	public bool isQosEnabled()
250 	{
251 		return gst_base_transform_is_qos_enabled(gstBaseTransform) != 0;
252 	}
253 
254 	/**
255 	 * Instructs @trans to request renegotiation upstream. This function is
256 	 * typically called after properties on the transform were set that
257 	 * influence the input format.
258 	 */
259 	public void reconfigureSink()
260 	{
261 		gst_base_transform_reconfigure_sink(gstBaseTransform);
262 	}
263 
264 	/**
265 	 * Instructs @trans to renegotiate a new downstream transform on the next
266 	 * buffer. This function is typically called after properties on the transform
267 	 * were set that influence the output format.
268 	 */
269 	public void reconfigureSrc()
270 	{
271 		gst_base_transform_reconfigure_src(gstBaseTransform);
272 	}
273 
274 	/**
275 	 * If @gap_aware is %FALSE (the default), output buffers will have the
276 	 * %GST_BUFFER_FLAG_GAP flag unset.
277 	 *
278 	 * If set to %TRUE, the element must handle output buffers with this flag set
279 	 * correctly, i.e. it can assume that the buffer contains neutral data but must
280 	 * unset the flag if the output is no neutral data.
281 	 *
282 	 * MT safe.
283 	 *
284 	 * Params:
285 	 *     gapAware = New state
286 	 */
287 	public void setGapAware(bool gapAware)
288 	{
289 		gst_base_transform_set_gap_aware(gstBaseTransform, gapAware);
290 	}
291 
292 	/**
293 	 * Determines whether a non-writable buffer will be copied before passing
294 	 * to the transform_ip function.
295 	 *
296 	 * * Always %TRUE if no transform function is implemented.
297 	 * * Always %FALSE if ONLY transform function is implemented.
298 	 *
299 	 * MT safe.
300 	 *
301 	 * Params:
302 	 *     inPlace = Boolean value indicating that we would like to operate
303 	 *         on in_place buffers.
304 	 */
305 	public void setInPlace(bool inPlace)
306 	{
307 		gst_base_transform_set_in_place(gstBaseTransform, inPlace);
308 	}
309 
310 	/**
311 	 * Set passthrough mode for this filter by default. This is mostly
312 	 * useful for filters that do not care about negotiation.
313 	 *
314 	 * Always %TRUE for filters which don't implement either a transform
315 	 * or transform_ip method.
316 	 *
317 	 * MT safe.
318 	 *
319 	 * Params:
320 	 *     passthrough = boolean indicating passthrough mode.
321 	 */
322 	public void setPassthrough(bool passthrough)
323 	{
324 		gst_base_transform_set_passthrough(gstBaseTransform, passthrough);
325 	}
326 
327 	/**
328 	 * If @prefer_passthrough is %TRUE (the default), @trans will check and
329 	 * prefer passthrough caps from the list of caps returned by the
330 	 * transform_caps vmethod.
331 	 *
332 	 * If set to %FALSE, the element must order the caps returned from the
333 	 * transform_caps function in such a way that the preferred format is
334 	 * first in the list. This can be interesting for transforms that can do
335 	 * passthrough transforms but prefer to do something else, like a
336 	 * capsfilter.
337 	 *
338 	 * MT safe.
339 	 *
340 	 * Params:
341 	 *     preferPassthrough = New state
342 	 *
343 	 * Since: 1.0.1
344 	 */
345 	public void setPreferPassthrough(bool preferPassthrough)
346 	{
347 		gst_base_transform_set_prefer_passthrough(gstBaseTransform, preferPassthrough);
348 	}
349 
350 	/**
351 	 * Enable or disable QoS handling in the transform.
352 	 *
353 	 * MT safe.
354 	 *
355 	 * Params:
356 	 *     enabled = new state
357 	 */
358 	public void setQosEnabled(bool enabled)
359 	{
360 		gst_base_transform_set_qos_enabled(gstBaseTransform, enabled);
361 	}
362 
363 	/**
364 	 * Set the QoS parameters in the transform. This function is called internally
365 	 * when a QOS event is received but subclasses can provide custom information
366 	 * when needed.
367 	 *
368 	 * MT safe.
369 	 *
370 	 * Params:
371 	 *     proportion = the proportion
372 	 *     diff = the diff against the clock
373 	 *     timestamp = the timestamp of the buffer generating the QoS expressed in
374 	 *         running_time.
375 	 */
376 	public void updateQos(double proportion, GstClockTimeDiff diff, GstClockTime timestamp)
377 	{
378 		gst_base_transform_update_qos(gstBaseTransform, proportion, diff, timestamp);
379 	}
380 
381 	/**
382 	 * Updates the srcpad caps and send the caps downstream. This function
383 	 * can be used by subclasses when they have already negotiated their caps
384 	 * but found a change in them (or computed new information). This way,
385 	 * they can notify downstream about that change without losing any
386 	 * buffer.
387 	 *
388 	 * Params:
389 	 *     updatedCaps = An updated version of the srcpad caps to be pushed
390 	 *         downstream
391 	 *
392 	 * Returns: %TRUE if the caps could be send downstream %FALSE otherwise
393 	 *
394 	 * Since: 1.6
395 	 */
396 	public bool updateSrcCaps(Caps updatedCaps)
397 	{
398 		return gst_base_transform_update_src_caps(gstBaseTransform, (updatedCaps is null) ? null : updatedCaps.getCapsStruct()) != 0;
399 	}
400 }