print video frame information on receiver test

This commit is contained in:
2025-10-20 19:08:32 +03:00
parent af697d699c
commit bfca9bc0a0
4 changed files with 75 additions and 26 deletions

View File

@@ -67,6 +67,22 @@ pub fn build(b: *std.Build) void {
);
install_vmx_so.step.dependOn(&libvmx_build.step);
// The output lib and header directories
const lib_output_path: std.Build.LazyPath = .{
.cwd_relative = b.lib_dir,
};
const include_output_path: std.Build.LazyPath = .{
.cwd_relative = b.h_dir,
};
// Zig omt module
const omt_module = b.addModule("omt", .{
.root_source_file = b.path("src/omt.zig"),
.target = target,
.optimize = optimize,
});
omt_module.linkSystemLibrary("omt", .{});
// Define executable
const sender_exe = b.addExecutable(.{
.name = "omtoy-sender",
@@ -76,13 +92,10 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
}),
});
sender_exe.root_module.addImport("omt", omt_module);
const lib_output_path: std.Build.LazyPath = .{
.cwd_relative = b.lib_dir,
};
const include_output_path: std.Build.LazyPath = .{
.cwd_relative = b.h_dir,
};
omt_module.addLibraryPath(lib_output_path);
omt_module.addIncludePath(include_output_path);
sender_exe.root_module.addLibraryPath(lib_output_path);
sender_exe.root_module.addIncludePath(include_output_path);
@@ -97,6 +110,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
}),
});
receiver_exe.root_module.addImport("omt", omt_module);
receiver_exe.root_module.addLibraryPath(lib_output_path);
receiver_exe.root_module.addIncludePath(include_output_path);

18
src/omt.zig Normal file
View File

@@ -0,0 +1,18 @@
const std = @import("std");
const c = @cImport(@cInclude("libomt.h"));
pub fn codecToString(codec: c.OMTCodec) []const u8 {
return switch (codec) {
c.OMTCodec_VMX1 => "VMX1",
c.OMTCodec_FPA1 => "FPA1", //Planar audio
c.OMTCodec_UYVY => "UYVY",
c.OMTCodec_YUY2 => "YUY2",
c.OMTCodec_BGRA => "BGRA",
c.OMTCodec_NV12 => "NV12",
c.OMTCodec_YV12 => "YV12",
c.OMTCodec_UYVA => "UYVA",
c.OMTCodec_P216 => "P216",
c.OMTCodec_PA16 => "PA16,",
else => "Invalid",
};
}

View File

@@ -1,11 +1,12 @@
const std = @import("std");
const omt = @cImport(@cInclude("libomt.h"));
const omt = @import("omt");
const comt = @cImport(@cInclude("libomt.h"));
fn discoverStream() ?[*c]u8 {
var discovery_count: i32 = 0;
while (discovery_count == 0) {
const discovered = omt.omt_discovery_getaddresses(&discovery_count);
const discovered = comt.omt_discovery_getaddresses(&discovery_count);
std.log.info("Found {} streams:", .{discovery_count});
const count: usize = @intCast(discovery_count);
@@ -27,51 +28,66 @@ pub fn main() !void {
// const allocator = gpa.allocator();
std.log.info("Receiving...", .{});
omt.omt_setloggingfilename("omtrecvtest.log");
comt.omt_setloggingfilename("omtrecvtest.log");
const stream = discoverStream() orelse undefined;
// TODO: How to coerce C string array into something printable again?
// std.log.info("Listening to {s}", @as([*:0]u8, stream));
const frametype_flags = omt.OMTFrameType_Video | omt.OMTFrameType_Audio | omt.OMTFrameType_Metadata;
const receiver = omt.omt_receive_create(
const frametype_flags = comt.OMTFrameType_Video | comt.OMTFrameType_Audio | comt.OMTFrameType_Metadata;
const receiver = comt.omt_receive_create(
stream,
frametype_flags,
omt.OMTPreferredVideoFormat_UYVYorBGRA,
comt.OMTPreferredVideoFormat_UYVYorBGRA,
0,
);
defer omt.omt_receive_destroy(receiver);
defer comt.omt_receive_destroy(receiver);
while (true) {
const frame = omt.omt_receive(receiver, frametype_flags, 40);
const frame = comt.omt_receive(receiver, frametype_flags, 40);
if (frame != null) {
dumpOMTMediaFrameInfo(frame);
}
}
}
fn dumpOMTMediaFrameInfo(frame: *omt.OMTMediaFrame) void {
fn dumpOMTMediaFrameInfo(frame: *comt.OMTMediaFrame) void {
std.log.info("--------- Received --------", .{});
switch (frame.*.Type) {
omt.OMTFrameType_Video => dumpVideoFrameInfo(frame),
omt.OMTFrameType_Audio => dumpAudioFrameInfo(frame),
omt.OMTFrameType_Metadata => dumpMetadataFrameInfo(frame),
comt.OMTFrameType_Video => dumpVideoFrameInfo(frame),
comt.OMTFrameType_Audio => dumpAudioFrameInfo(frame),
comt.OMTFrameType_Metadata => dumpMetadataFrameInfo(frame),
else => std.log.err("Undefined frame type", .{}),
}
}
fn dumpVideoFrameInfo(frame: *omt.OMTMediaFrame) void {
std.log.info("Frame: Video", .{});
_ = frame;
fn dumpVideoFrameInfo(frame: *comt.OMTMediaFrame) void {
std.log.info(
\\Frame: Video
\\Timestamp: {d}
\\Codec: {s}
\\Width: {d}
\\Height: {d}
\\Stride: {d}
\\FrameRateN: {d}
\\FrameRateD: {d}
\\AspectRatio: {d}
, .{
frame.Timestamp,
omt.codecToString(frame.Codec),
frame.Width,
frame.Height,
frame.Stride,
frame.FrameRateN,
frame.FrameRateD,
frame.AspectRatio,
});
}
fn dumpAudioFrameInfo(frame: *omt.OMTMediaFrame) void {
fn dumpAudioFrameInfo(frame: *comt.OMTMediaFrame) void {
std.log.info("Frame: Audio", .{});
_ = frame;
}
fn dumpMetadataFrameInfo(frame: *omt.OMTMediaFrame) void {
fn dumpMetadataFrameInfo(frame: *comt.OMTMediaFrame) void {
std.log.info("Frame: Metadata", .{});
_ = frame;
}

View File

@@ -48,6 +48,7 @@ pub fn main() !void {
.Data = @ptrCast(frame_buffer),
.FrameRateN = 60000,
.FrameRateD = 1000,
.AspectRatio = @as(f32, width) / @as(f32, height),
.CompressedData = null,
.CompressedLength = 0,
.FrameMetadata = null,