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 	protected override void setStruct(GObject* obj)
170 	{
171 		gstBaseSink = cast(GstBaseSink*)obj;
172 		super.setStruct(obj);
173 	}
174 
175 	/**
176 	 * Sets our main struct and passes it to the parent class.
177 	 */
178 	public this (GstBaseSink* gstBaseSink, bool ownedRef = false)
179 	{
180 		this.gstBaseSink = gstBaseSink;
181 		super(cast(GstElement*)gstBaseSink, ownedRef);
182 	}
183 
184 
185 	/** */
186 	public static GType getType()
187 	{
188 		return gst_base_sink_get_type();
189 	}
190 
191 	/**
192 	 * If the @sink spawns its own thread for pulling buffers from upstream it
193 	 * should call this method after it has pulled a buffer. If the element needed
194 	 * to preroll, this function will perform the preroll and will then block
195 	 * until the element state is changed.
196 	 *
197 	 * This function should be called with the PREROLL_LOCK held.
198 	 *
199 	 * Params:
200 	 *     obj = the mini object that caused the preroll
201 	 *
202 	 * Returns: %GST_FLOW_OK if the preroll completed and processing can
203 	 *     continue. Any other return value should be returned from the render vmethod.
204 	 */
205 	public GstFlowReturn doPreroll(MiniObject obj)
206 	{
207 		return gst_base_sink_do_preroll(gstBaseSink, (obj is null) ? null : obj.getMiniObjectStruct());
208 	}
209 
210 	/**
211 	 * Get the number of bytes that the sink will pull when it is operating in pull
212 	 * mode.
213 	 *
214 	 * Returns: the number of bytes @sink will pull in pull mode.
215 	 */
216 	public uint getBlocksize()
217 	{
218 		return gst_base_sink_get_blocksize(gstBaseSink);
219 	}
220 
221 	/**
222 	 * Checks if @sink is currently configured to drop buffers which are outside
223 	 * the current segment
224 	 *
225 	 * Returns: %TRUE if the sink is configured to drop buffers outside the
226 	 *     current segment.
227 	 *
228 	 * Since: 1.12
229 	 */
230 	public bool getDropOutOfSegment()
231 	{
232 		return gst_base_sink_get_drop_out_of_segment(gstBaseSink) != 0;
233 	}
234 
235 	/**
236 	 * Get the last sample that arrived in the sink and was used for preroll or for
237 	 * rendering. This property can be used to generate thumbnails.
238 	 *
239 	 * The #GstCaps on the sample can be used to determine the type of the buffer.
240 	 *
241 	 * Free-function: gst_sample_unref
242 	 *
243 	 * Returns: a #GstSample. gst_sample_unref() after
244 	 *     usage.  This function returns %NULL when no buffer has arrived in the
245 	 *     sink yet or when the sink is not in PAUSED or PLAYING.
246 	 */
247 	public Sample getLastSample()
248 	{
249 		auto p = gst_base_sink_get_last_sample(gstBaseSink);
250 
251 		if(p is null)
252 		{
253 			return null;
254 		}
255 
256 		return ObjectG.getDObject!(Sample)(cast(GstSample*) p, true);
257 	}
258 
259 	/**
260 	 * Get the currently configured latency.
261 	 *
262 	 * Returns: The configured latency.
263 	 */
264 	public GstClockTime getLatency()
265 	{
266 		return gst_base_sink_get_latency(gstBaseSink);
267 	}
268 
269 	/**
270 	 * Get the maximum amount of bits per second that the sink will render.
271 	 *
272 	 * Returns: the maximum number of bits per second @sink will render.
273 	 *
274 	 * Since: 1.2
275 	 */
276 	public ulong getMaxBitrate()
277 	{
278 		return gst_base_sink_get_max_bitrate(gstBaseSink);
279 	}
280 
281 	/**
282 	 * Gets the max lateness value. See gst_base_sink_set_max_lateness() for
283 	 * more details.
284 	 *
285 	 * Returns: The maximum time in nanoseconds that a buffer can be late
286 	 *     before it is dropped and not rendered. A value of -1 means an
287 	 *     unlimited time.
288 	 */
289 	public long getMaxLateness()
290 	{
291 		return gst_base_sink_get_max_lateness(gstBaseSink);
292 	}
293 
294 	/**
295 	 * Get the render delay of @sink. see gst_base_sink_set_render_delay() for more
296 	 * information about the render delay.
297 	 *
298 	 * Returns: the render delay of @sink.
299 	 */
300 	public GstClockTime getRenderDelay()
301 	{
302 		return gst_base_sink_get_render_delay(gstBaseSink);
303 	}
304 
305 	/**
306 	 * Checks if @sink is currently configured to synchronize against the
307 	 * clock.
308 	 *
309 	 * Returns: %TRUE if the sink is configured to synchronize against the clock.
310 	 */
311 	public bool getSync()
312 	{
313 		return gst_base_sink_get_sync(gstBaseSink) != 0;
314 	}
315 
316 	/**
317 	 * Get the time that will be inserted between frames to control the
318 	 * maximum buffers per second.
319 	 *
320 	 * Returns: the number of nanoseconds @sink will put between frames.
321 	 */
322 	public ulong getThrottleTime()
323 	{
324 		return gst_base_sink_get_throttle_time(gstBaseSink);
325 	}
326 
327 	/**
328 	 * Get the synchronisation offset of @sink.
329 	 *
330 	 * Returns: The synchronisation offset.
331 	 */
332 	public GstClockTimeDiff getTsOffset()
333 	{
334 		return gst_base_sink_get_ts_offset(gstBaseSink);
335 	}
336 
337 	/**
338 	 * Checks if @sink is currently configured to perform asynchronous state
339 	 * changes to PAUSED.
340 	 *
341 	 * Returns: %TRUE if the sink is configured to perform asynchronous state
342 	 *     changes.
343 	 */
344 	public bool isAsyncEnabled()
345 	{
346 		return gst_base_sink_is_async_enabled(gstBaseSink) != 0;
347 	}
348 
349 	/**
350 	 * Checks if @sink is currently configured to store the last received sample in
351 	 * the last-sample property.
352 	 *
353 	 * Returns: %TRUE if the sink is configured to store the last received sample.
354 	 */
355 	public bool isLastSampleEnabled()
356 	{
357 		return gst_base_sink_is_last_sample_enabled(gstBaseSink) != 0;
358 	}
359 
360 	/**
361 	 * Checks if @sink is currently configured to send Quality-of-Service events
362 	 * upstream.
363 	 *
364 	 * Returns: %TRUE if the sink is configured to perform Quality-of-Service.
365 	 */
366 	public bool isQosEnabled()
367 	{
368 		return gst_base_sink_is_qos_enabled(gstBaseSink) != 0;
369 	}
370 
371 	/**
372 	 * Query the sink for the latency parameters. The latency will be queried from
373 	 * the upstream elements. @live will be %TRUE if @sink is configured to
374 	 * synchronize against the clock. @upstream_live will be %TRUE if an upstream
375 	 * element is live.
376 	 *
377 	 * If both @live and @upstream_live are %TRUE, the sink will want to compensate
378 	 * for the latency introduced by the upstream elements by setting the
379 	 * @min_latency to a strictly positive value.
380 	 *
381 	 * This function is mostly used by subclasses.
382 	 *
383 	 * Params:
384 	 *     live = if the sink is live
385 	 *     upstreamLive = if an upstream element is live
386 	 *     minLatency = the min latency of the upstream elements
387 	 *     maxLatency = the max latency of the upstream elements
388 	 *
389 	 * Returns: %TRUE if the query succeeded.
390 	 */
391 	public bool queryLatency(out bool live, out bool upstreamLive, out GstClockTime minLatency, out GstClockTime maxLatency)
392 	{
393 		int outlive;
394 		int outupstreamLive;
395 
396 		auto p = gst_base_sink_query_latency(gstBaseSink, &outlive, &outupstreamLive, &minLatency, &maxLatency) != 0;
397 
398 		live = (outlive == 1);
399 		upstreamLive = (outupstreamLive == 1);
400 
401 		return p;
402 	}
403 
404 	/**
405 	 * Configures @sink to perform all state changes asynchronously. When async is
406 	 * disabled, the sink will immediately go to PAUSED instead of waiting for a
407 	 * preroll buffer. This feature is useful if the sink does not synchronize
408 	 * against the clock or when it is dealing with sparse streams.
409 	 *
410 	 * Params:
411 	 *     enabled = the new async value.
412 	 */
413 	public void setAsyncEnabled(bool enabled)
414 	{
415 		gst_base_sink_set_async_enabled(gstBaseSink, enabled);
416 	}
417 
418 	/**
419 	 * Set the number of bytes that the sink will pull when it is operating in pull
420 	 * mode.
421 	 *
422 	 * Params:
423 	 *     blocksize = the blocksize in bytes
424 	 */
425 	public void setBlocksize(uint blocksize)
426 	{
427 		gst_base_sink_set_blocksize(gstBaseSink, blocksize);
428 	}
429 
430 	/**
431 	 * Configure @sink to drop buffers which are outside the current segment
432 	 *
433 	 * Params:
434 	 *     dropOutOfSegment = drop buffers outside the segment
435 	 *
436 	 * Since: 1.12
437 	 */
438 	public void setDropOutOfSegment(bool dropOutOfSegment)
439 	{
440 		gst_base_sink_set_drop_out_of_segment(gstBaseSink, dropOutOfSegment);
441 	}
442 
443 	/**
444 	 * Configures @sink to store the last received sample in the last-sample
445 	 * property.
446 	 *
447 	 * Params:
448 	 *     enabled = the new enable-last-sample value.
449 	 */
450 	public void setLastSampleEnabled(bool enabled)
451 	{
452 		gst_base_sink_set_last_sample_enabled(gstBaseSink, enabled);
453 	}
454 
455 	/**
456 	 * Set the maximum amount of bits per second that the sink will render.
457 	 *
458 	 * Params:
459 	 *     maxBitrate = the max_bitrate in bits per second
460 	 *
461 	 * Since: 1.2
462 	 */
463 	public void setMaxBitrate(ulong maxBitrate)
464 	{
465 		gst_base_sink_set_max_bitrate(gstBaseSink, maxBitrate);
466 	}
467 
468 	/**
469 	 * Sets the new max lateness value to @max_lateness. This value is
470 	 * used to decide if a buffer should be dropped or not based on the
471 	 * buffer timestamp and the current clock time. A value of -1 means
472 	 * an unlimited time.
473 	 *
474 	 * Params:
475 	 *     maxLateness = the new max lateness value.
476 	 */
477 	public void setMaxLateness(long maxLateness)
478 	{
479 		gst_base_sink_set_max_lateness(gstBaseSink, maxLateness);
480 	}
481 
482 	/**
483 	 * Configures @sink to send Quality-of-Service events upstream.
484 	 *
485 	 * Params:
486 	 *     enabled = the new qos value.
487 	 */
488 	public void setQosEnabled(bool enabled)
489 	{
490 		gst_base_sink_set_qos_enabled(gstBaseSink, enabled);
491 	}
492 
493 	/**
494 	 * Set the render delay in @sink to @delay. The render delay is the time
495 	 * between actual rendering of a buffer and its synchronisation time. Some
496 	 * devices might delay media rendering which can be compensated for with this
497 	 * function.
498 	 *
499 	 * After calling this function, this sink will report additional latency and
500 	 * other sinks will adjust their latency to delay the rendering of their media.
501 	 *
502 	 * This function is usually called by subclasses.
503 	 *
504 	 * Params:
505 	 *     delay = the new delay
506 	 */
507 	public void setRenderDelay(GstClockTime delay)
508 	{
509 		gst_base_sink_set_render_delay(gstBaseSink, delay);
510 	}
511 
512 	/**
513 	 * Configures @sink to synchronize on the clock or not. When
514 	 * @sync is %FALSE, incoming samples will be played as fast as
515 	 * possible. If @sync is %TRUE, the timestamps of the incoming
516 	 * buffers will be used to schedule the exact render time of its
517 	 * contents.
518 	 *
519 	 * Params:
520 	 *     sync = the new sync value.
521 	 */
522 	public void setSync(bool sync)
523 	{
524 		gst_base_sink_set_sync(gstBaseSink, sync);
525 	}
526 
527 	/**
528 	 * Set the time that will be inserted between rendered buffers. This
529 	 * can be used to control the maximum buffers per second that the sink
530 	 * will render.
531 	 *
532 	 * Params:
533 	 *     throttle = the throttle time in nanoseconds
534 	 */
535 	public void setThrottleTime(ulong throttle)
536 	{
537 		gst_base_sink_set_throttle_time(gstBaseSink, throttle);
538 	}
539 
540 	/**
541 	 * Adjust the synchronisation of @sink with @offset. A negative value will
542 	 * render buffers earlier than their timestamp. A positive value will delay
543 	 * rendering. This function can be used to fix playback of badly timestamped
544 	 * buffers.
545 	 *
546 	 * Params:
547 	 *     offset = the new offset
548 	 */
549 	public void setTsOffset(GstClockTimeDiff offset)
550 	{
551 		gst_base_sink_set_ts_offset(gstBaseSink, offset);
552 	}
553 
554 	/**
555 	 * This function will wait for preroll to complete and will then block until @time
556 	 * is reached. It is usually called by subclasses that use their own internal
557 	 * synchronisation but want to let some synchronization (like EOS) be handled
558 	 * by the base class.
559 	 *
560 	 * This function should only be called with the PREROLL_LOCK held (like when
561 	 * receiving an EOS event in the ::event vmethod or when handling buffers in
562 	 * ::render).
563 	 *
564 	 * The @time argument should be the running_time of when the timeout should happen
565 	 * and will be adjusted with any latency and offset configured in the sink.
566 	 *
567 	 * Params:
568 	 *     time = the running_time to be reached
569 	 *     jitter = the jitter to be filled with time diff, or %NULL
570 	 *
571 	 * Returns: #GstFlowReturn
572 	 */
573 	public GstFlowReturn wait(GstClockTime time, out GstClockTimeDiff jitter)
574 	{
575 		return gst_base_sink_wait(gstBaseSink, time, &jitter);
576 	}
577 
578 	/**
579 	 * This function will block until @time is reached. It is usually called by
580 	 * subclasses that use their own internal synchronisation.
581 	 *
582 	 * If @time is not valid, no synchronisation is done and %GST_CLOCK_BADTIME is
583 	 * returned. Likewise, if synchronisation is disabled in the element or there
584 	 * is no clock, no synchronisation is done and %GST_CLOCK_BADTIME is returned.
585 	 *
586 	 * This function should only be called with the PREROLL_LOCK held, like when
587 	 * receiving an EOS event in the #GstBaseSinkClass.event() vmethod or when
588 	 * receiving a buffer in
589 	 * the #GstBaseSinkClass.render() vmethod.
590 	 *
591 	 * The @time argument should be the running_time of when this method should
592 	 * return and is not adjusted with any latency or offset configured in the
593 	 * sink.
594 	 *
595 	 * Params:
596 	 *     time = the running_time to be reached
597 	 *     jitter = the jitter to be filled with time diff, or %NULL
598 	 *
599 	 * Returns: #GstClockReturn
600 	 */
601 	public GstClockReturn waitClock(GstClockTime time, out GstClockTimeDiff jitter)
602 	{
603 		return gst_base_sink_wait_clock(gstBaseSink, time, &jitter);
604 	}
605 
606 	/**
607 	 * If the #GstBaseSinkClass.render() method performs its own synchronisation
608 	 * against the clock it must unblock when going from PLAYING to the PAUSED state
609 	 * and call this method before continuing to render the remaining data.
610 	 *
611 	 * If the #GstBaseSinkClass.render() method can block on something else than
612 	 * the clock, it must also be ready to unblock immediately on
613 	 * the #GstBaseSinkClass.unlock() method and cause the
614 	 * #GstBaseSinkClass.render() method to immediately call this function.
615 	 * In this case, the subclass must be prepared to continue rendering where it
616 	 * left off if this function returns %GST_FLOW_OK.
617 	 *
618 	 * This function will block until a state change to PLAYING happens (in which
619 	 * case this function returns %GST_FLOW_OK) or the processing must be stopped due
620 	 * to a state change to READY or a FLUSH event (in which case this function
621 	 * returns %GST_FLOW_FLUSHING).
622 	 *
623 	 * This function should only be called with the PREROLL_LOCK held, like in the
624 	 * render function.
625 	 *
626 	 * Returns: %GST_FLOW_OK if the preroll completed and processing can
627 	 *     continue. Any other return value should be returned from the render vmethod.
628 	 */
629 	public GstFlowReturn waitPreroll()
630 	{
631 		return gst_base_sink_wait_preroll(gstBaseSink);
632 	}
633 }