diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-05-22 22:09:42 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-05-22 22:09:42 +0200 |
commit | 7832f3bf3a9356112cab6ccb7faafb8256ea5271 (patch) | |
tree | 5f36e7b6aafb07132385ee4aaa8dae5149edd2d0 /src/VLCInput.cpp | |
parent | b5d910704541550fa23f14a610848402d51ba542 (diff) | |
download | ODR-AudioEnc-7832f3bf3a9356112cab6ccb7faafb8256ea5271.tar.gz ODR-AudioEnc-7832f3bf3a9356112cab6ccb7faafb8256ea5271.tar.bz2 ODR-AudioEnc-7832f3bf3a9356112cab6ccb7faafb8256ea5271.zip |
Move writing ICY Text to a separate async task
Diffstat (limited to 'src/VLCInput.cpp')
-rw-r--r-- | src/VLCInput.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/VLCInput.cpp b/src/VLCInput.cpp index 70381fb..3a2e9ec 100644 --- a/src/VLCInput.cpp +++ b/src/VLCInput.cpp @@ -20,6 +20,7 @@ #include <string> #include <cstring> #include <chrono> +#include <functional> #include "VLCInput.h" @@ -294,11 +295,39 @@ ssize_t VLCInput::read(uint8_t* buf, size_t length) return read; } -void VLCInput::write_icy_text(const std::string& filename) const +bool write_icy_to_file(const std::string& text, const std::string& filename) { FILE* fd = fopen(filename.c_str(), "wb"); - fputs_unlocked(m_nowplaying.c_str(), fd); - fclose(fd); + if (fd) { + int ret = fputs(text.c_str(), fd); + fclose(fd); + + return ret >= 0; + } + + return false; +} + +void VLCInput::write_icy_text(const std::string& filename) +{ + if (icy_text_written.valid()) { + auto status = icy_text_written.wait_for(std::chrono::microseconds(1)); + if (status == std::future_status::ready) { + if (not icy_text_written.get()) { + fprintf(stderr, "Failed to write ICY Text to file!\n"); + } + } + } + + else { + if (m_nowplaying_previous != m_nowplaying) { + icy_text_written = std::async(std::launch::async, + std::bind(write_icy_to_file, m_nowplaying, filename)); + + } + + m_nowplaying_previous = m_nowplaying; + } } /* VLC up to version 2.1.0 used a different callback function signature. |