From 61c770d72238b1ca25264fcd44dcfb9a623d6f83 Mon Sep 17 00:00:00 2001 From: Dmitry Sergeev Date: Wed, 26 Aug 2026 22:54:31 +0300 Subject: [PATCH] reuse context-aware video read --- internal/source/source.go | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/internal/source/source.go b/internal/source/source.go index d3a4aca..5d22c1c 100644 --- a/internal/source/source.go +++ b/internal/source/source.go @@ -102,31 +102,7 @@ func (s *Source) Close() error { } func (s *Source) Next(timeout time.Duration) (Frame, error) { - for { - 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) - } - } + return s.NextCtx(context.Background(), timeout) } func (s *Source) NextCtx(ctx context.Context, timeout time.Duration) (Frame, error) {