fix uint64 and cursors on 32bit systems.

This commit is contained in:
Miroslav Šedivý 2024-09-08 15:47:42 +02:00
parent d42165a5fd
commit bbefb393f8
2 changed files with 10 additions and 9 deletions

View file

@ -4,7 +4,6 @@ import (
"errors"
"reflect"
"sync"
"sync/atomic"
"time"
"github.com/prometheus/client_golang/prometheus"
@ -26,7 +25,7 @@ type StreamSinkManagerCtx struct {
// wait for a keyframe before sending samples
waitForKf bool
bitrate uint64 // atomic
bitrate uint64
brBuckets map[int]float64
logger zerolog.Logger
@ -144,7 +143,7 @@ func (manager *StreamSinkManagerCtx) ID() string {
}
func (manager *StreamSinkManagerCtx) Bitrate() uint64 {
return atomic.LoadUint64(&manager.bitrate)
return manager.bitrate
}
func (manager *StreamSinkManagerCtx) Codec() codec.RTPCodec {
@ -361,8 +360,8 @@ func (manager *StreamSinkManagerCtx) saveSampleBitrate(timestamp time.Time, delt
next := int((sec + 1) % 3)
if manager.brBuckets[next] != 0 {
// atomic update bitrate
atomic.StoreUint64(&manager.bitrate, uint64(manager.brBuckets[last]))
// update bitrate, TODO: atomic?
manager.bitrate = uint64(manager.brBuckets[last])
// empty next bucket
manager.brBuckets[next] = 0
}
@ -410,5 +409,5 @@ func (manager *StreamSinkManagerCtx) DestroyPipeline() {
manager.pipelinesActive.Set(0)
manager.brBuckets = make(map[int]float64)
atomic.StoreUint64(&manager.bitrate, 0)
manager.bitrate = 0
}

View file

@ -11,6 +11,7 @@ import (
"fmt"
"image"
"image/color"
"strconv"
"sync"
"time"
"unsafe"
@ -279,13 +280,14 @@ func GetCursorImage() *types.CursorImage {
width := int(cur.width)
height := int(cur.height)
// Xlib stores 32-bit data in longs, even if longs are 64-bits long.
pixels := C.GoBytes(unsafe.Pointer(cur.pixels), C.int(width*height*8))
// Xlib stores 32-bit data in longs, even if longs are 64-bits on 64-bit systems.
ptrSize := strconv.IntSize / 8
pixels := C.GoBytes(unsafe.Pointer(cur.pixels), C.int(width*height*ptrSize))
img := image.NewRGBA(image.Rect(0, 0, width, height))
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
pos := ((y * width) + x) * 8
pos := ((y * width) + x) * ptrSize
img.SetRGBA(x, y, color.RGBA{
A: pixels[pos+3],