Skip to main content

presentation_slack

Function presentation_slack 

Source
pub fn presentation_slack(num: i64, den: i64, quantum: i64) -> MediaTime
Expand description

How much later than a source time t a decoded frame’s timestamp may be and still be the frame shown at t, for a stream whose timestamps are whole multiples of num / den seconds and are rounded to quantum of those units (rounding_quantum; 0 for none shown).

A stream whose timestamps show a rounding is given half of it, rounded up to a tick, and one tick more, however coarse: 61 ticks for a Matroska file’s milliseconds and for an MP4 that kept them in a 1/16000 time base, 101 for 29.97 fps in 1/600, 601 in 1/100. A stream that shows none is given half its time base’s unit, rounded up to a tick, and one tick more, at most PRESENTATION_SLACK: its frames are exact in the time base, so a coarse one (1001/30000, 1/12) holds whole frames and is not widened.

The frame shown at a source time is the last one whose timestamp is at or before it. A frame’s timestamp is its true time quantized twice: by its stream’s rounding, to the nearest unit, and onto the tick grid. A sampled time is floored onto the grid (crate::FrameRate::frame_start). So the frame truly shown at t can carry a timestamp up to this much after it: a 29.97 fps Matroska file stores its third frame (66.73 ms) at 67 ms, 32 ticks after the project frame that shows it starts (8008), and a 90 fps file in a 1/90000 time base stores its third at 2666.67 ticks, rounded to 2667, after 2666. Every host decides the frame shown at t as the last one whose timestamp is at or before MediaTime::presentation_deadline. In a time base that resolves its frames exactly (most MP4s) the slack is a few ticks, so a frame that starts later than t is not shown at t; in a millisecond one a frame up to 0.5 ms later is.

A zero or negative num or den is a resolution not known: PRESENTATION_SLACK. A negative quantum is none shown.