gstreamer_app/auto/app_sink.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// Appsink is a sink plugin that supports many different methods for making
16 /// the application get a handle on the GStreamer data in a pipeline. Unlike
17 /// most GStreamer elements, Appsink provides external API functions.
18 ///
19 /// appsink can be used by linking to the gstappsink.h header file to access the
20 /// methods or by using the appsink action signals and properties.
21 ///
22 /// The normal way of retrieving samples from appsink is by using the
23 /// [`pull_sample()`][Self::pull_sample()] and [`pull_preroll()`][Self::pull_preroll()] methods.
24 /// These methods block until a sample becomes available in the sink or when the
25 /// sink is shut down or reaches EOS. There are also timed variants of these
26 /// methods, [`try_pull_sample()`][Self::try_pull_sample()] and [`try_pull_preroll()`][Self::try_pull_preroll()],
27 /// which accept a timeout parameter to limit the amount of time to wait.
28 ///
29 /// Appsink will internally use a queue to collect buffers from the streaming
30 /// thread. If the application is not pulling samples fast enough, this queue
31 /// will consume a lot of memory over time. The "max-buffers", "max-time" and "max-bytes"
32 /// properties can be used to limit the queue size. The "drop" property controls whether the
33 /// streaming thread blocks or if older buffers are dropped when the maximum
34 /// queue size is reached. Note that blocking the streaming thread can negatively
35 /// affect real-time performance and should be avoided.
36 ///
37 /// If a blocking behaviour is not desirable, setting the "emit-signals" property
38 /// to [`true`] will make appsink emit the "new-sample" and "new-preroll" signals
39 /// when a sample can be pulled without blocking.
40 ///
41 /// The "caps" property on appsink can be used to control the formats that
42 /// appsink can receive. This property can contain non-fixed caps, the format of
43 /// the pulled samples can be obtained by getting the sample caps.
44 ///
45 /// If one of the pull-preroll or pull-sample methods return [`None`], the appsink
46 /// is stopped or in the EOS state. You can check for the EOS state with the
47 /// "eos" property or with the [`is_eos()`][Self::is_eos()] method.
48 ///
49 /// The eos signal can also be used to be informed when the EOS state is reached
50 /// to avoid polling.
51 ///
52 /// ## Properties
53 ///
54 ///
55 /// #### `buffer-list`
56 /// Readable | Writeable
57 ///
58 ///
59 /// #### `caps`
60 /// Readable | Writeable
61 ///
62 ///
63 /// #### `drop`
64 /// Readable | Writeable
65 ///
66 ///
67 /// #### `emit-signals`
68 /// Readable | Writeable
69 ///
70 ///
71 /// #### `eos`
72 /// Readable
73 ///
74 ///
75 /// #### `max-buffers`
76 /// Maximum amount of buffers in the queue (0 = unlimited).
77 ///
78 /// Readable | Writeable
79 ///
80 ///
81 /// #### `max-bytes`
82 /// Maximum amount of bytes in the queue (0 = unlimited)
83 ///
84 /// Readable | Writeable
85 ///
86 ///
87 /// #### `max-time`
88 /// Maximum total duration of data in the queue (0 = unlimited)
89 ///
90 /// Readable | Writeable
91 ///
92 ///
93 /// #### `wait-on-eos`
94 /// Wait for all buffers to be processed after receiving an EOS.
95 ///
96 /// In cases where it is uncertain if an `appsink` will have a consumer for its buffers
97 /// when it receives an EOS, set to [`false`] to ensure that the `appsink` will not hang.
98 ///
99 /// Readable | Writeable
100 /// <details><summary><h4>BaseSink</h4></summary>
101 ///
102 ///
103 /// #### `async`
104 /// If set to [`true`], the basesink will perform asynchronous state changes.
105 /// When set to [`false`], the sink will not signal the parent when it prerolls.
106 /// Use this option when dealing with sparse streams or when synchronisation is
107 /// not required.
108 ///
109 /// Readable | Writeable
110 ///
111 ///
112 /// #### `blocksize`
113 /// The amount of bytes to pull when operating in pull mode.
114 ///
115 /// Readable | Writeable
116 ///
117 ///
118 /// #### `enable-last-sample`
119 /// Enable the last-sample property. If [`false`], basesink doesn't keep a
120 /// reference to the last buffer arrived and the last-sample property is always
121 /// set to [`None`]. This can be useful if you need buffers to be released as soon
122 /// as possible, eg. if you're using a buffer pool.
123 ///
124 /// Readable | Writeable
125 ///
126 ///
127 /// #### `last-sample`
128 /// The last buffer that arrived in the sink and was used for preroll or for
129 /// rendering. This property can be used to generate thumbnails. This property
130 /// can be [`None`] when the sink has not yet received a buffer.
131 ///
132 /// Readable
133 ///
134 ///
135 /// #### `max-bitrate`
136 /// Control the maximum amount of bits that will be rendered per second.
137 /// Setting this property to a value bigger than 0 will make the sink delay
138 /// rendering of the buffers when it would exceed to max-bitrate.
139 ///
140 /// Readable | Writeable
141 ///
142 ///
143 /// #### `max-lateness`
144 /// Readable | Writeable
145 ///
146 ///
147 /// #### `processing-deadline`
148 /// Maximum amount of time (in nanoseconds) that the pipeline can take
149 /// for processing the buffer. This is added to the latency of live
150 /// pipelines.
151 ///
152 /// Readable | Writeable
153 ///
154 ///
155 /// #### `qos`
156 /// Readable | Writeable
157 ///
158 ///
159 /// #### `render-delay`
160 /// The additional delay between synchronisation and actual rendering of the
161 /// media. This property will add additional latency to the device in order to
162 /// make other sinks compensate for the delay.
163 ///
164 /// Readable | Writeable
165 ///
166 ///
167 /// #### `stats`
168 /// Various `GstBaseSink` statistics. This property returns a [`gst::Structure`][crate::gst::Structure]
169 /// with name `application/x-gst-base-sink-stats` with the following fields:
170 ///
171 /// - "average-rate" G_TYPE_DOUBLE average frame rate
172 /// - "dropped" G_TYPE_UINT64 Number of dropped frames
173 /// - "rendered" G_TYPE_UINT64 Number of rendered frames
174 ///
175 /// Readable
176 ///
177 ///
178 /// #### `sync`
179 /// Readable | Writeable
180 ///
181 ///
182 /// #### `throttle-time`
183 /// The time to insert between buffers. This property can be used to control
184 /// the maximum amount of buffers per second to render. Setting this property
185 /// to a value bigger than 0 will make the sink create THROTTLE QoS events.
186 ///
187 /// Readable | Writeable
188 ///
189 ///
190 /// #### `ts-offset`
191 /// Controls the final synchronisation, a negative value will render the buffer
192 /// earlier while a positive value delays playback. This property can be
193 /// used to fix synchronisation in bad files.
194 ///
195 /// Readable | Writeable
196 /// </details>
197 /// <details><summary><h4>Object</h4></summary>
198 ///
199 ///
200 /// #### `name`
201 /// Readable | Writeable | Construct
202 ///
203 ///
204 /// #### `parent`
205 /// The parent of the object. Please note, that when changing the 'parent'
206 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
207 /// signals due to locking issues. In some cases one can use
208 /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
209 /// achieve a similar effect.
210 ///
211 /// Readable | Writeable
212 /// </details>
213 ///
214 /// ## Signals
215 ///
216 ///
217 /// #### `eos`
218 /// Signal that the end-of-stream has been reached. This signal is emitted from
219 /// the streaming thread.
220 ///
221 ///
222 ///
223 ///
224 /// #### `new-preroll`
225 /// Signal that a new preroll sample is available.
226 ///
227 /// This signal is emitted from the streaming thread and only when the
228 /// "emit-signals" property is [`true`].
229 ///
230 /// The new preroll sample can be retrieved with the "pull-preroll" action
231 /// signal or [`AppSink::pull_preroll()`][crate::AppSink::pull_preroll()] either from this signal callback
232 /// or from any other thread.
233 ///
234 /// Note that this signal is only emitted when the "emit-signals" property is
235 /// set to [`true`], which it is not by default for performance reasons.
236 ///
237 ///
238 ///
239 ///
240 /// #### `new-sample`
241 /// Signal that a new sample is available.
242 ///
243 /// This signal is emitted from the streaming thread and only when the
244 /// "emit-signals" property is [`true`].
245 ///
246 /// The new sample can be retrieved with the "pull-sample" action
247 /// signal or [`AppSink::pull_sample()`][crate::AppSink::pull_sample()] either from this signal callback
248 /// or from any other thread.
249 ///
250 /// Note that this signal is only emitted when the "emit-signals" property is
251 /// set to [`true`], which it is not by default for performance reasons.
252 ///
253 ///
254 ///
255 ///
256 /// #### `new-serialized-event`
257 /// Signal that a new downstream serialized event is available.
258 ///
259 /// This signal is emitted from the streaming thread and only when the
260 /// "emit-signals" property is [`true`].
261 ///
262 /// The new event can be retrieved with the "try-pull-object" action
263 /// signal or [`AppSink::pull_object()`][crate::AppSink::pull_object()] either from this signal callback
264 /// or from any other thread.
265 ///
266 /// EOS will not be notified using this signal, use [`eos`][struct@crate::AppSink#eos] instead.
267 /// EOS cannot be pulled either, use [`AppSink::is_eos()`][crate::AppSink::is_eos()] to check for it.
268 ///
269 /// Note that this signal is only emitted when the "emit-signals" property is
270 /// set to [`true`], which it is not by default for performance reasons.
271 ///
272 /// The callback should return [`true`] if the event has been handled, which will
273 /// skip basesink handling of the event, [`false`] otherwise.
274 ///
275 ///
276 ///
277 ///
278 /// #### `propose-allocation`
279 /// Signal that a new propose_allocation query is available.
280 ///
281 /// This signal is emitted from the streaming thread and only when the
282 /// "emit-signals" property is [`true`].
283 ///
284 ///
285 ///
286 ///
287 /// #### `pull-preroll`
288 /// Get the last preroll sample in `appsink`. This was the sample that caused the
289 /// appsink to preroll in the PAUSED state.
290 ///
291 /// This function is typically used when dealing with a pipeline in the PAUSED
292 /// state. Calling this function after doing a seek will give the sample right
293 /// after the seek position.
294 ///
295 /// Calling this function will clear the internal reference to the preroll
296 /// buffer.
297 ///
298 /// Note that the preroll sample will also be returned as the first sample
299 /// when calling [`AppSink::pull_sample()`][crate::AppSink::pull_sample()] or the "pull-sample" action signal.
300 ///
301 /// If an EOS event was received before any buffers, this function returns
302 /// [`None`]. Use gst_app_sink_is_eos () to check for the EOS condition.
303 ///
304 /// This function blocks until a preroll sample or EOS is received or the appsink
305 /// element is set to the READY/NULL state.
306 ///
307 /// Action
308 ///
309 ///
310 /// #### `pull-sample`
311 /// This function blocks until a sample or EOS becomes available or the appsink
312 /// element is set to the READY/NULL state.
313 ///
314 /// This function will only return samples when the appsink is in the PLAYING
315 /// state. All rendered samples will be put in a queue so that the application
316 /// can pull samples at its own rate.
317 ///
318 /// Note that when the application does not pull samples fast enough, the
319 /// queued samples could consume a lot of memory, especially when dealing with
320 /// raw video frames. It's possible to control the behaviour of the queue with
321 /// the "drop" and "max-buffers" / "max-bytes" / "max-time" set of properties.
322 ///
323 /// If an EOS event was received before any buffers, this function returns
324 /// [`None`]. Use gst_app_sink_is_eos () to check for the EOS condition.
325 ///
326 /// Action
327 ///
328 ///
329 /// #### `try-pull-object`
330 /// This function blocks until a sample or an event becomes available or the appsink
331 /// element is set to the READY/NULL state or the timeout expires.
332 ///
333 /// This function will only return samples when the appsink is in the PLAYING
334 /// state. All rendered samples and events will be put in a queue so that the application
335 /// can pull them at its own rate.
336 /// Events can be pulled when the appsink is in the READY, PAUSED or PLAYING state.
337 ///
338 /// Note that when the application does not pull samples fast enough, the
339 /// queued samples could consume a lot of memory, especially when dealing with
340 /// raw video frames. It's possible to control the behaviour of the queue with
341 /// the "drop" and "max-buffers" / "max-bytes" / "max-time" set of properties.
342 ///
343 /// This function will only pull serialized events, excluding
344 /// the EOS event for which this functions returns
345 /// [`None`]. Use [`AppSink::is_eos()`][crate::AppSink::is_eos()] to check for the EOS condition.
346 ///
347 /// This signal is a variant of [`try-pull-sample`][struct@crate::AppSink#try-pull-sample]: that can be used
348 /// to handle incoming events as well as samples.
349 ///
350 /// Note that future releases may extend this API to return other object types
351 /// so make sure that your code is checking for the actual type it is handling.
352 ///
353 /// Action
354 ///
355 ///
356 /// #### `try-pull-preroll`
357 /// Get the last preroll sample in `appsink`. This was the sample that caused the
358 /// appsink to preroll in the PAUSED state.
359 ///
360 /// This function is typically used when dealing with a pipeline in the PAUSED
361 /// state. Calling this function after doing a seek will give the sample right
362 /// after the seek position.
363 ///
364 /// Calling this function will clear the internal reference to the preroll
365 /// buffer.
366 ///
367 /// Note that the preroll sample will also be returned as the first sample
368 /// when calling [`AppSink::pull_sample()`][crate::AppSink::pull_sample()] or the "pull-sample" action signal.
369 ///
370 /// If an EOS event was received before any buffers or the timeout expires,
371 /// this function returns [`None`]. Use gst_app_sink_is_eos () to check for the EOS
372 /// condition.
373 ///
374 /// This function blocks until a preroll sample or EOS is received, the appsink
375 /// element is set to the READY/NULL state, or the timeout expires.
376 ///
377 /// Action
378 ///
379 ///
380 /// #### `try-pull-sample`
381 /// This function blocks until a sample or EOS becomes available or the appsink
382 /// element is set to the READY/NULL state or the timeout expires.
383 ///
384 /// This function will only return samples when the appsink is in the PLAYING
385 /// state. All rendered samples will be put in a queue so that the application
386 /// can pull samples at its own rate.
387 ///
388 /// Note that when the application does not pull samples fast enough, the
389 /// queued samples could consume a lot of memory, especially when dealing with
390 /// raw video frames. It's possible to control the behaviour of the queue with
391 /// the "drop" and "max-buffers" / "max-bytes" / "max-time" set of properties.
392 ///
393 /// If an EOS event was received before any buffers or the timeout expires,
394 /// this function returns [`None`]. Use gst_app_sink_is_eos () to check
395 /// for the EOS condition.
396 ///
397 /// Action
398 /// <details><summary><h4>Element</h4></summary>
399 ///
400 ///
401 /// #### `no-more-pads`
402 /// This signals that the element will not generate more dynamic pads.
403 /// Note that this signal will usually be emitted from the context of
404 /// the streaming thread.
405 ///
406 ///
407 ///
408 ///
409 /// #### `pad-added`
410 /// a new `GstPad` has been added to the element. Note that this signal will
411 /// usually be emitted from the context of the streaming thread. Also keep in
412 /// mind that if you add new elements to the pipeline in the signal handler
413 /// you will need to set them to the desired target state with
414 /// [`ElementExtManual::set_state()`][crate::gst::prelude::ElementExtManual::set_state()] or [`ElementExtManual::sync_state_with_parent()`][crate::gst::prelude::ElementExtManual::sync_state_with_parent()].
415 ///
416 ///
417 ///
418 ///
419 /// #### `pad-removed`
420 /// a `GstPad` has been removed from the element
421 ///
422 ///
423 /// </details>
424 /// <details><summary><h4>Object</h4></summary>
425 ///
426 ///
427 /// #### `deep-notify`
428 /// The deep notify signal is used to be notified of property changes. It is
429 /// typically attached to the toplevel bin to receive notifications from all
430 /// the elements contained in that bin.
431 ///
432 /// Detailed
433 /// </details>
434 ///
435 /// # Implements
436 ///
437 /// [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`], [`trait@gst::prelude::URIHandlerExt`]
438 #[doc(alias = "GstAppSink")]
439 pub struct AppSink(Object<ffi::GstAppSink, ffi::GstAppSinkClass>) @extends gst::Element, gst::Object, @implements gst::URIHandler;
440
441 match fn {
442 type_ => || ffi::gst_app_sink_get_type(),
443 }
444}
445
446impl AppSink {
447 /// Check if `self` supports buffer lists.
448 ///
449 /// # Returns
450 ///
451 /// [`true`] if `self` supports buffer lists.
452 #[doc(alias = "gst_app_sink_get_buffer_list_support")]
453 #[doc(alias = "get_buffer_list_support")]
454 pub fn is_buffer_list_support(&self) -> bool {
455 unsafe {
456 from_glib(ffi::gst_app_sink_get_buffer_list_support(
457 self.to_glib_none().0,
458 ))
459 }
460 }
461
462 /// Get the configured caps on `self`.
463 ///
464 /// # Returns
465 ///
466 /// the [`gst::Caps`][crate::gst::Caps] accepted by the sink. `gst_caps_unref()` after usage.
467 #[doc(alias = "gst_app_sink_get_caps")]
468 #[doc(alias = "get_caps")]
469 pub fn caps(&self) -> Option<gst::Caps> {
470 unsafe { from_glib_full(ffi::gst_app_sink_get_caps(self.to_glib_none().0)) }
471 }
472
473 /// Check if `self` will drop old buffers when the maximum amount of queued
474 /// data is reached (meaning max buffers, time or bytes limit, whichever is hit first).
475 ///
476 /// # Returns
477 ///
478 /// [`true`] if `self` is dropping old buffers when the queue is
479 /// filled.
480 #[doc(alias = "gst_app_sink_get_drop")]
481 #[doc(alias = "get_drop")]
482 #[doc(alias = "drop")]
483 pub fn is_drop(&self) -> bool {
484 unsafe { from_glib(ffi::gst_app_sink_get_drop(self.to_glib_none().0)) }
485 }
486
487 /// Get the maximum amount of buffers that can be queued in `self`.
488 ///
489 /// # Returns
490 ///
491 /// The maximum amount of buffers that can be queued.
492 #[doc(alias = "gst_app_sink_get_max_buffers")]
493 #[doc(alias = "get_max_buffers")]
494 #[doc(alias = "max-buffers")]
495 pub fn max_buffers(&self) -> u32 {
496 unsafe { ffi::gst_app_sink_get_max_buffers(self.to_glib_none().0) }
497 }
498
499 /// Get the maximum total size, in bytes, that can be queued in `self`.
500 ///
501 /// # Returns
502 ///
503 /// The maximum amount of bytes that can be queued
504 #[cfg(feature = "v1_24")]
505 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
506 #[doc(alias = "gst_app_sink_get_max_bytes")]
507 #[doc(alias = "get_max_bytes")]
508 #[doc(alias = "max-bytes")]
509 pub fn max_bytes(&self) -> u64 {
510 unsafe { ffi::gst_app_sink_get_max_bytes(self.to_glib_none().0) }
511 }
512
513 /// Get the maximum total duration that can be queued in `self`.
514 ///
515 /// # Returns
516 ///
517 /// The maximum total duration that can be queued.
518 #[cfg(feature = "v1_24")]
519 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
520 #[doc(alias = "gst_app_sink_get_max_time")]
521 #[doc(alias = "get_max_time")]
522 #[doc(alias = "max-time")]
523 pub fn max_time(&self) -> Option<gst::ClockTime> {
524 unsafe { from_glib(ffi::gst_app_sink_get_max_time(self.to_glib_none().0)) }
525 }
526
527 /// Check if `self` will wait for all buffers to be consumed when an EOS is
528 /// received.
529 ///
530 /// # Returns
531 ///
532 /// [`true`] if `self` will wait for all buffers to be consumed when an
533 /// EOS is received.
534 #[doc(alias = "gst_app_sink_get_wait_on_eos")]
535 #[doc(alias = "get_wait_on_eos")]
536 #[doc(alias = "wait-on-eos")]
537 pub fn is_wait_on_eos(&self) -> bool {
538 unsafe { from_glib(ffi::gst_app_sink_get_wait_on_eos(self.to_glib_none().0)) }
539 }
540
541 /// Check if `self` is EOS, which is when no more samples can be pulled because
542 /// an EOS event was received.
543 ///
544 /// This function also returns [`true`] when the appsink is not in the PAUSED or
545 /// PLAYING state.
546 ///
547 /// # Returns
548 ///
549 /// [`true`] if no more samples can be pulled and the appsink is EOS.
550 #[doc(alias = "gst_app_sink_is_eos")]
551 #[doc(alias = "eos")]
552 pub fn is_eos(&self) -> bool {
553 unsafe { from_glib(ffi::gst_app_sink_is_eos(self.to_glib_none().0)) }
554 }
555
556 /// This function blocks until a sample or an event becomes available or the appsink
557 /// element is set to the READY/NULL state.
558 ///
559 /// This function will only return samples when the appsink is in the PLAYING
560 /// state. All rendered buffers and events will be put in a queue so that the application
561 /// can pull them at its own rate. Note that when the application does not
562 /// pull samples fast enough, the queued buffers could consume a lot of memory,
563 /// especially when dealing with raw video frames.
564 /// Events can be pulled when the appsink is in the READY, PAUSED or PLAYING state.
565 ///
566 /// This function will only pull serialized events, excluding
567 /// the EOS event for which this functions returns
568 /// [`None`]. Use [`is_eos()`][Self::is_eos()] to check for the EOS condition.
569 ///
570 /// This method is a variant of [`pull_sample()`][Self::pull_sample()] that can be used
571 /// to handle incoming events events as well as samples.
572 ///
573 /// Note that future releases may extend this API to return other object types
574 /// so make sure that your code is checking for the actual type it is handling.
575 ///
576 /// # Returns
577 ///
578 /// a [`gst::Sample`][crate::gst::Sample], or a `GstEvent` or NULL when the appsink is stopped or EOS.
579 /// Call `gst_mini_object_unref()` after usage.
580 #[cfg(feature = "v1_20")]
581 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
582 #[doc(alias = "gst_app_sink_pull_object")]
583 pub fn pull_object(&self) -> Result<gst::MiniObject, glib::BoolError> {
584 unsafe {
585 Option::<_>::from_glib_full(ffi::gst_app_sink_pull_object(self.to_glib_none().0))
586 .ok_or_else(|| glib::bool_error!("Failed to pull object"))
587 }
588 }
589
590 /// Get the last preroll sample in `self`. This was the sample that caused the
591 /// appsink to preroll in the PAUSED state.
592 ///
593 /// This function is typically used when dealing with a pipeline in the PAUSED
594 /// state. Calling this function after doing a seek will give the sample right
595 /// after the seek position.
596 ///
597 /// Calling this function will clear the internal reference to the preroll
598 /// buffer.
599 ///
600 /// Note that the preroll sample will also be returned as the first sample
601 /// when calling [`pull_sample()`][Self::pull_sample()].
602 ///
603 /// If an EOS event was received before any buffers, this function returns
604 /// [`None`]. Use gst_app_sink_is_eos () to check for the EOS condition.
605 ///
606 /// This function blocks until a preroll sample or EOS is received or the appsink
607 /// element is set to the READY/NULL state.
608 ///
609 /// # Returns
610 ///
611 /// a [`gst::Sample`][crate::gst::Sample] or NULL when the appsink is stopped or EOS.
612 /// Call `gst_sample_unref()` after usage.
613 #[doc(alias = "gst_app_sink_pull_preroll")]
614 pub fn pull_preroll(&self) -> Result<gst::Sample, glib::BoolError> {
615 unsafe {
616 Option::<_>::from_glib_full(ffi::gst_app_sink_pull_preroll(self.to_glib_none().0))
617 .ok_or_else(|| glib::bool_error!("Failed to pull preroll sample"))
618 }
619 }
620
621 /// This function blocks until a sample or EOS becomes available or the appsink
622 /// element is set to the READY/NULL state.
623 ///
624 /// This function will only return samples when the appsink is in the PLAYING
625 /// state. All rendered buffers will be put in a queue so that the application
626 /// can pull samples at its own rate. Note that when the application does not
627 /// pull samples fast enough, the queued buffers could consume a lot of memory,
628 /// especially when dealing with raw video frames.
629 ///
630 /// If an EOS event was received before any buffers, this function returns
631 /// [`None`]. Use gst_app_sink_is_eos () to check for the EOS condition.
632 ///
633 /// # Returns
634 ///
635 /// a [`gst::Sample`][crate::gst::Sample] or NULL when the appsink is stopped or EOS.
636 /// Call `gst_sample_unref()` after usage.
637 #[doc(alias = "gst_app_sink_pull_sample")]
638 pub fn pull_sample(&self) -> Result<gst::Sample, glib::BoolError> {
639 unsafe {
640 Option::<_>::from_glib_full(ffi::gst_app_sink_pull_sample(self.to_glib_none().0))
641 .ok_or_else(|| glib::bool_error!("Failed to pull sample"))
642 }
643 }
644
645 /// Instruct `self` to enable or disable buffer list support.
646 ///
647 /// For backwards-compatibility reasons applications need to opt in
648 /// to indicate that they will be able to handle buffer lists.
649 /// ## `enable_lists`
650 /// enable or disable buffer list support
651 #[doc(alias = "gst_app_sink_set_buffer_list_support")]
652 pub fn set_buffer_list_support(&self, enable_lists: bool) {
653 unsafe {
654 ffi::gst_app_sink_set_buffer_list_support(
655 self.to_glib_none().0,
656 enable_lists.into_glib(),
657 );
658 }
659 }
660
661 //#[doc(alias = "gst_app_sink_set_callbacks")]
662 //pub fn set_callbacks(&self, callbacks: /*Ignored*/&mut AppSinkCallbacks, user_data: /*Unimplemented*/Option<Basic: Pointer>) {
663 // unsafe { TODO: call ffi:gst_app_sink_set_callbacks() }
664 //}
665
666 /// Set the capabilities on the appsink element. This function takes
667 /// a copy of the caps structure. After calling this method, the sink will only
668 /// accept caps that match `caps`. If `caps` is non-fixed, or incomplete,
669 /// you must check the caps on the samples to get the actual used caps.
670 /// ## `caps`
671 /// caps to set
672 #[doc(alias = "gst_app_sink_set_caps")]
673 #[doc(alias = "caps")]
674 pub fn set_caps(&self, caps: Option<&gst::Caps>) {
675 unsafe {
676 ffi::gst_app_sink_set_caps(self.to_glib_none().0, caps.to_glib_none().0);
677 }
678 }
679
680 /// Instruct `self` to drop old buffers when the maximum amount of queued
681 /// data is reached, that is, when any configured limit is hit (max-buffers, max-time or max-bytes).
682 /// ## `drop`
683 /// the new state
684 #[doc(alias = "gst_app_sink_set_drop")]
685 #[doc(alias = "drop")]
686 pub fn set_drop(&self, drop: bool) {
687 unsafe {
688 ffi::gst_app_sink_set_drop(self.to_glib_none().0, drop.into_glib());
689 }
690 }
691
692 /// Set the maximum amount of buffers that can be queued in `self`. After this
693 /// amount of buffers are queued in appsink, any more buffers will block upstream
694 /// elements until a sample is pulled from `self`, unless 'drop' is set, in which
695 /// case new buffers will be discarded.
696 /// ## `max`
697 /// the maximum number of buffers to queue
698 #[doc(alias = "gst_app_sink_set_max_buffers")]
699 #[doc(alias = "max-buffers")]
700 pub fn set_max_buffers(&self, max: u32) {
701 unsafe {
702 ffi::gst_app_sink_set_max_buffers(self.to_glib_none().0, max);
703 }
704 }
705
706 /// Set the maximum total size that can be queued in `self`. After this
707 /// amount of buffers are queued in appsink, any more buffers will block upstream
708 /// elements until a sample is pulled from `self`, unless 'drop' is set, in which
709 /// case new buffers will be discarded.
710 /// ## `max`
711 /// the maximum total size of buffers to queue, in bytes
712 #[cfg(feature = "v1_24")]
713 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
714 #[doc(alias = "gst_app_sink_set_max_bytes")]
715 #[doc(alias = "max-bytes")]
716 pub fn set_max_bytes(&self, max: u64) {
717 unsafe {
718 ffi::gst_app_sink_set_max_bytes(self.to_glib_none().0, max);
719 }
720 }
721
722 /// Set the maximum total duration that can be queued in `self`. After this
723 /// amount of buffers are queued in appsink, any more buffers will block upstream
724 /// elements until a sample is pulled from `self`, unless 'drop' is set, in which
725 /// case new buffers will be discarded.
726 /// ## `max`
727 /// the maximum total duration to queue
728 #[cfg(feature = "v1_24")]
729 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
730 #[doc(alias = "gst_app_sink_set_max_time")]
731 #[doc(alias = "max-time")]
732 pub fn set_max_time(&self, max: impl Into<Option<gst::ClockTime>>) {
733 unsafe {
734 ffi::gst_app_sink_set_max_time(self.to_glib_none().0, max.into().into_glib());
735 }
736 }
737
738 /// Instruct `self` to wait for all buffers to be consumed when an EOS is received.
739 /// ## `wait`
740 /// the new state
741 #[doc(alias = "gst_app_sink_set_wait_on_eos")]
742 #[doc(alias = "wait-on-eos")]
743 pub fn set_wait_on_eos(&self, wait: bool) {
744 unsafe {
745 ffi::gst_app_sink_set_wait_on_eos(self.to_glib_none().0, wait.into_glib());
746 }
747 }
748
749 /// This function blocks until a sample or an event or EOS becomes available or the appsink
750 /// element is set to the READY/NULL state or the timeout expires.
751 ///
752 /// This function will only return samples when the appsink is in the PLAYING
753 /// state. All rendered buffers and events will be put in a queue so that the application
754 /// can pull them at its own rate. Note that when the application does not
755 /// pull samples fast enough, the queued buffers could consume a lot of memory,
756 /// especially when dealing with raw video frames.
757 /// Events can be pulled when the appsink is in the READY, PAUSED or PLAYING state.
758 ///
759 /// This function will only pull serialized events, excluding
760 /// the EOS event for which this functions returns
761 /// [`None`]. Use [`is_eos()`][Self::is_eos()] to check for the EOS condition.
762 ///
763 /// This method is a variant of [`try_pull_sample()`][Self::try_pull_sample()] that can be used
764 /// to handle incoming events events as well as samples.
765 ///
766 /// Note that future releases may extend this API to return other object types
767 /// so make sure that your code is checking for the actual type it is handling.
768 /// ## `timeout`
769 /// the maximum amount of time to wait for a sample
770 ///
771 /// # Returns
772 ///
773 /// a [`gst::Sample`][crate::gst::Sample], or `GstEvent` or NULL when the appsink is stopped or EOS or the timeout expires.
774 /// Call `gst_mini_object_unref()` after usage.
775 #[cfg(feature = "v1_20")]
776 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
777 #[doc(alias = "gst_app_sink_try_pull_object")]
778 pub fn try_pull_object(
779 &self,
780 timeout: impl Into<Option<gst::ClockTime>>,
781 ) -> Option<gst::MiniObject> {
782 unsafe {
783 from_glib_full(ffi::gst_app_sink_try_pull_object(
784 self.to_glib_none().0,
785 timeout.into().into_glib(),
786 ))
787 }
788 }
789
790 /// Get the last preroll sample in `self`. This was the sample that caused the
791 /// appsink to preroll in the PAUSED state.
792 ///
793 /// This function is typically used when dealing with a pipeline in the PAUSED
794 /// state. Calling this function after doing a seek will give the sample right
795 /// after the seek position.
796 ///
797 /// Calling this function will clear the internal reference to the preroll
798 /// buffer.
799 ///
800 /// Note that the preroll sample will also be returned as the first sample
801 /// when calling [`pull_sample()`][Self::pull_sample()].
802 ///
803 /// If an EOS event was received before any buffers or the timeout expires,
804 /// this function returns [`None`]. Use gst_app_sink_is_eos () to check for the EOS
805 /// condition.
806 ///
807 /// This function blocks until a preroll sample or EOS is received, the appsink
808 /// element is set to the READY/NULL state, or the timeout expires.
809 /// ## `timeout`
810 /// the maximum amount of time to wait for the preroll sample
811 ///
812 /// # Returns
813 ///
814 /// a [`gst::Sample`][crate::gst::Sample] or NULL when the appsink is stopped or EOS or the timeout expires.
815 /// Call `gst_sample_unref()` after usage.
816 #[doc(alias = "gst_app_sink_try_pull_preroll")]
817 pub fn try_pull_preroll(
818 &self,
819 timeout: impl Into<Option<gst::ClockTime>>,
820 ) -> Option<gst::Sample> {
821 unsafe {
822 from_glib_full(ffi::gst_app_sink_try_pull_preroll(
823 self.to_glib_none().0,
824 timeout.into().into_glib(),
825 ))
826 }
827 }
828
829 /// This function blocks until a sample or EOS becomes available or the appsink
830 /// element is set to the READY/NULL state or the timeout expires.
831 ///
832 /// This function will only return samples when the appsink is in the PLAYING
833 /// state. All rendered buffers will be put in a queue so that the application
834 /// can pull samples at its own rate. Note that when the application does not
835 /// pull samples fast enough, the queued buffers could consume a lot of memory,
836 /// especially when dealing with raw video frames.
837 ///
838 /// If an EOS event was received before any buffers or the timeout expires,
839 /// this function returns [`None`]. Use gst_app_sink_is_eos () to check for the EOS
840 /// condition.
841 /// ## `timeout`
842 /// the maximum amount of time to wait for a sample
843 ///
844 /// # Returns
845 ///
846 /// a [`gst::Sample`][crate::gst::Sample] or NULL when the appsink is stopped or EOS or the timeout expires.
847 /// Call `gst_sample_unref()` after usage.
848 #[doc(alias = "gst_app_sink_try_pull_sample")]
849 pub fn try_pull_sample(
850 &self,
851 timeout: impl Into<Option<gst::ClockTime>>,
852 ) -> Option<gst::Sample> {
853 unsafe {
854 from_glib_full(ffi::gst_app_sink_try_pull_sample(
855 self.to_glib_none().0,
856 timeout.into().into_glib(),
857 ))
858 }
859 }
860
861 #[doc(alias = "buffer-list")]
862 pub fn is_buffer_list(&self) -> bool {
863 ObjectExt::property(self, "buffer-list")
864 }
865
866 #[doc(alias = "buffer-list")]
867 pub fn set_buffer_list(&self, buffer_list: bool) {
868 ObjectExt::set_property(self, "buffer-list", buffer_list)
869 }
870
871 #[doc(alias = "buffer-list")]
872 pub fn connect_buffer_list_notify<F: Fn(&Self) + Send + Sync + 'static>(
873 &self,
874 f: F,
875 ) -> SignalHandlerId {
876 unsafe extern "C" fn notify_buffer_list_trampoline<
877 F: Fn(&AppSink) + Send + Sync + 'static,
878 >(
879 this: *mut ffi::GstAppSink,
880 _param_spec: glib::ffi::gpointer,
881 f: glib::ffi::gpointer,
882 ) {
883 let f: &F = &*(f as *const F);
884 f(&from_glib_borrow(this))
885 }
886 unsafe {
887 let f: Box_<F> = Box_::new(f);
888 connect_raw(
889 self.as_ptr() as *mut _,
890 c"notify::buffer-list".as_ptr() as *const _,
891 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
892 notify_buffer_list_trampoline::<F> as *const (),
893 )),
894 Box_::into_raw(f),
895 )
896 }
897 }
898
899 #[doc(alias = "caps")]
900 pub fn connect_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(
901 &self,
902 f: F,
903 ) -> SignalHandlerId {
904 unsafe extern "C" fn notify_caps_trampoline<F: Fn(&AppSink) + Send + Sync + 'static>(
905 this: *mut ffi::GstAppSink,
906 _param_spec: glib::ffi::gpointer,
907 f: glib::ffi::gpointer,
908 ) {
909 let f: &F = &*(f as *const F);
910 f(&from_glib_borrow(this))
911 }
912 unsafe {
913 let f: Box_<F> = Box_::new(f);
914 connect_raw(
915 self.as_ptr() as *mut _,
916 c"notify::caps".as_ptr() as *const _,
917 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
918 notify_caps_trampoline::<F> as *const (),
919 )),
920 Box_::into_raw(f),
921 )
922 }
923 }
924
925 #[doc(alias = "drop")]
926 pub fn connect_drop_notify<F: Fn(&Self) + Send + Sync + 'static>(
927 &self,
928 f: F,
929 ) -> SignalHandlerId {
930 unsafe extern "C" fn notify_drop_trampoline<F: Fn(&AppSink) + Send + Sync + 'static>(
931 this: *mut ffi::GstAppSink,
932 _param_spec: glib::ffi::gpointer,
933 f: glib::ffi::gpointer,
934 ) {
935 let f: &F = &*(f as *const F);
936 f(&from_glib_borrow(this))
937 }
938 unsafe {
939 let f: Box_<F> = Box_::new(f);
940 connect_raw(
941 self.as_ptr() as *mut _,
942 c"notify::drop".as_ptr() as *const _,
943 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
944 notify_drop_trampoline::<F> as *const (),
945 )),
946 Box_::into_raw(f),
947 )
948 }
949 }
950
951 #[doc(alias = "eos")]
952 pub fn connect_eos_notify<F: Fn(&Self) + Send + Sync + 'static>(
953 &self,
954 f: F,
955 ) -> SignalHandlerId {
956 unsafe extern "C" fn notify_eos_trampoline<F: Fn(&AppSink) + Send + Sync + 'static>(
957 this: *mut ffi::GstAppSink,
958 _param_spec: glib::ffi::gpointer,
959 f: glib::ffi::gpointer,
960 ) {
961 let f: &F = &*(f as *const F);
962 f(&from_glib_borrow(this))
963 }
964 unsafe {
965 let f: Box_<F> = Box_::new(f);
966 connect_raw(
967 self.as_ptr() as *mut _,
968 c"notify::eos".as_ptr() as *const _,
969 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
970 notify_eos_trampoline::<F> as *const (),
971 )),
972 Box_::into_raw(f),
973 )
974 }
975 }
976
977 #[doc(alias = "max-buffers")]
978 pub fn connect_max_buffers_notify<F: Fn(&Self) + Send + Sync + 'static>(
979 &self,
980 f: F,
981 ) -> SignalHandlerId {
982 unsafe extern "C" fn notify_max_buffers_trampoline<
983 F: Fn(&AppSink) + Send + Sync + 'static,
984 >(
985 this: *mut ffi::GstAppSink,
986 _param_spec: glib::ffi::gpointer,
987 f: glib::ffi::gpointer,
988 ) {
989 let f: &F = &*(f as *const F);
990 f(&from_glib_borrow(this))
991 }
992 unsafe {
993 let f: Box_<F> = Box_::new(f);
994 connect_raw(
995 self.as_ptr() as *mut _,
996 c"notify::max-buffers".as_ptr() as *const _,
997 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
998 notify_max_buffers_trampoline::<F> as *const (),
999 )),
1000 Box_::into_raw(f),
1001 )
1002 }
1003 }
1004
1005 #[cfg(feature = "v1_24")]
1006 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
1007 #[doc(alias = "max-bytes")]
1008 pub fn connect_max_bytes_notify<F: Fn(&Self) + Send + Sync + 'static>(
1009 &self,
1010 f: F,
1011 ) -> SignalHandlerId {
1012 unsafe extern "C" fn notify_max_bytes_trampoline<
1013 F: Fn(&AppSink) + Send + Sync + 'static,
1014 >(
1015 this: *mut ffi::GstAppSink,
1016 _param_spec: glib::ffi::gpointer,
1017 f: glib::ffi::gpointer,
1018 ) {
1019 let f: &F = &*(f as *const F);
1020 f(&from_glib_borrow(this))
1021 }
1022 unsafe {
1023 let f: Box_<F> = Box_::new(f);
1024 connect_raw(
1025 self.as_ptr() as *mut _,
1026 c"notify::max-bytes".as_ptr() as *const _,
1027 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1028 notify_max_bytes_trampoline::<F> as *const (),
1029 )),
1030 Box_::into_raw(f),
1031 )
1032 }
1033 }
1034
1035 #[cfg(feature = "v1_24")]
1036 #[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
1037 #[doc(alias = "max-time")]
1038 pub fn connect_max_time_notify<F: Fn(&Self) + Send + Sync + 'static>(
1039 &self,
1040 f: F,
1041 ) -> SignalHandlerId {
1042 unsafe extern "C" fn notify_max_time_trampoline<F: Fn(&AppSink) + Send + Sync + 'static>(
1043 this: *mut ffi::GstAppSink,
1044 _param_spec: glib::ffi::gpointer,
1045 f: glib::ffi::gpointer,
1046 ) {
1047 let f: &F = &*(f as *const F);
1048 f(&from_glib_borrow(this))
1049 }
1050 unsafe {
1051 let f: Box_<F> = Box_::new(f);
1052 connect_raw(
1053 self.as_ptr() as *mut _,
1054 c"notify::max-time".as_ptr() as *const _,
1055 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1056 notify_max_time_trampoline::<F> as *const (),
1057 )),
1058 Box_::into_raw(f),
1059 )
1060 }
1061 }
1062
1063 #[doc(alias = "wait-on-eos")]
1064 pub fn connect_wait_on_eos_notify<F: Fn(&Self) + Send + Sync + 'static>(
1065 &self,
1066 f: F,
1067 ) -> SignalHandlerId {
1068 unsafe extern "C" fn notify_wait_on_eos_trampoline<
1069 F: Fn(&AppSink) + Send + Sync + 'static,
1070 >(
1071 this: *mut ffi::GstAppSink,
1072 _param_spec: glib::ffi::gpointer,
1073 f: glib::ffi::gpointer,
1074 ) {
1075 let f: &F = &*(f as *const F);
1076 f(&from_glib_borrow(this))
1077 }
1078 unsafe {
1079 let f: Box_<F> = Box_::new(f);
1080 connect_raw(
1081 self.as_ptr() as *mut _,
1082 c"notify::wait-on-eos".as_ptr() as *const _,
1083 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1084 notify_wait_on_eos_trampoline::<F> as *const (),
1085 )),
1086 Box_::into_raw(f),
1087 )
1088 }
1089 }
1090}
1091
1092unsafe impl Send for AppSink {}
1093unsafe impl Sync for AppSink {}