moved more onto the zig-gobject bindings
This commit is contained in:
parent
ee5b34c46c
commit
4dfc19159e
3 changed files with 40 additions and 44 deletions
17
build.zig
17
build.zig
|
@ -53,26 +53,21 @@ pub fn build(b: *std.Build) void {
|
|||
|
||||
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("gobject", gobject.module("gobject2"));
|
||||
exe.root_module.addImport("gst", gobject.module("gst1"));
|
||||
|
||||
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.root_module.addImport("gstapp", gobject.module("gstapp1"));
|
||||
|
||||
// exe.addIncludePath(.{ .cwd_relative = "/usr/include/hailo" });
|
||||
// exe.addLibraryPath(.{ .cwd_relative = "/home/nixolas/Documents/hailort/build/hailort/libhailort/src"});
|
||||
// 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
|
||||
// standard location when the user invokes the "install" step (the default
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
GLIB_DEV_PATH = pkgs.glib.dev;
|
||||
GLIB_PATH = pkgs.glib.out;
|
||||
|
||||
HAILORT_LOGGER_PATH = "./logs";
|
||||
HAILORT_CONSOLE_LOGGER_LEVEL = "info";
|
||||
HAILO_MONITOR = 1;
|
||||
HAILORT_LOGGER_PATH = "./logs";
|
||||
HAILORT_CONSOLE_LOGGER_LEVEL = "info";
|
||||
HAILO_MONITOR = 1;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
61
src/main.zig
61
src/main.zig
|
@ -2,11 +2,15 @@ const std = @import("std");
|
|||
const hlo = @cImport({
|
||||
@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 gstapp = @import ("gstapp");
|
||||
const glib = @import("glib");
|
||||
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,
|
||||
// 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
|
||||
// when calling each individually
|
||||
_ = gst.bin_add(bin, source);
|
||||
_ = gst.bin_add(bin, sink);
|
||||
_ = gst.Bin.add(*bin, source);
|
||||
_ = gst.Bin.add(*bin, sink);
|
||||
|
||||
// the failure return code is -1 I believe
|
||||
if (gst.element_link(source, sink) < 0) {
|
||||
gst.object_unref(pipeline);
|
||||
if (gst.Element.link(source, sink) < 0) {
|
||||
pipeline.unref();
|
||||
std.debug.panic("Elements could not be linked\n", .{});
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (ret == gst.GST_STATE_CHANGE_FAILURE) {
|
||||
gst.object_unref(pipeline);
|
||||
const ret = pipeline.setState(gst.State.playing);
|
||||
if (ret == gst.StateChangeReturn.failure) {
|
||||
pipeline.unref();
|
||||
std.debug.panic("Could not start pipeline", .{});
|
||||
}
|
||||
|
||||
const bus: *gst.GstBus = gst.element_get_bus(pipeline);
|
||||
const msg: *gst.GstMessage = gst.bus_timed_pop_filtered( // This call holds until there is a valid message
|
||||
bus,
|
||||
gst.GST_CLOCK_TIME_NONE,
|
||||
gst.GST_MESSAGE_ERROR | gst.GST_MESSAGE_EOS,
|
||||
);
|
||||
const bus: *gst.Bus = pipeline.getBus();
|
||||
const msg: *gst.Message = bus.popFiltered( gst.MessageType.flags_eos + gst.MessageType.flags_warning );
|
||||
|
||||
if (gst.GST_MESSAGE_TYPE(msg) == gst.GST_MESSAGE_ERROR) {
|
||||
const err: [*c][*c]gst.GError = null;
|
||||
var debug_info: ?*gst.gchar = null;
|
||||
if (msg.f_type == 1) {
|
||||
const err: glib.Error = null;
|
||||
var debug_info: [*][*:0]u8 = null;
|
||||
|
||||
switch (gst.GST_MESSAGE_TYPE(msg)) {
|
||||
gst.GST_MESSAGE_ERROR => {
|
||||
gst.message_parse_error(msg, err, &debug_info);
|
||||
switch (msg.f_type) {
|
||||
1 => {
|
||||
msg.parseError(err, &debug_info);
|
||||
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.
|
||||
std.debug.print("Debugging information: {s}", .{debug_info.?});
|
||||
}
|
||||
gst.g_clear_error(err);
|
||||
gst.g_free(debug_info);
|
||||
glib.clearError(err);
|
||||
glib.free(debug_info);
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
gst.message_unref(msg);
|
||||
|
||||
msg.unref();
|
||||
}
|
||||
|
||||
gst.object_unref(bus);
|
||||
_ = gst.element_set_state(pipeline, gst.GST_STATE_NULL);
|
||||
gst.object_unref(pipeline);
|
||||
bus.unref();
|
||||
pipeline.setState(gst.State.null);
|
||||
pipeline.unref();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue