Simplify Formatted value handling

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
This commit is contained in:
François Laignel 2022-07-04 18:04:11 +02:00
parent a1b87669f2
commit 5c5c15d36a
10 changed files with 31 additions and 60 deletions

View file

@ -1455,7 +1455,7 @@ impl AggregatorImpl for FMP4Mux {
match query.view_mut() {
QueryViewMut::Seeking(q) => {
// We can't really handle seeking, it would break everything
q.set(false, gst::ClockTime::ZERO.into(), gst::ClockTime::NONE);
q.set(false, gst::ClockTime::ZERO, gst::ClockTime::NONE);
true
}
_ => self.parent_src_query(aggregator, query),

View file

@ -190,14 +190,8 @@ fn test_pull_range() {
// get the seeking capabilities
let (seekable, start, stop) = q.result();
assert!(seekable);
assert_eq!(
start,
gst::GenericFormattedValue::Bytes(Some(gst::format::Bytes(0)))
);
assert_eq!(
stop,
gst::GenericFormattedValue::Bytes(Some(gst::format::Bytes(6043)))
);
assert_eq!(start, gst::format::Bytes(0).into());
assert_eq!(stop, gst::format::Bytes(6043).into());
// do pulls
let expected_array_1 = [

View file

@ -801,11 +801,7 @@ impl JsonGstParse {
if fmt == gst::Format::Time {
if let Some(pull) = state.pull.as_ref() {
q.set(
true,
gst::GenericFormattedValue::Time(Some(gst::ClockTime::ZERO)),
gst::GenericFormattedValue::Time(pull.duration),
);
q.set(true, gst::ClockTime::ZERO, pull.duration);
true
} else {
false

View file

@ -266,14 +266,10 @@ impl SinkState {
None
}
});
let end_ts = Option::zip(start_ts, duration)
.map(|(start_ts, duration)| start_ts.saturating_add(duration));
let end_ts = start_ts.opt_saturating_add(duration);
let (clipped_start_ts, clipped_end_ts) = self.segment.clip(start_ts, end_ts)?;
let clipped_duration = Option::zip(clipped_start_ts, clipped_end_ts)
.map(|(clipped_start_ts, clipped_end_ts)| clipped_end_ts - clipped_start_ts);
let clipped_duration = clipped_end_ts.opt_sub(clipped_start_ts);
if clipped_start_ts != start_ts || clipped_duration != buffer.duration() {
let buffer = buffer.make_mut();
buffer.set_pts(clipped_start_ts);
@ -284,17 +280,13 @@ impl SinkState {
}
CapsInfo::None => {
let start_ts = buffer.pts();
let end_ts = Option::zip(start_ts, buffer.duration())
.map(|(start_ts, duration)| start_ts.saturating_add(duration));
let end_ts = start_ts.opt_saturating_add(buffer.duration());
// Can only clip buffers completely away, i.e. drop them, if they're raw
if let Some((clipped_start_ts, clipped_end_ts)) =
self.segment.clip(start_ts, end_ts)
{
let clipped_duration = Option::zip(clipped_start_ts, clipped_end_ts).map(
|(clipped_start_ts, clipped_end_ts)| clipped_end_ts - clipped_start_ts,
);
let clipped_duration = clipped_end_ts.opt_sub(clipped_start_ts);
if clipped_start_ts != start_ts || clipped_duration != buffer.duration() {
let buffer = buffer.make_mut();
buffer.set_pts(clipped_start_ts);
@ -719,12 +711,10 @@ impl FallbackSwitch {
}
if is_active {
if Option::zip(start_running_time, state.output_running_time).map_or(
false,
|(start_running_time, output_running_time)| {
start_running_time < output_running_time
},
) {
if start_running_time
.opt_lt(state.output_running_time)
.unwrap_or(false)
{
if raw_pad {
log!(
CAT,

View file

@ -210,10 +210,10 @@ impl BaseParseImpl for CdgParse {
Ok((gst::FlowSuccess::Ok, skip))
}
fn convert<V: Into<gst::GenericFormattedValue>>(
fn convert(
&self,
_element: &Self::Type,
src_val: V,
src_val: impl FormattedValue,
dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue> {
let src_val = src_val.into();

View file

@ -620,7 +620,7 @@ mod tests {
gst::init().unwrap();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
segment.set_start(Some(gst::ClockTime::from_nseconds(2)));
segment.set_start(gst::ClockTime::from_nseconds(2));
let pts = gst::ClockTime::from_nseconds(0);
let duration = Some(gst::ClockTime::from_nseconds(10));
@ -639,7 +639,7 @@ mod tests {
gst::init().unwrap();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
segment.set_stop(Some(gst::ClockTime::from_nseconds(7)));
segment.set_stop(gst::ClockTime::from_nseconds(7));
let pts = gst::ClockTime::from_nseconds(0);
let duration = Some(gst::ClockTime::from_nseconds(10));
@ -658,8 +658,8 @@ mod tests {
gst::init().unwrap();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
segment.set_start(Some(gst::ClockTime::from_nseconds(2)));
segment.set_stop(Some(gst::ClockTime::from_nseconds(7)));
segment.set_start(gst::ClockTime::from_nseconds(2));
segment.set_stop(gst::ClockTime::from_nseconds(7));
let pts = gst::ClockTime::from_nseconds(0);
let duration = Some(gst::ClockTime::from_nseconds(10));
@ -678,7 +678,7 @@ mod tests {
gst::init().unwrap();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
segment.set_start(Some(gst::ClockTime::from_nseconds(15)));
segment.set_start(gst::ClockTime::from_nseconds(15));
let pts = gst::ClockTime::from_nseconds(0);
let duration = Some(gst::ClockTime::from_nseconds(10));
@ -691,7 +691,7 @@ mod tests {
gst::init().unwrap();
let mut segment = gst::FormattedSegment::<gst::ClockTime>::new();
segment.set_stop(Some(gst::ClockTime::from_nseconds(10)));
segment.set_stop(gst::ClockTime::from_nseconds(10));
let pts = gst::ClockTime::from_nseconds(15);
let duration = Some(gst::ClockTime::from_nseconds(10));

View file

@ -548,12 +548,11 @@ impl MccParse {
// Update the last_timecode to the current one
state.last_timecode = Some(timecode);
let send_eos = state.segment.stop().map_or(false, |stop| {
buffer
.pts()
.zip(buffer.duration())
.map_or(false, |(pts, duration)| pts + duration >= stop)
});
let send_eos = state
.segment
.stop()
.opt_lt(buffer.pts().opt_add(buffer.duration()))
.unwrap_or(false);
// Drop our state mutex while we push out buffers or events
drop(state);
@ -1061,11 +1060,7 @@ impl MccParse {
if fmt == gst::Format::Time {
if let Some(pull) = state.pull.as_ref() {
q.set(
true,
gst::GenericFormattedValue::Time(gst::ClockTime::ZERO.into()),
gst::GenericFormattedValue::Time(pull.duration),
);
q.set(true, gst::ClockTime::ZERO, pull.duration);
true
} else {
false

View file

@ -938,11 +938,7 @@ impl SccParse {
if fmt == gst::Format::Time {
if let Some(pull) = state.pull.as_ref() {
q.set(
true,
gst::GenericFormattedValue::Time(gst::ClockTime::ZERO.into()),
gst::GenericFormattedValue::Time(pull.duration),
);
q.set(true, gst::ClockTime::ZERO, pull.duration);
true
} else {
false

View file

@ -168,9 +168,9 @@ fn test_pull() {
1.0,
gst::SeekFlags::FLUSH,
gst::SeekType::Set,
gst::GenericFormattedValue::Time(Some(gst::ClockTime::SECOND)),
gst::ClockTime::SECOND,
gst::SeekType::Set,
gst::GenericFormattedValue::Time(Some(2 * gst::ClockTime::SECOND)),
2 * gst::ClockTime::SECOND,
));
loop {

View file

@ -235,9 +235,9 @@ fn test_pull() {
1.0,
gst::SeekFlags::FLUSH,
gst::SeekType::Set,
gst::GenericFormattedValue::Time(Some(18 * gst::ClockTime::SECOND)),
18 * gst::ClockTime::SECOND,
gst::SeekType::Set,
gst::GenericFormattedValue::Time(Some(19 * gst::ClockTime::SECOND)),
19 * gst::ClockTime::SECOND,
));
loop {