From aae1de82912a33b0445f264286eb6b6a5369d630 Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Fri, 25 Oct 2024 03:28:52 +0000 Subject: [PATCH] got it compiling and fixed errors Signed-off-by: Nickiel12 --- flake.nix | 1 + src/main.zig | 68 +++++++++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/flake.nix b/flake.nix index b0040b9..e6527bc 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,7 @@ ]; buildInputs = with pkgs; [ zig_exe + pkg-config glib glib.dev gst_all_1.gstreamer diff --git a/src/main.zig b/src/main.zig index 9f303af..de877ac 100644 --- a/src/main.zig +++ b/src/main.zig @@ -25,24 +25,20 @@ pub fn main() !void { // This allows me to utilize the same command line args and gstreamer gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr)); - const source: ?*gst.Element = gst.ElementFactory.make("videotestsrc", "source"); - const sink: ?*gst.Element = gst.ElementFactory.make("autovideosink", "sink"); + const source: *gst.Element = gst.ElementFactory.make("videotestsrc", "source") orelse unreachable; + const sink: *gst.Element = gst.ElementFactory.make("autovideosink", "sink") orelse unreachable; - const pipeline: ?*gst.Element = gst.Pipeline.new("test-pipeline"); - - if (source == null or sink == null or pipeline == null) { - std.debug.panic("Not all elements could be created!", .{}); - } + const pipeline: *gst.Pipeline = gst.Pipeline.new("test-pipeline"); // 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.Bin = pipeline.Parent; + const bin: *gst.Bin = &pipeline.f_bin; // 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) { @@ -51,38 +47,50 @@ pub fn main() !void { } // g_int is just i32. You can - source.set("pattern", @as(i16, 0)); + // source.set("pattern", @as(i16, 0)); + gobject.Object.set(source.as(gobject.Object), "pattern", @as(i16, 0)); - const ret = pipeline.setState(gst.State.playing); + 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(); - const msg: *gst.Message = bus.popFiltered( gst.MessageType.flags_eos + gst.MessageType.flags_warning ); + // const msg: *gst.Message = bus.popFiltered( gst.MessageType.flags_eos + gst.MessageType.flags_warning ); + const message_type: gst.MessageType = .{ .eos = true, .warning = true }; + const ret_msg: ?*gst.Message = bus.popFiltered(message_type); - if (msg.f_type == 1) { - const err: glib.Error = null; - var debug_info: [*][*:0]u8 = null; + std.debug.print("reg_msg returned!\n", .{}); - 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.?}); - } - glib.clearError(err); - glib.free(debug_info); - }, - else => {}, + if (ret_msg) |msg| { + if (msg.f_type.eos == true) { + std.debug.print("EOS recieved\n", .{}); + } else if (msg.f_type.warning == true) { + std.debug.print("Warning message received\n", .{}); + const err: ?**glib.Error = null; + const debug_info: ?*[*:0]u8 = null; + + msg.parseError(err, debug_info); + if (err) |e| { + std.debug.print("Error received from element {s}: {s}", .{ msg.f_src, e.*.*.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.?}); + } + glib.clearError(@ptrCast(err)); + glib.free(@ptrCast(debug_info)); + } else { + std.debug.print("Unknown type received {any}\n", .{ msg }); } - - msg.unref(); + // msg.unref(); + } else { + std.debug.print("ret message not handled type: {any}\n", .{ ret_msg }); } bus.unref(); - pipeline.setState(gst.State.null); + _ = pipeline.as(gst.Element).setState(gst.State.null); pipeline.unref(); + + std.debug.print("run complete\n", .{}); }