ReviewOS

also looking at this

home-lang/home

feat(video): add native AVC/HEVC and synchronized AAC MP4 streaming

#913
Merged chris wants to merge feat/avc-hevc-mp4 into main
14 files +1119 -0
packages/video/src/native_media_tests.zigadded+49-0
Changes to packages/video/src/native_media_tests.zig
@@ -0,0 +1,49 @@
1//! Focused optional codec suite, independent of Home's broad video import graph.
2const std = @import("std");
3const native = @import("codecs/video/native_encoder.zig");
4test {
5 _ = @import("codecs/video/rgb_i420.zig");
6 _ = @import("containers/mp4_stream.zig");
7}
8test "AVC/HEVC drain every frame with original timestamps and reject invalid lifecycle" {
9 var y: [1024]u8 = undefined;
10 @memset(&y, 90);
11 var uv: [256]u8 = undefined;
12 @memset(&uv, 128);
13 for ([_]u32{ 1, 2 }) |codec| {
14 var encoder = try native.Encoder.init(.{ .codec = codec, .width = 32, .height = 32, .fps_num = 24, .fps_den = 1, .quality = 90, .bitrate = 0, .gop = 4 });
15 defer encoder.deinit();
16 try std.testing.expect((try encoder.headers()).len > 8);
17 var count: usize = 0;
18 for (0..6) |i| {
19 const pts: i64 = @intCast(i * 41667);
20 if (try encoder.encode(.{ &y, &uv, &uv }, .{ 32, 16, 16 }, 32, 32, pts)) |packet| {
21 try std.testing.expectEqual(@as(i64, @intCast(count * 41667)), packet.pts);
22 count += 1;
23 }
24 try std.testing.expectError(error.InvalidTimestamp, encoder.encode(.{ &y, &uv, &uv }, .{ 32, 16, 16 }, 32, 32, pts));
25 }
26 while (try encoder.flush()) |packet| {
27 try std.testing.expectEqual(@as(i64, @intCast(count * 41667)), packet.pts);
28 count += 1;
29 }
30 try std.testing.expectEqual(@as(usize, 6), count);
31 try std.testing.expectError(error.EncoderFailed, encoder.encode(.{ &y, &uv, &uv }, .{ 32, 16, 16 }, 32, 32, 999999));
32 }
33}
34test "codec configuration and plane bounds fail before vendor calls" {
35 try std.testing.expectError(error.InvalidConfiguration, native.Encoder.init(.{ .codec = 1, .width = 17, .height = 16, .fps_num = 30, .fps_den = 1, .quality = 90, .bitrate = 0, .gop = 0 }));
36 var encoder = try native.Encoder.init(.{ .codec = 1, .width = 32, .height = 32, .fps_num = 30, .fps_den = 1, .quality = 90, .bitrate = 0, .gop = 0 });
37 defer encoder.deinit();
38 try std.testing.expectError(error.InvalidFrame, encoder.encode(.{ &.{}, &.{}, &.{} }, .{ 32, 16, 16 }, 32, 32, 0));
39}
40test "quality endpoints preserve supported profiles" {
41 for ([_]u32{ 1, 2 }) |codec| {
42 for ([_]u32{ 1, 100 }) |quality| {
43 var encoder = try native.Encoder.init(.{ .codec = codec, .width = 32, .height = 32, .fps_num = 30, .fps_den = 1, .quality = quality, .bitrate = 0, .gop = 0 });
44 defer encoder.deinit();
45 try std.testing.expect((try encoder.headers()).len > 8);
46 try std.testing.expectEqual(@as(?native.Packet, null), try encoder.flush());
47 }
48 }
49}