From 57f37fbd6a4816f3a70041e04877beeb0a37b45c Mon Sep 17 00:00:00 2001 From: s-ol Date: Tue, 5 Aug 2025 02:48:42 +0200 Subject: dynamic OSC method registration for sources --- src/ffmpeg.zig | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/ffmpeg.zig') diff --git a/src/ffmpeg.zig b/src/ffmpeg.zig index dda3f8c..700638f 100644 --- a/src/ffmpeg.zig +++ b/src/ffmpeg.zig @@ -1,6 +1,8 @@ const std = @import("std"); const c = @import("c.zig"); const gl = @import("gl.zig"); +const src = @import("source.zig"); +const ctrl = @import("control.zig"); const build_config = @import("build_config"); pub const Errors = error{ @@ -248,7 +250,7 @@ pub const AVDecoder = struct { }; pub const VideoSource = struct { - source: gl.Source, + source: src.Source, decoder: *Decoder, pub fn init( @@ -258,7 +260,7 @@ pub const VideoSource = struct { filename: [*:0]const u8, format_name: ?[*:0]const u8, format_options: []const [*c]c.lo_arg, - ) !*gl.Source { + ) !*src.Source { const self = try allocator.create(VideoSource); errdefer allocator.destroy(self); @@ -293,12 +295,13 @@ pub const VideoSource = struct { else try AVDecoder.init(allocator, codec_par), }; + errdefer self.decoder.deinit(allocator); self.source.texture = try self.decoder.createTexture(progress, format, video_stream, texture_type); return &self.source; } - fn deinit(source: *const gl.Source, allocator: std.mem.Allocator) void { + fn deinit(source: *const src.Source, allocator: std.mem.Allocator) void { const self: *const VideoSource = @fieldParentPtr("source", source); self.decoder.deinit(allocator); @@ -307,7 +310,8 @@ pub const VideoSource = struct { }; pub const StreamSource = struct { - source: gl.Source, + source: src.Source, + flags: src.StreamFlags, decoder: *Decoder, format: *c.AVFormatContext, @@ -322,7 +326,7 @@ pub const StreamSource = struct { filename: [*:0]const u8, format_name: ?[*:0]const u8, format_options: []const [*c]c.lo_arg, - ) !*gl.Source { + ) !*src.Source { const self = try allocator.create(StreamSource); errdefer allocator.destroy(self); @@ -351,12 +355,16 @@ pub const StreamSource = struct { ); const decoder = try AVDecoder.init(allocator, codec_par); + errdefer decoder.deinit(allocator); self.* = .{ .source = .{ .texture = texture, .deinit_fn = deinit, + .register_fn = register_methods, + .unregister_fn = unregister_methods, }, + .flags = .{}, .decoder = decoder, .format = format, @@ -372,6 +380,15 @@ pub const StreamSource = struct { return &self.source; } + fn register_methods(source: *src.Source, name: []const u8, control: *ctrl.ControlServer) void { + const self: *StreamSource = @fieldParentPtr("source", source); + self.flags.register(name, control); + } + fn unregister_methods(source: *src.Source, name: []const u8, control: *ctrl.ControlServer) void { + const self: *StreamSource = @fieldParentPtr("source", source); + self.flags.unregister(name, control); + } + fn update_loop(self: *StreamSource) !void { while (!self.thread.quit) { try self.update(); @@ -390,11 +407,11 @@ pub const StreamSource = struct { _ = try self.decoder.process_packet_fn( self.decoder, self.packet, - if (self.source.shouldStep()) &self.source.texture else null, + if (self.flags.shouldStep()) &self.source.texture else null, ); } - fn deinit(source: *gl.Source, allocator: std.mem.Allocator) void { + fn deinit(source: *src.Source, allocator: std.mem.Allocator) void { const self: *StreamSource = @fieldParentPtr("source", source); self.thread.deinit(allocator); -- cgit v1.2.3