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.app.AppSink;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gst.app.c.functions;
30 public  import gst.app.c.types;
31 private import gst.base.BaseSink;
32 private import gstreamer.Caps;
33 private import gstreamer.Sample;
34 private import gstreamer.URIHandlerIF;
35 private import gstreamer.URIHandlerT;
36 private import std.algorithm;
37 
38 
39 /**
40  * Appsink is a sink plugin that supports many different methods for making
41  * the application get a handle on the GStreamer data in a pipeline. Unlike
42  * most GStreamer elements, Appsink provides external API functions.
43  * 
44  * appsink can be used by linking to the gstappsink.h header file to access the
45  * methods or by using the appsink action signals and properties.
46  * 
47  * The normal way of retrieving samples from appsink is by using the
48  * gst_app_sink_pull_sample() and gst_app_sink_pull_preroll() methods.
49  * These methods block until a sample becomes available in the sink or when the
50  * sink is shut down or reaches EOS. There are also timed variants of these
51  * methods, gst_app_sink_try_pull_sample() and gst_app_sink_try_pull_preroll(),
52  * which accept a timeout parameter to limit the amount of time to wait.
53  * 
54  * Appsink will internally use a queue to collect buffers from the streaming
55  * thread. If the application is not pulling samples fast enough, this queue
56  * will consume a lot of memory over time. The "max-buffers" property can be
57  * used to limit the queue size. The "drop" property controls whether the
58  * streaming thread blocks or if older buffers are dropped when the maximum
59  * queue size is reached. Note that blocking the streaming thread can negatively
60  * affect real-time performance and should be avoided.
61  * 
62  * If a blocking behaviour is not desirable, setting the "emit-signals" property
63  * to %TRUE will make appsink emit the "new-sample" and "new-preroll" signals
64  * when a sample can be pulled without blocking.
65  * 
66  * The "caps" property on appsink can be used to control the formats that
67  * appsink can receive. This property can contain non-fixed caps, the format of
68  * the pulled samples can be obtained by getting the sample caps.
69  * 
70  * If one of the pull-preroll or pull-sample methods return %NULL, the appsink
71  * is stopped or in the EOS state. You can check for the EOS state with the
72  * "eos" property or with the gst_app_sink_is_eos() method.
73  * 
74  * The eos signal can also be used to be informed when the EOS state is reached
75  * to avoid polling.
76  */
77 public class AppSink : BaseSink, URIHandlerIF
78 {
79 	/** the main Gtk struct */
80 	protected GstAppSink* gstAppSink;
81 
82 	/** Get the main Gtk struct */
83 	public GstAppSink* getAppSinkStruct(bool transferOwnership = false)
84 	{
85 		if (transferOwnership)
86 			ownedRef = false;
87 		return gstAppSink;
88 	}
89 
90 	/** the main Gtk struct as a void* */
91 	protected override void* getStruct()
92 	{
93 		return cast(void*)gstAppSink;
94 	}
95 
96 	/**
97 	 * Sets our main struct and passes it to the parent class.
98 	 */
99 	public this (GstAppSink* gstAppSink, bool ownedRef = false)
100 	{
101 		this.gstAppSink = gstAppSink;
102 		super(cast(GstBaseSink*)gstAppSink, ownedRef);
103 	}
104 
105 	// add the URIHandler capabilities
106 	mixin URIHandlerT!(GstAppSink);
107 
108 
109 	/** */
110 	public static GType getType()
111 	{
112 		return gst_app_sink_get_type();
113 	}
114 
115 	/**
116 	 * Check if @appsink supports buffer lists.
117 	 *
118 	 * Returns: %TRUE if @appsink supports buffer lists.
119 	 *
120 	 * Since: 1.12
121 	 */
122 	public bool getBufferListSupport()
123 	{
124 		return gst_app_sink_get_buffer_list_support(gstAppSink) != 0;
125 	}
126 
127 	/**
128 	 * Get the configured caps on @appsink.
129 	 *
130 	 * Returns: the #GstCaps accepted by the sink. gst_caps_unref() after usage.
131 	 */
132 	public Caps getCaps()
133 	{
134 		auto p = gst_app_sink_get_caps(gstAppSink);
135 
136 		if(p is null)
137 		{
138 			return null;
139 		}
140 
141 		return ObjectG.getDObject!(Caps)(cast(GstCaps*) p, true);
142 	}
143 
144 	/**
145 	 * Check if @appsink will drop old buffers when the maximum amount of queued
146 	 * buffers is reached.
147 	 *
148 	 * Returns: %TRUE if @appsink is dropping old buffers when the queue is
149 	 *     filled.
150 	 */
151 	public bool getDrop()
152 	{
153 		return gst_app_sink_get_drop(gstAppSink) != 0;
154 	}
155 
156 	/**
157 	 * Check if appsink will emit the "new-preroll" and "new-sample" signals.
158 	 *
159 	 * Returns: %TRUE if @appsink is emiting the "new-preroll" and "new-sample"
160 	 *     signals.
161 	 */
162 	public bool getEmitSignals()
163 	{
164 		return gst_app_sink_get_emit_signals(gstAppSink) != 0;
165 	}
166 
167 	/**
168 	 * Get the maximum amount of buffers that can be queued in @appsink.
169 	 *
170 	 * Returns: The maximum amount of buffers that can be queued.
171 	 */
172 	public uint getMaxBuffers()
173 	{
174 		return gst_app_sink_get_max_buffers(gstAppSink);
175 	}
176 
177 	/**
178 	 * Check if @appsink will wait for all buffers to be consumed when an EOS is
179 	 * received.
180 	 *
181 	 * Returns: %TRUE if @appsink will wait for all buffers to be consumed when an
182 	 *     EOS is received.
183 	 */
184 	public bool getWaitOnEos()
185 	{
186 		return gst_app_sink_get_wait_on_eos(gstAppSink) != 0;
187 	}
188 
189 	/**
190 	 * Check if @appsink is EOS, which is when no more samples can be pulled because
191 	 * an EOS event was received.
192 	 *
193 	 * This function also returns %TRUE when the appsink is not in the PAUSED or
194 	 * PLAYING state.
195 	 *
196 	 * Returns: %TRUE if no more samples can be pulled and the appsink is EOS.
197 	 */
198 	public bool isEos()
199 	{
200 		return gst_app_sink_is_eos(gstAppSink) != 0;
201 	}
202 
203 	/**
204 	 * Get the last preroll sample in @appsink. This was the sample that caused the
205 	 * appsink to preroll in the PAUSED state.
206 	 *
207 	 * This function is typically used when dealing with a pipeline in the PAUSED
208 	 * state. Calling this function after doing a seek will give the sample right
209 	 * after the seek position.
210 	 *
211 	 * Calling this function will clear the internal reference to the preroll
212 	 * buffer.
213 	 *
214 	 * Note that the preroll sample will also be returned as the first sample
215 	 * when calling gst_app_sink_pull_sample().
216 	 *
217 	 * If an EOS event was received before any buffers, this function returns
218 	 * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
219 	 *
220 	 * This function blocks until a preroll sample or EOS is received or the appsink
221 	 * element is set to the READY/NULL state.
222 	 *
223 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS.
224 	 *     Call gst_sample_unref() after usage.
225 	 */
226 	public Sample pullPreroll()
227 	{
228 		auto p = gst_app_sink_pull_preroll(gstAppSink);
229 
230 		if(p is null)
231 		{
232 			return null;
233 		}
234 
235 		return ObjectG.getDObject!(Sample)(cast(GstSample*) p, true);
236 	}
237 
238 	/**
239 	 * This function blocks until a sample or EOS becomes available or the appsink
240 	 * element is set to the READY/NULL state.
241 	 *
242 	 * This function will only return samples when the appsink is in the PLAYING
243 	 * state. All rendered buffers will be put in a queue so that the application
244 	 * can pull samples at its own rate. Note that when the application does not
245 	 * pull samples fast enough, the queued buffers could consume a lot of memory,
246 	 * especially when dealing with raw video frames.
247 	 *
248 	 * If an EOS event was received before any buffers, this function returns
249 	 * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
250 	 *
251 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS.
252 	 *     Call gst_sample_unref() after usage.
253 	 */
254 	public Sample pullSample()
255 	{
256 		auto p = gst_app_sink_pull_sample(gstAppSink);
257 
258 		if(p is null)
259 		{
260 			return null;
261 		}
262 
263 		return ObjectG.getDObject!(Sample)(cast(GstSample*) p, true);
264 	}
265 
266 	/**
267 	 * Instruct @appsink to enable or disable buffer list support.
268 	 *
269 	 * For backwards-compatibility reasons applications need to opt in
270 	 * to indicate that they will be able to handle buffer lists.
271 	 *
272 	 * Params:
273 	 *     enableLists = enable or disable buffer list support
274 	 *
275 	 * Since: 1.12
276 	 */
277 	public void setBufferListSupport(bool enableLists)
278 	{
279 		gst_app_sink_set_buffer_list_support(gstAppSink, enableLists);
280 	}
281 
282 	/**
283 	 * Set callbacks which will be executed for each new preroll, new sample and eos.
284 	 * This is an alternative to using the signals, it has lower overhead and is thus
285 	 * less expensive, but also less flexible.
286 	 *
287 	 * If callbacks are installed, no signals will be emitted for performance
288 	 * reasons.
289 	 *
290 	 * Params:
291 	 *     callbacks = the callbacks
292 	 *     userData = a user_data argument for the callbacks
293 	 *     notify = a destroy notify function
294 	 */
295 	public void setCallbacks(GstAppSinkCallbacks* callbacks, void* userData, GDestroyNotify notify)
296 	{
297 		gst_app_sink_set_callbacks(gstAppSink, callbacks, userData, notify);
298 	}
299 
300 	/**
301 	 * Set the capabilities on the appsink element.  This function takes
302 	 * a copy of the caps structure. After calling this method, the sink will only
303 	 * accept caps that match @caps. If @caps is non-fixed, or incomplete,
304 	 * you must check the caps on the samples to get the actual used caps.
305 	 *
306 	 * Params:
307 	 *     caps = caps to set
308 	 */
309 	public void setCaps(Caps caps)
310 	{
311 		gst_app_sink_set_caps(gstAppSink, (caps is null) ? null : caps.getCapsStruct());
312 	}
313 
314 	/**
315 	 * Instruct @appsink to drop old buffers when the maximum amount of queued
316 	 * buffers is reached.
317 	 *
318 	 * Params:
319 	 *     drop = the new state
320 	 */
321 	public void setDrop(bool drop)
322 	{
323 		gst_app_sink_set_drop(gstAppSink, drop);
324 	}
325 
326 	/**
327 	 * Make appsink emit the "new-preroll" and "new-sample" signals. This option is
328 	 * by default disabled because signal emission is expensive and unneeded when
329 	 * the application prefers to operate in pull mode.
330 	 *
331 	 * Params:
332 	 *     emit = the new state
333 	 */
334 	public void setEmitSignals(bool emit)
335 	{
336 		gst_app_sink_set_emit_signals(gstAppSink, emit);
337 	}
338 
339 	/**
340 	 * Set the maximum amount of buffers that can be queued in @appsink. After this
341 	 * amount of buffers are queued in appsink, any more buffers will block upstream
342 	 * elements until a sample is pulled from @appsink.
343 	 *
344 	 * Params:
345 	 *     max = the maximum number of buffers to queue
346 	 */
347 	public void setMaxBuffers(uint max)
348 	{
349 		gst_app_sink_set_max_buffers(gstAppSink, max);
350 	}
351 
352 	/**
353 	 * Instruct @appsink to wait for all buffers to be consumed when an EOS is received.
354 	 *
355 	 * Params:
356 	 *     wait = the new state
357 	 */
358 	public void setWaitOnEos(bool wait)
359 	{
360 		gst_app_sink_set_wait_on_eos(gstAppSink, wait);
361 	}
362 
363 	/**
364 	 * Get the last preroll sample in @appsink. This was the sample that caused the
365 	 * appsink to preroll in the PAUSED state.
366 	 *
367 	 * This function is typically used when dealing with a pipeline in the PAUSED
368 	 * state. Calling this function after doing a seek will give the sample right
369 	 * after the seek position.
370 	 *
371 	 * Calling this function will clear the internal reference to the preroll
372 	 * buffer.
373 	 *
374 	 * Note that the preroll sample will also be returned as the first sample
375 	 * when calling gst_app_sink_pull_sample().
376 	 *
377 	 * If an EOS event was received before any buffers or the timeout expires,
378 	 * this function returns %NULL. Use gst_app_sink_is_eos () to check for the EOS
379 	 * condition.
380 	 *
381 	 * This function blocks until a preroll sample or EOS is received, the appsink
382 	 * element is set to the READY/NULL state, or the timeout expires.
383 	 *
384 	 * Params:
385 	 *     timeout = the maximum amount of time to wait for the preroll sample
386 	 *
387 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
388 	 *     Call gst_sample_unref() after usage.
389 	 *
390 	 * Since: 1.10
391 	 */
392 	public Sample tryPullPreroll(GstClockTime timeout)
393 	{
394 		auto p = gst_app_sink_try_pull_preroll(gstAppSink, timeout);
395 
396 		if(p is null)
397 		{
398 			return null;
399 		}
400 
401 		return ObjectG.getDObject!(Sample)(cast(GstSample*) p, true);
402 	}
403 
404 	/**
405 	 * This function blocks until a sample or EOS becomes available or the appsink
406 	 * element is set to the READY/NULL state or the timeout expires.
407 	 *
408 	 * This function will only return samples when the appsink is in the PLAYING
409 	 * state. All rendered buffers will be put in a queue so that the application
410 	 * can pull samples at its own rate. Note that when the application does not
411 	 * pull samples fast enough, the queued buffers could consume a lot of memory,
412 	 * especially when dealing with raw video frames.
413 	 *
414 	 * If an EOS event was received before any buffers or the timeout expires,
415 	 * this function returns %NULL. Use gst_app_sink_is_eos () to check for the EOS
416 	 * condition.
417 	 *
418 	 * Params:
419 	 *     timeout = the maximum amount of time to wait for a sample
420 	 *
421 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
422 	 *     Call gst_sample_unref() after usage.
423 	 *
424 	 * Since: 1.10
425 	 */
426 	public Sample tryPullSample(GstClockTime timeout)
427 	{
428 		auto p = gst_app_sink_try_pull_sample(gstAppSink, timeout);
429 
430 		if(p is null)
431 		{
432 			return null;
433 		}
434 
435 		return ObjectG.getDObject!(Sample)(cast(GstSample*) p, true);
436 	}
437 
438 	/**
439 	 * Signal that the end-of-stream has been reached. This signal is emitted from
440 	 * the streaming thread.
441 	 */
442 	gulong addOnEos(void delegate(AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
443 	{
444 		return Signals.connect(this, "eos", dlg, connectFlags ^ ConnectFlags.SWAPPED);
445 	}
446 
447 	/**
448 	 * Signal that a new preroll sample is available.
449 	 *
450 	 * This signal is emitted from the streaming thread and only when the
451 	 * "emit-signals" property is %TRUE.
452 	 *
453 	 * The new preroll sample can be retrieved with the "pull-preroll" action
454 	 * signal or gst_app_sink_pull_preroll() either from this signal callback
455 	 * or from any other thread.
456 	 *
457 	 * Note that this signal is only emitted when the "emit-signals" property is
458 	 * set to %TRUE, which it is not by default for performance reasons.
459 	 */
460 	gulong addOnNewPreroll(GstFlowReturn delegate(AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
461 	{
462 		return Signals.connect(this, "new-preroll", dlg, connectFlags ^ ConnectFlags.SWAPPED);
463 	}
464 
465 	/**
466 	 * Signal that a new sample is available.
467 	 *
468 	 * This signal is emitted from the streaming thread and only when the
469 	 * "emit-signals" property is %TRUE.
470 	 *
471 	 * The new sample can be retrieved with the "pull-sample" action
472 	 * signal or gst_app_sink_pull_sample() either from this signal callback
473 	 * or from any other thread.
474 	 *
475 	 * Note that this signal is only emitted when the "emit-signals" property is
476 	 * set to %TRUE, which it is not by default for performance reasons.
477 	 */
478 	gulong addOnNewSample(GstFlowReturn delegate(AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
479 	{
480 		return Signals.connect(this, "new-sample", dlg, connectFlags ^ ConnectFlags.SWAPPED);
481 	}
482 
483 	/**
484 	 * Get the last preroll sample in @appsink. This was the sample that caused the
485 	 * appsink to preroll in the PAUSED state.
486 	 *
487 	 * This function is typically used when dealing with a pipeline in the PAUSED
488 	 * state. Calling this function after doing a seek will give the sample right
489 	 * after the seek position.
490 	 *
491 	 * Calling this function will clear the internal reference to the preroll
492 	 * buffer.
493 	 *
494 	 * Note that the preroll sample will also be returned as the first sample
495 	 * when calling gst_app_sink_pull_sample() or the "pull-sample" action signal.
496 	 *
497 	 * If an EOS event was received before any buffers, this function returns
498 	 * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
499 	 *
500 	 * This function blocks until a preroll sample or EOS is received or the appsink
501 	 * element is set to the READY/NULL state.
502 	 *
503 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS.
504 	 */
505 	gulong addOnPullPreroll(Sample delegate(AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
506 	{
507 		return Signals.connect(this, "pull-preroll", dlg, connectFlags ^ ConnectFlags.SWAPPED);
508 	}
509 
510 	/**
511 	 * This function blocks until a sample or EOS becomes available or the appsink
512 	 * element is set to the READY/NULL state.
513 	 *
514 	 * This function will only return samples when the appsink is in the PLAYING
515 	 * state. All rendered samples will be put in a queue so that the application
516 	 * can pull samples at its own rate.
517 	 *
518 	 * Note that when the application does not pull samples fast enough, the
519 	 * queued samples could consume a lot of memory, especially when dealing with
520 	 * raw video frames. It's possible to control the behaviour of the queue with
521 	 * the "drop" and "max-buffers" properties.
522 	 *
523 	 * If an EOS event was received before any buffers, this function returns
524 	 * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
525 	 *
526 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS.
527 	 */
528 	gulong addOnPullSample(Sample delegate(AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
529 	{
530 		return Signals.connect(this, "pull-sample", dlg, connectFlags ^ ConnectFlags.SWAPPED);
531 	}
532 
533 	/**
534 	 * Get the last preroll sample in @appsink. This was the sample that caused the
535 	 * appsink to preroll in the PAUSED state.
536 	 *
537 	 * This function is typically used when dealing with a pipeline in the PAUSED
538 	 * state. Calling this function after doing a seek will give the sample right
539 	 * after the seek position.
540 	 *
541 	 * Calling this function will clear the internal reference to the preroll
542 	 * buffer.
543 	 *
544 	 * Note that the preroll sample will also be returned as the first sample
545 	 * when calling gst_app_sink_pull_sample() or the "pull-sample" action signal.
546 	 *
547 	 * If an EOS event was received before any buffers or the timeout expires,
548 	 * this function returns %NULL. Use gst_app_sink_is_eos () to check for the EOS
549 	 * condition.
550 	 *
551 	 * This function blocks until a preroll sample or EOS is received, the appsink
552 	 * element is set to the READY/NULL state, or the timeout expires.
553 	 *
554 	 * Params:
555 	 *     timeout = the maximum amount of time to wait for the preroll sample
556 	 *
557 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
558 	 *
559 	 * Since: 1.10
560 	 */
561 	gulong addOnTryPullPreroll(Sample delegate(ulong, AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
562 	{
563 		return Signals.connect(this, "try-pull-preroll", dlg, connectFlags ^ ConnectFlags.SWAPPED);
564 	}
565 
566 	/**
567 	 * This function blocks until a sample or EOS becomes available or the appsink
568 	 * element is set to the READY/NULL state or the timeout expires.
569 	 *
570 	 * This function will only return samples when the appsink is in the PLAYING
571 	 * state. All rendered samples will be put in a queue so that the application
572 	 * can pull samples at its own rate.
573 	 *
574 	 * Note that when the application does not pull samples fast enough, the
575 	 * queued samples could consume a lot of memory, especially when dealing with
576 	 * raw video frames. It's possible to control the behaviour of the queue with
577 	 * the "drop" and "max-buffers" properties.
578 	 *
579 	 * If an EOS event was received before any buffers or the timeout expires,
580 	 * this function returns %NULL. Use gst_app_sink_is_eos () to check
581 	 * for the EOS condition.
582 	 *
583 	 * Params:
584 	 *     timeout = the maximum amount of time to wait for a sample
585 	 *
586 	 * Returns: a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
587 	 *
588 	 * Since: 1.10
589 	 */
590 	gulong addOnTryPullSample(Sample delegate(ulong, AppSink) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
591 	{
592 		return Signals.connect(this, "try-pull-sample", dlg, connectFlags ^ ConnectFlags.SWAPPED);
593 	}
594 }