dropped-frame tracke
This commit is contained in:
+10
-8
@@ -467,7 +467,7 @@ func main() {
|
||||
displayedVideoStride uint32 = placeholderStride
|
||||
|
||||
fps float64
|
||||
lastIndex uint64
|
||||
dropTracker videoDropTracker
|
||||
dropped uint64
|
||||
droppedTotal uint64
|
||||
frameCount uint64
|
||||
@@ -530,6 +530,8 @@ func main() {
|
||||
resized = false
|
||||
}
|
||||
var shownIndex uint64
|
||||
var shownGeneration uint64
|
||||
var shownSource playback.FeedConfig
|
||||
hasFrame := false
|
||||
|
||||
frameCtx, frameCancel := context.WithTimeout(ctx, 100*time.Millisecond)
|
||||
@@ -555,6 +557,8 @@ func main() {
|
||||
}
|
||||
|
||||
shownIndex = pendingFrame.Frame.Index
|
||||
shownGeneration = pendingFrame.Generation
|
||||
shownSource = pendingFrame.Source
|
||||
displayedVideoWidth = pendingFrame.Frame.Width
|
||||
displayedVideoHeight = pendingFrame.Frame.Height
|
||||
displayedVideoStride = pendingFrame.Frame.Stride
|
||||
@@ -565,15 +569,14 @@ func main() {
|
||||
panic(frameErr)
|
||||
}
|
||||
|
||||
snapshot, hasSnapshot := player.Controller.Snapshot()
|
||||
|
||||
// stats
|
||||
if hasFrame {
|
||||
if lastIndex != 0 && shownIndex > lastIndex {
|
||||
if g := shownIndex - lastIndex - 1; g > 0 {
|
||||
dropped += g
|
||||
droppedTotal += g
|
||||
}
|
||||
if gap := dropTracker.Observe(shownGeneration, shownSource, shownIndex); gap > 0 {
|
||||
dropped += gap
|
||||
droppedTotal += gap
|
||||
}
|
||||
lastIndex = shownIndex
|
||||
frameCount++
|
||||
if now := time.Now(); now.Sub(lastReport) >= time.Second {
|
||||
dt := now.Sub(lastReport).Seconds()
|
||||
@@ -588,7 +591,6 @@ func main() {
|
||||
// end of stats
|
||||
if r != nil {
|
||||
gui.BeginFrame(time.Since(lastFrame), int32(r.Extent().Width), int32(r.Extent().Height))
|
||||
snapshot, hasSnapshot := player.Controller.Snapshot()
|
||||
if showStats {
|
||||
cimgui.SetNextWindowPos(cimgui.Vec2{X: 0, Y: 0})
|
||||
cimgui.SetNextWindowSize(cimgui.Vec2{X: 460, Y: 510})
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import "mxl-player/internal/playback"
|
||||
|
||||
// videoDropTracker counts gaps only within one playback generation. Frame
|
||||
// indices belong to their source and cannot be compared across feed changes.
|
||||
type videoDropTracker struct {
|
||||
generation uint64
|
||||
source playback.FeedConfig
|
||||
lastIndex uint64
|
||||
hasIndex bool
|
||||
}
|
||||
|
||||
func (t *videoDropTracker) Observe(
|
||||
generation uint64,
|
||||
source playback.FeedConfig,
|
||||
index uint64,
|
||||
) uint64 {
|
||||
if !t.hasIndex ||
|
||||
generation != t.generation ||
|
||||
!sameVideoSource(source, t.source) ||
|
||||
index <= t.lastIndex {
|
||||
t.generation = generation
|
||||
t.source = source
|
||||
t.lastIndex = index
|
||||
t.hasIndex = true
|
||||
return 0
|
||||
}
|
||||
|
||||
dropped := index - t.lastIndex - 1
|
||||
t.lastIndex = index
|
||||
return dropped
|
||||
}
|
||||
|
||||
func sameVideoSource(a, b playback.FeedConfig) bool {
|
||||
return a.Domain == b.Domain && a.UUID == b.UUID
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"mxl-player/internal/playback"
|
||||
)
|
||||
|
||||
func TestVideoDropTracker(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
observations [][2]uint64
|
||||
want []uint64
|
||||
}{
|
||||
{
|
||||
name: "counts gaps within generation",
|
||||
observations: [][2]uint64{{1, 10}, {1, 11}, {1, 15}},
|
||||
want: []uint64{0, 0, 3},
|
||||
},
|
||||
{
|
||||
name: "higher index from new generation resets baseline",
|
||||
observations: [][2]uint64{{1, 10}, {2, 1000000}, {2, 1000001}},
|
||||
want: []uint64{0, 0, 0},
|
||||
},
|
||||
{
|
||||
name: "lower index from new generation resets baseline",
|
||||
observations: [][2]uint64{{1, 100}, {2, 5}, {2, 7}},
|
||||
want: []uint64{0, 0, 1},
|
||||
},
|
||||
{
|
||||
name: "index restart within generation resets baseline",
|
||||
observations: [][2]uint64{{1, 100}, {1, 0}, {1, 1}},
|
||||
want: []uint64{0, 0, 0},
|
||||
},
|
||||
{
|
||||
name: "zero is a valid first index",
|
||||
observations: [][2]uint64{{1, 0}, {1, 2}},
|
||||
want: []uint64{0, 1},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var tracker videoDropTracker
|
||||
source := playback.FeedConfig{Domain: "/mxl", UUID: "video"}
|
||||
for index, observation := range test.observations {
|
||||
got := tracker.Observe(observation[0], source, observation[1])
|
||||
if got != test.want[index] {
|
||||
t.Fatalf("Observe(%d, %d) = %d, want %d",
|
||||
observation[0], observation[1], got, test.want[index])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVideoDropTrackerResetsWhenSourceChanges(t *testing.T) {
|
||||
var tracker videoDropTracker
|
||||
first := playback.FeedConfig{Domain: "/mxl", UUID: "first"}
|
||||
second := playback.FeedConfig{Domain: "/mxl", UUID: "second"}
|
||||
|
||||
if got := tracker.Observe(1, first, 10); got != 0 {
|
||||
t.Fatalf("first Observe() = %d, want 0", got)
|
||||
}
|
||||
if got := tracker.Observe(1, second, 1000000); got != 0 {
|
||||
t.Fatalf("source-changing Observe() = %d, want 0", got)
|
||||
}
|
||||
if got := tracker.Observe(1, second, 1000002); got != 1 {
|
||||
t.Fatalf("same-source Observe() = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user