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