From f32f5b6fa1dc1f0fffce96a38984e1bdf747073f Mon Sep 17 00:00:00 2001 From: s-ol Date: Sat, 8 Nov 2025 22:15:40 +0100 Subject: lib/glsl-view: add buffered-stream-source --- alv-lib/glsl-view.moon | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'alv-lib') diff --git a/alv-lib/glsl-view.moon b/alv-lib/glsl-view.moon index 51f854c..0cb0a93 100644 --- a/alv-lib/glsl-view.moon +++ b/alv-lib/glsl-view.moon @@ -57,6 +57,22 @@ When absent, `glsl-type` is inferred based on the type of `value`: type or= get_typestr @inputs[2]\type! @out\set :type, :val +offset= Constant.meta + meta: + name: 'offset' + summary: "get the playback offset of a buffered-stream-source." + examples: { '(offset [glsl-type] source)' } + description: "GLSL type: float/double/int/uint" + + value: class extends PureOp + pattern: -sig.str + sig! + type: => Uniform + tick: => + { type, source } = @unwrap_all! + type or= "float" + name = source.val + @out\set :type, val: "/source/#{name}/offset" + video_source = Constant.meta meta: name: 'video-source' @@ -146,6 +162,49 @@ stream_source = Constant.meta add_item msg, @inputs.args\type!, args if args \send Message.pack msg.content +buffered_stream_source = Constant.meta + meta: + name: 'buffered-stream-source' + summary: "load a stream as a 3d texture source." + examples: { '(stream-source [socket] type depth uri [format] [args])' } + description: "Creates a circular buffer 3d texture from a capture source. + +- `type` must be `3D` or `2D_ARRAY`. +- `depth` is the number of frames to keep in the buffer. +- `uri` is the ffmpeg URI to load. If it starts with `./` it will be resolved relative to the current alv module. +- `format` optionally specifies the ffmpeg/avformat input format to use. +- `args` is a struct of optional arguments for the ffmpeg/avformat input format. + + (stream-source 'webcam' '3D' 64 '/dev/video0')" + + value: class extends Op + pattern = -sig['osc/out'] + const.str + const.num + const.str + -const.str + -const! + setup: (inputs, scope) => + { socket, type, depth, filename, format, args } = pattern\match inputs + + @prefix = COPILOT.active_module.file\match'(.*/)[^/]*$' + + super + socket: Input.hot socket or scope\get '*oscout*' + type: Input.cold type + depth: Input.cold depth + filename: Input.cold filename + format: format and Input.cold format + args: args and Input.cold args + + samplertype = assert GLSL_SAMPLER_TYPES[@inputs.type!] + @setup_out '=', Uniform, type: samplertype, val: "alv-#{fmttag @tag}" + + tick: => + { :socket, :name, :type, :depth, :filename, :format, :args } = @unwrap_all! + + with @inputs.socket! + filename = tryprefix @prefix, filename + msg = Message.new{ address: "/source/alv-#{fmttag @tag}/buffered-stream", types: "sis", "TEXTURE_#{type}", depth, filename } + msg\add 's', format if format + add_item msg, @inputs.args\type!, args if args + \send Message.pack msg.content + tsv_source = Constant.meta meta: name: 'tsv-source' @@ -333,8 +392,11 @@ Constant.meta 'video-source': video_source 'stream-source': stream_source + 'buffered-stream-source': buffered_stream_source 'tsv-source': tsv_source + :offset + :freeze, 'step!': step_ shader: shader_ -- cgit v1.2.3