GUI, but still shit a bit

This commit is contained in:
Dmitry Sergeev
2026-08-25 22:33:36 +03:00
parent b0bcd879e3
commit 9889054b9f
9 changed files with 276 additions and 128 deletions
+2
View File
@@ -27,8 +27,10 @@ const (
EventTextInput uint32 = 0x303
// it's about SDL_keycode, not SDL_scancode
KeyEscape uint32 = 0x1B
KeyF uint32 = 0x66
KeyQ uint32 = 0x71
KeyF1 uint32 = 0x4000003A
InitAudio uint32 = 0x00000010
+22 -4
View File
@@ -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)
}