moved half the gstreamer code to the main file

This commit is contained in:
Nickiel12 2024-10-19 05:37:59 +00:00
parent 2a36a68ebe
commit 5d91ea4476

View file

@ -3,6 +3,11 @@ const std = @import("std");
const hlo = @cImport({
@cInclude("hailort.h");
});
const gst = @cImport({ // glib-object for g_object_* functions
@cInclude("glib-object.h");
@cInclude("gst.h");
@cInclude("glib.h"); // and glib for other g_* functions
});
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
@ -12,6 +17,8 @@ const max_edge_layers = 32;
pub fn main() !void {
// This allows me to utilize the same command line args and gstreamer
gst.gst_init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr));
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
@ -82,8 +89,51 @@ pub fn main() !void {
std.debug.print("Output vstreams initialized\n", .{});
std.debug.print("Output_vstream_size is: '{d}'\n", .{ output_vstream_size });
std.debug.print("Input_vstream_size is: '{d}'\n", .{ input_vstream_size });
std.debug.print("HailoRT init completed\nGstreamer Init starting", .{});
const source: ?*gst.GstElement = gst.gst_element_factory_make("videotestsrc", "source");
const sink: ?*gst.GstElement = gst.gst_element_factory_make("autovideosink", "sink");
const pipeline: ?*gst.GstElement = gst.gst_pipeline_new("test-pipeline");
if (source == null or sink == null or pipeline == null) {
std.debug.panic("Not all elements could be created!", .{});
}
// 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);
// Gstreamer gives a critical warning when using gst.gst_bin_add_many, but doesn't
// when calling each individually
_ = gst.gst_bin_add(bin, source);
_ = gst.gst_bin_add(bin, sink);
// the failure return code is -1 I believe
if (gst.gst_element_link(source, sink) < 0) {
gst.gst_object_unref(pipeline);
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));
const ret = gst.gst_element_set_state(pipeline, gst.GST_STATE_PLAYING);
if (ret == gst.GST_STATE_CHANGE_FAILURE) {
gst.gst_object_unref(pipeline);
std.debug.panic("Could not start pipeline", .{});
}
const bus: *gst.GstBus = gst.gst_element_get_bus(pipeline);
const msg: *gst.GstMessage = gst.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,
);