add synchronized playback attempt
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package playback
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func runSyncAttempt(
|
||||
ctx context.Context,
|
||||
factory SyncReaderFactory,
|
||||
videoSink VideoSink,
|
||||
audioSink AudioSink,
|
||||
videoConfig FeedConfig,
|
||||
audioConfig FeedConfig,
|
||||
) (resultErr error) {
|
||||
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(ctx, 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}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user