more frame informationon dump
This commit is contained in:
11
src/omt.zig
11
src/omt.zig
@@ -1,7 +1,7 @@
|
||||
const std = @import("std");
|
||||
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) {
|
||||
c.OMTCodec_VMX1 => "VMX1",
|
||||
c.OMTCodec_FPA1 => "FPA1", //Planar audio
|
||||
@@ -16,3 +16,12 @@ pub fn codecToString(codec: c.OMTCodec) []const u8 {
|
||||
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",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ fn discoverStream() ?[*c]u8 {
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
// var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
// const allocator = gpa.allocator();
|
||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
std.log.info("Receiving...", .{});
|
||||
comt.omt_setloggingfilename("omtrecvtest.log");
|
||||
@@ -44,24 +44,24 @@ pub fn main() !void {
|
||||
while (true) {
|
||||
const frame = comt.omt_receive(receiver, frametype_flags, 40);
|
||||
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 --------", .{});
|
||||
switch (frame.*.Type) {
|
||||
comt.OMTFrameType_Video => dumpVideoFrameInfo(frame),
|
||||
comt.OMTFrameType_Audio => dumpAudioFrameInfo(frame),
|
||||
comt.OMTFrameType_Metadata => dumpMetadataFrameInfo(frame),
|
||||
comt.OMTFrameType_Metadata => dumpMetadataFrameInfo(allocator, frame),
|
||||
else => std.log.err("Undefined frame type", .{}),
|
||||
}
|
||||
}
|
||||
|
||||
fn dumpVideoFrameInfo(frame: *comt.OMTMediaFrame) void {
|
||||
std.log.info("Frame: Video", .{});
|
||||
std.log.info(
|
||||
\\Frame: Video
|
||||
\\Timestamp: {d}
|
||||
\\Codec: {s}
|
||||
\\Width: {d}
|
||||
@@ -70,24 +70,42 @@ fn dumpVideoFrameInfo(frame: *comt.OMTMediaFrame) void {
|
||||
\\FrameRateN: {d}
|
||||
\\FrameRateD: {d}
|
||||
\\AspectRatio: {d}
|
||||
\\ColorSpace: {s}
|
||||
, .{
|
||||
frame.Timestamp,
|
||||
omt.codecToString(frame.Codec),
|
||||
omt.codecToString(frame.Codec) orelse "Invalid",
|
||||
frame.Width,
|
||||
frame.Height,
|
||||
frame.Stride,
|
||||
frame.FrameRateN,
|
||||
frame.FrameRateD,
|
||||
frame.AspectRatio,
|
||||
omt.colorSpaceToString(frame.ColorSpace),
|
||||
});
|
||||
}
|
||||
|
||||
fn dumpAudioFrameInfo(frame: *comt.OMTMediaFrame) void {
|
||||
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", .{});
|
||||
_ = 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});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user