diff --git a/src/zm_decoder_thread.cpp b/src/zm_decoder_thread.cpp index d32a578c7..0ffeadfc5 100644 --- a/src/zm_decoder_thread.cpp +++ b/src/zm_decoder_thread.cpp @@ -22,6 +22,13 @@ void DecoderThread::Run() { Debug(2, "DecoderThread::Run() for %d", monitor_->Id()); while (!(terminate_ or zm_terminate)) { - monitor_->Decode(); + if (!monitor_->Decode()) { + if (!(terminate_ or zm_terminate)) { + // We only sleep when Decode returns false because it is an error condition and we will spin like mad if it persists. + Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE); + Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count())); + std::this_thread::sleep_for(sleep_for); + } + } } }