also looking at this
feat(media): add bounded PCM capture, owned snapshots and A/V streaming
#917
11 files
+683
-0
| @@ -0,0 +1,18 @@ | ||
| 1 | //! Soft rotation thresholds: caller stages a keyframe-aligned split when due. | |
| 2 | const std = @import("std"); | |
| 3 | pub const Policy = struct { | |
| 4 | duration_ns: u64 = 0, | |
| 5 | max_bytes: u64 = 0, | |
| 6 | pub fn due(s: Policy, frames: u64, elapsed_ns: u64, bytes: u64, pending: bool) bool { | |
| 7 | return frames > 0 and !pending and ((s.duration_ns != 0 and elapsed_ns >= s.duration_ns) or (s.max_bytes != 0 and bytes >= s.max_bytes)); | |
| 8 | } | |
| 9 | }; | |
| 10 | test "thresholds include equality, ignore empty and pending segments, and can disable" { | |
| 11 | const p = Policy{ .duration_ns = 100, .max_bytes = 200 }; | |
| 12 | try std.testing.expect(!p.due(0, 100, 200, false)); | |
| 13 | try std.testing.expect(!p.due(1, 100, 200, true)); | |
| 14 | try std.testing.expect(!p.due(1, 99, 199, false)); | |
| 15 | try std.testing.expect(p.due(1, 100, 0, false)); | |
| 16 | try std.testing.expect(p.due(1, 0, 200, false)); | |
| 17 | try std.testing.expect(!(Policy{}).due(1, 100, 200, false)); | |
| 18 | } | |