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