diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-06-24 10:48:06 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-06-24 10:48:23 +0200 |
commit | 31c8fca44d11d44b70d90721c27a77ec5a83faa1 (patch) | |
tree | bb57f0996fa866b8ea55aaca01ad198792aa6f25 /src/dabplus-enc.cpp | |
parent | 9183cd317bebe96b54a227da13d8e7c70b4ae67f (diff) | |
download | ODR-AudioEnc-31c8fca44d11d44b70d90721c27a77ec5a83faa1.tar.gz ODR-AudioEnc-31c8fca44d11d44b70d90721c27a77ec5a83faa1.tar.bz2 ODR-AudioEnc-31c8fca44d11d44b70d90721c27a77ec5a83faa1.zip |
Add blocking sample queue and adapt VLC input
Diffstat (limited to 'src/dabplus-enc.cpp')
-rw-r--r-- | src/dabplus-enc.cpp | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/src/dabplus-enc.cpp b/src/dabplus-enc.cpp index 0385930..5b2b403 100644 --- a/src/dabplus-enc.cpp +++ b/src/dabplus-enc.cpp @@ -750,8 +750,7 @@ int main(int argc, char *argv[]) JackInput jack_in(jack_name, channels, sample_rate, queue); #endif #if HAVE_VLC - VLCInputDirect vlc_in_direct(vlc_uri, sample_rate, channels, verbosity, vlc_gain, vlc_cache, vlc_additional_opts); - VLCInputThreaded vlc_in_threaded(vlc_uri, sample_rate, channels, verbosity, vlc_gain, vlc_cache, vlc_additional_opts, queue); + VLCInput vlc_input(vlc_uri, sample_rate, channels, verbosity, vlc_gain, vlc_cache, vlc_additional_opts, queue); #endif if (infile) { @@ -770,21 +769,13 @@ int main(int argc, char *argv[]) #endif #if HAVE_VLC else if (vlc_uri != "") { - if (drift_compensation) { - if (vlc_in_threaded.prepare() != 0) { - fprintf(stderr, "VLC with drift compensation: preparation failed\n"); - return 1; - } - - fprintf(stderr, "Start VLC thread\n"); - vlc_in_threaded.start(); - } - else { - if (vlc_in_direct.prepare() != 0) { - fprintf(stderr, "VLC preparation failed\n"); - return 1; - } + if (vlc_input.prepare() != 0) { + fprintf(stderr, "VLC with drift compensation: preparation failed\n"); + return 1; } + + fprintf(stderr, "Start VLC thread\n"); + vlc_input.start(); } #endif #if HAVE_ALSA @@ -896,17 +887,14 @@ int main(int argc, char *argv[]) } #if HAVE_VLC else if (not vlc_uri.empty()) { - VLCInput* vlc_in = nullptr; - - if (drift_compensation) { - vlc_in = &vlc_in_threaded; - if (drift_compensation && vlc_in_threaded.fault_detected()) { - fprintf(stderr, "Detected fault in VLC input!\n"); - retval = 5; - break; - } + if (drift_compensation && vlc_input.fault_detected()) { + fprintf(stderr, "Detected fault in VLC input!\n"); + retval = 5; + break; + } + if (drift_compensation) { size_t overruns; size_t bytes_from_queue = queue.pop(&input_buf[0], input_buf.size(), &overruns); // returns bytes read_bytes = input_buf.size(); @@ -921,21 +909,20 @@ int main(int argc, char *argv[]) } } else { - vlc_in = &vlc_in_direct; + const int timeout_ms = 1000; + read_bytes = input_buf.size(); + size_t bytes_from_queue = queue.pop_wait(&input_buf[0], read_bytes, timeout_ms); // returns bytes - read_bytes = vlc_in_direct.read(&input_buf[0], input_buf.size()); - if (read_bytes < 0) { - fprintf(stderr, "Detected fault in VLC input!\n"); - break; - } - else if (read_bytes != input_buf.size()) { - fprintf(stderr, "Short VLC read !\n"); + if (bytes_from_queue < read_bytes) { + // queue timeout occurred + fprintf(stderr, "Detected fault in VLC input! No data in time.\n"); + retval = 5; break; } } if (not vlc_icytext_file.empty()) { - vlc_in->write_icy_text(vlc_icytext_file, vlc_icytext_dlplus); + vlc_input.write_icy_text(vlc_icytext_file, vlc_icytext_dlplus); } } #endif |