summaryrefslogtreecommitdiff
path: root/internal/media/ffmpeg/wasm.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-10-28 10:55:48 +0000
committerLibravatar GitHub <noreply@github.com>2024-10-28 10:55:48 +0000
commite86592bc320ba0c127bb47bb6b0028ffe69e77e3 (patch)
tree87309bc74b9c59fe7c56ed25b4e96b76280369b8 /internal/media/ffmpeg/wasm.go
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.21.0 to 2.21.1 (#3489) (diff)
downloadgotosocial-e86592bc320ba0c127bb47bb6b0028ffe69e77e3.tar.xz
[chore] pull in go-ffmpreg v0.4.1 (#3485)
* pull in go-ffmpreg v0.4.1 * bring back GTS_WAZERO_COMPILATION_CACHE
Diffstat (limited to 'internal/media/ffmpeg/wasm.go')
-rw-r--r--internal/media/ffmpeg/wasm.go35
1 files changed, 9 insertions, 26 deletions
diff --git a/internal/media/ffmpeg/wasm.go b/internal/media/ffmpeg/wasm.go
index 4a230eec7..b23809d93 100644
--- a/internal/media/ffmpeg/wasm.go
+++ b/internal/media/ffmpeg/wasm.go
@@ -27,13 +27,8 @@ import (
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"
)
-// Use all core features required by ffmpeg / ffprobe
-// (these should be the same but we OR just in case).
-const corefeatures = wasm.CoreFeatures
-
var (
// shared WASM runtime instance.
runtime wazero.Runtime
@@ -91,38 +86,26 @@ func compileFfprobe(ctx context.Context) error {
// initRuntime initializes the global wazero.Runtime,
// if already initialized this function is a no-op.
-func initRuntime(ctx context.Context) error {
+func initRuntime(ctx context.Context) (err error) {
if runtime != nil {
return nil
}
- var cache wazero.CompilationCache
+ // Create new runtime config.
+ cfg := wazero.NewRuntimeConfig()
if dir := os.Getenv("GTS_WAZERO_COMPILATION_CACHE"); dir != "" {
- var err error
-
// Use on-filesystem compilation cache given by env.
- cache, err = wazero.NewCompilationCacheWithDir(dir)
+ cache, err := wazero.NewCompilationCacheWithDir(dir)
if err != nil {
return err
}
- }
-
- // Prepare config with cache.
- cfg := wazero.NewRuntimeConfig()
- cfg = cfg.WithCoreFeatures(corefeatures)
- cfg = cfg.WithCompilationCache(cache)
-
- // Instantiate runtime with prepared config.
- rt := wazero.NewRuntimeWithConfig(ctx, cfg)
- // Instantiate wasi snapshot preview features into runtime.
- _, err := wasi_snapshot_preview1.Instantiate(ctx, rt)
- if err != nil {
- return err
+ // Update runtime config with cache.
+ cfg = cfg.WithCompilationCache(cache)
}
- // Set runtime.
- runtime = rt
- return nil
+ // Initialize new runtime from config.
+ runtime, err = wasm.NewRuntime(ctx, cfg)
+ return
}