S3: move ps clock, epoch and picture index into ps/{clock,epochs,es_index}.rs (pure move)
Browse files at this commit0d05533df7b073622ab22f56d73894202bdbedb1Parent: e496c684 changed files +64 -60
- crates/ec-mpegts/src/ps.rs +8 -60
- crates/ec-mpegts/src/ps/clock.rs +31 -0
- crates/ec-mpegts/src/ps/epochs.rs +8 -0
- crates/ec-mpegts/src/ps/es_index.rs +17 -0
crates/ec-mpegts/src/ps.rsmodified+8 -60
| @@ -26,6 +26,14 @@ use crate::psi::{EsEntry, descriptors}; | |||
| 26 | use crate::track::{self, PesIn, Queued, TICKS, Track}; | 26 | use crate::track::{self, PesIn, Queued, TICKS, Track}; |
| 27 | use crate::window::Window; | 27 | use crate::window::Window; |
| 28 | 28 | ||
| 29 | +mod clock; | ||
| 30 | +mod epochs; | ||
| 31 | +mod es_index; | ||
| 32 | + | ||
| 33 | +use clock::Clock; | ||
| 34 | +use epochs::Epoch; | ||
| 35 | +use es_index::{EsIndex, Pic}; | ||
| 36 | + | ||
| 29 | const MAX_TRACKS: usize = 128; | 37 | const MAX_TRACKS: usize = 128; |
| 30 | const PROBE_BYTES: u64 = 32 << 20; | 38 | const PROBE_BYTES: u64 = 32 << 20; |
| 31 | /// Files up to this size are walked completely at open to find SCR discontinuities. | 39 | /// Files up to this size are walked completely at open to find SCR discontinuities. |
| @@ -168,66 +176,6 @@ fn es_start(head: &[u8]) -> Option<usize> { | |||
| 168 | /// A PSM entry: stream type and its descriptors (tag, body). | 176 | /// A PSM entry: stream type and its descriptors (tag, body). |
| 169 | type PsmEntry = (u8, Vec<(u8, Vec<u8>)>); | 177 | type PsmEntry = (u8, Vec<(u8, Vec<u8>)>); |
| 170 | 178 | ||
| 171 | -/// The pack clock unwrapped into a continuous `u` (33-bit wraps removed) and the shift | ||
| 172 | -/// that keeps the presented timeline monotonic over SCR resets: `T = u + shift`. | ||
| 173 | -#[derive(Debug, Clone, Copy)] | ||
| 174 | -struct Clock { | ||
| 175 | - last_raw: Option<u64>, | ||
| 176 | - cur_u: i64, | ||
| 177 | - shift: i64, | ||
| 178 | -} | ||
| 179 | - | ||
| 180 | -impl Clock { | ||
| 181 | - /// Feeds a pack's SCR. `true` when it stepped back far enough to start a new epoch. | ||
| 182 | - fn feed(&mut self, raw: u64) -> bool { | ||
| 183 | - let Some(last) = self.last_raw.replace(raw) else { | ||
| 184 | - self.cur_u = unwrap33(raw, Some(self.cur_u)); | ||
| 185 | - return false; | ||
| 186 | - }; | ||
| 187 | - let d = wrap_delta(raw as i64, last as i64); | ||
| 188 | - if !(-BACK..=FWD).contains(&d) { | ||
| 189 | - let last_t = self.cur_u + self.shift; | ||
| 190 | - self.cur_u = raw as i64; | ||
| 191 | - self.shift = last_t - self.cur_u; | ||
| 192 | - true | ||
| 193 | - } else { | ||
| 194 | - self.cur_u += d; | ||
| 195 | - false | ||
| 196 | - } | ||
| 197 | - } | ||
| 198 | -} | ||
| 199 | - | ||
| 200 | -/// A stretch of the file with one SCR timeline. | ||
| 201 | -#[derive(Debug, Clone, Copy)] | ||
| 202 | -struct Epoch { | ||
| 203 | - off: u64, | ||
| 204 | - shift: i64, | ||
| 205 | - /// `u` of the first pack. | ||
| 206 | - base: i64, | ||
| 207 | -} | ||
| 208 | - | ||
| 209 | -// --------------------------------------------------------------------------- | ||
| 210 | -// Raw video elementary streams: the picture index | ||
| 211 | -// --------------------------------------------------------------------------- | ||
| 212 | - | ||
| 213 | -struct Pic { | ||
| 214 | - off: u64, | ||
| 215 | - key: bool, | ||
| 216 | - pts: i64, | ||
| 217 | - dts: i64, | ||
| 218 | -} | ||
| 219 | - | ||
| 220 | -/// Every picture of a raw stream with timestamps made from the frame rate: pictures are | ||
| 221 | -/// grouped (a GOP or sequence header, or an anchor whose temporal reference does not | ||
| 222 | -/// advance, starts a group), the display index is the group's frame count so far plus | ||
| 223 | -/// the temporal reference, `pts` is that index and `dts` the decode index less the | ||
| 224 | -/// reordering depth, both in frame durations. | ||
| 225 | -struct EsIndex { | ||
| 226 | - pics: Vec<Pic>, | ||
| 227 | - start: i64, | ||
| 228 | - end: i64, | ||
| 229 | -} | ||
| 230 | - | ||
| 231 | // --------------------------------------------------------------------------- | 179 | // --------------------------------------------------------------------------- |
| 232 | // The demuxer | 180 | // The demuxer |
| 233 | // --------------------------------------------------------------------------- | 181 | // --------------------------------------------------------------------------- |
crates/ec-mpegts/src/ps/clock.rsadded+31 -0
| @@ -0,0 +1,31 @@ | |||
| 1 | +use super::{BACK, FWD}; | ||
| 2 | +use crate::demux::{unwrap33, wrap_delta}; | ||
| 3 | + | ||
| 4 | +/// The pack clock unwrapped into a continuous `u` (33-bit wraps removed) and the shift | ||
| 5 | +/// that keeps the presented timeline monotonic over SCR resets: `T = u + shift`. | ||
| 6 | +#[derive(Debug, Clone, Copy)] | ||
| 7 | +pub(super) struct Clock { | ||
| 8 | + pub(super) last_raw: Option<u64>, | ||
| 9 | + pub(super) cur_u: i64, | ||
| 10 | + pub(super) shift: i64, | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +impl Clock { | ||
| 14 | + /// Feeds a pack's SCR. `true` when it stepped back far enough to start a new epoch. | ||
| 15 | + pub(super) fn feed(&mut self, raw: u64) -> bool { | ||
| 16 | + let Some(last) = self.last_raw.replace(raw) else { | ||
| 17 | + self.cur_u = unwrap33(raw, Some(self.cur_u)); | ||
| 18 | + return false; | ||
| 19 | + }; | ||
| 20 | + let d = wrap_delta(raw as i64, last as i64); | ||
| 21 | + if !(-BACK..=FWD).contains(&d) { | ||
| 22 | + let last_t = self.cur_u + self.shift; | ||
| 23 | + self.cur_u = raw as i64; | ||
| 24 | + self.shift = last_t - self.cur_u; | ||
| 25 | + true | ||
| 26 | + } else { | ||
| 27 | + self.cur_u += d; | ||
| 28 | + false | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | +} | ||
crates/ec-mpegts/src/ps/epochs.rsadded+8 -0
| @@ -0,0 +1,8 @@ | |||
| 1 | +/// A stretch of the file with one SCR timeline. | ||
| 2 | +#[derive(Debug, Clone, Copy)] | ||
| 3 | +pub(super) struct Epoch { | ||
| 4 | + pub(super) off: u64, | ||
| 5 | + pub(super) shift: i64, | ||
| 6 | + /// `u` of the first pack. | ||
| 7 | + pub(super) base: i64, | ||
| 8 | +} | ||
crates/ec-mpegts/src/ps/es_index.rsadded+17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | +pub(super) struct Pic { | ||
| 2 | + pub(super) off: u64, | ||
| 3 | + pub(super) key: bool, | ||
| 4 | + pub(super) pts: i64, | ||
| 5 | + pub(super) dts: i64, | ||
| 6 | +} | ||
| 7 | + | ||
| 8 | +/// Every picture of a raw stream with timestamps made from the frame rate: pictures are | ||
| 9 | +/// grouped (a GOP or sequence header, or an anchor whose temporal reference does not | ||
| 10 | +/// advance, starts a group), the display index is the group's frame count so far plus | ||
| 11 | +/// the temporal reference, `pts` is that index and `dts` the decode index less the | ||
| 12 | +/// reordering depth, both in frame durations. | ||
| 13 | +pub(super) struct EsIndex { | ||
| 14 | + pub(super) pics: Vec<Pic>, | ||
| 15 | + pub(super) start: i64, | ||
| 16 | + pub(super) end: i64, | ||
| 17 | +} | ||