Add white frame detection and debug frame capture

This commit is contained in:
zarazaex69
2026-04-27 03:59:39 +03:00
parent 12d22770b4
commit e4aeb3ac28

View File

@@ -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
}