more frame informationon dump

This commit is contained in:
2025-10-20 22:41:49 +03:00
parent bfca9bc0a0
commit a8f1bf5d85
2 changed files with 38 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
const std = @import("std"); const std = @import("std");
const c = @cImport(@cInclude("libomt.h")); const c = @cImport(@cInclude("libomt.h"));
pub fn codecToString(codec: c.OMTCodec) []const u8 { pub fn codecToString(codec: c.OMTCodec) ?[]const u8 {
return switch (codec) { return switch (codec) {
c.OMTCodec_VMX1 => "VMX1", c.OMTCodec_VMX1 => "VMX1",
c.OMTCodec_FPA1 => "FPA1", //Planar audio c.OMTCodec_FPA1 => "FPA1", //Planar audio
@@ -16,3 +16,12 @@ pub fn codecToString(codec: c.OMTCodec) []const u8 {
else => "Invalid", else => "Invalid",
}; };
} }
pub fn colorSpaceToString(cs: c.OMTColorSpace) []const u8 {
return switch (cs) {
c.OMTColorSpace_Undefined => "Undefined",
c.OMTColorSpace_BT601 => "BT601",
c.OMTColorSpace_BT709 => "BT709",
else => "Invalid",
};
}

View File

@@ -24,8 +24,8 @@ fn discoverStream() ?[*c]u8 {
} }
pub fn main() !void { pub fn main() !void {
// var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
// const allocator = gpa.allocator(); const allocator = gpa.allocator();
std.log.info("Receiving...", .{}); std.log.info("Receiving...", .{});
comt.omt_setloggingfilename("omtrecvtest.log"); comt.omt_setloggingfilename("omtrecvtest.log");
@@ -44,24 +44,24 @@ pub fn main() !void {
while (true) { while (true) {
const frame = comt.omt_receive(receiver, frametype_flags, 40); const frame = comt.omt_receive(receiver, frametype_flags, 40);
if (frame != null) { if (frame != null) {
dumpOMTMediaFrameInfo(frame); dumpOMTMediaFrameInfo(allocator, frame);
} }
} }
} }
fn dumpOMTMediaFrameInfo(frame: *comt.OMTMediaFrame) void { fn dumpOMTMediaFrameInfo(allocator: std.mem.Allocator, frame: *comt.OMTMediaFrame) void {
std.log.info("--------- Received --------", .{}); std.log.info("--------- Received --------", .{});
switch (frame.*.Type) { switch (frame.*.Type) {
comt.OMTFrameType_Video => dumpVideoFrameInfo(frame), comt.OMTFrameType_Video => dumpVideoFrameInfo(frame),
comt.OMTFrameType_Audio => dumpAudioFrameInfo(frame), comt.OMTFrameType_Audio => dumpAudioFrameInfo(frame),
comt.OMTFrameType_Metadata => dumpMetadataFrameInfo(frame), comt.OMTFrameType_Metadata => dumpMetadataFrameInfo(allocator, frame),
else => std.log.err("Undefined frame type", .{}), else => std.log.err("Undefined frame type", .{}),
} }
} }
fn dumpVideoFrameInfo(frame: *comt.OMTMediaFrame) void { fn dumpVideoFrameInfo(frame: *comt.OMTMediaFrame) void {
std.log.info("Frame: Video", .{});
std.log.info( std.log.info(
\\Frame: Video
\\Timestamp: {d} \\Timestamp: {d}
\\Codec: {s} \\Codec: {s}
\\Width: {d} \\Width: {d}
@@ -70,24 +70,42 @@ fn dumpVideoFrameInfo(frame: *comt.OMTMediaFrame) void {
\\FrameRateN: {d} \\FrameRateN: {d}
\\FrameRateD: {d} \\FrameRateD: {d}
\\AspectRatio: {d} \\AspectRatio: {d}
\\ColorSpace: {s}
, .{ , .{
frame.Timestamp, frame.Timestamp,
omt.codecToString(frame.Codec), omt.codecToString(frame.Codec) orelse "Invalid",
frame.Width, frame.Width,
frame.Height, frame.Height,
frame.Stride, frame.Stride,
frame.FrameRateN, frame.FrameRateN,
frame.FrameRateD, frame.FrameRateD,
frame.AspectRatio, frame.AspectRatio,
omt.colorSpaceToString(frame.ColorSpace),
}); });
} }
fn dumpAudioFrameInfo(frame: *comt.OMTMediaFrame) void { fn dumpAudioFrameInfo(frame: *comt.OMTMediaFrame) void {
std.log.info("Frame: Audio", .{}); std.log.info("Frame: Audio", .{});
_ = frame; std.log.info(
\\Timestamp: {d}
\\SampleRate: {d}
\\Channels: {d}
\\SamplesPerChannel: {d}
, .{ frame.Timestamp, frame.SampleRate, frame.Channels, frame.SamplesPerChannel });
} }
fn dumpMetadataFrameInfo(frame: *comt.OMTMediaFrame) void { fn dumpMetadataFrameInfo(allocator: std.mem.Allocator, frame: *comt.OMTMediaFrame) void {
std.log.info("Frame: Metadata", .{}); std.log.info("Frame: Metadata", .{});
_ = frame; if (frame.FrameMetadataLength == 0 or frame.FrameMetadata == null) {
std.log.info("None", .{});
return;
}
const metadata_length: usize = @intCast(frame.FrameMetadataLength);
const buffer = allocator.alloc(u8, metadata_length) catch @panic("OOM");
defer allocator.free(buffer);
std.debug.print("metadata: {?p}\n", .{frame.FrameMetadata});
std.mem.copyForwards(u8, buffer, @ptrCast(@alignCast(frame.FrameMetadata)));
std.log.info("{s}", .{buffer});
} }