mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 06:02:26 -05:00
[chore] ffmpeg webassembly fiddling (#4454)
This disables ffmpeg / ffprobe support on platforms where the wazero compiler is not available. The slowness introduced is hard to pindown for admins (and us!), so it's easier to just return an error message linking to docs on attempted media processing. It still allows the instance to run, just erroring if anything other than a jpeg is attempted to be processed. This should hopefully make it easier for users to notice these issues. Also further locks down our wazero 'allowFiles' fs and other media code to address: https://codeberg.org/superseriousbusiness/gotosocial/issues/4408 relates to: https://codeberg.org/superseriousbusiness/gotosocial/issues/4427 also relates to issues raised in #gotosocial-help on matrix closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4408 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4454 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
121677754c
commit
3db2d42247
7 changed files with 111 additions and 97 deletions
|
|
@ -21,12 +21,12 @@ package ffmpeg
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"code.superseriousbusiness.org/gotosocial/internal/log"
|
||||
"codeberg.org/gruf/go-ffmpreg/embed"
|
||||
"codeberg.org/gruf/go-ffmpreg/wasm"
|
||||
"github.com/tetratelabs/wazero"
|
||||
|
|
@ -49,24 +49,19 @@ func initWASM(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var cfg wazero.RuntimeConfig
|
||||
|
||||
// Allocate new runtime config, letting
|
||||
// wazero determine compiler / interpreter.
|
||||
cfg = wazero.NewRuntimeConfig()
|
||||
|
||||
// Though still perform a check of CPU features at
|
||||
// runtime to warn about slow interpreter performance.
|
||||
if reason, supported := compilerSupported(); !supported {
|
||||
log.Warn(ctx, "!!! WAZERO COMPILER MAY NOT BE AVAILABLE !!!"+
|
||||
" Reason: "+reason+"."+
|
||||
" Wazero will likely fall back to interpreter mode,"+
|
||||
" resulting in poor performance for media processing (and SQLite, if in use)."+
|
||||
" For more info and possible workarounds, please check:"+
|
||||
" https://docs.gotosocial.org/en/latest/getting_started/releases/#supported-platforms",
|
||||
)
|
||||
// Check at runtime whether Wazero compiler support is available,
|
||||
// interpreter mode is too slow for a usable gotosocial experience.
|
||||
if reason, supported := isCompilerSupported(); !supported {
|
||||
return errors.New("!!! WAZERO COMPILER SUPPORT NOT AVAILABLE !!!" +
|
||||
" Reason: " + reason + "." +
|
||||
" Wazero in interpreter mode is too slow to use ffmpeg" +
|
||||
" (this will also affect SQLite if in use)." +
|
||||
" For more info and possible workarounds, please check: https://docs.gotosocial.org/en/latest/getting_started/releases/#supported-platforms")
|
||||
}
|
||||
|
||||
// Allocate new runtime compiler config.
|
||||
cfg := wazero.NewRuntimeConfigCompiler()
|
||||
|
||||
if dir := os.Getenv("GTS_WAZERO_COMPILATION_CACHE"); dir != "" {
|
||||
// Use on-filesystem compilation cache given by env.
|
||||
cache, err := wazero.NewCompilationCacheWithDir(dir)
|
||||
|
|
@ -128,7 +123,7 @@ func initWASM(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func compilerSupported() (string, bool) {
|
||||
func isCompilerSupported() (string, bool) {
|
||||
switch runtime.GOOS {
|
||||
case "linux", "android",
|
||||
"windows", "darwin",
|
||||
|
|
@ -141,10 +136,11 @@ func compilerSupported() (string, bool) {
|
|||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
// NOTE: wazero in the future may decouple the
|
||||
// requirement of simd (sse4_1) from requirements
|
||||
// requirement of simd (sse4_1+2) from requirements
|
||||
// for compiler support in the future, but even
|
||||
// still our module go-ffmpreg makes use of them.
|
||||
return "amd64 SSE4.1 required", cpu.X86.HasSSE41
|
||||
return "amd64 x86-64-v2 required (see: https://en.wikipedia.org/wiki/X86-64-v2)",
|
||||
cpu.Initialized && cpu.X86.HasSSE3 && cpu.X86.HasSSE41 && cpu.X86.HasSSE42
|
||||
case "arm64":
|
||||
// NOTE: this particular check may change if we
|
||||
// later update go-ffmpreg to a version that makes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue