From 7ebdbdf5b49d00653b73f9b42b7f0c8e64f8833c Mon Sep 17 00:00:00 2001 From: Kasper Sauramo Date: Mon, 13 Oct 2025 01:06:07 +0300 Subject: [PATCH] Add random audio to tester --- src/main.zig | 114 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 41 deletions(-) diff --git a/src/main.zig b/src/main.zig index 6973a77..d074b10 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2,59 +2,91 @@ const std = @import("std"); const omt = @cImport(@cInclude("libomt.h")); pub fn main() !void { - const gpa = std.heap.GeneralPurposeAllocator(.{}){}; + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); std.log.info("Send test...", .{}); omt.omt_setloggingfilename("omtsendtest.log"); - const sender = omt.omt_send_create("Omtoy Sender", omt.OMTQuality_Default); - if (sender != null) { - std.log.info("Sender created", .{}); + const sender = omt.omt_send_create("Omtoy Sender", omt.OMTQuality_Default) orelse undefined; + defer omt.omt_send_destroy(sender); - { - var sender_info = std.mem.zeroes(omt.OMTSenderInfo); + std.log.info("Sender created", .{}); - const product_name = "Omtoy"; - const manufacturer = "Kasper Toy Productions"; - const version = "0.1"; + { + var sender_info = std.mem.zeroes(omt.OMTSenderInfo); - @memcpy(sender_info.ProductName[0..product_name.len], product_name); - @memcpy(sender_info.Manufacturer[0..manufacturer.len], manufacturer); - @memcpy(sender_info.Version[0..version.len], version); + const product_name = "Omtoy"; + const manufacturer = "Kasper Toy Productions"; + const version = "0.1"; - omt.omt_send_setsenderinformation(sender, &sender_info); - } + @memcpy(sender_info.ProductName[0..product_name.len], product_name); + @memcpy(sender_info.Manufacturer[0..manufacturer.len], manufacturer); + @memcpy(sender_info.Version[0..version.len], version); - const width = 1920; - const height = 1080; - const stride = width * 2; - const data_length = stride * height; - - const frame_buffer = allocator.alloc(u8, data_length); - { - const frame = omt.OMTMediaFrame{ - .Type = omt.OMTFrameType_Video, - .Width = width, - .Height = height, - .Codec = omt.OMTCodec_UYVY, - .Timestamp = -1, - .ColorSpace = omt.OMTColorSpace_BT709, - .Flags = omt.OMTVideoFlags_None, - .Stride = width * 2, - .DataLength = width * 2 * height, - .Data = frame_buffer, - .FrameRateN = 60000, - .FrameRateD = 1000, - .CompressedData = 0, - .CompressedLength = 0, - .FrameMetadata = 0, - .FrameMetadataLength = 0, - // TODO - }; - } + omt.omt_send_setsenderinformation(sender, &sender_info); } + const width = 1920; + const height = 1080; + const stride = width * 2; + const data_length = stride * height; + + const frame_buffer = allocator.alloc(u8, data_length) catch undefined; + defer allocator.free(frame_buffer); + + const video_frame = omt.OMTMediaFrame{ + .Type = omt.OMTFrameType_Video, + .Width = width, + .Height = height, + .Codec = omt.OMTCodec_UYVY, + .Timestamp = -1, + .ColorSpace = omt.OMTColorSpace_BT709, + .Flags = omt.OMTVideoFlags_None, + .Stride = width * 2, + .DataLength = width * 2 * height, + .Data = @ptrCast(frame_buffer), + .FrameRateN = 60000, + .FrameRateD = 1000, + .CompressedData = null, + .CompressedLength = 0, + .FrameMetadata = null, + .FrameMetadataLength = 0, + }; + + _ = video_frame; + const content = try std.fs.cwd().readFileAlloc("california-1080-uyvy.yuv", allocator, .unlimited); + defer allocator.free(content); + + const audio_samples = 800; + const audio_buffer = try allocator.alloc(f32, audio_samples); + + var prng = std.Random.DefaultPrng.init(80085); + const rng = prng.random(); + for (audio_buffer) |*val| { + val.* = rng.float(f32) * 2 - 1.0; + } + + const audio_frame = omt.OMTMediaFrame{ + .Type = omt.OMTFrameType_Audio, + .Timestamp = -1, + .Codec = omt.OMTCodec_FPA1, + .SampleRate = 48000, + .Channels = 2, + .SamplesPerChannel = audio_samples, + .Data = @ptrCast(audio_buffer), + .DataLength = audio_buffer.len * 2, + .FrameMetadata = null, + .FrameMetadataLength = 0, + }; + + var tally = omt.OMTTally{ .preview = 0, .program = 0 }; + var stats = std.mem.zeroes(omt.OMTStatistics); + + var frame_count = 0; + var bytes = 0; + + // Check we're on! var found_address_count: i32 = 0; _ = omt.omt_discovery_getaddresses(&found_address_count);