reuse context-aware video read

This commit is contained in:
Dmitry Sergeev
2026-08-26 22:54:31 +03:00
parent 0b91a52b99
commit 61c770d722
+1 -25
View File
@@ -102,31 +102,7 @@ func (s *Source) Close() error {
} }
func (s *Source) Next(timeout time.Duration) (Frame, error) { func (s *Source) Next(timeout time.Duration) (Frame, error) {
for { return s.NextCtx(context.Background(), timeout)
g, err := s.reader.GetGrain(s.idx, timeout)
switch {
case err == nil:
f := Frame{
Index: g.Index,
Width: s.width,
Height: s.height,
Stride: s.stride,
Size: g.GrainSize,
Invalid: g.Invalid(),
Payload: g.Payload,
}
s.idx++
return f, nil
case errors.Is(err, mxl.ErrTimeout):
s.idx = mxl.CurrentIndex(s.rate)
case errors.Is(err, mxl.ErrOutOfRangeEarly):
time.Sleep(10 * time.Millisecond)
case errors.Is(err, mxl.ErrOutOfRangeLate):
s.idx = mxl.CurrentIndex(s.rate)
default:
return Frame{}, fmt.Errorf("GetGrain: %w", err)
}
}
} }
func (s *Source) NextCtx(ctx context.Context, timeout time.Duration) (Frame, error) { func (s *Source) NextCtx(ctx context.Context, timeout time.Duration) (Frame, error) {