diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-07-08 09:57:33 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-07-08 09:57:33 +0200 |
commit | 561b6adce76dd209ebc547fcd98f525501742d97 (patch) | |
tree | 17f36fb2f9170b2108851e613b8b3f7100736410 /src | |
parent | 5774d9b236567767cc473a790290d41ac65e6600 (diff) | |
download | fdk-aac-dabplus-561b6adce76dd209ebc547fcd98f525501742d97.tar.gz fdk-aac-dabplus-561b6adce76dd209ebc547fcd98f525501742d97.tar.bz2 fdk-aac-dabplus-561b6adce76dd209ebc547fcd98f525501742d97.zip |
Protect m_nowplaying with mutex
Diffstat (limited to 'src')
-rw-r--r-- | src/VLCInput.cpp | 12 | ||||
-rw-r--r-- | src/VLCInput.h | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index 37ad1e0..33c4594 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -320,14 +320,22 @@ ssize_t VLCInput::m_read(uint8_t* buf, size_t length) char* nowplaying_sz = libvlc_media_get_meta(media, libvlc_meta_NowPlaying); if (nowplaying_sz) { + std::lock_guard<std::mutex> lock(m_nowplaying_mutex); m_nowplaying = nowplaying_sz; + free(nowplaying_sz); } } return err; } -bool write_icy_to_file(const std::string& text, const std::string& filename, bool dl_plus) +/* Write the corresponding text to a file readable by mot-encoder, with optional + * DL+ information. The text is passed as a copy because we actually use the m_nowplaying + * variable which is also accessed in another thread, so better make a copy. + * + * Returns false on failure + */ +bool write_icy_to_file(const std::string text, const std::string& filename, bool dl_plus) { FILE* fd = fopen(filename.c_str(), "wb"); if (fd) { @@ -368,6 +376,8 @@ void VLCInput::write_icy_text(const std::string& filename, bool dl_plus) } else { + std::lock_guard<std::mutex> lock(m_nowplaying_mutex); + if (m_nowplaying_previous != m_nowplaying) { icy_text_written = std::async(std::launch::async, std::bind(write_icy_to_file, m_nowplaying, filename, dl_plus)); diff --git a/src/VLCInput.h b/src/VLCInput.h index ad23c4d..1ea0bee 100644 --- a/src/VLCInput.h +++ b/src/VLCInput.h @@ -119,7 +119,7 @@ class VLCInput std::vector<uint8_t> m_current_buf; - mutable std::mutex m_queue_mutex; + std::mutex m_queue_mutex; std::deque<uint8_t> m_queue; std::string m_uri; @@ -138,6 +138,7 @@ class VLCInput std::future<bool> icy_text_written; + std::mutex m_nowplaying_mutex; std::string m_nowplaying; std::string m_nowplaying_previous; |