Skip to main content

Segment

Struct Segment 

Source
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: f64

Playback rate (sign carries direction).

§applied_rate: f64

Rate already applied to the buffers (scales stream time). Usually 1.0.

§base: u64

Running time of the segment’s playback start. Accumulates across non-flushing seeks; resets on a flushing seek.

§start: u64

Earliest valid stream timestamp in the segment (ns).

§stop: Option<u64>

Latest valid stream timestamp (ns), or None for an open-ended segment.

§time: u64

Stream time of the segment start (ns).

§position: u64

Current playback position within the segment (ns).

§key_units_only: bool

Trick 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

Source

pub fn new() -> Segment

An open-ended, normal-rate segment starting at 0.

Source

pub fn contains(&self, ts: u64) -> bool

Whether ts (ns, stream timeline) lies within [start, stop].

Source

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|
Source

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|.

Source

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.

Source

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.

Source

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).

Trait Implementations§

Source§

impl Clone for Segment

Source§

fn clone(&self) -> Segment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Segment

Source§

impl Debug for Segment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Segment

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Segment

Source§

fn eq(&self, other: &Segment) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Segment

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ElementBound for T
where T: Send,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.