From f11cf6baefa1ad293987e55ae141e83c5b1f7311 Mon Sep 17 00:00:00 2001 From: zarazaex69 Date: Thu, 30 Apr 2026 05:09:07 +0300 Subject: [PATCH] refactor: remove "b" codec support --- internal/app/session/session.go | 4 +- internal/transport/videochannel/ffmpeg.go | 12 +-- internal/transport/videochannel/transport.go | 4 +- magefile.go | 106 ++----------------- 4 files changed, 15 insertions(+), 111 deletions(-) diff --git a/internal/app/session/session.go b/internal/app/session/session.go index 7ed5ea1..8c4cca0 100644 --- a/internal/app/session/session.go +++ b/internal/app/session/session.go @@ -48,7 +48,7 @@ var ( ErrVideoFPSRequired = errors.New("video fps required for videochannel (use -video-fps)") ErrVideoBitrateRequired = errors.New("video bitrate required for videochannel (use -video-bitrate)") ErrVideoHWRequired = errors.New("video hardware acceleration required for videochannel (use -video-hw none/nvenc)") - ErrVideoCodecInvalid = errors.New("invalid video codec for videochannel (use -video-codec qrcode or -video-codec b)") + ErrVideoCodecInvalid = errors.New("invalid video codec for videochannel (use -video-codec qrcode)") // VP8channel errors ErrVP8FPSRequired = errors.New("vp8 fps required for vp8channel (use -vp8-fps)") @@ -179,7 +179,7 @@ func Validate(cfg Config) error { if cfg.VideoHW == "" { return ErrVideoHWRequired } - if cfg.VideoCodec != "" && cfg.VideoCodec != "qrcode" && cfg.VideoCodec != "b" { + if cfg.VideoCodec != "" && cfg.VideoCodec != "qrcode" { return ErrVideoCodecInvalid } } diff --git a/internal/transport/videochannel/ffmpeg.go b/internal/transport/videochannel/ffmpeg.go index ff96a16..130b97e 100644 --- a/internal/transport/videochannel/ffmpeg.go +++ b/internal/transport/videochannel/ffmpeg.go @@ -134,7 +134,7 @@ type ffmpegEncoder struct { err error } -func newFFmpegEncoder(spec codecSpec, width, height, fps int, bitrate, hw, visualCodec string) (*ffmpegEncoder, error) { +func newFFmpegEncoder(spec codecSpec, width, height, fps int, bitrate, hw string) (*ffmpegEncoder, error) { if _, err := exec.LookPath("ffmpeg"); err != nil { return nil, ErrFFmpegUnavailable } @@ -158,10 +158,6 @@ func newFFmpegEncoder(spec codecSpec, width, height, fps int, bitrate, hw, visua inputPixFmt := "gray" frameSize := width * height - if visualCodec == "b" { - inputPixFmt = "rgba" - frameSize = width * height * 4 - } args = append(args, "-f", "rawvideo", @@ -345,7 +341,7 @@ type ffmpegDecoder struct { err error } -func newFFmpegDecoder(spec codecSpec, width, height, fps int, hw, visualCodec string) (*ffmpegDecoder, error) { +func newFFmpegDecoder(spec codecSpec, width, height, fps int, hw string) (*ffmpegDecoder, error) { if _, err := exec.LookPath("ffmpeg"); err != nil { return nil, ErrFFmpegUnavailable } @@ -364,10 +360,6 @@ func newFFmpegDecoder(spec codecSpec, width, height, fps int, hw, visualCodec st outputPixFmt := "gray" frameSize := width * height - if visualCodec == "b" { - outputPixFmt = "rgba" - frameSize = width * height * 4 - } args := []string{"-loglevel", "info"} if spec.mimeType == webrtc.MimeTypeH264 { diff --git a/internal/transport/videochannel/transport.go b/internal/transport/videochannel/transport.go index db7ea52..f33dece 100644 --- a/internal/transport/videochannel/transport.go +++ b/internal/transport/videochannel/transport.go @@ -137,7 +137,7 @@ func (p *streamTransport) Connect(ctx context.Context) error { connectCtx, cancel := context.WithTimeout(ctx, defaultConnectTimeout) defer cancel() - encoder, err := newFFmpegEncoder(p.codec, p.videoW, p.videoH, p.videoFPS, p.videoBitrate, p.videoHW, p.videoCodec) + encoder, err := newFFmpegEncoder(p.codec, p.videoW, p.videoH, p.videoFPS, p.videoBitrate, p.videoHW) if err != nil { return err } @@ -347,7 +347,7 @@ func (p *streamTransport) handleRemoteTrack(track *webrtc.TrackRemote, _ *webrtc return } - decoder, err := newFFmpegDecoder(codec, p.videoW, p.videoH, p.videoFPS, p.videoHW, p.videoCodec) + decoder, err := newFFmpegDecoder(codec, p.videoW, p.videoH, p.videoFPS, p.videoHW) if err != nil { logger.Warnf("videochannel decoder init failed: %v", err) return diff --git a/magefile.go b/magefile.go index 0f463b5..7fc94f2 100644 --- a/magefile.go +++ b/magefile.go @@ -19,7 +19,6 @@ const ( buildDir = "build" ldflags = "-s -w" goVersion = "1.25" - bRepo = "github.com/zarazaex69/b" ) var ( @@ -37,18 +36,9 @@ func Build() error { // BuildCLI builds the olcrtc server/client binary. func BuildCLI() error { mg.Deps(Deps) - return buildBinary("olcrtc", "./cmd/olcrtc", goos, goarch, false) + return buildBinary("olcrtc", "./cmd/olcrtc", goos, goarch) } -// BuildCLIB builds the olcrtc CLI with b codec support (requires libb.so). -func BuildCLIB() error { - mg.Deps(Deps) - mg.Deps(B.Build) - return buildBinary("olcrtc", "./cmd/olcrtc", goos, goarch, true) -} - -// TODO: BuildUIB, BuildB (cli+ui with b codec) - // BuildUI builds the Fyne desktop UI binary. func BuildUI() error { return buildUIBinary(goos, goarch) @@ -71,7 +61,7 @@ func Cross() error { } for _, t := range targets { - if err := buildBinary("olcrtc", "./cmd/olcrtc", t.os, t.arch, false); err != nil { + if err := buildBinary("olcrtc", "./cmd/olcrtc", t.os, t.arch); err != nil { return err } } @@ -134,7 +124,7 @@ func Mobile() error { ) } -func buildBinary(name, pkg, os_, arch string, withB bool) error { +func buildBinary(name, pkg, os_, arch string) error { if err := ensureBuildDir(); err != nil { return err } @@ -143,25 +133,14 @@ func buildBinary(name, pkg, os_, arch string, withB bool) error { if os_ == "windows" { ext = ".exe" } - suffix := "" - if withB { - suffix = "-b" - } - outName := fmt.Sprintf("%s%s-%s-%s%s", name, suffix, os_, arch, ext) + outName := fmt.Sprintf("%s-%s-%s%s", name, os_, arch, ext) out := filepath.Join(buildDir, outName) - fmt.Printf("building %s (%s/%s, b=%v) -> %s\n", name, os_, arch, withB, out) + fmt.Printf("building %s (%s/%s) -> %s\n", name, os_, arch, out) env := map[string]string{ - "GOOS": os_, - "GOARCH": arch, - } - - if withB { - env["CGO_ENABLED"] = "1" - bLibDir := bLibPath() - env["CGO_LDFLAGS"] = fmt.Sprintf("-L%s -Wl,-rpath,%s", bLibDir, bLibDir) - } else { - env["CGO_ENABLED"] = "0" + "GOOS": os_, + "GOARCH": arch, + "CGO_ENABLED": "0", } flags := ldflags @@ -169,11 +148,7 @@ func buildBinary(name, pkg, os_, arch string, withB bool) error { flags += " -checklinkname=0" } - args := []string{"build", "-trimpath", "-ldflags", flags} - if withB { - args = append(args, "-tags", "b") - } - args = append(args, "-o", out, pkg) + args := []string{"build", "-trimpath", "-ldflags", flags, "-o", out, pkg} return sh.RunWithV(env, goexe, args...) } @@ -212,69 +187,6 @@ func buildUIBinary(os_, arch string) error { return cmd.Run() } -type B mg.Namespace - -func bLibPath() string { - return filepath.Join(buildDir, "lib") -} - -func bSrcPath() string { - return filepath.Join(buildDir, "b-src") -} - -func (B) Build() error { - if err := ensureBuildDir(); err != nil { - return err - } - - libDir := bLibPath() - libPath := filepath.Join(libDir, "libb.so") - if _, err := os.Stat(libPath); err == nil { - fmt.Println("libb.so already exists, skipping build") - return nil - } - - srcDir := bSrcPath() - if _, err := os.Stat(srcDir); os.IsNotExist(err) { - fmt.Println("cloning b repository...") - if err := sh.RunV("git", "clone", "--depth=1", "https://"+bRepo, srcDir); err != nil { - return fmt.Errorf("failed to clone b: %w", err) - } - } - - fmt.Println("building libb.so with cargo...") - if err := sh.RunV("cargo", "build", "--release", "--manifest-path", filepath.Join(srcDir, "Cargo.toml")); err != nil { - return fmt.Errorf("cargo build failed: %w", err) - } - - if err := os.MkdirAll(libDir, 0o755); err != nil { - return err - } - - srcLib := filepath.Join(srcDir, "target", "release", "libb.so") - if err := sh.Copy(libPath, srcLib); err != nil { - return fmt.Errorf("failed to copy libb.so: %w", err) - } - - fmt.Printf("libb.so installed to %s\n", libPath) - return nil -} - -func (B) Clean() error { - srcDir := bSrcPath() - if _, err := os.Stat(srcDir); err == nil { - if err := os.RemoveAll(srcDir); err != nil { - return err - } - } - libPath := filepath.Join(bLibPath(), "libb.so") - if _, err := os.Stat(libPath); err == nil { - return os.Remove(libPath) - } - return nil -} - - func ensureBuildDir() error { return os.MkdirAll(buildDir, 0o755) }