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, &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 processing deadline of @sink. see 290 * gst_base_sink_set_processing_deadline() for more information about 291 * the processing deadline. 292 * 293 * Returns: the processing deadline 294 * 295 * Since: 1.16 296 */ 297 public GstClockTime getProcessingDeadline() 298 { 299 return gst_base_sink_get_processing_deadline(gstBaseSink); 300 } 301 302 /** 303 * Get the render delay of @sink. see gst_base_sink_set_render_delay() for more 304 * information about the render delay. 305 * 306 * Returns: the render delay of @sink. 307 */ 308 public GstClockTime getRenderDelay() 309 { 310 return gst_base_sink_get_render_delay(gstBaseSink); 311 } 312 313 /** 314 * Checks if @sink is currently configured to synchronize against the 315 * clock. 316 * 317 * Returns: %TRUE if the sink is configured to synchronize against the clock. 318 */ 319 public bool getSync() 320 { 321 return gst_base_sink_get_sync(gstBaseSink) != 0; 322 } 323 324 /** 325 * Get the time that will be inserted between frames to control the 326 * maximum buffers per second. 327 * 328 * Returns: the number of nanoseconds @sink will put between frames. 329 */ 330 public ulong getThrottleTime() 331 { 332 return gst_base_sink_get_throttle_time(gstBaseSink); 333 } 334 335 /** 336 * Get the synchronisation offset of @sink. 337 * 338 * Returns: The synchronisation offset. 339 */ 340 public GstClockTimeDiff getTsOffset() 341 { 342 return gst_base_sink_get_ts_offset(gstBaseSink); 343 } 344 345 /** 346 * Checks if @sink is currently configured to perform asynchronous state 347 * changes to PAUSED. 348 * 349 * Returns: %TRUE if the sink is configured to perform asynchronous state 350 * changes. 351 */ 352 public bool isAsyncEnabled() 353 { 354 return gst_base_sink_is_async_enabled(gstBaseSink) != 0; 355 } 356 357 /** 358 * Checks if @sink is currently configured to store the last received sample in 359 * the last-sample property. 360 * 361 * Returns: %TRUE if the sink is configured to store the last received sample. 362 */ 363 public bool isLastSampleEnabled() 364 { 365 return gst_base_sink_is_last_sample_enabled(gstBaseSink) != 0; 366 } 367 368 /** 369 * Checks if @sink is currently configured to send Quality-of-Service events 370 * upstream. 371 * 372 * Returns: %TRUE if the sink is configured to perform Quality-of-Service. 373 */ 374 public bool isQosEnabled() 375 { 376 return gst_base_sink_is_qos_enabled(gstBaseSink) != 0; 377 } 378 379 /** 380 * Query the sink for the latency parameters. The latency will be queried from 381 * the upstream elements. @live will be %TRUE if @sink is configured to 382 * synchronize against the clock. @upstream_live will be %TRUE if an upstream 383 * element is live. 384 * 385 * If both @live and @upstream_live are %TRUE, the sink will want to compensate 386 * for the latency introduced by the upstream elements by setting the 387 * @min_latency to a strictly positive value. 388 * 389 * This function is mostly used by subclasses. 390 * 391 * Params: 392 * live = if the sink is live 393 * upstreamLive = if an upstream element is live 394 * minLatency = the min latency of the upstream elements 395 * maxLatency = the max latency of the upstream elements 396 * 397 * Returns: %TRUE if the query succeeded. 398 */ 399 public bool queryLatency(out bool live, out bool upstreamLive, out GstClockTime minLatency, out GstClockTime maxLatency) 400 { 401 int outlive; 402 int outupstreamLive; 403 404 auto p = gst_base_sink_query_latency(gstBaseSink, &outlive, &outupstreamLive, &minLatency, &maxLatency) != 0; 405 406 live = (outlive == 1); 407 upstreamLive = (outupstreamLive == 1); 408 409 return p; 410 } 411 412 /** 413 * Configures @sink to perform all state changes asynchronously. When async is 414 * disabled, the sink will immediately go to PAUSED instead of waiting for a 415 * preroll buffer. This feature is useful if the sink does not synchronize 416 * against the clock or when it is dealing with sparse streams. 417 * 418 * Params: 419 * enabled = the new async value. 420 */ 421 public void setAsyncEnabled(bool enabled) 422 { 423 gst_base_sink_set_async_enabled(gstBaseSink, enabled); 424 } 425 426 /** 427 * Set the number of bytes that the sink will pull when it is operating in pull 428 * mode. 429 * 430 * Params: 431 * blocksize = the blocksize in bytes 432 */ 433 public void setBlocksize(uint blocksize) 434 { 435 gst_base_sink_set_blocksize(gstBaseSink, blocksize); 436 } 437 438 /** 439 * Configure @sink to drop buffers which are outside the current segment 440 * 441 * Params: 442 * dropOutOfSegment = drop buffers outside the segment 443 * 444 * Since: 1.12 445 */ 446 public void setDropOutOfSegment(bool dropOutOfSegment) 447 { 448 gst_base_sink_set_drop_out_of_segment(gstBaseSink, dropOutOfSegment); 449 } 450 451 /** 452 * Configures @sink to store the last received sample in the last-sample 453 * property. 454 * 455 * Params: 456 * enabled = the new enable-last-sample value. 457 */ 458 public void setLastSampleEnabled(bool enabled) 459 { 460 gst_base_sink_set_last_sample_enabled(gstBaseSink, enabled); 461 } 462 463 /** 464 * Set the maximum amount of bits per second that the sink will render. 465 * 466 * Params: 467 * maxBitrate = the max_bitrate in bits per second 468 * 469 * Since: 1.2 470 */ 471 public void setMaxBitrate(ulong maxBitrate) 472 { 473 gst_base_sink_set_max_bitrate(gstBaseSink, maxBitrate); 474 } 475 476 /** 477 * Sets the new max lateness value to @max_lateness. This value is 478 * used to decide if a buffer should be dropped or not based on the 479 * buffer timestamp and the current clock time. A value of -1 means 480 * an unlimited time. 481 * 482 * Params: 483 * maxLateness = the new max lateness value. 484 */ 485 public void setMaxLateness(long maxLateness) 486 { 487 gst_base_sink_set_max_lateness(gstBaseSink, maxLateness); 488 } 489 490 /** 491 * Maximum amount of time (in nanoseconds) that the pipeline can take 492 * for processing the buffer. This is added to the latency of live 493 * pipelines. 494 * 495 * This function is usually called by subclasses. 496 * 497 * Params: 498 * processingDeadline = the new processing deadline in nanoseconds. 499 * 500 * Since: 1.16 501 */ 502 public void setProcessingDeadline(GstClockTime processingDeadline) 503 { 504 gst_base_sink_set_processing_deadline(gstBaseSink, processingDeadline); 505 } 506 507 /** 508 * Configures @sink to send Quality-of-Service events upstream. 509 * 510 * Params: 511 * enabled = the new qos value. 512 */ 513 public void setQosEnabled(bool enabled) 514 { 515 gst_base_sink_set_qos_enabled(gstBaseSink, enabled); 516 } 517 518 /** 519 * Set the render delay in @sink to @delay. The render delay is the time 520 * between actual rendering of a buffer and its synchronisation time. Some 521 * devices might delay media rendering which can be compensated for with this 522 * function. 523 * 524 * After calling this function, this sink will report additional latency and 525 * other sinks will adjust their latency to delay the rendering of their media. 526 * 527 * This function is usually called by subclasses. 528 * 529 * Params: 530 * delay = the new delay 531 */ 532 public void setRenderDelay(GstClockTime delay) 533 { 534 gst_base_sink_set_render_delay(gstBaseSink, delay); 535 } 536 537 /** 538 * Configures @sink to synchronize on the clock or not. When 539 * @sync is %FALSE, incoming samples will be played as fast as 540 * possible. If @sync is %TRUE, the timestamps of the incoming 541 * buffers will be used to schedule the exact render time of its 542 * contents. 543 * 544 * Params: 545 * sync = the new sync value. 546 */ 547 public void setSync(bool sync) 548 { 549 gst_base_sink_set_sync(gstBaseSink, sync); 550 } 551 552 /** 553 * Set the time that will be inserted between rendered buffers. This 554 * can be used to control the maximum buffers per second that the sink 555 * will render. 556 * 557 * Params: 558 * throttle = the throttle time in nanoseconds 559 */ 560 public void setThrottleTime(ulong throttle) 561 { 562 gst_base_sink_set_throttle_time(gstBaseSink, throttle); 563 } 564 565 /** 566 * Adjust the synchronisation of @sink with @offset. A negative value will 567 * render buffers earlier than their timestamp. A positive value will delay 568 * rendering. This function can be used to fix playback of badly timestamped 569 * buffers. 570 * 571 * Params: 572 * offset = the new offset 573 */ 574 public void setTsOffset(GstClockTimeDiff offset) 575 { 576 gst_base_sink_set_ts_offset(gstBaseSink, offset); 577 } 578 579 /** 580 * This function will wait for preroll to complete and will then block until @time 581 * is reached. It is usually called by subclasses that use their own internal 582 * synchronisation but want to let some synchronization (like EOS) be handled 583 * by the base class. 584 * 585 * This function should only be called with the PREROLL_LOCK held (like when 586 * receiving an EOS event in the ::event vmethod or when handling buffers in 587 * ::render). 588 * 589 * The @time argument should be the running_time of when the timeout should happen 590 * and will be adjusted with any latency and offset configured in the sink. 591 * 592 * Params: 593 * time = the running_time to be reached 594 * jitter = the jitter to be filled with time diff, or %NULL 595 * 596 * Returns: #GstFlowReturn 597 */ 598 public GstFlowReturn wait(GstClockTime time, out GstClockTimeDiff jitter) 599 { 600 return gst_base_sink_wait(gstBaseSink, time, &jitter); 601 } 602 603 /** 604 * This function will block until @time is reached. It is usually called by 605 * subclasses that use their own internal synchronisation. 606 * 607 * If @time is not valid, no synchronisation is done and %GST_CLOCK_BADTIME is 608 * returned. Likewise, if synchronisation is disabled in the element or there 609 * is no clock, no synchronisation is done and %GST_CLOCK_BADTIME is returned. 610 * 611 * This function should only be called with the PREROLL_LOCK held, like when 612 * receiving an EOS event in the #GstBaseSinkClass.event() vmethod or when 613 * receiving a buffer in 614 * the #GstBaseSinkClass.render() vmethod. 615 * 616 * The @time argument should be the running_time of when this method should 617 * return and is not adjusted with any latency or offset configured in the 618 * sink. 619 * 620 * Params: 621 * time = the running_time to be reached 622 * jitter = the jitter to be filled with time diff, or %NULL 623 * 624 * Returns: #GstClockReturn 625 */ 626 public GstClockReturn waitClock(GstClockTime time, out GstClockTimeDiff jitter) 627 { 628 return gst_base_sink_wait_clock(gstBaseSink, time, &jitter); 629 } 630 631 /** 632 * If the #GstBaseSinkClass.render() method performs its own synchronisation 633 * against the clock it must unblock when going from PLAYING to the PAUSED state 634 * and call this method before continuing to render the remaining data. 635 * 636 * If the #GstBaseSinkClass.render() method can block on something else than 637 * the clock, it must also be ready to unblock immediately on 638 * the #GstBaseSinkClass.unlock() method and cause the 639 * #GstBaseSinkClass.render() method to immediately call this function. 640 * In this case, the subclass must be prepared to continue rendering where it 641 * left off if this function returns %GST_FLOW_OK. 642 * 643 * This function will block until a state change to PLAYING happens (in which 644 * case this function returns %GST_FLOW_OK) or the processing must be stopped due 645 * to a state change to READY or a FLUSH event (in which case this function 646 * returns %GST_FLOW_FLUSHING). 647 * 648 * This function should only be called with the PREROLL_LOCK held, like in the 649 * render function. 650 * 651 * Returns: %GST_FLOW_OK if the preroll completed and processing can 652 * continue. Any other return value should be returned from the render vmethod. 653 */ 654 public GstFlowReturn waitPreroll() 655 { 656 return gst_base_sink_wait_preroll(gstBaseSink); 657 } 658 }