got it compiling and fixed errors
Signed-off-by: Nickiel12 <nickiel@nickiel.net>
This commit is contained in:
parent
4dfc19159e
commit
aae1de8291
2 changed files with 39 additions and 30 deletions
|
@ -21,6 +21,7 @@
|
||||||
];
|
];
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
zig_exe
|
zig_exe
|
||||||
|
pkg-config
|
||||||
glib
|
glib
|
||||||
glib.dev
|
glib.dev
|
||||||
gst_all_1.gstreamer
|
gst_all_1.gstreamer
|
||||||
|
|
68
src/main.zig
68
src/main.zig
|
@ -25,24 +25,20 @@ pub fn main() !void {
|
||||||
// This allows me to utilize the same command line args and gstreamer
|
// This allows me to utilize the same command line args and gstreamer
|
||||||
gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr));
|
gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr));
|
||||||
|
|
||||||
const source: ?*gst.Element = gst.ElementFactory.make("videotestsrc", "source");
|
const source: *gst.Element = gst.ElementFactory.make("videotestsrc", "source") orelse unreachable;
|
||||||
const sink: ?*gst.Element = gst.ElementFactory.make("autovideosink", "sink");
|
const sink: *gst.Element = gst.ElementFactory.make("autovideosink", "sink") orelse unreachable;
|
||||||
|
|
||||||
const pipeline: ?*gst.Element = gst.Pipeline.new("test-pipeline");
|
const pipeline: *gst.Pipeline = 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,
|
// 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.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
|
// 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) {
|
||||||
|
@ -51,38 +47,50 @@ pub fn main() !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// g_int is just i32. You can
|
// 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) {
|
if (ret == gst.StateChangeReturn.failure) {
|
||||||
pipeline.unref();
|
pipeline.unref();
|
||||||
std.debug.panic("Could not start pipeline", .{});
|
std.debug.panic("Could not start pipeline", .{});
|
||||||
}
|
}
|
||||||
|
|
||||||
const bus: *gst.Bus = pipeline.getBus();
|
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) {
|
std.debug.print("reg_msg returned!\n", .{});
|
||||||
const err: glib.Error = null;
|
|
||||||
var debug_info: [*][*:0]u8 = null;
|
|
||||||
|
|
||||||
switch (msg.f_type) {
|
if (ret_msg) |msg| {
|
||||||
1 => {
|
if (msg.f_type.eos == true) {
|
||||||
msg.parseError(err, &debug_info);
|
std.debug.print("EOS recieved\n", .{});
|
||||||
std.debug.print("Error received from element {s}: {s}", .{ gst.GST_OBJECT_NAME(msg.src), err.*.*.message });
|
} else if (msg.f_type.warning == true) {
|
||||||
if (debug_info != null) { // I couldn't figure out how to do a orelse statement for this unwrap.
|
std.debug.print("Warning message received\n", .{});
|
||||||
std.debug.print("Debugging information: {s}", .{debug_info.?});
|
const err: ?**glib.Error = null;
|
||||||
}
|
const debug_info: ?*[*:0]u8 = null;
|
||||||
glib.clearError(err);
|
|
||||||
glib.free(debug_info);
|
msg.parseError(err, debug_info);
|
||||||
},
|
if (err) |e| {
|
||||||
else => {},
|
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();
|
bus.unref();
|
||||||
pipeline.setState(gst.State.null);
|
_ = pipeline.as(gst.Element).setState(gst.State.null);
|
||||||
pipeline.unref();
|
pipeline.unref();
|
||||||
|
|
||||||
|
std.debug.print("run complete\n", .{});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue