diff --git a/src/main.zig b/src/main.zig index de877ac..194ab7b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -26,7 +26,8 @@ pub fn main() !void { gst.init(@ptrCast(&std.os.argv.len), @ptrCast(&std.os.argv.ptr)); const source: *gst.Element = gst.ElementFactory.make("videotestsrc", "source") orelse unreachable; - const sink: *gst.Element = gst.ElementFactory.make("autovideosink", "sink") orelse unreachable; + const sink_el: *gst.Element = gst.ElementFactory.make("appsink", "sink") orelse unreachable; + const sink: *gstapp.AppSink = gobject.ext.cast(gstapp.AppSink, sink_el) orelse unreachable; const pipeline: *gst.Pipeline = gst.Pipeline.new("test-pipeline"); @@ -38,28 +39,36 @@ pub fn main() !void { // 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, sink_el); // the failure return code is -1 I believe - if (gst.Element.link(source, sink) < 0) { + if (gst.Element.link(source, sink_el) < 0) { pipeline.unref(); std.debug.panic("Elements could not be linked\n", .{}); } // g_int is just i32. You can // source.set("pattern", @as(i16, 0)); - gobject.Object.set(source.as(gobject.Object), "pattern", @as(i16, 0)); + // gobject.Object.set(source.as(gobject.Object), "pattern", @as(i16, 0)); const ret = pipeline.as(gst.Element).setState(gst.State.playing); + std.debug.print("pipeline state change returned: {any}\n", .{ ret }); if (ret == gst.StateChangeReturn.failure) { pipeline.unref(); std.debug.panic("Could not start pipeline", .{}); } const bus: *gst.Bus = pipeline.getBus(); + + const sample = sink.pullSample() orelse unreachable; + const buffer: *gst.Buffer = sample.getBuffer() orelse unreachable; + std.debug.print("Got the buffer! {any}\n", .{ buffer }); + std.debug.print("My buffer was '{d}' big!\n", .{ buffer.getSize() }); + + // 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); + const ret_msg: ?*gst.Message = bus.timedPopFiltered(std.math.maxInt(u64), message_type); std.debug.print("reg_msg returned!\n", .{});