moved more onto the zig-gobject bindings

This commit is contained in:
Nickiel12 2024-10-24 03:10:37 +00:00
parent ee5b34c46c
commit 4dfc19159e
3 changed files with 40 additions and 44 deletions

View file

@ -53,26 +53,21 @@ pub fn build(b: *std.Build) void {
exe.linkSystemLibrary("c"); exe.linkSystemLibrary("c");
exe.linkSystemLibrary("gstreamer-1.0");
exe.linkSystemLibrary("gstapp-1.0");
exe.linkSystemLibrary("glib-2.0");
exe.linkSystemLibrary("gobject-2.0");
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.addIncludePath(.{ .cwd_relative = b.fmt("{s}/include/gstreamer-1.0", .{gst_dev_path.?}) }); // not sure why both are needed, but
exe.addIncludePath(.{ .cwd_relative = b.fmt("{s}/include/gstreamer-1.0/gst", .{gst_dev_path.?}) }); // it won't compile without them
exe.addIncludePath(.{ .cwd_relative = b.fmt("{s}/include/gstreamer-1.0", .{gst_plugins_base_dev_path.?}) }); // needed for header resolution of below dep
exe.addIncludePath(.{ .cwd_relative = b.fmt("{s}/include/glib-2.0", .{glib_dev_path.?}) });
exe.addIncludePath(.{ .cwd_relative = b.fmt("{s}/lib/glib-2.0/include", .{glib_path.?}) });
// exe.addIncludePath(.{ .cwd_relative = "/usr/include/hailo" }); // exe.addIncludePath(.{ .cwd_relative = "/usr/include/hailo" });
// 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");
exe.addLibraryPath(.{ .cwd_relative = b.fmt("{s}/lib", .{ gst_plugins_base_path.? }) });
exe.linkSystemLibrary("gstreamer-1.0");
exe.linkSystemLibrary("gstapp-1.0");
exe.linkSystemLibrary("glib-2.0");
exe.linkSystemLibrary("gobject-2.0");
// This declares intent for the executable to be installed into the // This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default // standard location when the user invokes the "install" step (the default

View file

@ -36,9 +36,9 @@
GLIB_DEV_PATH = pkgs.glib.dev; GLIB_DEV_PATH = pkgs.glib.dev;
GLIB_PATH = pkgs.glib.out; GLIB_PATH = pkgs.glib.out;
HAILORT_LOGGER_PATH = "./logs"; HAILORT_LOGGER_PATH = "./logs";
HAILORT_CONSOLE_LOGGER_LEVEL = "info"; HAILORT_CONSOLE_LOGGER_LEVEL = "info";
HAILO_MONITOR = 1; HAILO_MONITOR = 1;
}; };
} }
); );

View file

@ -2,11 +2,15 @@ const std = @import("std");
const hlo = @cImport({ const hlo = @cImport({
@cInclude("hailort.h"); @cInclude("hailort.h");
}); });
const gst_app = @cImport({ // glib-object for g_object_* functions
@cInclude("gstappsrc.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 gst = @import("gst");
const gstapp = @import ("gstapp");
const glib = @import("glib"); const glib = @import("glib");
const gobject = @import("gobject"); const gobject = @import("gobject");
@ -32,56 +36,53 @@ pub fn main() !void {
// When you look into the GST_BIN macro that zig can't compile, // When you look into the GST_BIN macro that zig can't compile,
// it really is just this pointer cast with extra steps of verification // it really is just this pointer cast with extra steps of verification
const bin: *gst.GstBin = @ptrCast(pipeline); const bin: *gst.Bin = pipeline.Parent;
// Gstreamer gives a critical warning when using gst.gst_bin_add_many, but doesn't // Gstreamer gives a critical warning when using gst.gst_bin_add_many, but doesn't
// when calling each individually // when calling each individually
_ = gst.bin_add(bin, source); _ = gst.Bin.add(*bin, source);
_ = gst.bin_add(bin, sink); _ = gst.Bin.add(*bin, sink);
// the failure return code is -1 I believe // the failure return code is -1 I believe
if (gst.element_link(source, sink) < 0) { if (gst.Element.link(source, sink) < 0) {
gst.object_unref(pipeline); pipeline.unref();
std.debug.panic("Elements could not be linked\n", .{}); std.debug.panic("Elements could not be linked\n", .{});
} }
// g_int is just i32. You can // g_int is just i32. You can
gst.g_object_set(source, "pattern", @as(i16, 0)); source.set("pattern", @as(i16, 0));
const ret = gst.element_set_state(pipeline, gst.GST_STATE_PLAYING); const ret = pipeline.setState(gst.State.playing);
if (ret == gst.GST_STATE_CHANGE_FAILURE) { if (ret == gst.StateChangeReturn.failure) {
gst.object_unref(pipeline); pipeline.unref();
std.debug.panic("Could not start pipeline", .{}); std.debug.panic("Could not start pipeline", .{});
} }
const bus: *gst.GstBus = gst.element_get_bus(pipeline); const bus: *gst.Bus = pipeline.getBus();
const msg: *gst.GstMessage = gst.bus_timed_pop_filtered( // This call holds until there is a valid message const msg: *gst.Message = bus.popFiltered( gst.MessageType.flags_eos + gst.MessageType.flags_warning );
bus,
gst.GST_CLOCK_TIME_NONE,
gst.GST_MESSAGE_ERROR | gst.GST_MESSAGE_EOS,
);
if (gst.GST_MESSAGE_TYPE(msg) == gst.GST_MESSAGE_ERROR) { if (msg.f_type == 1) {
const err: [*c][*c]gst.GError = null; const err: glib.Error = null;
var debug_info: ?*gst.gchar = null; var debug_info: [*][*:0]u8 = null;
switch (gst.GST_MESSAGE_TYPE(msg)) { switch (msg.f_type) {
gst.GST_MESSAGE_ERROR => { 1 => {
gst.message_parse_error(msg, err, &debug_info); msg.parseError(err, &debug_info);
std.debug.print("Error received from element {s}: {s}", .{ gst.GST_OBJECT_NAME(msg.src), err.*.*.message }); std.debug.print("Error received from element {s}: {s}", .{ gst.GST_OBJECT_NAME(msg.src), err.*.*.message });
if (debug_info != null) { // I couldn't figure out how to do a orelse statement for this unwrap. if (debug_info != null) { // I couldn't figure out how to do a orelse statement for this unwrap.
std.debug.print("Debugging information: {s}", .{debug_info.?}); std.debug.print("Debugging information: {s}", .{debug_info.?});
} }
gst.g_clear_error(err); glib.clearError(err);
gst.g_free(debug_info); glib.free(debug_info);
}, },
else => {}, else => {},
} }
gst.message_unref(msg);
msg.unref();
} }
gst.object_unref(bus); bus.unref();
_ = gst.element_set_state(pipeline, gst.GST_STATE_NULL); pipeline.setState(gst.State.null);
gst.object_unref(pipeline); pipeline.unref();
} }