fixed the synchronized-audio corruption

This commit is contained in:
Dmitry Sergeev
2026-09-01 01:04:40 +03:00
parent 19e2e076e9
commit e830da4a32
5 changed files with 153 additions and 642 deletions
+4 -22
View File
@@ -13,8 +13,7 @@ import (
)
const (
DefaultSyncReadTimeout = 200 * time.Millisecond
DefaultSyncBatchDuration = 10 * time.Millisecond
DefaultSyncReadTimeout = 200 * time.Millisecond
)
var ErrNativeSyncDifferentDomains = errors.New(
@@ -22,15 +21,13 @@ var ErrNativeSyncDifferentDomains = errors.New(
)
type SyncFactory struct {
ReadTimeout time.Duration
BatchDuration time.Duration
open func(string, string, string) (localSyncSource, error)
ReadTimeout time.Duration
open func(string, string, string) (localSyncSource, error)
}
type localSyncSource interface {
NextSync(
context.Context,
uint64,
time.Duration,
) (source.Frame, source.AudioFrame, error)
@@ -41,7 +38,6 @@ type localSyncSource interface {
type syncReader struct {
source localSyncSource
readTimeout time.Duration
audioBatch uint64
rateNumerator int64
rateDenominator int64
}
@@ -118,25 +114,11 @@ func (f SyncFactory) OpenSync(
if readTimeout <= 0 {
readTimeout = DefaultSyncReadTimeout
}
batchDuration := f.BatchDuration
if batchDuration <= 0 {
batchDuration = DefaultSyncBatchDuration
}
audioRate := src.AudioRate()
batch, err := audioBatchSize(audioRate.Num, audioRate.Den, batchDuration)
if err != nil {
_ = src.Close()
return nil, &source.SourceError{
Op: "calculate sync audio batch",
Kind: source.ErrorKindInvalidConfig,
Err: err,
}
}
return &syncReader{
source: src,
readTimeout: readTimeout,
audioBatch: batch,
rateNumerator: audioRate.Num,
rateDenominator: audioRate.Den,
}, nil
@@ -145,7 +127,7 @@ func (f SyncFactory) OpenSync(
func (r *syncReader) ReadSync(
ctx context.Context,
) (playback.SyncFrame, error) {
video, audio, err := r.source.NextSync(ctx, r.audioBatch, r.readTimeout)
video, audio, err := r.source.NextSync(ctx, r.readTimeout)
if err != nil {
return playback.SyncFrame{}, err
}