Compare commits
No commits in common. "d5f78f80317949eff56bbff0054c78e901215234" and "e4cd8bd855361ab4845742c2f976c1eabff8bb43" have entirely different histories.
d5f78f8031
...
e4cd8bd855
3 changed files with 35 additions and 152 deletions
11
build.zig
11
build.zig
|
@ -28,9 +28,7 @@ pub fn build(b: *std.Build) void {
|
||||||
exe.linkSystemLibrary("c");
|
exe.linkSystemLibrary("c");
|
||||||
exe.addIncludePath(.{ .cwd_relative = "/usr/include/hailo" });
|
exe.addIncludePath(.{ .cwd_relative = "/usr/include/hailo" });
|
||||||
|
|
||||||
// Gstreamer makes it unhappy
|
|
||||||
// exe.linkSystemLibrary("gstreamer-1.0");
|
// exe.linkSystemLibrary("gstreamer-1.0");
|
||||||
|
|
||||||
// exe.linkSystemLibrary("gstapp-1.0");
|
// exe.linkSystemLibrary("gstapp-1.0");
|
||||||
// exe.linkSystemLibrary("glib-2.0");
|
// exe.linkSystemLibrary("glib-2.0");
|
||||||
// exe.linkSystemLibrary("gstvideotestsrc");
|
// exe.linkSystemLibrary("gstvideotestsrc");
|
||||||
|
@ -38,13 +36,12 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
exe.root_module.addImport("glib", gobject.module("glib2"));
|
exe.root_module.addImport("glib", gobject.module("glib2"));
|
||||||
exe.root_module.addImport("gobject", gobject.module("gobject2"));
|
exe.root_module.addImport("gobject", gobject.module("gobject2"));
|
||||||
exe.root_module.addImport("gst", gobject.module("gst1"));
|
// exe.root_module.addImport("gst", gobject.module("gst1"));
|
||||||
exe.root_module.addImport("gstapp", gobject.module("gstapp1"));
|
// exe.root_module.addImport("gstapp", gobject.module("gstapp1"));
|
||||||
|
|
||||||
// exe.addLibraryPath( .{ .cwd_relative = "/lib/aarch64-linux-gnu" }); // glib
|
exe.addLibraryPath( .{ .cwd_relative = "/lib/aarch64-linux-gnu" }); // glib
|
||||||
// exe.addLibraryPath( .{ .cwd_relative = "/lib/aarch64-linux-gnu/gstreamer-1.0" }); // gstreamer
|
exe.addLibraryPath( .{ .cwd_relative = "/lib/aarch64-linux-gnu/gstreamer-1.0" }); // gstreamer
|
||||||
exe.addLibraryPath( .{ .cwd_relative = "/usr/lib" }); // hailort
|
exe.addLibraryPath( .{ .cwd_relative = "/usr/lib" }); // hailort
|
||||||
exe.addLibraryPath( .{ .cwd_relative = "/lib/aarch64-linux-gnu/" });
|
|
||||||
|
|
||||||
// exe.addLibraryPath(.{ .cwd_relative = "/home/nixolas/Documents/hailort/build/hailort/libhailort/src"});
|
// exe.addLibraryPath(.{ .cwd_relative = "/home/nixolas/Documents/hailort/build/hailort/libhailort/src"});
|
||||||
exe.linkSystemLibrary("hailort");
|
exe.linkSystemLibrary("hailort");
|
||||||
|
|
12
flake.lock
12
flake.lock
|
@ -54,11 +54,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1729880355,
|
"lastModified": 1729665710,
|
||||||
"narHash": "sha256-RP+OQ6koQQLX5nw0NmcDrzvGL8HDLnyXt/jHhL1jwjM=",
|
"narHash": "sha256-AlcmCXJZPIlO5dmFzV3V2XF6x/OpNWUV8Y/FMPGd8Z4=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "18536bf04cd71abd345f9579158841376fdd0c5a",
|
"rev": "2768c7d042a37de65bb1b5b3268fc987e534c49d",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -128,11 +128,11 @@
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1730334608,
|
"lastModified": 1729858295,
|
||||||
"narHash": "sha256-NT/xmtGvwkiFfDC+FdIThG387OakQS0hnnT3etJbbNE=",
|
"narHash": "sha256-Ia6PEIsGiaP3d4ewuJ3QR46pd0b3qyt2/RM2yUZZtL8=",
|
||||||
"owner": "mitchellh",
|
"owner": "mitchellh",
|
||||||
"repo": "zig-overlay",
|
"repo": "zig-overlay",
|
||||||
"rev": "0802240ae001576ebf9cf0bbc003a8b1291c910b",
|
"rev": "71a0618a10c2fb8d6c60b3498bcdb5dc4573e403",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
158
src/main.zig
158
src/main.zig
|
@ -1,50 +1,18 @@
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const hlo = @cImport({
|
const hlo = @cImport({
|
||||||
@cInclude("hailort.h");
|
@cInclude("hailort.h");
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove "sources/" and "X.zig"
|
|
||||||
// const gst = @import("sources/gst1.zig");
|
|
||||||
// const gstapp = @import ("sources/gstapp1.zig");
|
|
||||||
// const glib = @import("sources/glib2.zig");
|
|
||||||
// const gobject = @import("sources/gobject2.zig");
|
|
||||||
|
|
||||||
const gst = @import("gst");
|
|
||||||
const gstapp = @import ("gstapp");
|
|
||||||
const glib = @import("glib");
|
|
||||||
const gobject = @import("gobject");
|
|
||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
const hef_file = "yolov7.hef";
|
const hef_file = "yolov7.hef";
|
||||||
const max_edge_layers = 32;
|
const max_edge_layers = 32;
|
||||||
|
|
||||||
var exit_loop: bool = false;
|
|
||||||
|
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
|
||||||
std.posix.sigaction(std.posix.SIG.INT, &std.posix.Sigaction {
|
|
||||||
.handler = .{
|
|
||||||
.handler = struct {
|
|
||||||
pub fn handler(_: c_int) callconv(.C) void {
|
|
||||||
std.debug.print("Control C caught!\n", .{});
|
|
||||||
exit_loop = true;
|
|
||||||
}
|
|
||||||
}.handler
|
|
||||||
},
|
|
||||||
.mask = std.posix.empty_sigset,
|
|
||||||
.flags = 0,
|
|
||||||
}, null);
|
|
||||||
|
|
||||||
std.debug.print("ctrl+c handler registered\n", .{});
|
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("Program started\n", .{});
|
|
||||||
// This allows me to utilize the same command line args and gstreamer
|
|
||||||
gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr));
|
|
||||||
|
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
|
||||||
|
@ -115,66 +83,18 @@ pub fn main() !void {
|
||||||
std.debug.print("Output vstreams initialized\n", .{});
|
std.debug.print("Output vstreams initialized\n", .{});
|
||||||
|
|
||||||
|
|
||||||
|
var input_frame_size: usize = 0;
|
||||||
|
|
||||||
|
status = hlo.hailo_get_input_vstream_frame_size(input_vstreams[0], &input_frame_size);
|
||||||
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
|
|
||||||
|
const frame_count = input_frame_size / @sizeOf(u8);
|
||||||
|
const input_data: [:0]u8 = try alloc.allocSentinel(u8, frame_count, 0);
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("HailoRT init completed\nGstreamer Init starting", .{});
|
std.debug.print("HailoRT init completed\nGstreamer Init starting", .{});
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("Gstreamer Initialized\n", .{});
|
|
||||||
|
|
||||||
const source: *gst.Element = gst.ElementFactory.make("v4l2src", "source") orelse unreachable;
|
|
||||||
std.debug.print("test source created\n", .{});
|
|
||||||
const scale: *gst.Element = gst.ElementFactory.make("videoscale", "scale") orelse unreachable;
|
|
||||||
std.debug.print("video scale created\n", .{});
|
|
||||||
const format: *gst.Element = gst.ElementFactory.make("videoconvert", "format") orelse unreachable;
|
|
||||||
std.debug.print("video convert created\n", .{});
|
|
||||||
const sink_el: *gst.Element = gst.ElementFactory.make("appsink", "sink") orelse unreachable;
|
|
||||||
std.debug.print("appsink created\n", .{});
|
|
||||||
const sink: *gstapp.AppSink = gobject.ext.cast(gstapp.AppSink, sink_el) orelse unreachable;
|
|
||||||
std.debug.print("appsink cast to an AppSink\n", .{});
|
|
||||||
|
|
||||||
|
|
||||||
const sink_caps = gst.Caps.fromString("video/x-raw,format=RGB,width=640,height=640") orelse unreachable;
|
|
||||||
std.debug.print("sink caps created\n", .{});
|
|
||||||
sink.setCaps(sink_caps);
|
|
||||||
std.debug.print("sink caps applied\n", .{});
|
|
||||||
|
|
||||||
const pipeline: *gst.Pipeline = gst.Pipeline.new("test-pipeline");
|
|
||||||
std.debug.print("pipeline created\n", .{});
|
|
||||||
|
|
||||||
const bin: *gst.Bin = &pipeline.f_bin;
|
|
||||||
std.debug.print("Bin retrieved from Pipeline\n", .{});
|
|
||||||
|
|
||||||
|
|
||||||
_ = bin.add(source);
|
|
||||||
std.debug.print("source added to bin\n", .{});
|
|
||||||
_ = bin.add(scale);
|
|
||||||
std.debug.print("scale added to bin\n", .{});
|
|
||||||
_ = bin.add(format);
|
|
||||||
std.debug.print("format added to bin\n", .{});
|
|
||||||
_ = bin.add(sink_el);
|
|
||||||
// _ = bin.addMany(source, scale, format, sink_el);
|
|
||||||
std.debug.print("Elements added to bin\n", .{});
|
|
||||||
|
|
||||||
// the failure return code is -1 I believe
|
|
||||||
if (gst.Element.linkMany(source, scale, format, sink_el) < 0) {
|
|
||||||
pipeline.unref();
|
|
||||||
std.debug.panic("Elements could not be linked\n", .{});
|
|
||||||
}
|
|
||||||
std.debug.print("Elements linked\n", .{});
|
|
||||||
|
|
||||||
// g_int is just i32. You can
|
|
||||||
// source.set("pattern", @as(i16, 0));
|
|
||||||
// gobject.Object.set(source.as(gobject.Object), "pattern", @as(i16, 0));
|
|
||||||
|
|
||||||
const ret = pipeline.as(gst.Element).setState(gst.State.playing);
|
|
||||||
if (ret == gst.StateChangeReturn.failure) {
|
|
||||||
pipeline.unref();
|
|
||||||
std.debug.panic("Could not start pipeline", .{});
|
|
||||||
}
|
|
||||||
|
|
||||||
const bus: *gst.Bus = pipeline.getBus();
|
|
||||||
|
|
||||||
|
|
||||||
std.debug.print("Getting vstream info\n", .{});
|
std.debug.print("Getting vstream info\n", .{});
|
||||||
var stream_info: hlo.hailo_vstream_info_t = undefined;
|
var stream_info: hlo.hailo_vstream_info_t = undefined;
|
||||||
status = hlo.hailo_get_input_vstream_info(input_vstreams[0], &stream_info);
|
status = hlo.hailo_get_input_vstream_info(input_vstreams[0], &stream_info);
|
||||||
|
@ -185,14 +105,15 @@ pub fn main() !void {
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
std.debug.print("\nOutput info: {any}\n\n", .{ output_info });
|
std.debug.print("\nOutput info: {any}\n\n", .{ output_info });
|
||||||
|
|
||||||
|
std.debug.print("Writing vstream data\n", .{});
|
||||||
var input_frame_size: usize = 0;
|
status = hlo.hailo_vstream_write_raw_buffer(input_vstreams[0], input_data.ptr, input_frame_size);
|
||||||
|
|
||||||
status = hlo.hailo_get_input_vstream_frame_size(input_vstreams[0], &input_frame_size);
|
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
|
std.debug.print("Input written\n", .{});
|
||||||
|
|
||||||
|
status = hlo.hailo_flush_input_vstream(input_vstreams[0]);
|
||||||
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
|
std.debug.print("input flushed!\n", .{});
|
||||||
|
|
||||||
const frame_count = input_frame_size / @sizeOf(u8);
|
|
||||||
const input_data: [:0]u8 = try alloc.allocSentinel(u8, frame_count, 0);
|
|
||||||
|
|
||||||
|
|
||||||
var output_frame_size: usize = 0;
|
var output_frame_size: usize = 0;
|
||||||
|
@ -200,54 +121,19 @@ pub fn main() !void {
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
std.debug.print("output frame size is: {d}\n", .{ output_frame_size });
|
std.debug.print("output frame size is: {d}\n", .{ output_frame_size });
|
||||||
|
|
||||||
const output_frame_count = output_frame_size / @sizeOf(f32);
|
const output_frame_count = output_frame_size / @sizeOf(u8);
|
||||||
const output_data: [:0]f32 = try alloc.allocSentinel(f32, output_frame_count, 0);
|
const output_data: [:0]u8 = try alloc.allocSentinel(u8, output_frame_count, 0);
|
||||||
|
|
||||||
|
|
||||||
var run_count: u8 = 0;
|
|
||||||
|
|
||||||
while (!exit_loop) {
|
|
||||||
const sample = sink.pullSample() orelse unreachable;
|
|
||||||
const buffer: *gst.Buffer = sample.getBuffer() orelse unreachable;
|
|
||||||
|
|
||||||
_ = buffer.extract(0, @ptrCast(input_data), input_frame_size);
|
|
||||||
|
|
||||||
status = hlo.hailo_vstream_write_raw_buffer(input_vstreams[0], input_data.ptr, input_frame_size);
|
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
|
||||||
|
|
||||||
status = hlo.hailo_flush_input_vstream(input_vstreams[0]);
|
|
||||||
assert(status == hlo.HAILO_SUCCESS);
|
|
||||||
|
|
||||||
status = hlo.hailo_vstream_read_raw_buffer(output_vstreams[0], output_data.ptr, output_frame_size);
|
status = hlo.hailo_vstream_read_raw_buffer(output_vstreams[0], output_data.ptr, output_frame_size);
|
||||||
if (status == hlo.HAILO_SUCCESS) {
|
assert(status == hlo.HAILO_SUCCESS);
|
||||||
for (0..50) |x| {
|
std.debug.print("Output finished reading! Cleanup time\n", .{});
|
||||||
std.debug.print(" {d} ", .{output_data[x]});
|
|
||||||
}
|
|
||||||
std.debug.print("\n", .{});
|
|
||||||
|
|
||||||
run_count += 1;
|
std.debug.print("good luck\n\n{x}", .{ output_data });
|
||||||
if (run_count > 20) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std.debug.print("Read failed!\n", .{});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std.debug.print("Staring shutdown\n", .{ });
|
|
||||||
|
|
||||||
|
|
||||||
bus.unref();
|
|
||||||
_ = pipeline.as(gst.Element).setState(gst.State.null);
|
|
||||||
pipeline.unref();
|
|
||||||
// const bus: *gst.Bus = pipeline.getBus();
|
|
||||||
|
|
||||||
|
|
||||||
_ = hlo.hailo_release_output_vstreams(&output_vstreams, output_vstream_size);
|
_ = hlo.hailo_release_output_vstreams(&output_vstreams, output_vstream_size);
|
||||||
_ = hlo.hailo_release_input_vstreams(&input_vstreams, input_vstream_size);
|
_ = hlo.hailo_release_input_vstreams(&input_vstreams, input_vstream_size);
|
||||||
_ = hlo.hailo_release_hef(hef);
|
_ = hlo.hailo_release_hef(hef);
|
||||||
_ = hlo.hailo_release_vdevice(vdevice);
|
_ = hlo.hailo_release_vdevice(vdevice);
|
||||||
|
|
||||||
std.debug.print("run complete\n", .{});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue