Diagnose stream audio underruns and fixture timing jitter
This commit is contained in:
1 parent
dd4d458f74
commit
4d9930dc0b
3 files changed
+75
-13
No files matched your search
@@ -43,9 +43,13 @@ QString text(const char* value) { return QCoreApplication::translate("ChatGui",
|
||||
struct StreamPlayerWindow::Playback {
|
||||
struct Video { QImage image; int64_t pts; };
|
||||
struct AudioGap {
|
||||
uint64_t count = 0, silentFrames = 0;
|
||||
uint64_t count = 0, silentFrames = 0, episodes = 0;
|
||||
int64_t at = 0;
|
||||
unsigned requested = 0, received = 0;
|
||||
unsigned pcmBefore = 0, pcmAfter = 0;
|
||||
int tempo = 1000;
|
||||
int64_t reserve = 0, feedAge = -1, workerAge = -1, audioPts = -1;
|
||||
int64_t deviceLead = 0, guard = 0, minimum = 0, callbackGap = 0, pendingGain = 0;
|
||||
size_t videoQueue = 0;
|
||||
} audioGap;
|
||||
uint64_t id = ++nextId, group = 0, source = 0, epoch = 0;
|
||||
@@ -73,8 +77,8 @@ struct StreamPlayerWindow::Playback {
|
||||
int64_t decoderLead = 0, framePeriod = 33333, lastInputPts = -1, lastDecodedPts = -1;
|
||||
uint64_t audioFrameStart = 0, shown = 0, discarded = 0, underruns = 0, endFrames = UINT64_MAX;
|
||||
bool started = false, presenting = false, videoReady = false, ended = false, videoEnded = false;
|
||||
bool activeAudio = false, audioEnded = false, resync = false;
|
||||
int64_t audioFedAt = 0, audioFedPts = -1, workerAt = 0, guiAt = 0, guiGapMax = 0;
|
||||
bool activeAudio = false, audioEnded = false, resync = false, audioUnderrunning = false;
|
||||
int64_t audioFedAt = 0, audioFedPts = -1, workerAt = 0, guiAt = 0, guiGapMax = 0, audioCallbackAt = 0;
|
||||
~Playback() { stream_playback_audio_destroy(sound); }
|
||||
|
||||
// Отдельный lock: уведомление из ядра не ждёт codec/PCM lock и не вызывает bridge.
|
||||
@@ -148,24 +152,32 @@ void StreamPlayerWindow::attachAudio() {
|
||||
auto& p = *m_playback; std::lock_guard<std::mutex> guard(p.lock);
|
||||
p.notify();
|
||||
int64_t now = nowUs();
|
||||
int64_t callbackGap = p.audioCallbackAt ? now - p.audioCallbackAt : 0; p.audioCallbackAt = now;
|
||||
bool restored = !p.audioAvailable.exchange(true);
|
||||
if ((p.audioGeneration && p.audioGeneration != generation) || (restored && p.started)) p.resync = true;
|
||||
p.audioGeneration = generation;
|
||||
p.deviceLead = std::max<int64_t>(0, firstTimeUs - now);
|
||||
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);
|
||||
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.audioUnderrunning) { p.audioGap.episodes++; p.audioUnderrunning = true; }
|
||||
p.audioGap.at = now;
|
||||
p.audioGap.requested = frames; p.audioGap.received = (unsigned)count;
|
||||
p.audioGap.reserve = p.ready - p.position; p.audioGap.videoQueue = p.videos.size();
|
||||
p.audioGap.feedAge = p.audioFedAt ? now - p.audioFedAt : -1; p.audioGap.audioPts = p.audioFedPts;
|
||||
p.audioGap.workerAge = p.workerAt ? now - p.workerAt : -1;
|
||||
p.audioGap.pcmBefore = pcmBefore; p.audioGap.pcmAfter = stream_playback_audio_buffered(p.sound);
|
||||
p.audioGap.tempo = p.adaptation.tempo_milli; p.audioGap.deviceLead = p.deviceLead;
|
||||
p.audioGap.guard = p.timing.guard_us; p.audioGap.minimum = p.timing.minimum_us;
|
||||
p.audioGap.callbackGap = callbackGap; p.audioGap.pendingGain = p.timing.pending_gain_us;
|
||||
}
|
||||
}
|
||||
} else p.audioUnderrunning = false;
|
||||
float volume = p.volume.load();
|
||||
for (int i = 0; i < count; i++) {
|
||||
p.outputVolume += std::clamp(volume - p.outputVolume, -1.0f / 480, 1.0f / 480);
|
||||
@@ -250,7 +262,7 @@ void StreamPlayerWindow::decode() {
|
||||
p.failed = p.complete = true; emit statusChanged(text("Live video playback requires FFmpeg"));
|
||||
#else
|
||||
std::deque<StreamRecord> records;
|
||||
uint64_t reportedGaps = 0, observedGaps = 0;
|
||||
uint64_t reportedGaps = 0, observedGaps = 0, reportedEpisodes = 0;
|
||||
int64_t reportAt = nowUs(), gapReportAt = 0;
|
||||
int64_t playReportAt = reportAt;
|
||||
uint64_t shownBase = 0, discardedBase = 0, underrunBase = 0, silenceBase = 0;
|
||||
@@ -274,7 +286,7 @@ void StreamPlayerWindow::decode() {
|
||||
p.lastInputPts = p.lastDecodedPts = p.lastShownPts = -1;
|
||||
p.ended = p.videoEnded = p.audioEnded = p.resync = false;
|
||||
p.audioDacAt = 0; p.audioFrameStart = 0; p.endFrames = UINT64_MAX;
|
||||
p.audioFedAt = 0; p.audioFedPts = -1; observedGaps = p.underruns;
|
||||
p.audioFedAt = 0; p.audioFedPts = -1; observedGaps = p.underruns; p.audioUnderrunning = false;
|
||||
}
|
||||
stream_playback_audio_destroy(previous); p.notify();
|
||||
if (request && !gui_stream_resync(p.id)) DEBUG_WARN(DEBUG_CATEGORY_STREAM, "desktop playback resync refused id=%llu",
|
||||
@@ -310,14 +322,19 @@ void StreamPlayerWindow::decode() {
|
||||
bool resync;
|
||||
Playback::AudioGap gap;
|
||||
{ std::lock_guard<std::mutex> guard(p.lock); resync = p.resync; p.workerAt = began; gap = p.audioGap; }
|
||||
if (gap.count != reportedGaps && began - gapReportAt >= 1000000) {
|
||||
if (gap.episodes != reportedEpisodes || (gap.count != reportedGaps && began - gapReportAt >= 1000000)) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_STREAM,
|
||||
"desktop audio gap id=%llu count=%llu delta=%llu silence_frames=%llu got=%u/%u reserve_us=%lld "
|
||||
"feed_age_us=%lld worker_age_us=%lld audio_pts=%lld videoQ=%zu",
|
||||
"desktop audio gap id=%llu count=%llu delta=%llu episodes=%llu event_us=%lld report_delay_us=%lld "
|
||||
"silence_frames=%llu got=%u/%u reserve_us=%lld "
|
||||
"feed_age_us=%lld worker_age_us=%lld audio_pts=%lld videoQ=%zu "
|
||||
"pcm_before=%u pcm_after=%u tempo=%d device_us=%lld guard_us=%lld minimum_us=%lld callback_gap_us=%lld pending_gain_us=%lld",
|
||||
(unsigned long long)p.id, (unsigned long long)gap.count, (unsigned long long)(gap.count - reportedGaps),
|
||||
(unsigned long long)gap.episodes, (long long)gap.at, (long long)(began - gap.at),
|
||||
(unsigned long long)gap.silentFrames, gap.received, gap.requested, (long long)gap.reserve,
|
||||
(long long)gap.feedAge, (long long)gap.workerAge, (long long)gap.audioPts, gap.videoQueue);
|
||||
reportedGaps = gap.count; gapReportAt = began;
|
||||
(long long)gap.feedAge, (long long)gap.workerAge, (long long)gap.audioPts, gap.videoQueue,
|
||||
gap.pcmBefore, gap.pcmAfter, gap.tempo, (long long)gap.deviceLead, (long long)gap.guard,
|
||||
(long long)gap.minimum, (long long)gap.callbackGap, (long long)gap.pendingGain);
|
||||
reportedGaps = gap.count; reportedEpisodes = gap.episodes; gapReportAt = began;
|
||||
}
|
||||
if (resync) reset(true);
|
||||
observe();
|
||||
|
||||
Reference in new issue
Block a user