From a3d8608ae73e7ff1ab4fccedb24455597275d544 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 12 Mar 2015 19:04:14 +0100 Subject: Add limit on maximal buffer for VLC --- src/VLCInput.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index 555b1e1..6b7a4bb 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -111,10 +111,20 @@ int VLCInput::prepare() void VLCInput::preRender(uint8_t** pp_pcm_buffer, size_t size) { - boost::mutex::scoped_lock lock(m_queue_mutex); + const size_t max_length = 20 * size; - m_current_buf.resize(size); - *pp_pcm_buffer = &m_current_buf[0]; + for (;;) { + boost::mutex::scoped_lock lock(m_queue_mutex); + + if (m_queue.size() < max_length) { + m_current_buf.resize(size); + *pp_pcm_buffer = &m_current_buf[0]; + return; + } + + lock.unlock(); + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + } } void VLCInput::postRender(uint8_t* p_pcm_buffer, size_t size) -- cgit v1.2.3