Buffer stream PCM before playback and recover underruns without resets
This commit is contained in:
1 parent
4d9930dc0b
commit
61d07e12c8
7 files changed
+152
-16
No files matched your search
@@ -160,12 +160,14 @@ void StreamPlayerWindow::attachAudio() {
|
||||
if (!p.sound || !p.started || p.resync) return;
|
||||
p.audioFrameStart = stream_playback_audio_written(p.sound); p.audioDacAt = firstTimeUs;
|
||||
unsigned pcmBefore = stream_playback_audio_buffered(p.sound);
|
||||
bool buffering = stream_playback_audio_buffering(p.sound);
|
||||
int count = !p.presenting ? 0 : stream_playback_audio_pull(p.sound, pcm, frames, INT64_MAX);
|
||||
if (count < 0) { p.resync = true; count = 0; }
|
||||
if ((unsigned)count < frames) {
|
||||
stream_playback_audio_silence(p.sound, frames - (unsigned)count);
|
||||
if (p.presenting && !p.audioEnded) {
|
||||
p.underruns++; p.audioGap.count++; p.audioGap.silentFrames += frames - (unsigned)count;
|
||||
if (p.presenting && !p.audioEnded) p.audioGap.silentFrames += frames - (unsigned)count;
|
||||
if (p.presenting && !p.audioEnded && !buffering) {
|
||||
p.underruns++; p.audioGap.count++;
|
||||
if (!p.audioUnderrunning) { p.audioGap.episodes++; p.audioUnderrunning = true; }
|
||||
p.audioGap.at = now;
|
||||
p.audioGap.requested = frames; p.audioGap.received = (unsigned)count;
|
||||
@@ -305,7 +307,7 @@ void StreamPlayerWindow::decode() {
|
||||
p.clockAt = nowUs(); p.started = true;
|
||||
stream_playback_clock_reset(&p.adaptation, p.id);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_STREAM,
|
||||
"desktop playback starts id=%llu pts=%lld fixed_prefill=0 elapsed_us=%lld audio=%d PCM_target_ms=250 separate_video=1",
|
||||
"desktop playback starts id=%llu pts=%lld elapsed_us=%lld audio=%d PCM_prefill_resume_ms=250 separate_video=1",
|
||||
(unsigned long long)p.id, (long long)p.position, (long long)(nowUs() - p.createdAt), audio);
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(p.lock);
|
||||
@@ -352,6 +354,7 @@ void StreamPlayerWindow::decode() {
|
||||
if (p.presenting && p.ready >= 0) {
|
||||
uint64_t played = p.played(now);
|
||||
bool starved = p.underruns != observedGaps; observedGaps = p.underruns;
|
||||
if (p.sound && stream_playback_audio_buffering(p.sound)) starved = true;
|
||||
if (!p.activeAudio && p.position + (now - p.clockAt) * p.adaptation.tempo_milli / 1000 > p.ready) starved = true;
|
||||
int64_t guardUs = p.activeAudio ? std::max<int64_t>(40000, p.deviceLead + 20000) : p.framePeriod;
|
||||
if (p.sound) guardUs += stream_playback_audio_latency_us(p.sound);
|
||||
@@ -386,7 +389,7 @@ void StreamPlayerWindow::decode() {
|
||||
"TIME{position_ms=%s ready_ms=%s reserve_ms=%s minimum_ms=%s guard_ms=%s tempo=%d reason=%s "
|
||||
"correction_ms=%s pending_gain_ms=%s} "
|
||||
"VIDEO{shown=%llu drop=%llu pts_ms=%s av_ms=%s queue=%zu input=%zu decoder_lead_ms=%s wait_key=%d} "
|
||||
"AUDIO{enabled=%d pcm_ms=%.1f device_ms=%s underruns=%llu silence_frames=%llu} waiting=%d ended=%d",
|
||||
"AUDIO{enabled=%d pcm_ms=%.1f buffering=%d device_ms=%s underruns=%llu silence_frames=%llu} waiting=%d ended=%d",
|
||||
(unsigned long long)p.group, (unsigned long long)p.source, (unsigned long long)p.epoch,
|
||||
(unsigned long long)p.id, (long long)((began - playReportAt) / 1000), (unsigned long long)p.media.generation,
|
||||
ms(p.position, p.started).constData(), ms(p.ready, p.ready >= 0).constData(),
|
||||
@@ -399,6 +402,7 @@ void StreamPlayerWindow::decode() {
|
||||
ms(p.lastShownPts - position, p.lastShownPts >= 0 && position >= 0).constData(),
|
||||
p.videos.size(), p.videoInput.size(), ms(p.decoderLead, p.videoReady).constData(), !p.videoReady,
|
||||
p.activeAudio, p.sound ? stream_playback_audio_buffered(p.sound) / 48.0 : 0,
|
||||
stream_playback_audio_buffering(p.sound),
|
||||
ms(p.deviceLead, p.activeAudio && p.audioDacAt).constData(),
|
||||
(unsigned long long)(p.underruns - underrunBase),
|
||||
(unsigned long long)(p.audioGap.silentFrames - silenceBase), timing && p.timing.waiting, p.ended);
|
||||
|
||||
Reference in new issue
Block a user