From e4aeb3ac289e6c0a96b09b60a4a1d687afc97467 Mon Sep 17 00:00:00 2001 From: zarazaex69 Date: Mon, 27 Apr 2026 03:59:39 +0300 Subject: [PATCH] Add white frame detection and debug frame capture --- internal/transport/videochannel/visual_b.go | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/internal/transport/videochannel/visual_b.go b/internal/transport/videochannel/visual_b.go index 4b5d87b..c0a027f 100644 --- a/internal/transport/videochannel/visual_b.go +++ b/internal/transport/videochannel/visual_b.go @@ -4,6 +4,7 @@ package videochannel import ( "fmt" + "os" "github.com/openlibrecommunity/olcrtc/internal/logger" "github.com/zarazaex69/b/go" @@ -51,12 +52,25 @@ func renderVisualFrameB(payload []byte, width, height int) ([]byte, error) { return rgba, nil } +var frameCounter int + func extractVisualPayloadB(frame []byte, width, height int) ([]byte, error) { expectedSize := width * height * 4 if len(frame) != expectedSize { return nil, fmt.Errorf("unexpected frame size: %d (expected %dx%dx4=%d)", len(frame), width, height, expectedSize) } + if isWhiteFrame(frame) { + return nil, nil + } + + frameCounter++ + if frameCounter <= 3 { + fname := fmt.Sprintf("/tmp/b_frame_%d.rgba", frameCounter) + _ = writeFile(fname, frame) + logger.Debugf("saved non-white frame to %s", fname) + } + cfg := b.DefaultConfig() decoded, err := b.Decode(frame, uint32(width), uint32(height), cfg) if err != nil { @@ -66,3 +80,22 @@ func extractVisualPayloadB(frame []byte, width, height int) ([]byte, error) { return decoded, nil } + +func isWhiteFrame(frame []byte) bool { + for i := 0; i < len(frame); i += 4 { + if frame[i] != 0xff || frame[i+1] != 0xff || frame[i+2] != 0xff { + return false + } + } + return true +} + +func writeFile(path string, data []byte) error { + f, err := os.Create(path) + if err != nil { + return err + } + defer f.Close() + _, err = f.Write(data) + return err +}