Files
2026-09-01 23:45:10 +03:00

58 lines
1.1 KiB
Go

package playback
import (
"context"
"errors"
"fmt"
)
func runSyncAttempt(
ctx context.Context,
factory SyncReaderFactory,
videoSink VideoSink,
audioSink AudioSink,
videoConfig FeedConfig,
audioConfig FeedConfig,
) (resultErr error) {
videoCtx := withVideoSource(ctx, videoConfig)
reader, err := factory.OpenSync(
ctx,
videoConfig,
audioConfig,
)
if err != nil {
return fmt.Errorf("open sync group: %w", err)
}
defer func() {
if closeErr := reader.Close(); closeErr != nil {
closeErr = fmt.Errorf("close sync group: %w", closeErr)
resultErr = errors.Join(resultErr, closeErr)
}
}()
for {
frame, err := reader.ReadSync(ctx)
if err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
return fmt.Errorf("read sync group: %w", err)
}
if err := videoSink.ConsumeVideo(videoCtx, frame.Video); err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
return &videoSinkError{err: err}
}
if err := audioSink.ConsumeAudio(ctx, frame.Audio); err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
return &audioSinkError{err: err}
}
}
}