Skip to main content

audio_frame_grid

Function audio_frame_grid 

Source
pub fn audio_frame_grid(
    timestamps: &[i64],
    num: i64,
    den: i64,
    sample_rate: u32,
) -> Option<AudioFrameGrid>
Expand description

The frame grid an audio stream’s first packet timestamps show, at sample_rate, in a stream whose timestamps are whole multiples of num / den seconds; None when they show none to place frames on.

timestamps are the stream’s first packets’ presentation timestamps in any order: its first crate::ROUNDING_SCAN_FRAMES packets’, fewer when those before hold crate::ROUNDING_SCAN_BYTES, as for rounding_quantum. Their rounding unit is that one’s quantum, or one unit of the time base when they show none. The grid is one every timestamp is within half a unit of: of the whole-sample periods within a unit over their count of their span over it, the one that leaves the most room, the shortest of those that leave as much; and of the anchors it leaves, the one at the middle of where they can lie, rounded to a sample, which for a rounding to the nearest unit is where the frames are. There is none when:

  • half the unit is under a sample (an MP4’s time base is usually the sample rate, MPEG-TS’s 1/90000): a timestamp is then where its frame starts;
  • fewer than three distinct timestamps are given, or no grid holds them all: the frames are not one length (Vorbis’s long and short blocks, an Opus stream that changes frame size), or a packet is missing;
  • no period longer than twice the trimmed tolerance holds them, so a timestamp could stand for either of two frames;
  • num, den or sample_rate is not positive.