diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/media/ffmpeg/runner.go | 5 | ||||
| -rw-r--r-- | internal/media/ffmpeg/wasm.go | 66 | 
2 files changed, 6 insertions, 65 deletions
diff --git a/internal/media/ffmpeg/runner.go b/internal/media/ffmpeg/runner.go index 403131ff7..8c59ac752 100644 --- a/internal/media/ffmpeg/runner.go +++ b/internal/media/ffmpeg/runner.go @@ -20,6 +20,7 @@ package ffmpeg  import (  	"context" +	"codeberg.org/gruf/go-ffmpreg/wasm"  	"github.com/tetratelabs/wazero"  ) @@ -65,6 +66,6 @@ func (r *runner) Run(ctx context.Context, cmod wazero.CompiledModule, args Args)  	// Release slot back to pool on end.  	defer func() { r.pool <- struct{}{} }() -	// Pass to main module runner. -	return run(ctx, cmod, args) +	// Pass to main module runner function. +	return wasm.Run(ctx, runtime, cmod, args)  } diff --git a/internal/media/ffmpeg/wasm.go b/internal/media/ffmpeg/wasm.go index 705b16fc3..d76e9017b 100644 --- a/internal/media/ffmpeg/wasm.go +++ b/internal/media/ffmpeg/wasm.go @@ -19,20 +19,18 @@ package ffmpeg  import (  	"context" -	"io"  	"os"  	ffmpeglib "codeberg.org/gruf/go-ffmpreg/embed/ffmpeg"  	ffprobelib "codeberg.org/gruf/go-ffmpreg/embed/ffprobe" +	"codeberg.org/gruf/go-ffmpreg/wasm"  	"github.com/tetratelabs/wazero"  	"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" -	"github.com/tetratelabs/wazero/sys"  )  // Use all core features required by ffmpeg / ffprobe  // (these should be the same but we OR just in case). -const corefeatures = ffprobelib.CoreFeatures | -	ffmpeglib.CoreFeatures +const corefeatures = wasm.CoreFeatures  var (  	// shared WASM runtime instance. @@ -47,65 +45,7 @@ var (  // configuration options to run an instance  // of a compiled WebAssembly module that is  // run in a typical CLI manner. -type Args struct { - -	// Optional further module configuration function. -	// (e.g. to mount filesystem dir, set env vars, etc). -	Config func(wazero.ModuleConfig) wazero.ModuleConfig - -	// Standard FDs. -	Stdin  io.Reader -	Stdout io.Writer -	Stderr io.Writer - -	// CLI args. -	Args []string -} - -// run will run the given compiled -// WebAssembly module using given args, -// using the global wazero runtime. -func run( -	ctx context.Context, -	cmod wazero.CompiledModule, -	args Args, -) ( -	uint32, // exit code -	error, -) { -	// Prefix module name as argv0 to args. -	cargs := make([]string, len(args.Args)+1) -	copy(cargs[1:], args.Args) -	cargs[0] = cmod.Name() - -	// Create base module config. -	modcfg := wazero.NewModuleConfig() -	modcfg = modcfg.WithArgs(cargs...) -	modcfg = modcfg.WithStdin(args.Stdin) -	modcfg = modcfg.WithStdout(args.Stdout) -	modcfg = modcfg.WithStderr(args.Stderr) - -	if args.Config != nil { -		// Pass through config fn. -		modcfg = args.Config(modcfg) -	} - -	// Instantiate the module from precompiled wasm module data. -	mod, err := runtime.InstantiateModule(ctx, cmod, modcfg) - -	if mod != nil { -		// Ensure closed. -		_ = mod.Close(ctx) -	} - -	// Try extract exit code. -	switch err := err.(type) { -	case *sys.ExitError: -		return err.ExitCode(), nil -	default: -		return 0, err -	} -} +type Args = wasm.Args  // compileFfmpeg ensures the ffmpeg WebAssembly has been  // pre-compiled into memory. If already compiled is a no-op.  | 
