dropped-frame tracke
This commit is contained in:
@@ -14,6 +14,7 @@ func runSyncAttempt(
|
||||
videoConfig FeedConfig,
|
||||
audioConfig FeedConfig,
|
||||
) (resultErr error) {
|
||||
videoCtx := withVideoSource(ctx, videoConfig)
|
||||
reader, err := factory.OpenSync(
|
||||
ctx,
|
||||
videoConfig,
|
||||
@@ -39,7 +40,7 @@ func runSyncAttempt(
|
||||
return fmt.Errorf("read sync group: %w", err)
|
||||
}
|
||||
|
||||
if err := videoSink.ConsumeVideo(ctx, frame.Video); err != nil {
|
||||
if err := videoSink.ConsumeVideo(videoCtx, frame.Video); err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
@@ -2,6 +2,17 @@ package playback
|
||||
|
||||
import "context"
|
||||
|
||||
type videoSourceContextKey struct{}
|
||||
|
||||
func withVideoSource(ctx context.Context, source FeedConfig) context.Context {
|
||||
return context.WithValue(ctx, videoSourceContextKey{}, source)
|
||||
}
|
||||
|
||||
func videoSourceFromContext(ctx context.Context) FeedConfig {
|
||||
source, _ := ctx.Value(videoSourceContextKey{}).(FeedConfig)
|
||||
return source
|
||||
}
|
||||
|
||||
// VideoFrame contains metadata and borrowed source payload.
|
||||
//
|
||||
// Payload is valid only until the next VideoReader.ReadVideo call or until the
|
||||
|
||||
@@ -24,6 +24,7 @@ func runVideoAttempt(
|
||||
sink VideoSink,
|
||||
config FeedConfig,
|
||||
) (resultErr error) {
|
||||
ctx = withVideoSource(ctx, config)
|
||||
reader, err := factory.OpenVideo(ctx, config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open video: %w", err)
|
||||
|
||||
@@ -6,7 +6,9 @@ import (
|
||||
)
|
||||
|
||||
type PendingVideoFrame struct {
|
||||
Frame VideoFrame
|
||||
Frame VideoFrame
|
||||
Generation uint64
|
||||
Source FeedConfig
|
||||
|
||||
completeOnce sync.Once
|
||||
result chan error
|
||||
@@ -27,8 +29,10 @@ func (b *VideoBridge) ConsumeVideo(
|
||||
frame VideoFrame,
|
||||
) error {
|
||||
pending := &PendingVideoFrame{
|
||||
Frame: frame,
|
||||
result: make(chan error, 1),
|
||||
Frame: frame,
|
||||
Generation: generationFromContext(ctx),
|
||||
Source: videoSourceFromContext(ctx),
|
||||
result: make(chan error, 1),
|
||||
}
|
||||
|
||||
select {
|
||||
|
||||
@@ -21,8 +21,10 @@ func TestVideoBridgeDeliversFrameAndCompletionResult(t *testing.T) {
|
||||
}
|
||||
consumeResult := make(chan error, 1)
|
||||
|
||||
wantSource := FeedConfig{Domain: "/video", UUID: "video", Active: true}
|
||||
go func() {
|
||||
consumeResult <- bridge.ConsumeVideo(context.Background(), wantFrame)
|
||||
ctx := withGeneration(context.Background(), 17)
|
||||
consumeResult <- bridge.ConsumeVideo(withVideoSource(ctx, wantSource), wantFrame)
|
||||
}()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), videoBridgeTestTimeout)
|
||||
@@ -34,6 +36,12 @@ func TestVideoBridgeDeliversFrameAndCompletionResult(t *testing.T) {
|
||||
if pending.Frame.Index != wantFrame.Index {
|
||||
t.Fatalf("Next() frame index = %d, want %d", pending.Frame.Index, wantFrame.Index)
|
||||
}
|
||||
if pending.Generation != 17 {
|
||||
t.Fatalf("Next() generation = %d, want 17", pending.Generation)
|
||||
}
|
||||
if pending.Source != wantSource {
|
||||
t.Fatalf("Next() source = %#v, want %#v", pending.Source, wantSource)
|
||||
}
|
||||
if &pending.Frame.Payload[0] != &wantFrame.Payload[0] {
|
||||
t.Fatal("Next() copied the borrowed payload")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user