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: Clock33The 33-bit base (27 MHz ticks / 300).
ext: u16The 9-bit extension (27 MHz ticks within the current base tick).
Implementations§
Source§impl Clock27
impl Clock27
Sourcepub const fn from_parts(base: u64, ext: u16) -> Result<Clock27, ClockOutOfRange>
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").
Sourcepub fn from_27mhz(ticks: u64) -> Result<Clock27, ClockOutOfRange>
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.
Sourcepub const fn from_27mhz_wrapping(ticks: u64) -> Clock27
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.
Sourcepub const fn ticks(self) -> u64
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.
Sourcepub fn signed_distance_to(self, to: Clock27) -> i64
pub fn signed_distance_to(self, to: Clock27) -> i64
The shortest signed distance from self to to — see
pcr_signed_distance.
Sourcepub const fn from_wire_parts(base: u64, ext: u16) -> Clock27
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.
Sourcepub const fn to_clock27(self) -> Result<Clock27, ClockOutOfRange>
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.
Trait Implementations§
impl Copy for Clock27
impl Eq for Clock27
Source§impl Ord for Clock27
impl Ord for Clock27
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Clock27
impl PartialOrd for Clock27
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.
impl Serialize for Clock27
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.