Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/video
diff options
context:
space:
mode:
authorFrançois Laignel <fengalin@free.fr>2021-10-09 13:17:05 +0300
committerFrançois Laignel <fengalin@free.fr>2021-10-18 16:09:47 +0300
commit27b9f0d868f436e9b2bcc3e51f393c40b56fcc02 (patch)
tree93c0db7b1cf26ea7d0e3a4d70a7d2844c2e00975 /video
parentbd8a7e8df7e8ebf751b2d00fe6a096d726683c00 (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 'video')
-rw-r--r--video/closedcaption/src/cea608tojson/imp.rs20
-rw-r--r--video/closedcaption/src/jsontovtt/imp.rs15
-rw-r--r--video/closedcaption/src/mcc_parse/imp.rs10
-rw-r--r--video/closedcaption/src/scc_parse/imp.rs31
-rw-r--r--video/flavors/src/flvdemux/imp.rs10
-rw-r--r--video/gif/src/gifenc/imp.rs6
-rw-r--r--video/webp/tests/webpdec.rs4
7 files changed, 30 insertions, 66 deletions
diff --git a/video/closedcaption/src/cea608tojson/imp.rs b/video/closedcaption/src/cea608tojson/imp.rs
index b60e77381..0c90ddc8c 100644
--- a/video/closedcaption/src/cea608tojson/imp.rs
+++ b/video/closedcaption/src/cea608tojson/imp.rs
@@ -400,9 +400,7 @@ fn dump(
duration: impl Into<Option<gst::ClockTime>>,
) {
let pts = pts.into();
- let end = pts
- .zip(duration.into())
- .map(|(pts, duration)| pts + duration);
+ let end = pts.opt_add(duration.into());
if cc_data != 0x8080 {
gst_debug!(
@@ -478,10 +476,10 @@ impl State {
Some(Cea608Mode::PopOn) => gst::ClockTime::NONE,
_ => self
.current_pts
- .zip(self.current_duration)
- .map(|(cur_pts, cur_duration)| cur_pts + cur_duration)
- .zip(self.first_pts)
- .and_then(|(cur_end, first_pts)| cur_end.checked_sub(first_pts)),
+ .opt_add(self.current_duration)
+ .opt_checked_sub(self.first_pts)
+ .ok()
+ .flatten(),
}
};
@@ -541,10 +539,10 @@ impl State {
gst_log!(CAT, obj: element, "Draining pending");
pending.duration = self
.current_pts
- .zip(self.current_duration)
- .map(|(cur_pts, cur_dur)| cur_pts + cur_dur)
- .zip(pending.pts)
- .and_then(|(cur_end, pending_pts)| cur_end.checked_sub(pending_pts));
+ .opt_add(self.current_duration)
+ .opt_checked_sub(pending.pts)
+ .ok()
+ .flatten();
Some(pending)
} else {
None
diff --git a/video/closedcaption/src/jsontovtt/imp.rs b/video/closedcaption/src/jsontovtt/imp.rs
index dc604c68a..436c388eb 100644
--- a/video/closedcaption/src/jsontovtt/imp.rs
+++ b/video/closedcaption/src/jsontovtt/imp.rs
@@ -68,7 +68,7 @@ fn clamp(
mut pts: gst::ClockTime,
mut duration: Option<gst::ClockTime>,
) -> Option<(gst::ClockTime, Option<gst::ClockTime>)> {
- let end_pts = duration.map(|duration| pts + duration).unwrap_or(pts);
+ let end_pts = pts.opt_add(duration).unwrap_or(pts);
if let Some(segment_start) = segment.start() {
if end_pts < segment_start {
@@ -76,9 +76,7 @@ fn clamp(
}
if pts < segment_start {
- if let Some(ref mut duration) = duration {
- *duration = duration.saturating_sub(segment_start - pts);
- }
+ duration.opt_sub_assign(segment_start - pts);
pts = segment_start;
}
}
@@ -89,9 +87,7 @@ fn clamp(
}
if end_pts > segment_stop {
- if let Some(ref mut duration) = duration {
- *duration = duration.saturating_sub(end_pts - segment_stop);
- }
+ duration.opt_sub_assign(end_pts - segment_stop);
}
}
@@ -322,10 +318,7 @@ impl State {
self.drain(&mut ret, self.segment.to_running_time(pts));
- self.last_pts = Some(pts)
- .zip(duration)
- .map(|(pts, duration)| pts + duration)
- .or(Some(pts));
+ self.last_pts = Some(pts).opt_add(duration).or(Some(pts));
ret
}
diff --git a/video/closedcaption/src/mcc_parse/imp.rs b/video/closedcaption/src/mcc_parse/imp.rs
index ff0f18bb9..c38c4f19d 100644
--- a/video/closedcaption/src/mcc_parse/imp.rs
+++ b/video/closedcaption/src/mcc_parse/imp.rs
@@ -1015,17 +1015,11 @@ impl MccParse {
let pull = state.pull.as_ref().unwrap();
if start_type == gst::SeekType::Set {
- start = start
- .zip(pull.duration)
- .map(|(start, duration)| start.min(duration))
- .or(start);
+ start = start.opt_min(pull.duration).or(start);
}
if stop_type == gst::SeekType::Set {
- stop = stop
- .zip(pull.duration)
- .map(|(stop, duration)| stop.min(duration))
- .or(stop);
+ stop = stop.opt_min(pull.duration).or(stop);
}
state.seeking = true;
diff --git a/video/closedcaption/src/scc_parse/imp.rs b/video/closedcaption/src/scc_parse/imp.rs
index 75cdaac13..2fa363f84 100644
--- a/video/closedcaption/src/scc_parse/imp.rs
+++ b/video/closedcaption/src/scc_parse/imp.rs
@@ -429,14 +429,8 @@ impl SccParse {
timecode.increment_frame();
if clip_buffers {
- let end_time = buffer
- .pts()
- .zip(buffer.duration())
- .map(|(pts, duration)| pts + duration);
- if end_time
- .zip(segment_start)
- .map_or(false, |(end_time, segment_start)| end_time < segment_start)
- {
+ let end_time = buffer.pts().opt_add(buffer.duration());
+ if end_time.opt_lt(segment_start).unwrap_or(false) {
gst_trace!(
CAT,
obj: element,
@@ -448,12 +442,11 @@ impl SccParse {
}
}
- send_eos = state.segment.stop().map_or(false, |stop| {
- buffer
- .pts()
- .zip(buffer.duration())
- .map_or(false, |(pts, duration)| pts + duration >= stop)
- });
+ send_eos = buffer
+ .pts()
+ .opt_add(buffer.duration())
+ .opt_ge(state.segment.stop())
+ .unwrap_or(false);
let buffers = buffers.get_mut().unwrap();
buffers.add(buffer);
@@ -899,17 +892,11 @@ impl SccParse {
let pull = state.pull.as_ref().unwrap();
if start_type == gst::SeekType::Set {
- start = start
- .zip(pull.duration)
- .map(|(start, duration)| start.min(duration))
- .or(start);
+ start = start.opt_min(pull.duration).or(start);
}
if stop_type == gst::SeekType::Set {
- stop = stop
- .zip(pull.duration)
- .map(|(stop, duration)| stop.min(duration))
- .or(stop);
+ stop = stop.opt_min(pull.duration).or(stop);
}
state.seeking = true;
diff --git a/video/flavors/src/flvdemux/imp.rs b/video/flavors/src/flvdemux/imp.rs
index 53cdd925e..78f21bdfa 100644
--- a/video/flavors/src/flvdemux/imp.rs
+++ b/video/flavors/src/flvdemux/imp.rs
@@ -1198,15 +1198,9 @@ impl StreamingState {
fn update_position(&mut self, buffer: &gst::Buffer) {
if let Some(pts) = buffer.pts() {
- self.last_position = self
- .last_position
- .map(|last_pos| last_pos.max(pts))
- .or(Some(pts));
+ self.last_position = self.last_position.opt_max(pts).or(Some(pts));
} else if let Some(dts) = buffer.dts() {
- self.last_position = self
- .last_position
- .map(|last_pos| last_pos.max(dts))
- .or(Some(dts));
+ self.last_position = self.last_position.opt_max(dts).or(Some(dts));
}
}
}
diff --git a/video/gif/src/gifenc/imp.rs b/video/gif/src/gifenc/imp.rs
index 481c3a590..9c0480274 100644
--- a/video/gif/src/gifenc/imp.rs
+++ b/video/gif/src/gifenc/imp.rs
@@ -401,9 +401,9 @@ impl VideoEncoderImpl for GifEnc {
// is probably less visible than the large stuttering when a complete 10ms have to
// "catch up".
gif_frame.delay = (frame_delay.mseconds() as f32 / 10.0).round() as u16;
- state.gif_pts = state.gif_pts.map(|gif_pts| {
- gif_pts + gst::ClockTime::from_mseconds(gif_frame.delay as u64 * 10)
- });
+ state.gif_pts = state
+ .gif_pts
+ .opt_add(gst::ClockTime::from_mseconds(gif_frame.delay as u64 * 10));
// encode new frame
let context = state.context.as_mut().unwrap();
diff --git a/video/webp/tests/webpdec.rs b/video/webp/tests/webpdec.rs
index 6dfb04656..4d8e2dd3a 100644
--- a/video/webp/tests/webpdec.rs
+++ b/video/webp/tests/webpdec.rs
@@ -48,9 +48,7 @@ fn test_decode() {
assert_eq!(buf.pts(), expected_timestamp);
assert_eq!(buf.duration(), expected_duration);
- expected_timestamp = expected_timestamp
- .zip(expected_duration)
- .map(|(ts, duration)| ts + duration);
+ expected_timestamp = expected_timestamp.opt_add(expected_duration);
count += 1;
}