95 lines
2.9 KiB
Zig
95 lines
2.9 KiB
Zig
const std = @import("std");
|
|
const omt = @cImport(@cInclude("libomt.h"));
|
|
|
|
pub fn main() !void {
|
|
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) orelse undefined;
|
|
defer omt.omt_send_destroy(sender);
|
|
|
|
std.log.info("Sender created", .{});
|
|
|
|
{
|
|
var sender_info = std.mem.zeroes(omt.OMTSenderInfo);
|
|
|
|
const product_name = "Omtoy";
|
|
const manufacturer = "Kasper Toy Productions";
|
|
const version = "0.1";
|
|
|
|
@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);
|
|
|
|
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);
|
|
|
|
std.debug.print("Found {d} omt addresses\n", .{found_address_count});
|
|
}
|