diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-08-05 00:48:42 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-08-05 01:06:20 +0000 |
| commit | 57f37fbd6a4816f3a70041e04877beeb0a37b45c (patch) | |
| tree | bd054c31e2a3b8705197f85705484bda4fe56698 /src/ffmpeg.zig | |
| parent | add freeze and step controls to Source (diff) | |
| download | glsl-view-57f37fbd6a4816f3a70041e04877beeb0a37b45c.tar.gz glsl-view-57f37fbd6a4816f3a70041e04877beeb0a37b45c.zip | |
dynamic OSC method registration for sources
Diffstat (limited to 'src/ffmpeg.zig')
| -rw-r--r-- | src/ffmpeg.zig | 31 |
1 files changed, 24 insertions, 7 deletions
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); |
