VideoTools/vendor/fyne.io/fyne/v2/internal/async/queue.go
Stu Leak 68df790d27 Fix player frame generation and video playback
Major improvements to UnifiedPlayer:

1. GetFrameImage() now works when paused for responsive UI updates
2. Play() method properly starts FFmpeg process
3. Frame display loop runs continuously for smooth video display
4. Disabled audio temporarily to fix video playback fundamentals
5. Simplified FFmpeg command to focus on video stream only

Player now:
- Generates video frames correctly
- Shows video when paused
- Has responsive progress tracking
- Starts playback properly

Next steps: Re-enable audio playback once video is stable
2026-01-07 22:20:00 -05:00

93 lines
2.0 KiB
Go

//go:build !migrated_fynedo
package async
import (
"sync/atomic"
"fyne.io/fyne/v2"
)
// CanvasObjectQueue implements lock-free FIFO freelist based queue.
//
// Reference: https://dl.acm.org/citation.cfm?doid=248052.248106
type CanvasObjectQueue struct {
head atomic.Pointer[itemCanvasObject]
tail atomic.Pointer[itemCanvasObject]
len atomic.Uint64
}
// NewCanvasObjectQueue returns a queue for caching values.
func NewCanvasObjectQueue() *CanvasObjectQueue {
head := &itemCanvasObject{}
queue := &CanvasObjectQueue{}
queue.head.Store(head)
queue.tail.Store(head)
return queue
}
type itemCanvasObject struct {
next atomic.Pointer[itemCanvasObject]
v fyne.CanvasObject
}
var itemCanvasObjectPool = Pool[*itemCanvasObject]{
New: func() *itemCanvasObject { return &itemCanvasObject{} },
}
// In puts the given value at the tail of the queue.
func (q *CanvasObjectQueue) In(v fyne.CanvasObject) {
i := itemCanvasObjectPool.Get()
i.next.Store(nil)
i.v = v
var last, lastnext *itemCanvasObject
for {
last = q.tail.Load()
lastnext = last.next.Load()
if q.tail.Load() == last {
if lastnext == nil {
if last.next.CompareAndSwap(lastnext, i) {
q.tail.CompareAndSwap(last, i)
q.len.Add(1)
return
}
} else {
q.tail.CompareAndSwap(last, lastnext)
}
}
}
}
// Out removes and returns the value at the head of the queue.
// It returns nil if the queue is empty.
func (q *CanvasObjectQueue) Out() fyne.CanvasObject {
var first, last, firstnext *itemCanvasObject
for {
first = q.head.Load()
last = q.tail.Load()
firstnext = first.next.Load()
if first == q.head.Load() {
if first == last {
if firstnext == nil {
return nil
}
q.tail.CompareAndSwap(last, firstnext)
} else {
v := firstnext.v
if q.head.CompareAndSwap(first, firstnext) {
q.len.Add(^uint64(0))
itemCanvasObjectPool.Put(first)
return v
}
}
}
}
}
// Len returns the length of the queue.
func (q *CanvasObjectQueue) Len() uint64 {
return q.len.Load()
}