printing reason on why no shit

This commit is contained in:
KingKDot
2026-03-06 13:27:51 -06:00
parent 843213f4b1
commit d0c4c1d750
3 changed files with 50 additions and 7 deletions
@@ -4,6 +4,7 @@ package capture
import (
"bytes"
"fmt"
"image"
"sync"
@@ -11,11 +12,12 @@ import (
)
var (
h264Mu sync.Mutex
h264Enc *x264.Encoder
h264Buf bytes.Buffer
h264Width int
h264Height int
h264Mu sync.Mutex
h264Enc *x264.Encoder
h264Buf bytes.Buffer
h264Width int
h264Height int
h264LastErr error
)
func encodeH264Frame(img *image.RGBA) ([]byte, error) {
@@ -27,13 +29,16 @@ func encodeH264Frame(img *image.RGBA) ([]byte, error) {
defer h264Mu.Unlock()
if err := ensureH264EncoderLocked(width, height); err != nil {
h264LastErr = err
return nil, err
}
h264Buf.Reset()
if err := h264Enc.Encode(img); err != nil {
h264LastErr = err
return nil, err
}
h264LastErr = nil
out := make([]byte, h264Buf.Len())
copy(out, h264Buf.Bytes())
@@ -44,6 +49,15 @@ func h264Available() bool {
return true
}
func h264AvailabilityDetail() string {
h264Mu.Lock()
defer h264Mu.Unlock()
if h264LastErr != nil {
return fmt.Sprintf("x264 runtime error: %v", h264LastErr)
}
return "cgo build with x264-go"
}
func ensureH264EncoderLocked(width, height int) error {
if h264Enc != nil && h264Width == width && h264Height == height {
return nil