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.BaseSink;
26 
27 private import gobject.ObjectG;
28 private import gst.base.c.functions;
29 public  import gst.base.c.types;
30 private import gstreamer.Element;
31 private import gstreamer.MiniObject;
32 private import gstreamer.Sample;
33 
34 
35 /**
36  * #GstBaseSink is the base class for sink elements in GStreamer, such as
37  * xvimagesink or filesink. It is a layer on top of #GstElement that provides a
38  * simplified interface to plugin writers. #GstBaseSink handles many details
39  * for you, for example: preroll, clock synchronization, state changes,
40  * activation in push or pull mode, and queries.
41  * 
42  * In most cases, when writing sink elements, there is no need to implement
43  * class methods from #GstElement or to set functions on pads, because the
44  * #GstBaseSink infrastructure should be sufficient.
45  * 
46  * #GstBaseSink provides support for exactly one sink pad, which should be
47  * named "sink". A sink implementation (subclass of #GstBaseSink) should
48  * install a pad template in its class_init function, like so:
49  * |[<!-- language="C" -->
50  * static void
51  * my_element_class_init (GstMyElementClass *klass)
52  * {
53  * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
54  * 
55  * // sinktemplate should be a #GstStaticPadTemplate with direction
56  * // %GST_PAD_SINK and name "sink"
57  * gst_element_class_add_static_pad_template (gstelement_class, &amp;sinktemplate);
58  * 
59  * gst_element_class_set_static_metadata (gstelement_class,
60  * "Sink name",
61  * "Sink",
62  * "My Sink element",
63  * "The author <my.sink@my.email>");
64  * }
65  * ]|
66  * 
67  * #GstBaseSink will handle the prerolling correctly. This means that it will
68  * return %GST_STATE_CHANGE_ASYNC from a state change to PAUSED until the first
69  * buffer arrives in this element. The base class will call the
70  * #GstBaseSinkClass.preroll() vmethod with this preroll buffer and will then
71  * commit the state change to the next asynchronously pending state.
72  * 
73  * When the element is set to PLAYING, #GstBaseSink will synchronise on the
74  * clock using the times returned from #GstBaseSinkClass.get_times(). If this
75  * function returns %GST_CLOCK_TIME_NONE for the start time, no synchronisation
76  * will be done. Synchronisation can be disabled entirely by setting the object
77  * #GstBaseSink:sync property to %FALSE.
78  * 
79  * After synchronisation the virtual method #GstBaseSinkClass.render() will be
80  * called. Subclasses should minimally implement this method.
81  * 
82  * Subclasses that synchronise on the clock in the #GstBaseSinkClass.render()
83  * method are supported as well. These classes typically receive a buffer in
84  * the render method and can then potentially block on the clock while
85  * rendering. A typical example is an audiosink.
86  * These subclasses can use gst_base_sink_wait_preroll() to perform the
87  * blocking wait.
88  * 
89  * Upon receiving the EOS event in the PLAYING state, #GstBaseSink will wait
90  * for the clock to reach the time indicated by the stop time of the last
91  * #GstBaseSinkClass.get_times() call before posting an EOS message. When the
92  * element receives EOS in PAUSED, preroll completes, the event is queued and an
93  * EOS message is posted when going to PLAYING.
94  * 
95  * #GstBaseSink will internally use the %GST_EVENT_SEGMENT events to schedule
96  * synchronisation and clipping of buffers. Buffers that fall completely outside
97  * of the current segment are dropped. Buffers that fall partially in the
98  * segment are rendered (and prerolled). Subclasses should do any subbuffer
99  * clipping themselves when needed.
100  * 
101  * #GstBaseSink will by default report the current playback position in
102  * %GST_FORMAT_TIME based on the current clock time and segment information.
103  * If no clock has been set on the element, the query will be forwarded
104  * upstream.
105  * 
106  * The #GstBaseSinkClass.set_caps() function will be called when the subclass
107  * should configure itself to process a specific media type.
108  * 
109  * The #GstBaseSinkClass.start() and #GstBaseSinkClass.stop() virtual methods
110  * will be called when resources should be allocated. Any
111  * #GstBaseSinkClass.preroll(), #GstBaseSinkClass.render() and
112  * #GstBaseSinkClass.set_caps() function will be called between the
113  * #GstBaseSinkClass.start() and #GstBaseSinkClass.stop() calls.
114  * 
115  * The #GstBaseSinkClass.event() virtual method will be called when an event is
116  * received by #GstBaseSink. Normally this method should only be overridden by
117  * very specific elements (such as file sinks) which need to handle the
118  * newsegment event specially.
119  * 
120  * The #GstBaseSinkClass.unlock() method is called when the elements should
121  * unblock any blocking operations they perform in the
122  * #GstBaseSinkClass.render() method. This is mostly useful when the
123  * #GstBaseSinkClass.render() method performs a blocking write on a file
124  * descriptor, for example.
125  * 
126  * The #GstBaseSink:max-lateness property affects how the sink deals with
127  * buffers that arrive too late in the sink. A buffer arrives too late in the
128  * sink when the presentation time (as a combination of the last segment, buffer
129  * timestamp and element base_time) plus the duration is before the current
130  * time of the clock.
131  * If the frame is later than max-lateness, the sink will drop the buffer
132  * without calling the render method.
133  * This feature is disabled if sync is disabled, the
134  * #GstBaseSinkClass.get_times() method does not return a valid start time or
135  * max-lateness is set to -1 (the default).
136  * Subclasses can use gst_base_sink_set_max_lateness() to configure the
137  * max-lateness value.
138  * 
139  * The #GstBaseSink:qos property will enable the quality-of-service features of
140  * the basesink which gather statistics about the real-time performance of the
141  * clock synchronisation. For each buffer received in the sink, statistics are
142  * gathered and a QOS event is sent upstream with these numbers. This
143  * information can then be used by upstream elements to reduce their processing
144  * rate, for example.
145  * 
146  * The #GstBaseSink:async property can be used to instruct the sink to never
147  * perform an ASYNC state change. This feature is mostly usable when dealing
148  * with non-synchronized streams or sparse streams.
149  */
150 public class BaseSink : Element
151 {
152 	/** the main Gtk struct */
153 	protected GstBaseSink* gstBaseSink;
154 
155 	/** Get the main Gtk struct */
156 	public GstBaseSink* getBaseSinkStruct(bool transferOwnership = false)
157 	{
158 		if (transferOwnership)
159 			ownedRef = false;
160 		return gstBaseSink;
161 	}
162 
163 	/** the main Gtk struct as a void* */
164 	protected override void* getStruct()
165 	{
166 		return cast(void*)gstBaseSink;
167 	}
168 
169 	/**
170 	 * Sets our main struct and passes it to the parent class.
171 	 */
172 	public this (GstBaseSink* gstBaseSink, bool ownedRef = false)
173 	{
174 		this.gstBaseSink = gstBaseSink;
175 		super(cast(GstElement*)gstBaseSink, ownedRef);
176 	}
177 
178 
179 	/** */
180 	public static GType getType()
181 	{
182 		return gst_base_sink_get_type();
183 	}
184 
185 	/**
186 	 * If the @sink spawns its own thread for pulling buffers from upstream it
187 	 * should call this method after it has pulled a buffer. If the element needed
188 	 * to preroll, this function will perform the preroll and will then block
189 	 * until the element state is changed.
190 	 *
191 	 * This function should be called with the PREROLL_LOCK held.
192 	 *
193 	 * Params:
194 	 *     obj = the mini object that caused the preroll
195 	 *
196 	 * Returns: %GST_FLOW_OK if the preroll completed and processing can
197 	 *     continue. Any other return value should be returned from the render vmethod.
198 	 */
199 	public GstFlowReturn doPreroll(MiniObject obj)
200 	{
201 		return gst_base_sink_do_preroll(gstBaseSink, (obj is null) ? null : obj.getMiniObjectStruct());
202 	}
203 
204 	/**
205 	 * Get the number of bytes that the sink will pull when it is operating in pull
206 	 * mode.
207 	 *
208 	 * Returns: the number of bytes @sink will pull in pull mode.
209 	 */
210 	public uint getBlocksize()
211 	{
212 		return gst_base_sink_get_blocksize(gstBaseSink);
213 	}
214 
215 	/**
216 	 * Checks if @sink is currently configured to drop buffers which are outside
217 	 * the current segment
218 	 *
219 	 * Returns: %TRUE if the sink is configured to drop buffers outside the
220 	 *     current segment.
221 	 *
222 	 * Since: 1.12
223 	 */
224 	public bool getDropOutOfSegment()
225 	{
226 		return gst_base_sink_get_drop_out_of_segment(gstBaseSink) != 0;
227 	}
228 
229 	/**
230 	 * Get the last sample that arrived in the sink and was used for preroll or for
231 	 * rendering. This property can be used to generate thumbnails.
232 	 *
233 	 * The #GstCaps on the sample can be used to determine the type of the buffer.
234 	 *
235 	 * Free-function: gst_sample_unref
236 	 *
237 	 * Returns: a #GstSample. gst_sample_unref() after
238 	 *     usage.  This function returns %NULL when no buffer has arrived in the
239 	 *     sink yet or when the sink is not in PAUSED or PLAYING.
240 	 */
241 	public Sample getLastSample()
242 	{
243 		auto p = gst_base_sink_get_last_sample(gstBaseSink);
244 
245 		if(p is null)
246 		{
247 			return null;
248 		}
249 
250 		return ObjectG.getDObject!(Sample)(cast(GstSample*) p, true);
251 	}
252 
253 	/**
254 	 * Get the currently configured latency.
255 	 *
256 	 * Returns: The configured latency.
257 	 */
258 	public GstClockTime getLatency()
259 	{
260 		return gst_base_sink_get_latency(gstBaseSink);
261 	}
262 
263 	/**
264 	 * Get the maximum amount of bits per second that the sink will render.
265 	 *
266 	 * Returns: the maximum number of bits per second @sink will render.
267 	 *
268 	 * Since: 1.2
269 	 */
270 	public ulong getMaxBitrate()
271 	{
272 		return gst_base_sink_get_max_bitrate(gstBaseSink);
273 	}
274 
275 	/**
276 	 * Gets the max lateness value. See gst_base_sink_set_max_lateness() for
277 	 * more details.
278 	 *
279 	 * Returns: The maximum time in nanoseconds that a buffer can be late
280 	 *     before it is dropped and not rendered. A value of -1 means an
281 	 *     unlimited time.
282 	 */
283 	public long getMaxLateness()
284 	{
285 		return gst_base_sink_get_max_lateness(gstBaseSink);
286 	}
287 
288 	/**
289 	 * Get the render delay of @sink. see gst_base_sink_set_render_delay() for more
290 	 * information about the render delay.
291 	 *
292 	 * Returns: the render delay of @sink.
293 	 */
294 	public GstClockTime getRenderDelay()
295 	{
296 		return gst_base_sink_get_render_delay(gstBaseSink);
297 	}
298 
299 	/**
300 	 * Checks if @sink is currently configured to synchronize against the
301 	 * clock.
302 	 *
303 	 * Returns: %TRUE if the sink is configured to synchronize against the clock.
304 	 */
305 	public bool getSync()
306 	{
307 		return gst_base_sink_get_sync(gstBaseSink) != 0;
308 	}
309 
310 	/**
311 	 * Get the time that will be inserted between frames to control the
312 	 * maximum buffers per second.
313 	 *
314 	 * Returns: the number of nanoseconds @sink will put between frames.
315 	 */
316 	public ulong getThrottleTime()
317 	{
318 		return gst_base_sink_get_throttle_time(gstBaseSink);
319 	}
320 
321 	/**
322 	 * Get the synchronisation offset of @sink.
323 	 *
324 	 * Returns: The synchronisation offset.
325 	 */
326 	public GstClockTimeDiff getTsOffset()
327 	{
328 		return gst_base_sink_get_ts_offset(gstBaseSink);
329 	}
330 
331 	/**
332 	 * Checks if @sink is currently configured to perform asynchronous state
333 	 * changes to PAUSED.
334 	 *
335 	 * Returns: %TRUE if the sink is configured to perform asynchronous state
336 	 *     changes.
337 	 */
338 	public bool isAsyncEnabled()
339 	{
340 		return gst_base_sink_is_async_enabled(gstBaseSink) != 0;
341 	}
342 
343 	/**
344 	 * Checks if @sink is currently configured to store the last received sample in
345 	 * the last-sample property.
346 	 *
347 	 * Returns: %TRUE if the sink is configured to store the last received sample.
348 	 */
349 	public bool isLastSampleEnabled()
350 	{
351 		return gst_base_sink_is_last_sample_enabled(gstBaseSink) != 0;
352 	}
353 
354 	/**
355 	 * Checks if @sink is currently configured to send Quality-of-Service events
356 	 * upstream.
357 	 *
358 	 * Returns: %TRUE if the sink is configured to perform Quality-of-Service.
359 	 */
360 	public bool isQosEnabled()
361 	{
362 		return gst_base_sink_is_qos_enabled(gstBaseSink) != 0;
363 	}
364 
365 	/**
366 	 * Query the sink for the latency parameters. The latency will be queried from
367 	 * the upstream elements. @live will be %TRUE if @sink is configured to
368 	 * synchronize against the clock. @upstream_live will be %TRUE if an upstream
369 	 * element is live.
370 	 *
371 	 * If both @live and @upstream_live are %TRUE, the sink will want to compensate
372 	 * for the latency introduced by the upstream elements by setting the
373 	 * @min_latency to a strictly positive value.
374 	 *
375 	 * This function is mostly used by subclasses.
376 	 *
377 	 * Params:
378 	 *     live = if the sink is live
379 	 *     upstreamLive = if an upstream element is live
380 	 *     minLatency = the min latency of the upstream elements
381 	 *     maxLatency = the max latency of the upstream elements
382 	 *
383 	 * Returns: %TRUE if the query succeeded.
384 	 */
385 	public bool queryLatency(out bool live, out bool upstreamLive, out GstClockTime minLatency, out GstClockTime maxLatency)
386 	{
387 		int outlive;
388 		int outupstreamLive;
389 
390 		auto p = gst_base_sink_query_latency(gstBaseSink, &outlive, &outupstreamLive, &minLatency, &maxLatency) != 0;
391 
392 		live = (outlive == 1);
393 		upstreamLive = (outupstreamLive == 1);
394 
395 		return p;
396 	}
397 
398 	/**
399 	 * Configures @sink to perform all state changes asynchronously. When async is
400 	 * disabled, the sink will immediately go to PAUSED instead of waiting for a
401 	 * preroll buffer. This feature is useful if the sink does not synchronize
402 	 * against the clock or when it is dealing with sparse streams.
403 	 *
404 	 * Params:
405 	 *     enabled = the new async value.
406 	 */
407 	public void setAsyncEnabled(bool enabled)
408 	{
409 		gst_base_sink_set_async_enabled(gstBaseSink, enabled);
410 	}
411 
412 	/**
413 	 * Set the number of bytes that the sink will pull when it is operating in pull
414 	 * mode.
415 	 *
416 	 * Params:
417 	 *     blocksize = the blocksize in bytes
418 	 */
419 	public void setBlocksize(uint blocksize)
420 	{
421 		gst_base_sink_set_blocksize(gstBaseSink, blocksize);
422 	}
423 
424 	/**
425 	 * Configure @sink to drop buffers which are outside the current segment
426 	 *
427 	 * Params:
428 	 *     dropOutOfSegment = drop buffers outside the segment
429 	 *
430 	 * Since: 1.12
431 	 */
432 	public void setDropOutOfSegment(bool dropOutOfSegment)
433 	{
434 		gst_base_sink_set_drop_out_of_segment(gstBaseSink, dropOutOfSegment);
435 	}
436 
437 	/**
438 	 * Configures @sink to store the last received sample in the last-sample
439 	 * property.
440 	 *
441 	 * Params:
442 	 *     enabled = the new enable-last-sample value.
443 	 */
444 	public void setLastSampleEnabled(bool enabled)
445 	{
446 		gst_base_sink_set_last_sample_enabled(gstBaseSink, enabled);
447 	}
448 
449 	/**
450 	 * Set the maximum amount of bits per second that the sink will render.
451 	 *
452 	 * Params:
453 	 *     maxBitrate = the max_bitrate in bits per second
454 	 *
455 	 * Since: 1.2
456 	 */
457 	public void setMaxBitrate(ulong maxBitrate)
458 	{
459 		gst_base_sink_set_max_bitrate(gstBaseSink, maxBitrate);
460 	}
461 
462 	/**
463 	 * Sets the new max lateness value to @max_lateness. This value is
464 	 * used to decide if a buffer should be dropped or not based on the
465 	 * buffer timestamp and the current clock time. A value of -1 means
466 	 * an unlimited time.
467 	 *
468 	 * Params:
469 	 *     maxLateness = the new max lateness value.
470 	 */
471 	public void setMaxLateness(long maxLateness)
472 	{
473 		gst_base_sink_set_max_lateness(gstBaseSink, maxLateness);
474 	}
475 
476 	/**
477 	 * Configures @sink to send Quality-of-Service events upstream.
478 	 *
479 	 * Params:
480 	 *     enabled = the new qos value.
481 	 */
482 	public void setQosEnabled(bool enabled)
483 	{
484 		gst_base_sink_set_qos_enabled(gstBaseSink, enabled);
485 	}
486 
487 	/**
488 	 * Set the render delay in @sink to @delay. The render delay is the time
489 	 * between actual rendering of a buffer and its synchronisation time. Some
490 	 * devices might delay media rendering which can be compensated for with this
491 	 * function.
492 	 *
493 	 * After calling this function, this sink will report additional latency and
494 	 * other sinks will adjust their latency to delay the rendering of their media.
495 	 *
496 	 * This function is usually called by subclasses.
497 	 *
498 	 * Params:
499 	 *     delay = the new delay
500 	 */
501 	public void setRenderDelay(GstClockTime delay)
502 	{
503 		gst_base_sink_set_render_delay(gstBaseSink, delay);
504 	}
505 
506 	/**
507 	 * Configures @sink to synchronize on the clock or not. When
508 	 * @sync is %FALSE, incoming samples will be played as fast as
509 	 * possible. If @sync is %TRUE, the timestamps of the incoming
510 	 * buffers will be used to schedule the exact render time of its
511 	 * contents.
512 	 *
513 	 * Params:
514 	 *     sync = the new sync value.
515 	 */
516 	public void setSync(bool sync)
517 	{
518 		gst_base_sink_set_sync(gstBaseSink, sync);
519 	}
520 
521 	/**
522 	 * Set the time that will be inserted between rendered buffers. This
523 	 * can be used to control the maximum buffers per second that the sink
524 	 * will render.
525 	 *
526 	 * Params:
527 	 *     throttle = the throttle time in nanoseconds
528 	 */
529 	public void setThrottleTime(ulong throttle)
530 	{
531 		gst_base_sink_set_throttle_time(gstBaseSink, throttle);
532 	}
533 
534 	/**
535 	 * Adjust the synchronisation of @sink with @offset. A negative value will
536 	 * render buffers earlier than their timestamp. A positive value will delay
537 	 * rendering. This function can be used to fix playback of badly timestamped
538 	 * buffers.
539 	 *
540 	 * Params:
541 	 *     offset = the new offset
542 	 */
543 	public void setTsOffset(GstClockTimeDiff offset)
544 	{
545 		gst_base_sink_set_ts_offset(gstBaseSink, offset);
546 	}
547 
548 	/**
549 	 * This function will wait for preroll to complete and will then block until @time
550 	 * is reached. It is usually called by subclasses that use their own internal
551 	 * synchronisation but want to let some synchronization (like EOS) be handled
552 	 * by the base class.
553 	 *
554 	 * This function should only be called with the PREROLL_LOCK held (like when
555 	 * receiving an EOS event in the ::event vmethod or when handling buffers in
556 	 * ::render).
557 	 *
558 	 * The @time argument should be the running_time of when the timeout should happen
559 	 * and will be adjusted with any latency and offset configured in the sink.
560 	 *
561 	 * Params:
562 	 *     time = the running_time to be reached
563 	 *     jitter = the jitter to be filled with time diff, or %NULL
564 	 *
565 	 * Returns: #GstFlowReturn
566 	 */
567 	public GstFlowReturn wait(GstClockTime time, out GstClockTimeDiff jitter)
568 	{
569 		return gst_base_sink_wait(gstBaseSink, time, &jitter);
570 	}
571 
572 	/**
573 	 * This function will block until @time is reached. It is usually called by
574 	 * subclasses that use their own internal synchronisation.
575 	 *
576 	 * If @time is not valid, no synchronisation is done and %GST_CLOCK_BADTIME is
577 	 * returned. Likewise, if synchronisation is disabled in the element or there
578 	 * is no clock, no synchronisation is done and %GST_CLOCK_BADTIME is returned.
579 	 *
580 	 * This function should only be called with the PREROLL_LOCK held, like when
581 	 * receiving an EOS event in the #GstBaseSinkClass.event() vmethod or when
582 	 * receiving a buffer in
583 	 * the #GstBaseSinkClass.render() vmethod.
584 	 *
585 	 * The @time argument should be the running_time of when this method should
586 	 * return and is not adjusted with any latency or offset configured in the
587 	 * sink.
588 	 *
589 	 * Params:
590 	 *     time = the running_time to be reached
591 	 *     jitter = the jitter to be filled with time diff, or %NULL
592 	 *
593 	 * Returns: #GstClockReturn
594 	 */
595 	public GstClockReturn waitClock(GstClockTime time, out GstClockTimeDiff jitter)
596 	{
597 		return gst_base_sink_wait_clock(gstBaseSink, time, &jitter);
598 	}
599 
600 	/**
601 	 * If the #GstBaseSinkClass.render() method performs its own synchronisation
602 	 * against the clock it must unblock when going from PLAYING to the PAUSED state
603 	 * and call this method before continuing to render the remaining data.
604 	 *
605 	 * If the #GstBaseSinkClass.render() method can block on something else than
606 	 * the clock, it must also be ready to unblock immediately on
607 	 * the #GstBaseSinkClass.unlock() method and cause the
608 	 * #GstBaseSinkClass.render() method to immediately call this function.
609 	 * In this case, the subclass must be prepared to continue rendering where it
610 	 * left off if this function returns %GST_FLOW_OK.
611 	 *
612 	 * This function will block until a state change to PLAYING happens (in which
613 	 * case this function returns %GST_FLOW_OK) or the processing must be stopped due
614 	 * to a state change to READY or a FLUSH event (in which case this function
615 	 * returns %GST_FLOW_FLUSHING).
616 	 *
617 	 * This function should only be called with the PREROLL_LOCK held, like in the
618 	 * render function.
619 	 *
620 	 * Returns: %GST_FLOW_OK if the preroll completed and processing can
621 	 *     continue. Any other return value should be returned from the render vmethod.
622 	 */
623 	public GstFlowReturn waitPreroll()
624 	{
625 		return gst_base_sink_wait_preroll(gstBaseSink);
626 	}
627 }