Skip to main content

Clock27

Struct Clock27 

Source
pub struct Clock27 {
    pub base: Clock33,
    pub ext: u16,
}
Expand description

A validated 27 MHz clock value: base * 300 + ext (ISO/IEC 13818-1 §2.4.3.5 PCR, §2.4.3.7 ESCR, §2.5.3.4 program-stream SCR).

Construction (from_parts, from_27mhz) keeps ext < 300, so a value built that way is always in [0, PCR_WRAP_27MHZ). A parsed field may carry a 9-bit extension in 300..=511 (off the clock): from_wire_parts keeps it losslessly and to_clock27 is the checked way to use it. This is the one representation of a PCR/ESCR/SCR: mpeg-ts’s Pcr and mpeg-ps’s Scr wrap it and add only their wire codecs.

Fields§

§base: Clock33

The 33-bit base (27 MHz ticks / 300).

§ext: u16

The 9-bit extension (27 MHz ticks within the current base tick).

Implementations§

Source§

impl Clock27

Source

pub const fn from_parts(base: u64, ext: u16) -> Result<Clock27, ClockOutOfRange>

Construct from the two wire parts, checking both widths.

§Errors

ClockOutOfRange when base >= 2^33 (field: "27 MHz base") or ext >= 300 (field: "27 MHz extension").

Source

pub fn from_27mhz(ticks: u64) -> Result<Clock27, ClockOutOfRange>

Split an absolute 27 MHz value into its two wire parts, the inverse of from_parts for any ticks < PCR_WRAP_27MHZ.

§Errors

ClockOutOfRange (field: "27 MHz ticks") when ticks >= PCR_WRAP_27MHZ.

Source

pub const fn from_27mhz_wrapping(ticks: u64) -> Clock27

The position ticks names on the 27 MHz clock, taking any count: ticks itself when it is below PCR_WRAP_27MHZ, and ticks reduced modulo the wrap otherwise (a reading from a free-running counter that has passed the wrap).

Infallible: the reduction puts both wire parts in range, so this is the constructor for a raw count that may be past the wrap, and from_27mhz the checked one that reports it.

Source

pub const fn ticks(self) -> u64

The full value on the 27 MHz clock: base * 300 + ext.

A constructed value is a real time reading. For a value from from_wire_parts with an extension at or above 300 this is not a time on the clock, so callers check is_valid or to_clock27 first.

Source

pub fn seconds(self) -> f64

The value in seconds.

Source

pub fn signed_distance_to(self, to: Clock27) -> i64

The shortest signed distance from self to to — see pcr_signed_distance.

Source

pub const fn from_wire_parts(base: u64, ext: u16) -> Clock27

Wrap the two parts exactly as the wire carried them, without validating.

A PCR/ESCR/SCR field is 33-bit base + 9-bit extension, so real captures do carry extensions in 300..=511 — a value off the 27 MHz clock that this type cannot hold. Parsing must stay lossless (the workspace’s byte-exact round-trip invariant), so a parser uses this to keep the wire bytes, and a caller that needs a real clock reading asks to_clock27 for the checked view.

Code that constructs a clock value uses from_parts instead, which rejects those parts.

Source

pub const fn to_clock27(self) -> Result<Clock27, ClockOutOfRange>

The checked view of these parts: Ok when they name a position on the 27 MHz clock.

§Errors

ClockOutOfRange when ext >= 300. The base is always a Clock33, so it cannot be out of range.

Source

pub const fn is_valid(self) -> bool

Whether ticks is base * 300 + ext (an extension below 300) rather than a wire value off the 27 MHz clock.

Trait Implementations§

Source§

impl Clone for Clock27

Source§

fn clone(&self) -> Clock27

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 Clock27

Source§

impl Debug for Clock27

Source§

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

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

impl Default for Clock27

Source§

fn default() -> Clock27

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

impl Display for Clock27

Source§

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

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

impl Eq for Clock27

Source§

impl Hash for Clock27

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Clock27

Source§

fn cmp(&self, other: &Clock27) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Clock27

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Clock27

Source§

fn partial_cmp(&self, other: &Clock27) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Clock27

Available on crate feature serde only.

Serializes as the 27 MHz tick count: a PCR is stored as the one number its wire fields code, so a snapshot survives the lossless from_wire_parts round trip.

Source§

fn serialize<S>( &self, s: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Clock27

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> 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> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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, !>

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.