send video and audio frames

This commit is contained in:
2025-10-13 22:09:41 +03:00
parent 7ebdbdf5b4
commit cc109157eb

View File

@@ -5,6 +5,11 @@ pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var found_address_count: i32 = 0;
_ = omt.omt_discovery_getaddresses(&found_address_count);
std.debug.print("Found {d} omt addresses\n", .{found_address_count});
std.log.info("Send test...", .{});
omt.omt_setloggingfilename("omtsendtest.log");
@@ -35,7 +40,7 @@ pub fn main() !void {
const frame_buffer = allocator.alloc(u8, data_length) catch undefined;
defer allocator.free(frame_buffer);
const video_frame = omt.OMTMediaFrame{
var video_frame = omt.OMTMediaFrame{
.Type = omt.OMTFrameType_Video,
.Width = width,
.Height = height,
@@ -54,7 +59,6 @@ pub fn main() !void {
.FrameMetadataLength = 0,
};
_ = video_frame;
const content = try std.fs.cwd().readFileAlloc("california-1080-uyvy.yuv", allocator, .unlimited);
defer allocator.free(content);
@@ -63,11 +67,9 @@ pub fn main() !void {
var prng = std.Random.DefaultPrng.init(80085);
const rng = prng.random();
for (audio_buffer) |*val| {
val.* = rng.float(f32) * 2 - 1.0;
}
fillAudioBuffer(rng, audio_buffer);
const audio_frame = omt.OMTMediaFrame{
var audio_frame = omt.OMTMediaFrame{
.Type = omt.OMTFrameType_Audio,
.Timestamp = -1,
.Codec = omt.OMTCodec_FPA1,
@@ -75,7 +77,7 @@ pub fn main() !void {
.Channels = 2,
.SamplesPerChannel = audio_samples,
.Data = @ptrCast(audio_buffer),
.DataLength = audio_buffer.len * 2,
.DataLength = @intCast(audio_buffer.len * 2),
.FrameMetadata = null,
.FrameMetadataLength = 0,
};
@@ -83,12 +85,56 @@ pub fn main() !void {
var tally = omt.OMTTally{ .preview = 0, .program = 0 };
var stats = std.mem.zeroes(omt.OMTStatistics);
var frame_count = 0;
var bytes = 0;
var frame_count: i32 = 0;
var bytes: i32 = 0;
const two_lines = try allocator.alloc(u8, stride * 2);
@memset(two_lines, 255);
var line_position: usize = 0;
// send 10000 frames
while (frame_count < 10000) : (frame_count += 1) {
@memcpy(frame_buffer, content);
// TODO: copy the white line over here
line_position += stride * 2;
if (line_position >= video_frame.DataLength) {
line_position = 0;
}
bytes += omt.omt_send(sender, &video_frame);
if (@mod(frame_count, 60) == 0) {
std.log.info("sent: {}", .{bytes});
_ = omt.omt_send_gettally(sender, 0, &tally);
std.log.info("tally preview: {}, program: {}", .{ tally.preview, tally.program });
const frame = omt.omt_send_receive(sender, 0);
if (frame != null) {
const metadata = frame.*.Data;
if (metadata != null) {
const metastr = @as([]u8, @ptrCast(metadata));
std.log.info("meta: {s}", .{metastr});
}
}
const connections = omt.omt_send_connections(sender);
std.log.info("connections: {}", .{connections});
omt.omt_send_getvideostatistics(sender, &stats);
std.log.info("statistics sent bytes: {}, frames: {}", .{ stats.BytesSent, stats.Frames });
}
_ = omt.omt_send(sender, &audio_frame);
fillAudioBuffer(rng, audio_buffer);
}
// Check we're on!
var found_address_count: i32 = 0;
_ = omt.omt_discovery_getaddresses(&found_address_count);
std.debug.print("Found {d} omt addresses\n", .{found_address_count});
}
fn fillAudioBuffer(rng: std.Random, buffer: []f32) void {
for (buffer) |*val| {
val.* = rng.float(f32) * 2 - 1.0;
}
}