From aabba6c6b56edbd4f64913af33651a2f2a641976 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 1 May 2017 06:22:25 +0200 Subject: Ensure buffer in OutputUHD is properly filled to reduce underruns --- src/OutputUHD.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 6679e62..e835d6e 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -639,16 +639,29 @@ void UHDWorker::process() num_underflows = 0; num_late_packets = 0; + int last_num_underflows = 0; + size_t pop_prebuffering = FRAMES_MAX_SIZE; + while (uwd->running) { md.has_time_spec = false; md.time_spec = uhd::time_spec_t(0.0); struct UHDWorkerFrameData frame; etiLog.log(trace, "UHD,wait"); - uwd->frames.wait_and_pop(frame); + uwd->frames.wait_and_pop(frame, pop_prebuffering); etiLog.log(trace, "UHD,pop"); handle_frame(&frame); + + /* Ensure we fill uwd->frames after every underrun and + * at startup to reduce underrun likelihood. */ + if (last_num_underflows < num_underflows) { + pop_prebuffering = FRAMES_MAX_SIZE; + } + else { + pop_prebuffering = 1; + } + last_num_underflows = num_underflows; } } -- cgit v1.2.3