also looking at this
feat(video): add checked elementary packet and PTS outputs
#919
4 files
+148
-0
| @@ -0,0 +1,34 @@ | ||
| 1 | # Checked elementary packet and PTS output | |
| 2 | ||
| 3 | `src/core/packet_output.zig` is a standalone, allocation-free boundary for | |
| 4 | reusable streaming sinks. The broader sink graph includes decoded-frame and | |
| 5 | accumulating packet collections; this module neither retains borrowed packets | |
| 6 | nor imports that graph. | |
| 7 | ||
| 8 | `annexB(input, output)` converts four-byte big-endian length-prefixed AVC/HEVC | |
| 9 | NAL units to four-byte Annex B start codes. It checks every length before writing | |
| 10 | any destination bytes, rejects empty/truncated/zero-length input, and checks | |
| 11 | output capacity. Input/output must not overlap. Parameter sets can be converted | |
| 12 | separately and prepended at the first key of a newly attached output. | |
| 13 | ||
| 14 | `formatPts(timestamp_us, output)` formats integer microsecond PTS as milliseconds | |
| 15 | with exactly three decimal digits and LF. Zero and all u64 timestamps are exact; | |
| 16 | no floating-point rounding or locale formatting is used. Too-small buffers remain | |
| 17 | unchanged. A 32-byte destination covers the complete u64 range. | |
| 18 | ||
| 19 | `PtsWriter` wraps an explicit synchronous `Sink{context,write}`. Sink callbacks | |
| 20 | must completely accept their borrowed data or return an error. Rejected | |
| 21 | non-increasing timestamps do not touch the sink. A sink failure poisons the | |
| 22 | writer; create a fresh writer for a new clip/epoch. The module does not own files, | |
| 23 | threads or packet storage and does not depend on FFmpeg/Libav. | |
| 24 | ||
| 25 | Focused tests on Zig 0.15.2 and the Home development toolchain: | |
| 26 | ||
| 27 | ```sh | |
| 28 | zig test packages/video/src/core/packet_output.zig | |
| 29 | ``` | |
| 30 | ||
| 31 | Tests cover multi-NAL conversion, malformed/truncated input, exact maximum PTS, | |
| 32 | small-buffer state preservation, monotonicity and sink-failure poisoning. | |
| 33 | zig-camera uses the helpers at its native callback output boundary, with | |
| 34 | independent video decoding and media/PTS timeline checks in its integration suite. | |