euv-core 0.46.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
use super::*;

/// Color space, transfer curve, matrix coefficients, range, and HDR mastering metadata preserved across decode and presentation.
#[derive(Clone, Copy, Data, Debug, Deserialize, Eq, Hash, New, PartialEq, Serialize)]
pub struct VideoColorInfo {
    /// Color primaries gamut (`BT.709`, `BT.2020`, `DisplayP3`, `BT.601`).
    #[get(type(copy))]
    pub(crate) primaries: ColorPrimaries,
    /// Electro-optical transfer function (`BT.709`, `sRGB`, `PQ ST.2084`, `HLG`).
    #[get(type(copy))]
    pub(crate) transfer: TransferCharacteristics,
    /// YCbCr-to-RGB matrix coefficients.
    #[get(type(copy))]
    pub(crate) matrix: MatrixCoefficients,
    /// Signal quantization range (`Limited` or `Full`).
    #[get(type(copy))]
    pub(crate) range: ColorRange,
    /// Bits per color component (`8`, `10`, or `12`).
    #[get(type(copy))]
    pub(crate) bit_depth: u8,
    /// Maximum Content Light Level (`MaxCLL`) in nits (`0` when unspecified).
    #[get(type(copy))]
    pub(crate) max_cll_nits: u16,
    /// Maximum Frame-Average Light Level (`MaxFALL`) in nits (`0` when unspecified).
    #[get(type(copy))]
    pub(crate) max_fall_nits: u16,
}

/// Capability report advertised by a hardware or software video decoder backend.
#[derive(Clone, Copy, Data, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct HardwareDecoderCapabilities {
    /// Decoder backend kind.
    #[get(type(copy))]
    pub(crate) kind: HardwareDecoderKind,
    /// `true` when decoded surfaces map directly to GPU textures without CPU readback.
    #[get(type(copy))]
    pub(crate) zero_copy_gpu_interop: bool,
    /// Whether H.264/AVC decoding is supported.
    #[get(type(copy))]
    pub(crate) supports_h264: bool,
    /// Whether H.265/HEVC decoding is supported.
    #[get(type(copy))]
    pub(crate) supports_h265: bool,
    /// Whether VP9 decoding is supported.
    #[get(type(copy))]
    pub(crate) supports_vp9: bool,
    /// Whether AV1 decoding is supported.
    #[get(type(copy))]
    pub(crate) supports_av1: bool,
    /// Whether 10-bit PQ/HLG HDR pipelines are supported.
    #[get(type(copy))]
    pub(crate) supports_hdr10: bool,
    /// Maximum supported coded width in pixels.
    #[get(type(copy))]
    pub(crate) max_width: u32,
    /// Maximum supported coded height in pixels.
    #[get(type(copy))]
    pub(crate) max_height: u32,
}

/// Stateless platform probe identifying the target OS hardware decode backend and host fallback capabilities.
#[derive(Clone, Copy, Debug, Default)]
pub struct HardwareDecoderProbe;

/// Zero-copy GPU texture/surface interop handle for hardware-decoded video frames (`CVPixelBuffer`, `AHardwareBuffer`, `DMA-BUF`, `ID3D11Texture2D`, `VideoFrame`).
#[derive(Clone, Copy, Data, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct VideoGpuSurfaceHandle {
    /// Backend-opaque surface or texture handle identifier.
    #[get(type(copy))]
    pub(crate) surface_id: u64,
    /// Target GPU device identifier.
    #[get(type(copy))]
    pub(crate) device_id: u64,
    /// Generation counter preventing stale handle reuse across seeks or device loss.
    #[get(type(copy))]
    pub(crate) generation: u64,
    /// Frame width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Frame height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Hardware surface pixel layout (`Nv12`, `P010`, `Bgra8`, `Rgba8`).
    #[get(type(copy))]
    pub(crate) pixel_format: VideoPixelFormat,
    /// Color space and HDR metadata bound to this GPU surface.
    #[get(type(copy))]
    pub(crate) color_info: VideoColorInfo,
    /// Synchronization fence value signaled when GPU decode writes complete.
    #[get(type(copy))]
    pub(crate) fence_value: u64,
    /// `true` when the surface is sampled directly by the compositor without CPU readback.
    #[get(type(copy))]
    pub(crate) zero_copy: bool,
    /// Hardware backend that produced this surface.
    #[get(type(copy))]
    pub(crate) backend: HardwareDecoderKind,
}

/// Pooled CPU RGBA8 video frame buffer checked out from a bounded `VideoFramePool`.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub struct PooledVideoFrame {
    /// Originating pool slot identifier for telemetry and debugging.
    #[get(type(copy))]
    pub(crate) slot_id: usize,
    /// Frame width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Frame height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Reusable packed RGBA8 pixel storage (`width * height * 4`).
    pub(crate) pixels: Vec<u8>,
}

/// Telemetry snapshot summarizing `VideoFramePool` capacity, reuse hits, allocations, and copy volume.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct VideoFramePoolStats {
    /// Maximum bounded slot capacity of the pool.
    #[get(type(copy))]
    pub(crate) capacity: usize,
    /// Number of pooled buffers currently checked out.
    #[get(type(copy))]
    pub(crate) in_use: usize,
    /// Number of free reusable buffers parked inside the pool.
    #[get(type(copy))]
    pub(crate) available: usize,
    /// Total cold heap allocations performed since pool creation.
    #[get(type(copy))]
    pub(crate) allocations: u64,
    /// Total steady-state buffer checkouts satisfied via reuse without reallocation.
    #[get(type(copy))]
    pub(crate) reuse_hits: u64,
    /// Total checkout attempts rejected due to bounded pool exhaustion.
    #[get(type(copy))]
    pub(crate) backpressure_rejects: u64,
    /// Total recycled frames returned into the pool.
    #[get(type(copy))]
    pub(crate) recycled_count: u64,
}

/// Internal state protected by synchronization primitives inside `VideoFramePool`.
#[derive(Clone, Data, Debug, Default)]
pub(crate) struct VideoFramePoolState {
    /// Maximum bounded number of buffers owned or checked out simultaneously.
    #[get(type(copy))]
    pub(crate) capacity: usize,
    /// Number of buffers currently checked out by decoders or queues.
    #[get(type(copy))]
    pub(crate) in_use: usize,
    /// Next unique slot identifier assigned to newly allocated buffers.
    #[get(type(copy))]
    pub(crate) next_slot_id: usize,
    /// Free buffers parked for zero-allocation steady-state reuse.
    pub(crate) free_buffers: Vec<PooledVideoFrame>,
    /// Cumulative cold heap allocations performed.
    #[get(type(copy))]
    pub(crate) allocations: u64,
    /// Cumulative reuse hits satisfied from `free_buffers`.
    #[get(type(copy))]
    pub(crate) reuse_hits: u64,
    /// Cumulative bounded backpressure rejections.
    #[get(type(copy))]
    pub(crate) backpressure_rejects: u64,
    /// Cumulative returned buffers.
    #[get(type(copy))]
    pub(crate) recycled_count: u64,
}

/// Thread-safe (native) or single-threaded (wasm32) bounded reusable CPU RGBA8 video frame pool.
#[derive(Clone, CustomDebug)]
pub struct VideoFramePool {
    /// Synchronized internal pool state on native targets.
    #[cfg(not(target_arch = "wasm32"))]
    pub(crate) inner: Arc<Mutex<VideoFramePoolState>>,
    /// Interior-mutable internal pool state on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) inner: Rc<RefCell<VideoFramePoolState>>,
}

/// Single parsed MP4/ISOBMFF sample table record with exact DTS, PTS (including `ctts`), byte range, and keyframe flag.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct Mp4Sample {
    /// Zero-based sample index in decode order.
    #[get(type(copy))]
    pub(crate) index: usize,
    /// Decoding timestamp in microseconds.
    #[get(type(copy))]
    pub(crate) dts_us: i64,
    /// Presentation timestamp in microseconds (`dts_us + composition_offset_us`).
    #[get(type(copy))]
    pub(crate) pts_us: i64,
    /// Sample display duration in microseconds.
    #[get(type(copy))]
    pub(crate) duration_us: u64,
    /// Byte offset inside the MP4 container buffer.
    #[get(type(copy))]
    pub(crate) byte_offset: u64,
    /// Encoded sample byte size.
    #[get(type(copy))]
    pub(crate) byte_size: u32,
    /// `true` when this sample is a random-access sync keyframe (`stss`).
    #[get(type(copy))]
    pub(crate) is_keyframe: bool,
}

/// Metadata extracted for an MP4/ISOBMFF video or audio track.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct Mp4TrackInfo {
    /// ISOBMFF track identifier from `tkhd`.
    #[get(type(copy))]
    pub(crate) track_id: u32,
    /// True for a `vide` track, false for a `soun` track.
    #[get(type(copy))]
    pub(crate) is_video: bool,
    /// Detected video codec when `is_video == true`.
    #[get(type(copy))]
    pub(crate) video_codec: VideoCodec,
    /// Detected audio codec when `is_video == false`.
    #[get(type(copy))]
    pub(crate) audio_codec: AudioCodec,
    /// FourCC codec box tag (e.g. `"avc1"`, `"hvc1"`, `"rawv"`, `"mp4a"`).
    pub(crate) codec_fourcc: String,
    /// Coded or display pixel width (`0` for audio tracks).
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Coded or display pixel height (`0` for audio tracks).
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Media timescale in ticks per second from `mdhd`.
    #[get(type(copy))]
    pub(crate) timescale: u32,
    /// Track duration in microseconds.
    #[get(type(copy))]
    pub(crate) duration_us: u64,
    /// Audio sample rate in Hz (`0` for video tracks).
    #[get(type(copy))]
    pub(crate) sample_rate_hz: u32,
    /// Audio channel count (`0` for video tracks).
    #[get(type(copy))]
    pub(crate) channels: u16,
    /// Color primaries, transfer function, matrix, and HDR metadata parsed from `colr`/`nclx`.
    #[get(type(copy))]
    pub(crate) color_info: VideoColorInfo,
    /// Complete ordered sample index built from `stts`, `ctts`, `stss`, `stsc`, `stsz`, and `stco`/`co64`.
    pub(crate) samples: Vec<Mp4Sample>,
}

/// Parsed pure-Rust MP4/ISOBMFF container demuxer supporting random-access keyframe seek and packet extraction.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct Mp4Demuxer {
    /// Backing MP4 container bytes.
    pub(crate) bytes: Vec<u8>,
    /// Major brand FourCC parsed from `ftyp` (e.g. `"isom"`, `"mp42"`).
    pub(crate) major_brand: String,
    /// Compatible brands listed in `ftyp`.
    pub(crate) compatible_brands: Vec<String>,
    /// Movie-level timescale from `mvhd`.
    #[get(type(copy))]
    pub(crate) movie_timescale: u32,
    /// Movie-level total duration in microseconds from `mvhd`.
    #[get(type(copy))]
    pub(crate) movie_duration_us: u64,
    /// Primary parsed video track metadata and sample table.
    pub(crate) video_track: Mp4TrackInfo,
    /// Optional parsed audio track metadata and sample table.
    #[get(skip)]
    pub(crate) audio_track: Option<Mp4TrackInfo>,
}

/// Input sample specification consumed by `Mp4ContainerBuilder` to emit valid ISOBMFF MP4 files.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct Mp4BuilderSample {
    /// Sample duration in track timescale ticks (`stts`).
    #[get(type(copy))]
    pub(crate) duration_ticks: u32,
    /// Composition time offset in track timescale ticks (`ctts`, added to DTS to obtain PTS).
    #[get(type(copy))]
    pub(crate) composition_offset_ticks: i32,
    /// Whether this sample is a keyframe listed in `stss`.
    #[get(type(copy))]
    pub(crate) is_keyframe: bool,
    /// Encoded sample payload bytes stored in `mdat`.
    pub(crate) payload: Vec<u8>,
}

/// Stateless pure-Rust ISOBMFF MP4 container builder producing spec-compliant `ftyp`/`moov`/`mdat` byte streams.
#[derive(Clone, Copy, Debug, Default)]
pub struct Mp4ContainerBuilder;

/// Decoder initialization descriptor derived from an MP4 video track.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct VideoDecoderConfig {
    /// Target video codec.
    #[get(type(copy))]
    pub(crate) codec: VideoCodec,
    /// Coded frame width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Coded frame height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Track color primaries, transfer curve, matrix, range, and HDR metadata.
    #[get(type(copy))]
    pub(crate) color_info: VideoColorInfo,
}

/// Demuxed video packet submitted to a `VideoDecoderBackend`.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub struct EncodedVideoPacket {
    /// Zero-based sample index inside the track.
    #[get(type(copy))]
    pub(crate) sample_index: usize,
    /// Seek/pipeline generation tag preventing stale pre-seek packets from rendering.
    #[get(type(copy))]
    pub(crate) generation: u64,
    /// Decoding timestamp in microseconds.
    #[get(type(copy))]
    pub(crate) dts_us: i64,
    /// Presentation timestamp in microseconds.
    #[get(type(copy))]
    pub(crate) pts_us: i64,
    /// Frame duration in microseconds.
    #[get(type(copy))]
    pub(crate) duration_us: u64,
    /// `true` when this packet is an intra keyframe.
    #[get(type(copy))]
    pub(crate) is_keyframe: bool,
    /// Encoded packet bytes.
    pub(crate) data: Vec<u8>,
}

/// Decoded video frame ordered by presentation timestamp (`pts_us`) with color/HDR metadata and GPU or pooled CPU backing.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct DecodedVideoFrame {
    /// Zero-based source sample index.
    #[get(type(copy))]
    pub(crate) sample_index: usize,
    /// Seek/pipeline generation tag verifying freshness after seeks.
    #[get(type(copy))]
    pub(crate) generation: u64,
    /// Decoding timestamp in microseconds.
    #[get(type(copy))]
    pub(crate) dts_us: i64,
    /// Presentation timestamp in microseconds.
    #[get(type(copy))]
    pub(crate) pts_us: i64,
    /// Frame display duration in microseconds.
    #[get(type(copy))]
    pub(crate) duration_us: u64,
    /// Decoded pixel width.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Decoded pixel height.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Color primaries, transfer curve, matrix, and HDR metadata.
    #[get(type(copy))]
    pub(crate) color_info: VideoColorInfo,
    /// Frame pixel backing (`GpuSurface` zero-copy handle or `CpuPooled` buffer).
    pub(crate) backing: VideoFrameBacking,
}

/// Pure-Rust software fallback decoder handling intra RGBA8, intra YUV420P (with full CICP color matrix math), and P-frame XOR delta packets.
#[derive(Clone, Data, Debug, Default)]
pub struct SoftwareVideoDecoder {
    /// Active configured track metadata.
    #[get(type(copy))]
    pub(crate) config: VideoDecoderConfig,
    /// Last decoded RGBA8 reference frame retained for P-frame delta reconstruction.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) reference_rgba: Vec<u8>,
    /// Whether `reference_rgba` currently holds a valid decoded frame since the last flush.
    #[get(type(copy))]
    pub(crate) has_reference: bool,
    /// Total frames decoded by this software decoder instance.
    #[get(type(copy))]
    pub(crate) decoded_frames: u64,
}

/// Zero-copy GPU interop hardware decoder adapter producing `VideoGpuSurfaceHandle` frames without CPU readback.
#[derive(Clone, Data, Debug, Default)]
pub struct HardwareZeroCopyDecoder {
    /// Target platform hardware backend kind (`VideoToolbox`, `MediaCodec`, `Vaapi`, `Dxva`, `WebCodecs`).
    #[get(type(copy))]
    pub(crate) kind: HardwareDecoderKind,
    /// Target GPU device identifier.
    #[get(type(copy))]
    pub(crate) device_id: u64,
    /// Preferred GPU hardware surface pixel layout (`Nv12` for SDR, `P010` for HDR10).
    #[get(type(copy))]
    pub(crate) pixel_format: VideoPixelFormat,
    /// Active configured video track metadata.
    #[get(type(copy))]
    pub(crate) config: VideoDecoderConfig,
    /// Monotonic GPU surface handle counter.
    #[get(type(copy))]
    pub(crate) next_surface_id: u64,
    /// Monotonic GPU synchronization fence value.
    #[get(type(copy))]
    pub(crate) next_fence_value: u64,
}

/// Bounded presentation-timestamp-ordered decoded frame queue supporting B-frame reordering and generation-tagged seek draining.
#[derive(Clone, Data, Debug, Default)]
pub struct PtsFrameQueue {
    /// Maximum frames retained simultaneously in the queue.
    #[get(type(copy))]
    pub(crate) capacity: usize,
    /// Frames maintained in strictly non-decreasing `pts_us` order.
    pub(crate) frames: Vec<DecodedVideoFrame>,
    /// Total frames discarded because their `generation` was older than an active seek.
    #[get(type(copy))]
    pub(crate) stale_generation_drops: u64,
}

/// Audio-master / monotonic-clock A/V synchronization scheduler that preserves source video cadence without forging frames on high-refresh displays.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct AvSyncScheduler {
    /// Active synchronization clock source (`AudioMaster` or `MonotonicFallback`).
    #[get(type(copy))]
    pub(crate) clock_source: AvSyncClockSource,
    /// Active playback clock position in microseconds.
    #[get(type(copy))]
    pub(crate) clock_pts_us: i64,
    /// Playback speed multiplier (`0.25..=4.0`).
    #[get(type(copy))]
    pub(crate) playback_rate: f32,
    /// Maximum frame lateness threshold in microseconds before dropping stale frames.
    #[get(type(copy))]
    pub(crate) max_late_us: i64,
    /// PTS of the most recently presented frame (`None` before first frame or after seek).
    #[get(skip)]
    pub(crate) last_presented_pts_us: Option<i64>,
    /// Count of distinct video frames newly presented to the display.
    #[get(type(copy))]
    pub(crate) frames_presented: u64,
    /// Count of VSync ticks that held the existing frame because the next PTS was not yet due.
    #[get(type(copy))]
    pub(crate) frames_held_vsync: u64,
    /// Count of overdue queued frames dropped to recover A/V sync.
    #[get(type(copy))]
    pub(crate) frames_dropped_late: u64,
}

/// Shared worker coordination state between the UI thread and the background decode worker thread.
#[cfg(not(target_arch = "wasm32"))]
#[derive(CustomDebug, Data)]
pub(crate) struct VideoWorkerShared {
    /// Bounded PTS-ordered decoded frame queue filled by the worker thread.
    pub(crate) queue: PtsFrameQueue,
    /// Active seek generation counter; increments invalidate in-flight older frames.
    #[get(type(copy))]
    pub(crate) active_generation: u64,
    /// Next demux sample index queued for decode.
    #[get(type(copy))]
    pub(crate) next_sample_index: usize,
    /// Target presentation timestamp after a seek; frames earlier than this during keyframe preroll are discarded.
    #[get(type(copy))]
    pub(crate) seek_preroll_target_us: i64,
    /// Pending seek request `(new_generation, keyframe_index, target_pts_us)` consumed by the worker.
    #[get(skip)]
    pub(crate) pending_seek: Option<(u64, usize, i64)>,
    /// Whether the pipeline is actively decoding.
    #[get(type(copy))]
    pub(crate) playing: bool,
    /// Whether the worker reached the end of the demuxed sample stream for the active generation.
    #[get(type(copy))]
    pub(crate) reached_eos: bool,
    /// Whether the worker thread should exit cleanly.
    #[get(type(copy))]
    pub(crate) shutdown: bool,
    /// Total packets decoded by the background worker.
    #[get(type(copy))]
    pub(crate) packets_decoded: u64,
    /// Total preroll frames decoded and discarded before reaching `seek_preroll_target_us`.
    #[get(type(copy))]
    pub(crate) seek_preroll_frames_discarded: u64,
    /// Last decode error string reported by the worker, if any.
    #[get(skip)]
    pub(crate) last_error: Option<String>,
}

/// Asynchronous multi-threaded (native) / deterministic pumpable (wasm32) structured video playback pipeline.
#[derive(CustomDebug)]
pub struct VideoPlaybackPipeline {
    /// Parsed MP4/ISOBMFF demuxer providing metadata and random-access sample lookup.
    pub(crate) demuxer: Mp4Demuxer,
    /// Bounded reusable CPU RGBA8 pixel buffer pool.
    pub(crate) pool: VideoFramePool,
    /// Audio-master / monotonic A/V synchronization scheduler.
    pub(crate) scheduler: AvSyncScheduler,
    /// Active hardware or software decoder backend kind.
    pub(crate) backend_kind: HardwareDecoderKind,
    /// Track color primaries, transfer curve, matrix, and HDR metadata.
    pub(crate) color_info: VideoColorInfo,
    /// Active playback transport state (`Idle`, `Playing`, `Paused`, `Ended`, `Error`).
    pub(crate) state: PlaybackState,
    /// Currently displayed decoded video frame held across intermediate VSync ticks.
    pub(crate) current_frame: Option<DecodedVideoFrame>,
    /// Active seek generation counter mirrored on the controller thread.
    pub(crate) active_generation: u64,
    /// Shared synchronization pair coordinating the background decode worker on native targets.
    #[cfg(not(target_arch = "wasm32"))]
    #[debug(skip)]
    pub(crate) worker_shared: Arc<(Mutex<VideoWorkerShared>, Condvar)>,
    /// Owned background decode thread handle joined cleanly on `Drop`.
    #[cfg(not(target_arch = "wasm32"))]
    #[debug(skip)]
    pub(crate) worker_handle: Option<JoinHandle<()>>,
    /// Single-threaded decoder instance used on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    #[debug(skip)]
    pub(crate) wasm_decoder: Box<dyn VideoDecoderBackend>,
    /// Bounded PTS queue used on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_queue: PtsFrameQueue,
    /// Next demux sample index on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_next_sample: usize,
    /// Seek preroll target timestamp on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_preroll_target_us: i64,
    /// End-of-stream flag on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_eos: bool,
    /// Total packets decoded on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_packets_decoded: u64,
    /// Total preroll frames discarded during seek on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_preroll_discarded: u64,
    /// Last decode error on WebAssembly targets.
    #[cfg(target_arch = "wasm32")]
    pub(crate) wasm_last_error: Option<String>,
}

/// Internal accumulator populated while parsing an ISOBMFF `stbl` box hierarchy.
#[derive(Clone, Data, Debug, Default)]
pub(crate) struct Mp4SampleTableRaw {
    /// `(sample_count, sample_delta_ticks)` pairs parsed from `stts`.
    pub(crate) stts: Vec<(u32, u32)>,
    /// `(sample_count, composition_offset_ticks)` pairs parsed from `ctts`.
    pub(crate) ctts: Vec<(u32, i32)>,
    /// 1-based sync keyframe sample numbers parsed from `stss`.
    pub(crate) stss: Vec<u32>,
    /// `(first_chunk, samples_per_chunk)` pairs parsed from `stsc`.
    pub(crate) stsc: Vec<(u32, u32)>,
    /// Constant sample size from `stsz` (`0` when per-sample sizes are present).
    #[get(type(copy))]
    pub(crate) default_sample_size: u32,
    /// Declared total sample count from `stsz`.
    #[get(type(copy))]
    pub(crate) sample_count: u32,
    /// Per-sample byte sizes parsed from `stsz`.
    pub(crate) sample_sizes: Vec<u32>,
    /// Chunk byte offsets parsed from `stco` or `co64`.
    pub(crate) chunk_offsets: Vec<u64>,
}