diff options
author | François Laignel <fengalin@free.fr> | 2021-10-09 13:17:05 +0300 |
---|---|---|
committer | François Laignel <fengalin@free.fr> | 2021-10-18 16:09:47 +0300 |
commit | 27b9f0d868f436e9b2bcc3e51f393c40b56fcc02 (patch) | |
tree | 93c0db7b1cf26ea7d0e3a4d70a7d2844c2e00975 /tutorial | |
parent | bd8a7e8df7e8ebf751b2d00fe6a096d726683c00 (diff) |
Improve usability thanks to opt-ops
The crate option-operations simplifies usage when dealing with
`Option`s, which is often the case with `ClockTime`.
Diffstat (limited to 'tutorial')
-rw-r--r-- | tutorial/src/sinesrc/imp.rs | 12 | ||||
-rw-r--r-- | tutorial/tutorial-2.md | 8 |
2 files changed, 4 insertions, 16 deletions
diff --git a/tutorial/src/sinesrc/imp.rs b/tutorial/src/sinesrc/imp.rs index 1fd22dd6f..bc03ad218 100644 --- a/tutorial/src/sinesrc/imp.rs +++ b/tutorial/src/sinesrc/imp.rs @@ -770,19 +770,11 @@ impl PushSrcImpl for SineSrc { let segment = element.segment().downcast::<gst::format::Time>().unwrap(); let base_time = element.base_time(); - let running_time = segment.to_running_time( - buffer - .pts() - .zip(buffer.duration()) - .map(|(pts, duration)| pts + duration), - ); + let running_time = segment.to_running_time(buffer.pts().opt_add(buffer.duration())); // The last sample's clock time is the base time of the element plus the // running time of the last sample - let wait_until = match running_time - .zip(base_time) - .map(|(running_time, base_time)| running_time + base_time) - { + let wait_until = match running_time.opt_add(base_time) { Some(wait_until) => wait_until, None => return Ok(CreateSuccess::NewBuffer(buffer)), }; diff --git a/tutorial/tutorial-2.md b/tutorial/tutorial-2.md index 983cbc265..26d55ef06 100644 --- a/tutorial/tutorial-2.md +++ b/tutorial/tutorial-2.md @@ -703,16 +703,12 @@ For working in live mode, we have to add a few different parts in various places let running_time = segment.to_running_time( buffer .pts() - .zip(buffer.duration()) - .map(|(pts, duration)| pts + duration), + .opt_add(buffer.duration()), ); // The last sample's clock time is the base time of the element plus the // running time of the last sample - let wait_until = match running_time - .zip(base_time) - .map(|(running_time, base_time)| running_time + base_time) - { + let wait_until = match running_time.opt_add(base_time) { Some(wait_until) => wait_until, None => return Ok(buffer), }; |