GUI, but still shit a bit
This commit is contained in:
@@ -403,6 +403,7 @@ func (s *SyncSource) Close() error {
|
||||
|
||||
// NextSync reads both at a synced timestamp. Returns video Frame + audio AudioFrame
|
||||
func (s *SyncSource) NextSync(ctx context.Context, audioBatch uint64, timeout time.Duration) (Frame, AudioFrame, error) {
|
||||
var timeouts int
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -421,7 +422,19 @@ func (s *SyncSource) NextSync(ctx context.Context, audioBatch uint64, timeout ti
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
continue
|
||||
}
|
||||
return Frame{}, AudioFrame{}, fmt.Errorf("GetGraing: %w", gerr)
|
||||
if errors.Is(gerr, mxl.ErrOutOfRangeLate) {
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
continue
|
||||
}
|
||||
if errors.Is(gerr, mxl.ErrOutOfRangeEarly) {
|
||||
select {
|
||||
case <-time.After(5 * time.Millisecond):
|
||||
case <-ctx.Done():
|
||||
return Frame{}, AudioFrame{}, ctx.Err()
|
||||
}
|
||||
continue
|
||||
}
|
||||
return Frame{}, AudioFrame{}, fmt.Errorf("GetGrain: %w", gerr)
|
||||
}
|
||||
// read audio at the same timestamp
|
||||
aIdx := mxl.TimestampToIndex(s.aRate, ts)
|
||||
@@ -451,14 +464,19 @@ func (s *SyncSource) NextSync(ctx context.Context, audioBatch uint64, timeout ti
|
||||
}
|
||||
// even if audio failed, video returns
|
||||
return vFrame, aFrame, nil
|
||||
case errors.Is(err, mxl.ErrTimeout), errors.Is(err, mxl.ErrOutOfRangeEarly):
|
||||
case errors.Is(err, mxl.ErrTimeout), errors.Is(err, mxl.ErrOutOfRangeEarly), errors.Is(err, mxl.ErrOutOfRangeLate):
|
||||
timeouts++
|
||||
if timeouts > 10 {
|
||||
timeouts = 0
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
return Frame{}, AudioFrame{}, fmt.Errorf("sync: feeds not responding")
|
||||
}
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
select {
|
||||
case <-time.After(5 * time.Millisecond):
|
||||
case <-ctx.Done():
|
||||
return Frame{}, AudioFrame{}, ctx.Err()
|
||||
}
|
||||
case errors.Is(err, mxl.ErrOutOfRangeLate):
|
||||
s.idx = mxl.CurrentIndex(s.rate)
|
||||
default:
|
||||
return Frame{}, AudioFrame{}, fmt.Errorf("WaitForDataAt: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user