also looking at this
feat(video): add native AVC/HEVC and synchronized AAC MP4 streaming
#913
14 files
+1119
-0
| @@ -0,0 +1,49 @@ | ||
| 1 | //! Focused optional codec suite, independent of Home's broad video import graph. | |
| 2 | const std = @import("std"); | |
| 3 | const native = @import("codecs/video/native_encoder.zig"); | |
| 4 | test { | |
| 5 | _ = @import("codecs/video/rgb_i420.zig"); | |
| 6 | _ = @import("containers/mp4_stream.zig"); | |
| 7 | } | |
| 8 | test "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 | } | |
| 34 | test "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 | } | |
| 40 | test "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 | } | |