summaryrefslogtreecommitdiff
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
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
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--internal/media/ffmpeg/wasm.go35
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasmbin13760061 -> 15504215 bytes
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasmbin13672019 -> 15415068 bytes
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go74
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go (renamed from vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go)13
-rw-r--r--vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go67
-rw-r--r--vendor/modules.txt2
9 files changed, 157 insertions, 40 deletions
diff --git a/go.mod b/go.mod
index 29da67ef6..18107be44 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,7 @@ require (
codeberg.org/gruf/go-debug v1.3.0
codeberg.org/gruf/go-errors/v2 v2.3.2
codeberg.org/gruf/go-fastcopy v1.1.3
- codeberg.org/gruf/go-ffmpreg v0.3.1
+ codeberg.org/gruf/go-ffmpreg v0.4.2
codeberg.org/gruf/go-iotools v0.0.0-20240710125620-934ae9c654cf
codeberg.org/gruf/go-kv v1.6.5
codeberg.org/gruf/go-list v0.0.0-20240425093752-494db03d641f
diff --git a/go.sum b/go.sum
index 3fdccd6fd..3c1d822c1 100644
--- a/go.sum
+++ b/go.sum
@@ -46,8 +46,8 @@ codeberg.org/gruf/go-fastcopy v1.1.3 h1:Jo9VTQjI6KYimlw25PPc7YLA3Xm+XMQhaHwKnM7x
codeberg.org/gruf/go-fastcopy v1.1.3/go.mod h1:GDDYR0Cnb3U/AIfGM3983V/L+GN+vuwVMvrmVABo21s=
codeberg.org/gruf/go-fastpath/v2 v2.0.0 h1:iAS9GZahFhyWEH0KLhFEJR+txx1ZhMXxYzu2q5Qo9c0=
codeberg.org/gruf/go-fastpath/v2 v2.0.0/go.mod h1:3pPqu5nZjpbRrOqvLyAK7puS1OfEtQvjd6342Cwz56Q=
-codeberg.org/gruf/go-ffmpreg v0.3.1 h1:5qE6sHQbLCbQ4RO7ZL4OKZBN4ViAYfDm9ExT8N0ZE7s=
-codeberg.org/gruf/go-ffmpreg v0.3.1/go.mod h1:Ar5nbt3tB2Wr0uoaqV3wDBNwAx+H+AB/mV7Kw7NlZTI=
+codeberg.org/gruf/go-ffmpreg v0.4.2 h1:HKkPapm/PWkxsnUdjyQOGpwl5Qoa2EBrUQ09s4R4/FA=
+codeberg.org/gruf/go-ffmpreg v0.4.2/go.mod h1:Ar5nbt3tB2Wr0uoaqV3wDBNwAx+H+AB/mV7Kw7NlZTI=
codeberg.org/gruf/go-iotools v0.0.0-20240710125620-934ae9c654cf h1:84s/ii8N6lYlskZjHH+DG6jyia8w2mXMZlRwFn8Gs3A=
codeberg.org/gruf/go-iotools v0.0.0-20240710125620-934ae9c654cf/go.mod h1:zZAICsp5rY7+hxnws2V0ePrWxE0Z2Z/KXcN3p/RQCfk=
codeberg.org/gruf/go-kv v1.6.5 h1:ttPf0NA8F79pDqBttSudPTVCZmGncumeNIxmeM9ztz0=
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
}
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm
index e2083fffd..9d1faa3ed 100644
--- a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm
+++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffmpeg/ffmpeg.wasm
Binary files differ
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm
index b460fa0f9..0094c53f4 100644
--- a/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm
+++ b/vendor/codeberg.org/gruf/go-ffmpreg/embed/ffprobe/ffprobe.wasm
Binary files differ
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go
new file mode 100644
index 000000000..a809ff120
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/funcs.go
@@ -0,0 +1,74 @@
+package wasm
+
+import (
+ "context"
+
+ "github.com/tetratelabs/wazero/api"
+ "github.com/tetratelabs/wazero/experimental"
+)
+
+type snapshotskey struct{}
+
+// withSetjmpLongjmp updates the context to contain wazero/experimental.Snapshotter{} support,
+// and embeds the necessary snapshots map required for later calls to Setjmp() / Longjmp().
+func withSetjmpLongjmp(ctx context.Context) context.Context {
+ snapshots := make(map[uint32]experimental.Snapshot, 10)
+ ctx = experimental.WithSnapshotter(ctx)
+ ctx = context.WithValue(ctx, snapshotskey{}, snapshots)
+ return ctx
+}
+
+func getSnapshots(ctx context.Context) map[uint32]experimental.Snapshot {
+ v, _ := ctx.Value(snapshotskey{}).(map[uint32]experimental.Snapshot)
+ return v
+}
+
+// setjmp implements the C function: setjmp(env jmp_buf)
+func setjmp(ctx context.Context, mod api.Module, stack []uint64) {
+
+ // Input arguments.
+ envptr := api.DecodeU32(stack[0])
+
+ // Take snapshot of current execution environment.
+ snapshotter := experimental.GetSnapshotter(ctx)
+ snapshot := snapshotter.Snapshot()
+
+ // Get stored snapshots map.
+ snapshots := getSnapshots(ctx)
+ if snapshots == nil {
+ panic("setjmp / longjmp not supported")
+ }
+
+ // Set latest snapshot in map.
+ snapshots[envptr] = snapshot
+
+ // Set return.
+ stack[0] = 0
+}
+
+// longjmp implements the C function: int longjmp(env jmp_buf, value int)
+func longjmp(ctx context.Context, mod api.Module, stack []uint64) {
+
+ // Input arguments.
+ envptr := api.DecodeU32(stack[0])
+ // val := stack[1]
+
+ // Get stored snapshots map.
+ snapshots := getSnapshots(ctx)
+ if snapshots == nil {
+ panic("setjmp / longjmp not supported")
+ }
+
+ // Get snapshot stored in map.
+ snapshot := snapshots[envptr]
+ if snapshot == nil {
+ panic("must first call setjmp")
+ }
+
+ // Set return.
+ stack[0] = 0
+
+ // Restore execution and
+ // return passed value arg.
+ snapshot.Restore(stack[1:])
+}
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go
index d2eccd9e9..62ce2bc25 100644
--- a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/instance.go
+++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/run.go
@@ -6,19 +6,9 @@ import (
"unsafe"
"github.com/tetratelabs/wazero"
- "github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/sys"
)
-// CoreFeatures are the WebAssembly Core specification
-// features our embedded binaries are compiled with.
-const CoreFeatures = api.CoreFeatureSIMD |
- api.CoreFeatureBulkMemoryOperations |
- api.CoreFeatureNonTrappingFloatToIntConversion |
- api.CoreFeatureMutableGlobal |
- api.CoreFeatureReferenceTypes |
- api.CoreFeatureSignExtensionOps
-
// Args encompasses a common set of
// configuration options often passed to
// wazero.Runtime on module instantiation.
@@ -64,6 +54,9 @@ func Run(
modcfg = args.Config(modcfg)
}
+ // Enable setjmp longjmp.
+ ctx = withSetjmpLongjmp(ctx)
+
// Instantiate the module from precompiled wasm module data.
mod, err := runtime.InstantiateModule(ctx, module, modcfg)
diff --git a/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go
new file mode 100644
index 000000000..328a26193
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-ffmpreg/wasm/runtime.go
@@ -0,0 +1,67 @@
+package wasm
+
+import (
+ "context"
+
+ "github.com/tetratelabs/wazero"
+ "github.com/tetratelabs/wazero/api"
+ "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
+)
+
+// CoreFeatures are the WebAssembly Core specification
+// features our embedded binaries are compiled with.
+const CoreFeatures = api.CoreFeatureSIMD |
+ api.CoreFeatureBulkMemoryOperations |
+ api.CoreFeatureNonTrappingFloatToIntConversion |
+ api.CoreFeatureMutableGlobal |
+ api.CoreFeatureReferenceTypes |
+ api.CoreFeatureSignExtensionOps
+
+// NewRuntime returns a new WebAssembly wazero.Runtime compatible with go-ffmpreg.
+func NewRuntime(ctx context.Context, cfg wazero.RuntimeConfig) (wazero.Runtime, error) {
+ var err error
+
+ if cfg == nil {
+ // Ensure runtime config is set.
+ cfg = wazero.NewRuntimeConfig()
+ }
+
+ // Set core features ffmpeg compiled with.
+ cfg = cfg.WithCoreFeatures(CoreFeatures)
+
+ // Instantiate runtime with prepared config.
+ rt := wazero.NewRuntimeWithConfig(ctx, cfg)
+
+ // Prepare default "env" host module.
+ env := rt.NewHostModuleBuilder("env")
+
+ // Register setjmp host function.
+ env = env.NewFunctionBuilder().
+ WithGoModuleFunction(
+ api.GoModuleFunc(setjmp),
+ []api.ValueType{api.ValueTypeI32},
+ []api.ValueType{api.ValueTypeI32},
+ ).Export("setjmp")
+
+ // Register longjmp host function.
+ env = env.NewFunctionBuilder().
+ WithGoModuleFunction(
+ api.GoModuleFunc(longjmp),
+ []api.ValueType{api.ValueTypeI32, api.ValueTypeI32},
+ []api.ValueType{},
+ ).Export("longjmp")
+
+ // Instantiate "env" module.
+ _, err = env.Instantiate(ctx)
+ if err != nil {
+ return nil, err
+ }
+
+ // Instantiate the wasi snapshot preview 1 in runtime.
+ _, err = wasi_snapshot_preview1.Instantiate(ctx, rt)
+ if err != nil {
+ return nil, err
+ }
+
+ return rt, nil
+}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 97e6f84c6..89e3a715e 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -24,7 +24,7 @@ codeberg.org/gruf/go-fastcopy
# codeberg.org/gruf/go-fastpath/v2 v2.0.0
## explicit; go 1.14
codeberg.org/gruf/go-fastpath/v2
-# codeberg.org/gruf/go-ffmpreg v0.3.1
+# codeberg.org/gruf/go-ffmpreg v0.4.2
## explicit; go 1.22.0
codeberg.org/gruf/go-ffmpreg/embed/ffmpeg
codeberg.org/gruf/go-ffmpreg/embed/ffprobe