Skip to content

Commit 44627c9

Browse files
committed
Few minor bugfixes
1 parent fe36ed3 commit 44627c9

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

cmd/streampanel/FyneApp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Website = "https://github.com/xaionaro/streamctl"
55
Name = "streampanel"
66
ID = "center.dx.streampanel"
77
Version = "0.1.0"
8-
Build = 350
8+
Build = 360

pkg/streampanel/dashboard.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ func (w *dashboardWindow) imagesLayer(width, height int) (_ret image.Image) {
222222
ctx := context.TODO()
223223
logger.Tracef(ctx, "imagesLayer(%d, %d)", width, height)
224224
defer func() { logger.Tracef(ctx, "/imagesLayer(%d, %d): size:%v", width, height, _ret.Bounds()) }()
225-
return xsync.DoR1(xsync.WithNoLogging(ctx, true), &w.imagesLocker, func() image.Image {
225+
ctx = xsync.WithNoLogging(ctx, true)
226+
return xsync.DoR1(ctx, &w.imagesLocker, func() image.Image {
226227
return w.renderImagesNoLock(ctx, width, height)
227228
})
228229
}
@@ -259,6 +260,7 @@ func (w *dashboardWindow) renderImagesNoLock(
259260

260261
canvasRatio := float64(dstSize.X) / float64(dstSize.Y)
261262

263+
logger.Tracef(ctx, "len(w.changedImages) == %d", len(w.changedImages))
262264
imgIsChanged := map[string]struct{}{}
263265
for _, img := range w.changedImages {
264266
if dashboardDebug {
@@ -577,7 +579,7 @@ func (w *dashboardWindow) startUpdatingNoLock(
577579
w.renderStreamStatus(ctx)
578580

579581
observability.Go(ctx, func() {
580-
t := time.NewTicker(500 * time.Millisecond)
582+
t := time.NewTicker(1000 * time.Millisecond)
581583
for {
582584
select {
583585
case <-ctx.Done():
@@ -645,8 +647,8 @@ func (w *dashboardWindow) updateImages(
645647
ctx context.Context,
646648
dashboardCfg streamdconfig.DashboardConfig,
647649
) {
648-
logger.Tracef(ctx, "updateImages")
649-
defer logger.Tracef(ctx, "/updateImages")
650+
logger.Debugf(ctx, "updateImages")
651+
defer logger.Debugf(ctx, "/updateImages")
650652

651653
w.dashboardLocker.Do(ctx, func() {
652654
w.updateImagesNoLock(ctx, dashboardCfg)
@@ -772,12 +774,9 @@ func (w *dashboardWindow) updateImagesNoLock(
772774
if !changed && lastWinSize == winSize && lastOrientation == orientation {
773775
return
774776
}
775-
logger.Tracef(
776-
ctx,
777+
logger.Tracef(ctx,
777778
"updating the screenshot image: %v %#+v %#+v",
778-
changed,
779-
lastWinSize,
780-
winSize,
779+
changed, lastWinSize, winSize,
781780
)
782781
b := img.Bounds()
783782
m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
@@ -787,18 +786,27 @@ func (w *dashboardWindow) updateImagesNoLock(
787786
el = elementsMap[screenshotElementName]
788787
el.Image = m
789788
})
789+
logger.Tracef(ctx, "push screenshot to changedElements")
790790
changedElements <- el
791791
})
792-
w.changedImages = w.changedImages[:0]
792+
793+
var receiverWG sync.WaitGroup
793794
changedCount := 0
794-
go func() {
795-
for el := range changedElements {
796-
changedCount++
797-
w.changedImages = append(w.changedImages, el)
798-
}
799-
}()
795+
w.imagesLocker.Do(xsync.WithNoLogging(ctx, true), func() {
796+
w.changedImages = w.changedImages[:0]
797+
receiverWG.Add(1)
798+
go func() {
799+
defer receiverWG.Done()
800+
for el := range changedElements {
801+
logger.Tracef(ctx, "<-changedElement: %s", el.ElementName)
802+
changedCount++
803+
w.changedImages = append(w.changedImages, el)
804+
}
805+
}()
806+
})
800807
wg.Wait()
801808
close(changedElements)
809+
receiverWG.Wait()
802810

803811
if changedCount > 0 {
804812
w.imagesLayerObj.Refresh()

pkg/streampanel/image.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ func (p *Panel) downloadImageNoLock(
103103
func (p *Panel) getImage(
104104
ctx context.Context,
105105
imageID consts.ImageID,
106-
) (image.Image, bool, error) {
106+
) (_ret0 image.Image, _ret1 bool, _err error) {
107+
logger.Tracef(ctx, "getImage(ctx, %v)", imageID)
108+
defer func() { logger.Tracef(ctx, "/getImage(ctx, %v): %p %v %v", imageID, _ret0, _ret1, _err) }()
109+
107110
b, changed, err := p.downloadImage(ctx, imageID)
108111
if err != nil {
109112
return nil, false, fmt.Errorf("unable to download image '%s': %w", imageID, err)

pkg/streamplayer/stream_player.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import (
2828
"github.com/xaionaro-go/xsync"
2929
)
3030

31+
const (
32+
enableSeekOnStart = false
33+
)
34+
3135
type Publisher interface {
3236
ClosedChan() <-chan struct{}
3337
}
@@ -615,13 +619,15 @@ func (p *StreamPlayerHandler) controllerLoop(
615619
logger.Errorf(ctx, "unable to unpause: %v", err)
616620
}
617621
}
618-
if err := player.Seek(ctx, time.Second, true, true); err != nil {
619-
logger.Errorf(ctx, "unable to seek: %v", err)
620-
}
621622
pos, err = player.GetPosition(ctx)
622623
if err != nil {
623624
err = fmt.Errorf("unable to get position: %w", err)
624625
}
626+
if enableSeekOnStart {
627+
if err := player.Seek(ctx, -time.Second, true, true); err != nil {
628+
logger.Errorf(ctx, "unable to seek: %v", err)
629+
}
630+
}
625631
})
626632
if err != nil {
627633
logger.Tracef(ctx, "StreamPlayer[%s].controllerLoop: unable to get the current position: %v", p.StreamID, err)
@@ -708,8 +714,10 @@ func (p *StreamPlayerHandler) controllerLoop(
708714
if err != nil {
709715
logger.Errorf(ctx, "unable to setup the player for streaming: %v", err)
710716
}
711-
if err := player.Seek(ctx, time.Second, true, true); err != nil {
712-
logger.Errorf(ctx, "unable to seek: %v", err)
717+
if enableSeekOnStart {
718+
if err := player.Seek(ctx, -time.Second, true, true); err != nil {
719+
logger.Errorf(ctx, "unable to seek: %v", err)
720+
}
713721
}
714722
})
715723
if err != nil {

0 commit comments

Comments
 (0)