pub struct Segment {
pub rate: f64,
pub applied_rate: f64,
pub base: u64,
pub start: u64,
pub stop: Option<u64>,
pub time: u64,
pub position: u64,
pub key_units_only: bool,
}Expand description
A playback segment (the GstSegment analog, TIME format). Describes the
portion of the stream currently being played, the rate, and the mapping
onto the pipeline running-time clock.
Fields§
§rate: f64Playback rate (sign carries direction).
applied_rate: f64Rate already applied to the buffers (scales stream time). Usually 1.0.
base: u64Running time of the segment’s playback start. Accumulates across non-flushing seeks; resets on a flushing seek.
start: u64Earliest valid stream timestamp in the segment (ns).
stop: Option<u64>Latest valid stream timestamp (ns), or None for an open-ended segment.
time: u64Stream time of the segment start (ns).
position: u64Current playback position within the segment (ns).
key_units_only: boolTrick mode: only key units (keyframes) are to be presented, the rest
dropped (the GST_SEGMENT_FLAG_TRICKMODE_KEY_UNITS analog). Set from a
seek’s TRICKMODE flag; a sink honoring it presents only frames whose
FrameTiming::keyframe is set.
Implementations§
Source§impl Segment
impl Segment
Sourcepub fn contains(&self, ts: u64) -> bool
pub fn contains(&self, ts: u64) -> bool
Whether ts (ns, stream timeline) lies within [start, stop].
Sourcepub fn to_running_time(&self, ts: u64) -> Option<u64>
pub fn to_running_time(&self, ts: u64) -> Option<u64>
Map a stream timestamp to running time (pipeline-clock ns), or
None if ts is outside the segment (or the segment is reverse with no
stop to measure from). Rate- and direction-aware:
- forward (
rate > 0):base + (ts - start) / |rate| - reverse (
rate < 0):base + (stop - ts) / |rate|
Sourcepub fn to_stream_time(&self, ts: u64) -> Option<u64>
pub fn to_stream_time(&self, ts: u64) -> Option<u64>
Map a stream timestamp to stream time (ns), or None if ts is
outside the segment. Direction-agnostic, scaled by applied_rate:
time + (ts - start) * |applied_rate|.
Sourcepub fn clip(
&self,
b_start: u64,
b_stop: Option<u64>,
) -> Option<(u64, Option<u64>)>
pub fn clip( &self, b_start: u64, b_stop: Option<u64>, ) -> Option<(u64, Option<u64>)>
Clip a buffer’s [b_start, b_stop] (ns, stream timeline) to the
segment, returning the visible sub-range, or None if the buffer falls
entirely outside. b_stop is exclusive-ish (a None open buffer end is
clipped to the segment stop). The GStreamer gst_segment_clip analog.
Sourcepub fn for_flush_seek(seek: &Seek, duration: Option<u64>) -> Segment
pub fn for_flush_seek(seek: &Seek, duration: Option<u64>) -> Segment
Build the fresh segment produced by applying a flushing seek from
a stream of total duration ns (used to resolve SeekType::End). The
flushing case resets base to 0 (running time restarts after a
flush). SeekType::None leaves that edge at its default (start
unchanged from 0, stop open). For the non-flushing (accumulating)
seek, which keeps the running-time clock advancing, see
accumulate_seek.
Sourcepub fn accumulate_seek(&self, seek: &Seek, duration: Option<u64>) -> Segment
pub fn accumulate_seek(&self, seek: &Seek, duration: Option<u64>) -> Segment
Build the segment produced by a non-flushing (accumulating) seek
applied to self (the segment in effect when the seek arrives). Unlike a
flushing seek, the running-time clock is NOT reset: the new segment’s
base is the running time playback has already reached in self (its
base plus the time elapsed to self.position), so downstream running
time stays monotonic across the seek. This is the gapless / segment-seek
case (looping, playlists), the gst_segment_do_seek non-flush path. If
self.position is somehow outside self, base falls back to self.base
(no negative jump). A SeekType::None edge keeps self’s current
start / stop (the “leave this edge unchanged” contract).