mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-26 13:31:00 +00:00
tutorial: Update for Caps API changes
This commit is contained in:
parent
af56755aaa
commit
9202e8fddd
2 changed files with 7 additions and 7 deletions
|
@ -698,7 +698,7 @@ impl BaseSrcImpl for SineSrc {
|
|||
Ok(buffer)
|
||||
}
|
||||
|
||||
fn fixate(&self, element: &gst_base::BaseSrc, caps: gst::Caps) -> gst::Caps {
|
||||
fn fixate(&self, element: &gst_base::BaseSrc, mut caps: gst::Caps) -> gst::Caps {
|
||||
// Fixate the caps. BaseSrc will do some fixation for us, but
|
||||
// as we allow any rate between 1 and MAX it would fixate to 1. 1Hz
|
||||
// is generally not a useful sample rate.
|
||||
|
@ -706,7 +706,7 @@ impl BaseSrcImpl for SineSrc {
|
|||
// We fixate to the closest integer value to 48kHz that is possible
|
||||
// here, and for good measure also decide that the closest value to 1
|
||||
// channel is good.
|
||||
let mut caps = gst::Caps::truncate(caps);
|
||||
caps.truncate();
|
||||
{
|
||||
let caps = caps.make_mut();
|
||||
let s = caps.get_mut_structure(0).unwrap();
|
||||
|
@ -715,7 +715,7 @@ impl BaseSrcImpl for SineSrc {
|
|||
}
|
||||
|
||||
// Let BaseSrc fixate anything else for us. We could've alternatively have
|
||||
// called Caps::fixate() here
|
||||
// called caps.fixate() here
|
||||
self.parent_fixate(element, caps)
|
||||
}
|
||||
|
||||
|
|
|
@ -441,7 +441,7 @@ As a last step we post a new `LATENCY` message on the bus whenever the sample
|
|||
`BaseSrc` is by default already selecting possible caps for us, if there are multiple options. However these defaults might not be (and often are not) ideal and we should override the default behaviour slightly. This is done in the `BaseSrc::fixate` virtual method.
|
||||
|
||||
```rust
|
||||
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
|
||||
fn fixate(&self, element: &BaseSrc, mut caps: gst::Caps) -> gst::Caps {
|
||||
// Fixate the caps. BaseSrc will do some fixation for us, but
|
||||
// as we allow any rate between 1 and MAX it would fixate to 1. 1Hz
|
||||
// is generally not a useful sample rate.
|
||||
|
@ -449,7 +449,7 @@ As a last step we post a new `LATENCY` message on the bus whenever the sample
|
|||
// We fixate to the closest integer value to 48kHz that is possible
|
||||
// here, and for good measure also decide that the closest value to 1
|
||||
// channel is good.
|
||||
let mut caps = gst::Caps::truncate(caps);
|
||||
caps.truncate();
|
||||
{
|
||||
let caps = caps.make_mut();
|
||||
let s = caps.get_mut_structure(0).unwrap();
|
||||
|
@ -458,14 +458,14 @@ As a last step we post a new `LATENCY` message on the bus whenever the sample
|
|||
}
|
||||
|
||||
// Let BaseSrc fixate anything else for us. We could've alternatively have
|
||||
// called Caps::fixate() here
|
||||
// called caps.fixate() here
|
||||
element.parent_fixate(caps)
|
||||
}
|
||||
```
|
||||
|
||||
Here we take the caps that are passed in, truncate them (i.e. remove all but the very first [`Structure`](https://slomo.pages.freedesktop.org/rustdocs/gstreamer/gstreamer/structure/struct.Structure.html)) and then manually fixate the sample rate to the closest value to 48kHz. By default, caps fixation would result in the lowest possible sample rate but this is usually not desired.
|
||||
|
||||
For good measure, we also fixate the number of channels to the closest value to 1, but this would already be the default behaviour anyway. And then chain up to the parent class' implementation of `fixate`, which for now basically does the same as `Caps::fixate()`. After this, the caps are fixated, i.e. there is only a single `Structure` left and all fields have concrete values (no ranges or sets).
|
||||
For good measure, we also fixate the number of channels to the closest value to 1, but this would already be the default behaviour anyway. And then chain up to the parent class' implementation of `fixate`, which for now basically does the same as `caps.fixate()`. After this, the caps are fixated, i.e. there is only a single `Structure` left and all fields have concrete values (no ranges or sets).
|
||||
|
||||
### Query Handling
|
||||
|
||||
|
|
Loading…
Reference in a new issue