1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
// This file was generated by gir (https://github.com/gtk-rs/gir) // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT use glib; use glib::object::Cast; use glib::object::IsA; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; use glib_sys; use gst; use gst_audio_sys; use std::boxed::Box as Box_; use std::mem; use std::mem::transmute; use AudioInfo; glib_wrapper! { /// This base class is for audio decoders turning encoded data into /// raw audio samples. /// /// GstAudioDecoder and subclass should cooperate as follows. /// /// ## Configuration /// /// * Initially, GstAudioDecoder calls `start` when the decoder element /// is activated, which allows subclass to perform any global setup. /// Base class (context) parameters can already be set according to subclass /// capabilities (or possibly upon receive more information in subsequent /// `set_format`). /// * GstAudioDecoder calls `set_format` to inform subclass of the format /// of input audio data that it is about to receive. /// While unlikely, it might be called more than once, if changing input /// parameters require reconfiguration. /// * GstAudioDecoder calls `stop` at end of all processing. /// /// As of configuration stage, and throughout processing, GstAudioDecoder /// provides various (context) parameters, e.g. describing the format of /// output audio data (valid when output caps have been set) or current parsing state. /// Conversely, subclass can and should configure context to inform /// base class of its expectation w.r.t. buffer handling. /// /// ## Data processing /// * Base class gathers input data, and optionally allows subclass /// to parse this into subsequently manageable (as defined by subclass) /// chunks. Such chunks are subsequently referred to as 'frames', /// though they may or may not correspond to 1 (or more) audio format frame. /// * Input frame is provided to subclass' `handle_frame`. /// * If codec processing results in decoded data, subclass should call /// `AudioDecoder::finish_frame` to have decoded data pushed /// downstream. /// * Just prior to actually pushing a buffer downstream, /// it is passed to `pre_push`. Subclass should either use this callback /// to arrange for additional downstream pushing or otherwise ensure such /// custom pushing occurs after at least a method call has finished since /// setting src pad caps. /// * During the parsing process GstAudioDecoderClass will handle both /// srcpad and sinkpad events. Sink events will be passed to subclass /// if `event` callback has been provided. /// /// ## Shutdown phase /// /// * GstAudioDecoder class calls `stop` to inform the subclass that data /// parsing will be stopped. /// /// Subclass is responsible for providing pad template caps for /// source and sink pads. The pads need to be named "sink" and "src". It also /// needs to set the fixed caps on srcpad, when the format is ensured. This /// is typically when base class calls subclass' `set_format` function, though /// it might be delayed until calling `AudioDecoder::finish_frame`. /// /// In summary, above process should have subclass concentrating on /// codec data processing while leaving other matters to base class, /// such as most notably timestamp handling. While it may exert more control /// in this area (see e.g. `pre_push`), it is very much not recommended. /// /// In particular, base class will try to arrange for perfect output timestamps /// as much as possible while tracking upstream timestamps. /// To this end, if deviation between the next ideal expected perfect timestamp /// and upstream exceeds `AudioDecoder:tolerance`, then resync to upstream /// occurs (which would happen always if the tolerance mechanism is disabled). /// /// In non-live pipelines, baseclass can also (configurably) arrange for /// output buffer aggregation which may help to redue large(r) numbers of /// small(er) buffers being pushed and processed downstream. Note that this /// feature is only available if the buffer layout is interleaved. For planar /// buffers, the decoder implementation is fully responsible for the output /// buffer size. /// /// On the other hand, it should be noted that baseclass only provides limited /// seeking support (upon explicit subclass request), as full-fledged support /// should rather be left to upstream demuxer, parser or alike. This simple /// approach caters for seeking and duration reporting using estimated input /// bitrates. /// /// Things that subclass need to take care of: /// /// * Provide pad templates /// * Set source pad caps when appropriate /// * Set user-configurable properties to sane defaults for format and /// implementing codec at hand, and convey some subclass capabilities and /// expectations in context. /// /// * Accept data in `handle_frame` and provide encoded results to /// `AudioDecoder::finish_frame`. If it is prepared to perform /// PLC, it should also accept NULL data in `handle_frame` and provide for /// data for indicated duration. /// /// # Implements /// /// [`AudioDecoderExt`](trait.AudioDecoderExt.html), [`gst::ElementExt`](../gst/trait.ElementExt.html), [`gst::ObjectExt`](../gst/trait.ObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html), [`AudioDecoderExtManual`](prelude/trait.AudioDecoderExtManual.html) pub struct AudioDecoder(Object<gst_audio_sys::GstAudioDecoder, gst_audio_sys::GstAudioDecoderClass, AudioDecoderClass>) @extends gst::Element, gst::Object; match fn { get_type => || gst_audio_sys::gst_audio_decoder_get_type(), } } unsafe impl Send for AudioDecoder {} unsafe impl Sync for AudioDecoder {} pub const NONE_AUDIO_DECODER: Option<&AudioDecoder> = None; /// Trait containing all `AudioDecoder` methods. /// /// # Implementors /// /// [`AudioDecoder`](struct.AudioDecoder.html) pub trait AudioDecoderExt: 'static { /// Helper function that allocates a buffer to hold an audio frame /// for `self`'s current output format. /// ## `size` /// size of the buffer /// /// # Returns /// /// allocated buffer fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError>; /// /// # Returns /// /// a `AudioInfo` describing the input audio format fn get_audio_info(&self) -> Option<AudioInfo>; /// /// # Returns /// /// currently configured decoder delay fn get_delay(&self) -> i32; /// Queries decoder drain handling. /// /// # Returns /// /// TRUE if drainable handling is enabled. /// /// MT safe. fn get_drainable(&self) -> bool; /// /// # Returns /// /// currently configured byte to time conversion setting fn get_estimate_rate(&self) -> i32; /// Sets the variables pointed to by `min` and `max` to the currently configured /// latency. /// ## `min` /// a pointer to storage to hold minimum latency /// ## `max` /// a pointer to storage to hold maximum latency fn get_latency(&self) -> (gst::ClockTime, gst::ClockTime); /// /// # Returns /// /// currently configured decoder tolerated error count. fn get_max_errors(&self) -> i32; /// Queries decoder's latency aggregation. /// /// # Returns /// /// aggregation latency. /// /// MT safe. fn get_min_latency(&self) -> gst::ClockTime; /// Queries decoder required format handling. /// /// # Returns /// /// TRUE if required format handling is enabled. /// /// MT safe. fn get_needs_format(&self) -> bool; /// Return current parsing (sync and eos) state. /// ## `sync` /// a pointer to a variable to hold the current sync state /// ## `eos` /// a pointer to a variable to hold the current eos state fn get_parse_state(&self) -> (bool, bool); /// Queries decoder packet loss concealment handling. /// /// # Returns /// /// TRUE if packet loss concealment is enabled. /// /// MT safe. fn get_plc(&self) -> bool; /// /// # Returns /// /// currently configured plc handling fn get_plc_aware(&self) -> i32; /// Queries current audio jitter tolerance threshold. /// /// # Returns /// /// decoder audio jitter tolerance threshold. /// /// MT safe. fn get_tolerance(&self) -> gst::ClockTime; /// Sets the audio decoder tags and how they should be merged with any /// upstream stream tags. This will override any tags previously-set /// with `AudioDecoderExt::merge_tags`. /// /// Note that this is provided for convenience, and the subclass is /// not required to use this and can still do tag handling on its own. /// ## `tags` /// a `gst::TagList` to merge, or NULL /// ## `mode` /// the `gst::TagMergeMode` to use, usually `gst::TagMergeMode::Replace` fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode); /// Returns caps that express `caps` (or sink template caps if `caps` == NULL) /// restricted to rate/channels/... combinations supported by downstream /// elements. /// ## `caps` /// initial caps /// ## `filter` /// filter caps /// /// # Returns /// /// a `gst::Caps` owned by caller fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps; /// Sets a caps in allocation query which are different from the set /// pad's caps. Use this function before calling /// `AudioDecoder::negotiate`. Setting to `None` the allocation /// query will use the caps from the pad. /// /// Feature: `v1_10` /// /// ## `allocation_caps` /// a `gst::Caps` or `None` #[cfg(any(feature = "v1_10", feature = "dox"))] fn set_allocation_caps(&self, allocation_caps: Option<&gst::Caps>); /// Configures decoder drain handling. If drainable, subclass might /// be handed a NULL buffer to have it return any leftover decoded data. /// Otherwise, it is not considered so capable and will only ever be passed /// real data. /// /// MT safe. /// ## `enabled` /// new state fn set_drainable(&self, enabled: bool); /// Allows baseclass to perform byte to time estimated conversion. /// ## `enabled` /// whether to enable byte to time conversion fn set_estimate_rate(&self, enabled: bool); /// Sets decoder latency. /// ## `min` /// minimum latency /// ## `max` /// maximum latency fn set_latency(&self, min: gst::ClockTime, max: gst::ClockTime); /// Sets numbers of tolerated decoder errors, where a tolerated one is then only /// warned about, but more than tolerated will lead to fatal error. You can set /// -1 for never returning fatal errors. Default is set to /// GST_AUDIO_DECODER_MAX_ERRORS. /// ## `num` /// max tolerated errors fn set_max_errors(&self, num: i32); /// Sets decoder minimum aggregation latency. /// /// MT safe. /// ## `num` /// new minimum latency fn set_min_latency(&self, num: gst::ClockTime); /// Configures decoder format needs. If enabled, subclass needs to be /// negotiated with format caps before it can process any data. It will then /// never be handed any data before it has been configured. /// Otherwise, it might be handed data without having been configured and /// is then expected being able to do so either by default /// or based on the input data. /// /// MT safe. /// ## `enabled` /// new state fn set_needs_format(&self, enabled: bool); /// Enable or disable decoder packet loss concealment, provided subclass /// and codec are capable and allow handling plc. /// /// MT safe. /// ## `enabled` /// new state fn set_plc(&self, enabled: bool); /// Indicates whether or not subclass handles packet loss concealment (plc). /// ## `plc` /// new plc state fn set_plc_aware(&self, plc: bool); /// Configures decoder audio jitter tolerance threshold. /// /// MT safe. /// ## `tolerance` /// new tolerance fn set_tolerance(&self, tolerance: gst::ClockTime); /// Lets `AudioDecoder` sub-classes decide if they want the sink pad /// to use the default pad query handler to reply to accept-caps queries. /// /// By setting this to true it is possible to further customize the default /// handler with `GST_PAD_SET_ACCEPT_INTERSECT` and /// `GST_PAD_SET_ACCEPT_TEMPLATE` /// ## `use_` /// if the default pad accept-caps query handling should be used fn set_use_default_pad_acceptcaps(&self, use_: bool); #[cfg(any(feature = "v1_18", feature = "dox"))] fn connect_property_max_errors_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId; fn connect_property_min_latency_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId; fn connect_property_plc_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId; fn connect_property_tolerance_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId; } impl<O: IsA<AudioDecoder>> AudioDecoderExt for O { fn allocate_output_buffer(&self, size: usize) -> Result<gst::Buffer, glib::BoolError> { unsafe { Option::<_>::from_glib_full(gst_audio_sys::gst_audio_decoder_allocate_output_buffer( self.as_ref().to_glib_none().0, size, )) .ok_or_else(|| glib_bool_error!("Failed to allocate output buffer")) } } fn get_audio_info(&self) -> Option<AudioInfo> { unsafe { from_glib_full(gst_audio_sys::gst_audio_decoder_get_audio_info( self.as_ref().to_glib_none().0, )) } } fn get_delay(&self) -> i32 { unsafe { gst_audio_sys::gst_audio_decoder_get_delay(self.as_ref().to_glib_none().0) } } fn get_drainable(&self) -> bool { unsafe { from_glib(gst_audio_sys::gst_audio_decoder_get_drainable( self.as_ref().to_glib_none().0, )) } } fn get_estimate_rate(&self) -> i32 { unsafe { gst_audio_sys::gst_audio_decoder_get_estimate_rate(self.as_ref().to_glib_none().0) } } fn get_latency(&self) -> (gst::ClockTime, gst::ClockTime) { unsafe { let mut min = mem::MaybeUninit::uninit(); let mut max = mem::MaybeUninit::uninit(); gst_audio_sys::gst_audio_decoder_get_latency( self.as_ref().to_glib_none().0, min.as_mut_ptr(), max.as_mut_ptr(), ); let min = min.assume_init(); let max = max.assume_init(); (from_glib(min), from_glib(max)) } } fn get_max_errors(&self) -> i32 { unsafe { gst_audio_sys::gst_audio_decoder_get_max_errors(self.as_ref().to_glib_none().0) } } fn get_min_latency(&self) -> gst::ClockTime { unsafe { from_glib(gst_audio_sys::gst_audio_decoder_get_min_latency( self.as_ref().to_glib_none().0, )) } } fn get_needs_format(&self) -> bool { unsafe { from_glib(gst_audio_sys::gst_audio_decoder_get_needs_format( self.as_ref().to_glib_none().0, )) } } fn get_parse_state(&self) -> (bool, bool) { unsafe { let mut sync = mem::MaybeUninit::uninit(); let mut eos = mem::MaybeUninit::uninit(); gst_audio_sys::gst_audio_decoder_get_parse_state( self.as_ref().to_glib_none().0, sync.as_mut_ptr(), eos.as_mut_ptr(), ); let sync = sync.assume_init(); let eos = eos.assume_init(); (from_glib(sync), from_glib(eos)) } } fn get_plc(&self) -> bool { unsafe { from_glib(gst_audio_sys::gst_audio_decoder_get_plc( self.as_ref().to_glib_none().0, )) } } fn get_plc_aware(&self) -> i32 { unsafe { gst_audio_sys::gst_audio_decoder_get_plc_aware(self.as_ref().to_glib_none().0) } } fn get_tolerance(&self) -> gst::ClockTime { unsafe { from_glib(gst_audio_sys::gst_audio_decoder_get_tolerance( self.as_ref().to_glib_none().0, )) } } fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) { unsafe { gst_audio_sys::gst_audio_decoder_merge_tags( self.as_ref().to_glib_none().0, tags.to_glib_none().0, mode.to_glib(), ); } } fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps { unsafe { from_glib_full(gst_audio_sys::gst_audio_decoder_proxy_getcaps( self.as_ref().to_glib_none().0, caps.to_glib_none().0, filter.to_glib_none().0, )) } } #[cfg(any(feature = "v1_10", feature = "dox"))] fn set_allocation_caps(&self, allocation_caps: Option<&gst::Caps>) { unsafe { gst_audio_sys::gst_audio_decoder_set_allocation_caps( self.as_ref().to_glib_none().0, allocation_caps.to_glib_none().0, ); } } fn set_drainable(&self, enabled: bool) { unsafe { gst_audio_sys::gst_audio_decoder_set_drainable( self.as_ref().to_glib_none().0, enabled.to_glib(), ); } } fn set_estimate_rate(&self, enabled: bool) { unsafe { gst_audio_sys::gst_audio_decoder_set_estimate_rate( self.as_ref().to_glib_none().0, enabled.to_glib(), ); } } fn set_latency(&self, min: gst::ClockTime, max: gst::ClockTime) { unsafe { gst_audio_sys::gst_audio_decoder_set_latency( self.as_ref().to_glib_none().0, min.to_glib(), max.to_glib(), ); } } fn set_max_errors(&self, num: i32) { unsafe { gst_audio_sys::gst_audio_decoder_set_max_errors(self.as_ref().to_glib_none().0, num); } } fn set_min_latency(&self, num: gst::ClockTime) { unsafe { gst_audio_sys::gst_audio_decoder_set_min_latency( self.as_ref().to_glib_none().0, num.to_glib(), ); } } fn set_needs_format(&self, enabled: bool) { unsafe { gst_audio_sys::gst_audio_decoder_set_needs_format( self.as_ref().to_glib_none().0, enabled.to_glib(), ); } } fn set_plc(&self, enabled: bool) { unsafe { gst_audio_sys::gst_audio_decoder_set_plc( self.as_ref().to_glib_none().0, enabled.to_glib(), ); } } fn set_plc_aware(&self, plc: bool) { unsafe { gst_audio_sys::gst_audio_decoder_set_plc_aware( self.as_ref().to_glib_none().0, plc.to_glib(), ); } } fn set_tolerance(&self, tolerance: gst::ClockTime) { unsafe { gst_audio_sys::gst_audio_decoder_set_tolerance( self.as_ref().to_glib_none().0, tolerance.to_glib(), ); } } fn set_use_default_pad_acceptcaps(&self, use_: bool) { unsafe { gst_audio_sys::gst_audio_decoder_set_use_default_pad_acceptcaps( self.as_ref().to_glib_none().0, use_.to_glib(), ); } } #[cfg(any(feature = "v1_18", feature = "dox"))] fn connect_property_max_errors_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn notify_max_errors_trampoline<P, F: Fn(&P) + Send + Sync + 'static>( this: *mut gst_audio_sys::GstAudioDecoder, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer, ) where P: IsA<AudioDecoder>, { let f: &F = &*(f as *const F); f(&AudioDecoder::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_<F> = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::max-errors\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( notify_max_errors_trampoline::<Self, F> as *const (), )), Box_::into_raw(f), ) } } fn connect_property_min_latency_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn notify_min_latency_trampoline<P, F: Fn(&P) + Send + Sync + 'static>( this: *mut gst_audio_sys::GstAudioDecoder, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer, ) where P: IsA<AudioDecoder>, { let f: &F = &*(f as *const F); f(&AudioDecoder::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_<F> = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::min-latency\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( notify_min_latency_trampoline::<Self, F> as *const (), )), Box_::into_raw(f), ) } } fn connect_property_plc_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn notify_plc_trampoline<P, F: Fn(&P) + Send + Sync + 'static>( this: *mut gst_audio_sys::GstAudioDecoder, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer, ) where P: IsA<AudioDecoder>, { let f: &F = &*(f as *const F); f(&AudioDecoder::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_<F> = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::plc\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( notify_plc_trampoline::<Self, F> as *const (), )), Box_::into_raw(f), ) } } fn connect_property_tolerance_notify<F: Fn(&Self) + Send + Sync + 'static>( &self, f: F, ) -> SignalHandlerId { unsafe extern "C" fn notify_tolerance_trampoline<P, F: Fn(&P) + Send + Sync + 'static>( this: *mut gst_audio_sys::GstAudioDecoder, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer, ) where P: IsA<AudioDecoder>, { let f: &F = &*(f as *const F); f(&AudioDecoder::from_glib_borrow(this).unsafe_cast_ref()) } unsafe { let f: Box_<F> = Box_::new(f); connect_raw( self.as_ptr() as *mut _, b"notify::tolerance\0".as_ptr() as *const _, Some(transmute::<_, unsafe extern "C" fn()>( notify_tolerance_trampoline::<Self, F> as *const (), )), Box_::into_raw(f), ) } } }