hls client: improve video / audio sync

This commit is contained in:
aler9 2022-05-10 23:35:07 +02:00
parent 0c4f6e2d43
commit ae23dde169

View File

@ -64,20 +64,17 @@ func (p *clientAudioProcessor) doProcess(
}
aus := make([][]byte, 0, len(adtsPkts))
pktPts := pts
now := time.Now()
elapsed := time.Since(p.clockStartRTC)
if pts > elapsed {
select {
case <-p.ctx.Done():
return fmt.Errorf("terminated")
case <-time.After(pts - elapsed):
}
}
for _, pkt := range adtsPkts {
elapsed := now.Sub(p.clockStartRTC)
if pktPts > elapsed {
select {
case <-p.ctx.Done():
return fmt.Errorf("terminated")
case <-time.After(pktPts - elapsed):
}
}
if !p.trackInitialized {
p.trackInitialized = true
@ -93,7 +90,6 @@ func (p *clientAudioProcessor) doProcess(
}
aus = append(aus, pkt.AU)
pktPts += aac.SamplesPerAccessUnit * time.Second / time.Duration(pkt.SampleRate)
}
p.onData(pts, aus)