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