diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/AlsaInput.cpp | 2 | ||||
-rw-r--r-- | src/AlsaInput.h | 10 | ||||
-rw-r--r-- | src/SampleQueue.h | 20 | ||||
-rw-r--r-- | src/VLCInput.cpp | 39 | ||||
-rw-r--r-- | src/VLCInput.h | 5 |
5 files changed, 40 insertions, 36 deletions
diff --git a/src/AlsaInput.cpp b/src/AlsaInput.cpp index 4b0da93..492ff62 100644 --- a/src/AlsaInput.cpp +++ b/src/AlsaInput.cpp @@ -128,7 +128,7 @@ void AlsaInputThreaded::start() } else { m_running = true; - m_thread = boost::thread(&AlsaInputThreaded::process, this); + m_thread = std::thread(&AlsaInputThreaded::process, this); } } diff --git a/src/AlsaInput.h b/src/AlsaInput.h index bd3a800..4f63ab5 100644 --- a/src/AlsaInput.h +++ b/src/AlsaInput.h @@ -21,9 +21,10 @@ #define __ALSA_H_ #include <cstdio> #include <string> +#include <thread> +#include <atomic> #include <alsa/asoundlib.h> -#include <boost/thread/thread.hpp> #include "SampleQueue.h" @@ -107,7 +108,6 @@ class AlsaInputThreaded : public AlsaInput { if (m_running) { m_running = false; - m_thread.interrupt(); m_thread.join(); } } @@ -124,9 +124,9 @@ class AlsaInputThreaded : public AlsaInput void process(); - bool m_fault; - bool m_running; - boost::thread m_thread; + std::atomic<bool> m_fault; + std::atomic<bool> m_running; + std::thread m_thread; SampleQueue<uint8_t>& m_queue; diff --git a/src/SampleQueue.h b/src/SampleQueue.h index 778526e..2df1934 100644 --- a/src/SampleQueue.h +++ b/src/SampleQueue.h @@ -1,8 +1,8 @@ /* - Copyright (C) 2013, 2014 + Copyright (C) 2013, 2014, 2015 Matthias P. Braendli, matthias.braendli@mpb.li - An implementation for a threadsafe queue using boost thread library + An implementation for a threadsafe queue using the C++11 thread library for audio samples. */ @@ -11,10 +11,12 @@ #define DEBUG_SAMPLE_QUEUE 0 -#include <boost/thread.hpp> +#include <mutex> #include <queue> - -#include <stdio.h> +#include <cassert> +#include <sstream> +#include <cstdio> +#include <cmath> /* This queue is meant to be used by two threads. One producer * that pushes elements into the queue, and one consumer that @@ -53,7 +55,7 @@ public: /* Push a bunch of samples into the buffer */ size_t push(const T *val, size_t len) { - boost::mutex::scoped_lock lock(m_mutex); + std::lock_guard<std::mutex> lock(m_mutex); assert(len % (m_channels * m_bytes_per_sample) == 0); @@ -81,7 +83,7 @@ public: size_t size() const { - boost::mutex::scoped_lock lock(m_mutex); + std::lock_guard<std::mutex> lock(m_mutex); return m_queue.size(); } @@ -103,7 +105,7 @@ public: */ size_t pop(T* buf, size_t len, size_t* overruns) { - boost::mutex::scoped_lock lock(m_mutex); + std::lock_guard<std::mutex> lock(m_mutex); assert(len % (m_channels * m_bytes_per_sample) == 0); @@ -163,7 +165,7 @@ public: private: std::deque<T> m_queue; - mutable boost::mutex m_mutex; + mutable std::mutex m_mutex; unsigned int m_channels; unsigned int m_bytes_per_sample; diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index d7b691f..5115c53 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -18,6 +18,7 @@ #include <cstdio> #include <string> +#include <chrono> #include "VLCInput.h" @@ -26,7 +27,6 @@ #if HAVE_VLC #include <sys/time.h> -#include <boost/date_time/posix_time/posix_time.hpp> using namespace std; @@ -124,7 +124,7 @@ int VLCInput::prepare() for (int timeout = 0; timeout < 100; timeout++) { st = libvlc_media_get_state(media); - boost::this_thread::sleep(boost::posix_time::milliseconds(10)); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); if (st != libvlc_NothingSpecial) { ret = 0; break; @@ -140,22 +140,23 @@ void VLCInput::preRender_cb(uint8_t** pp_pcm_buffer, size_t size) const size_t max_length = 20 * size; for (;;) { - boost::mutex::scoped_lock lock(m_queue_mutex); + { + std::lock_guard<std::mutex> lock(m_queue_mutex); - if (m_queue.size() < max_length) { - m_current_buf.resize(size); - *pp_pcm_buffer = &m_current_buf[0]; - return; + 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)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } void VLCInput::exit_cb() { - boost::mutex::scoped_lock lock(m_queue_mutex); + std::lock_guard<std::mutex> lock(m_queue_mutex); fprintf(stderr, "VLC exit, restarting...\n"); @@ -182,7 +183,7 @@ void VLCInput::cleanup() void VLCInput::postRender_cb() { - boost::mutex::scoped_lock lock(m_queue_mutex); + std::lock_guard<std::mutex> lock(m_queue_mutex); size_t queue_size = m_queue.size(); m_queue.resize(m_queue.size() + m_current_buf.size()); @@ -194,18 +195,18 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) { ssize_t err = 0; for (;;) { - boost::mutex::scoped_lock lock(m_queue_mutex); + { + std::lock_guard<std::mutex> lock(m_queue_mutex); - if (m_queue.size() >= length) { - std::copy(m_queue.begin(), m_queue.begin() + length, buf); + if (m_queue.size() >= length) { + std::copy(m_queue.begin(), m_queue.begin() + length, buf); - m_queue.erase(m_queue.begin(), m_queue.begin() + length); + m_queue.erase(m_queue.begin(), m_queue.begin() + length); - return length; + return length; + } } - - lock.unlock(); - boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); libvlc_media_t *media = libvlc_media_player_get_media(m_mp); libvlc_state_t st = libvlc_media_get_state(media); diff --git a/src/VLCInput.h b/src/VLCInput.h index ec7c80e..048c931 100644 --- a/src/VLCInput.h +++ b/src/VLCInput.h @@ -27,9 +27,10 @@ #include <string> #include <vector> #include <deque> +#include <thread> +#include <mutex> #include <vlc/vlc.h> -#include <boost/thread/thread.hpp> #include "SampleQueue.h" @@ -93,7 +94,7 @@ class VLCInput std::vector<uint8_t> m_current_buf; - boost::mutex m_queue_mutex; + mutable std::mutex m_queue_mutex; std::deque<uint8_t> m_queue; std::string m_uri; |