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.CollectPads;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gst.base.c.functions;
30 public  import gst.base.c.types;
31 private import gstreamer.Buffer;
32 private import gstreamer.Event;
33 private import gstreamer.ObjectGst;
34 private import gstreamer.Pad;
35 private import gstreamer.Query;
36 
37 
38 /**
39  * Manages a set of pads that operate in collect mode. This means that control
40  * is given to the manager of this object when all pads have data.
41  * 
42  * * Collectpads are created with gst_collect_pads_new(). A callback should then
43  * be installed with gst_collect_pads_set_function ().
44  * 
45  * * Pads are added to the collection with gst_collect_pads_add_pad()/
46  * gst_collect_pads_remove_pad(). The pad has to be a sinkpad. When added,
47  * the chain, event and query functions of the pad are overridden. The
48  * element_private of the pad is used to store private information for the
49  * collectpads.
50  * 
51  * * For each pad, data is queued in the _chain function or by
52  * performing a pull_range.
53  * 
54  * * When data is queued on all pads in waiting mode, the callback function is called.
55  * 
56  * * Data can be dequeued from the pad with the gst_collect_pads_pop() method.
57  * One can peek at the data with the gst_collect_pads_peek() function.
58  * These functions will return %NULL if the pad received an EOS event. When all
59  * pads return %NULL from a gst_collect_pads_peek(), the element can emit an EOS
60  * event itself.
61  * 
62  * * Data can also be dequeued in byte units using the gst_collect_pads_available(),
63  * gst_collect_pads_read_buffer() and gst_collect_pads_flush() calls.
64  * 
65  * * Elements should call gst_collect_pads_start() and gst_collect_pads_stop() in
66  * their state change functions to start and stop the processing of the collectpads.
67  * The gst_collect_pads_stop() call should be called before calling the parent
68  * element state change function in the PAUSED_TO_READY state change to ensure
69  * no pad is blocked and the element can finish streaming.
70  * 
71  * * gst_collect_pads_set_waiting() sets a pad to waiting or non-waiting mode.
72  * CollectPads element is not waiting for data to be collected on non-waiting pads.
73  * Thus these pads may but need not have data when the callback is called.
74  * All pads are in waiting mode by default.
75  */
76 public class CollectPads : ObjectGst
77 {
78 	/** the main Gtk struct */
79 	protected GstCollectPads* gstCollectPads;
80 
81 	/** Get the main Gtk struct */
82 	public GstCollectPads* getCollectPadsStruct(bool transferOwnership = false)
83 	{
84 		if (transferOwnership)
85 			ownedRef = false;
86 		return gstCollectPads;
87 	}
88 
89 	/** the main Gtk struct as a void* */
90 	protected override void* getStruct()
91 	{
92 		return cast(void*)gstCollectPads;
93 	}
94 
95 	/**
96 	 * Sets our main struct and passes it to the parent class.
97 	 */
98 	public this (GstCollectPads* gstCollectPads, bool ownedRef = false)
99 	{
100 		this.gstCollectPads = gstCollectPads;
101 		super(cast(GstObject*)gstCollectPads, ownedRef);
102 	}
103 
104 
105 	/** */
106 	public static GType getType()
107 	{
108 		return gst_collect_pads_get_type();
109 	}
110 
111 	/**
112 	 * Create a new instance of #GstCollectPads.
113 	 *
114 	 * MT safe.
115 	 *
116 	 * Returns: a new #GstCollectPads, or %NULL in case of an error.
117 	 *
118 	 * Throws: ConstructionException GTK+ fails to create the object.
119 	 */
120 	public this()
121 	{
122 		auto __p = gst_collect_pads_new();
123 
124 		if(__p is null)
125 		{
126 			throw new ConstructionException("null returned by new");
127 		}
128 
129 		this(cast(GstCollectPads*) __p, true);
130 	}
131 
132 	/**
133 	 * Add a pad to the collection of collect pads. The pad has to be
134 	 * a sinkpad. The refcount of the pad is incremented. Use
135 	 * gst_collect_pads_remove_pad() to remove the pad from the collection
136 	 * again.
137 	 *
138 	 * You specify a size for the returned #GstCollectData structure
139 	 * so that you can use it to store additional information.
140 	 *
141 	 * You can also specify a #GstCollectDataDestroyNotify that will be called
142 	 * just before the #GstCollectData structure is freed. It is passed the
143 	 * pointer to the structure and should free any custom memory and resources
144 	 * allocated for it.
145 	 *
146 	 * Keeping a pad locked in waiting state is only relevant when using
147 	 * the default collection algorithm (providing the oldest buffer).
148 	 * It ensures a buffer must be available on this pad for a collection
149 	 * to take place.  This is of typical use to a muxer element where
150 	 * non-subtitle streams should always be in waiting state,
151 	 * e.g. to assure that caps information is available on all these streams
152 	 * when initial headers have to be written.
153 	 *
154 	 * The pad will be automatically activated in push mode when @pads is
155 	 * started.
156 	 *
157 	 * MT safe.
158 	 *
159 	 * Params:
160 	 *     pad = the pad to add
161 	 *     size = the size of the returned #GstCollectData structure
162 	 *     destroyNotify = function to be called before the returned
163 	 *         #GstCollectData structure is freed
164 	 *     lock = whether to lock this pad in usual waiting state
165 	 *
166 	 * Returns: a new #GstCollectData to identify the
167 	 *     new pad. Or %NULL if wrong parameters are supplied.
168 	 */
169 	public GstCollectData* addPad(Pad pad, uint size, GstCollectDataDestroyNotify destroyNotify, bool lock)
170 	{
171 		return gst_collect_pads_add_pad(gstCollectPads, (pad is null) ? null : pad.getPadStruct(), size, destroyNotify, lock);
172 	}
173 
174 	/**
175 	 * Query how much bytes can be read from each queued buffer. This means
176 	 * that the result of this call is the maximum number of bytes that can
177 	 * be read from each of the pads.
178 	 *
179 	 * This function should be called with @pads STREAM_LOCK held, such as
180 	 * in the callback.
181 	 *
182 	 * MT safe.
183 	 *
184 	 * Returns: The maximum number of bytes queued on all pads. This function
185 	 *     returns 0 if a pad has no queued buffer.
186 	 */
187 	public uint available()
188 	{
189 		return gst_collect_pads_available(gstCollectPads);
190 	}
191 
192 	/**
193 	 * Convenience clipping function that converts incoming buffer's timestamp
194 	 * to running time, or clips the buffer if outside configured segment.
195 	 *
196 	 * Since 1.6, this clipping function also sets the DTS parameter of the
197 	 * GstCollectData structure. This version of the running time DTS can be
198 	 * negative. G_MININT64 is used to indicate invalid value.
199 	 *
200 	 * Params:
201 	 *     cdata = collect data of corresponding pad
202 	 *     buf = buffer being clipped
203 	 *     outbuf = output buffer with running time, or NULL if clipped
204 	 *     userData = user data (unused)
205 	 */
206 	public GstFlowReturn clipRunningTime(GstCollectData* cdata, Buffer buf, out Buffer outbuf, void* userData)
207 	{
208 		GstBuffer* outoutbuf = null;
209 
210 		auto __p = gst_collect_pads_clip_running_time(gstCollectPads, cdata, (buf is null) ? null : buf.getBufferStruct(), &outoutbuf, userData);
211 
212 		outbuf = ObjectG.getDObject!(Buffer)(outoutbuf);
213 
214 		return __p;
215 	}
216 
217 	/**
218 	 * Default #GstCollectPads event handling that elements should always
219 	 * chain up to to ensure proper operation.  Element might however indicate
220 	 * event should not be forwarded downstream.
221 	 *
222 	 * Params:
223 	 *     data = collect data of corresponding pad
224 	 *     event = event being processed
225 	 *     discard = process but do not send event downstream
226 	 */
227 	public bool eventDefault(GstCollectData* data, Event event, bool discard)
228 	{
229 		return gst_collect_pads_event_default(gstCollectPads, data, (event is null) ? null : event.getEventStruct(), discard) != 0;
230 	}
231 
232 	/**
233 	 * Flush @size bytes from the pad @data.
234 	 *
235 	 * This function should be called with @pads STREAM_LOCK held, such as
236 	 * in the callback.
237 	 *
238 	 * MT safe.
239 	 *
240 	 * Params:
241 	 *     data = the data to use
242 	 *     size = the number of bytes to flush
243 	 *
244 	 * Returns: The number of bytes flushed This can be less than @size and
245 	 *     is 0 if the pad was end-of-stream.
246 	 */
247 	public uint flush(GstCollectData* data, uint size)
248 	{
249 		return gst_collect_pads_flush(gstCollectPads, data, size);
250 	}
251 
252 	/**
253 	 * Peek at the buffer currently queued in @data. This function
254 	 * should be called with the @pads STREAM_LOCK held, such as in the callback
255 	 * handler.
256 	 *
257 	 * MT safe.
258 	 *
259 	 * Params:
260 	 *     data = the data to use
261 	 *
262 	 * Returns: The buffer in @data or %NULL if no
263 	 *     buffer is queued. should unref the buffer after usage.
264 	 */
265 	public Buffer peek(GstCollectData* data)
266 	{
267 		auto __p = gst_collect_pads_peek(gstCollectPads, data);
268 
269 		if(__p is null)
270 		{
271 			return null;
272 		}
273 
274 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
275 	}
276 
277 	/**
278 	 * Pop the buffer currently queued in @data. This function
279 	 * should be called with the @pads STREAM_LOCK held, such as in the callback
280 	 * handler.
281 	 *
282 	 * MT safe.
283 	 *
284 	 * Params:
285 	 *     data = the data to use
286 	 *
287 	 * Returns: The buffer in @data or %NULL if no
288 	 *     buffer was queued. You should unref the buffer after usage.
289 	 */
290 	public Buffer pop(GstCollectData* data)
291 	{
292 		auto __p = gst_collect_pads_pop(gstCollectPads, data);
293 
294 		if(__p is null)
295 		{
296 			return null;
297 		}
298 
299 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
300 	}
301 
302 	/**
303 	 * Default #GstCollectPads query handling that elements should always
304 	 * chain up to to ensure proper operation.  Element might however indicate
305 	 * query should not be forwarded downstream.
306 	 *
307 	 * Params:
308 	 *     data = collect data of corresponding pad
309 	 *     query = query being processed
310 	 *     discard = process but do not send event downstream
311 	 */
312 	public bool queryDefault(GstCollectData* data, Query query, bool discard)
313 	{
314 		return gst_collect_pads_query_default(gstCollectPads, data, (query is null) ? null : query.getQueryStruct(), discard) != 0;
315 	}
316 
317 	/**
318 	 * Get a subbuffer of @size bytes from the given pad @data.
319 	 *
320 	 * This function should be called with @pads STREAM_LOCK held, such as in the
321 	 * callback.
322 	 *
323 	 * MT safe.
324 	 *
325 	 * Params:
326 	 *     data = the data to use
327 	 *     size = the number of bytes to read
328 	 *
329 	 * Returns: A sub buffer. The size of the buffer can
330 	 *     be less that requested. A return of %NULL signals that the pad is
331 	 *     end-of-stream. Unref the buffer after use.
332 	 */
333 	public Buffer readBuffer(GstCollectData* data, uint size)
334 	{
335 		auto __p = gst_collect_pads_read_buffer(gstCollectPads, data, size);
336 
337 		if(__p is null)
338 		{
339 			return null;
340 		}
341 
342 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
343 	}
344 
345 	/**
346 	 * Remove a pad from the collection of collect pads. This function will also
347 	 * free the #GstCollectData and all the resources that were allocated with
348 	 * gst_collect_pads_add_pad().
349 	 *
350 	 * The pad will be deactivated automatically when @pads is stopped.
351 	 *
352 	 * MT safe.
353 	 *
354 	 * Params:
355 	 *     pad = the pad to remove
356 	 *
357 	 * Returns: %TRUE if the pad could be removed.
358 	 */
359 	public bool removePad(Pad pad)
360 	{
361 		return gst_collect_pads_remove_pad(gstCollectPads, (pad is null) ? null : pad.getPadStruct()) != 0;
362 	}
363 
364 	/**
365 	 * Set the callback function and user data that will be called with
366 	 * the oldest buffer when all pads have been collected, or %NULL on EOS.
367 	 * If a buffer is passed, the callback owns a reference and must unref
368 	 * it.
369 	 *
370 	 * MT safe.
371 	 *
372 	 * Params:
373 	 *     func = the function to set
374 	 *     userData = user data passed to the function
375 	 */
376 	public void setBufferFunction(GstCollectPadsBufferFunction func, void* userData)
377 	{
378 		gst_collect_pads_set_buffer_function(gstCollectPads, func, userData);
379 	}
380 
381 	/**
382 	 * Install a clipping function that is called right after a buffer is received
383 	 * on a pad managed by @pads. See #GstCollectPadsClipFunction for more info.
384 	 *
385 	 * Params:
386 	 *     clipfunc = clip function to install
387 	 *     userData = user data to pass to @clip_func
388 	 */
389 	public void setClipFunction(GstCollectPadsClipFunction clipfunc, void* userData)
390 	{
391 		gst_collect_pads_set_clip_function(gstCollectPads, clipfunc, userData);
392 	}
393 
394 	/**
395 	 * Set the timestamp comparison function.
396 	 *
397 	 * MT safe.
398 	 *
399 	 * Params:
400 	 *     func = the function to set
401 	 *     userData = user data passed to the function
402 	 */
403 	public void setCompareFunction(GstCollectPadsCompareFunction func, void* userData)
404 	{
405 		gst_collect_pads_set_compare_function(gstCollectPads, func, userData);
406 	}
407 
408 	/**
409 	 * Set the event callback function and user data that will be called when
410 	 * collectpads has received an event originating from one of the collected
411 	 * pads.  If the event being processed is a serialized one, this callback is
412 	 * called with @pads STREAM_LOCK held, otherwise not.  As this lock should be
413 	 * held when calling a number of CollectPads functions, it should be acquired
414 	 * if so (unusually) needed.
415 	 *
416 	 * MT safe.
417 	 *
418 	 * Params:
419 	 *     func = the function to set
420 	 *     userData = user data passed to the function
421 	 */
422 	public void setEventFunction(GstCollectPadsEventFunction func, void* userData)
423 	{
424 		gst_collect_pads_set_event_function(gstCollectPads, func, userData);
425 	}
426 
427 	/**
428 	 * Install a flush function that is called when the internal
429 	 * state of all pads should be flushed as part of flushing seek
430 	 * handling. See #GstCollectPadsFlushFunction for more info.
431 	 *
432 	 * Params:
433 	 *     func = flush function to install
434 	 *     userData = user data to pass to @func
435 	 *
436 	 * Since: 1.4
437 	 */
438 	public void setFlushFunction(GstCollectPadsFlushFunction func, void* userData)
439 	{
440 		gst_collect_pads_set_flush_function(gstCollectPads, func, userData);
441 	}
442 
443 	/**
444 	 * Change the flushing state of all the pads in the collection. No pad
445 	 * is able to accept anymore data when @flushing is %TRUE. Calling this
446 	 * function with @flushing %FALSE makes @pads accept data again.
447 	 * Caller must ensure that downstream streaming (thread) is not blocked,
448 	 * e.g. by sending a FLUSH_START downstream.
449 	 *
450 	 * MT safe.
451 	 *
452 	 * Params:
453 	 *     flushing = desired state of the pads
454 	 */
455 	public void setFlushing(bool flushing)
456 	{
457 		gst_collect_pads_set_flushing(gstCollectPads, flushing);
458 	}
459 
460 	/**
461 	 * CollectPads provides a default collection algorithm that will determine
462 	 * the oldest buffer available on all of its pads, and then delegate
463 	 * to a configured callback.
464 	 * However, if circumstances are more complicated and/or more control
465 	 * is desired, this sets a callback that will be invoked instead when
466 	 * all the pads added to the collection have buffers queued.
467 	 * Evidently, this callback is not compatible with
468 	 * gst_collect_pads_set_buffer_function() callback.
469 	 * If this callback is set, the former will be unset.
470 	 *
471 	 * MT safe.
472 	 *
473 	 * Params:
474 	 *     func = the function to set
475 	 *     userData = user data passed to the function
476 	 */
477 	public void setFunction(GstCollectPadsFunction func, void* userData)
478 	{
479 		gst_collect_pads_set_function(gstCollectPads, func, userData);
480 	}
481 
482 	/**
483 	 * Set the query callback function and user data that will be called after
484 	 * collectpads has received a query originating from one of the collected
485 	 * pads.  If the query being processed is a serialized one, this callback is
486 	 * called with @pads STREAM_LOCK held, otherwise not.  As this lock should be
487 	 * held when calling a number of CollectPads functions, it should be acquired
488 	 * if so (unusually) needed.
489 	 *
490 	 * MT safe.
491 	 *
492 	 * Params:
493 	 *     func = the function to set
494 	 *     userData = user data passed to the function
495 	 */
496 	public void setQueryFunction(GstCollectPadsQueryFunction func, void* userData)
497 	{
498 		gst_collect_pads_set_query_function(gstCollectPads, func, userData);
499 	}
500 
501 	/**
502 	 * Sets a pad to waiting or non-waiting mode, if at least this pad
503 	 * has not been created with locked waiting state,
504 	 * in which case nothing happens.
505 	 *
506 	 * This function should be called with @pads STREAM_LOCK held, such as
507 	 * in the callback.
508 	 *
509 	 * MT safe.
510 	 *
511 	 * Params:
512 	 *     data = the data to use
513 	 *     waiting = boolean indicating whether this pad should operate
514 	 *         in waiting or non-waiting mode
515 	 */
516 	public void setWaiting(GstCollectData* data, bool waiting)
517 	{
518 		gst_collect_pads_set_waiting(gstCollectPads, data, waiting);
519 	}
520 
521 	/**
522 	 * Default #GstCollectPads event handling for the src pad of elements.
523 	 * Elements can chain up to this to let flushing seek event handling
524 	 * be done by #GstCollectPads.
525 	 *
526 	 * Params:
527 	 *     pad = src #GstPad that received the event
528 	 *     event = event being processed
529 	 *
530 	 * Since: 1.4
531 	 */
532 	public bool srcEventDefault(Pad pad, Event event)
533 	{
534 		return gst_collect_pads_src_event_default(gstCollectPads, (pad is null) ? null : pad.getPadStruct(), (event is null) ? null : event.getEventStruct()) != 0;
535 	}
536 
537 	/**
538 	 * Starts the processing of data in the collect_pads.
539 	 *
540 	 * MT safe.
541 	 */
542 	public void start()
543 	{
544 		gst_collect_pads_start(gstCollectPads);
545 	}
546 
547 	/**
548 	 * Stops the processing of data in the collect_pads. this function
549 	 * will also unblock any blocking operations.
550 	 *
551 	 * MT safe.
552 	 */
553 	public void stop()
554 	{
555 		gst_collect_pads_stop(gstCollectPads);
556 	}
557 
558 	/**
559 	 * Get a subbuffer of @size bytes from the given pad @data. Flushes the amount
560 	 * of read bytes.
561 	 *
562 	 * This function should be called with @pads STREAM_LOCK held, such as in the
563 	 * callback.
564 	 *
565 	 * MT safe.
566 	 *
567 	 * Params:
568 	 *     data = the data to use
569 	 *     size = the number of bytes to read
570 	 *
571 	 * Returns: A sub buffer. The size of the buffer can
572 	 *     be less that requested. A return of %NULL signals that the pad is
573 	 *     end-of-stream. Unref the buffer after use.
574 	 */
575 	public Buffer takeBuffer(GstCollectData* data, uint size)
576 	{
577 		auto __p = gst_collect_pads_take_buffer(gstCollectPads, data, size);
578 
579 		if(__p is null)
580 		{
581 			return null;
582 		}
583 
584 		return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) __p, true);
585 	}
586 }