From 84febca8b268129cdd79ff0d1c4f8eeed092c5fb Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 7 Oct 2017 11:47:05 +0200 Subject: Use queue for all inputs and unify interface This also changes the --fifo-silence option. Instead of inserting silence separately, it uses the drift compensation to do that. --- src/FileInput.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'src/FileInput.cpp') diff --git a/src/FileInput.cpp b/src/FileInput.cpp index 89e1dab..5eb39ee 100644 --- a/src/FileInput.cpp +++ b/src/FileInput.cpp @@ -84,31 +84,44 @@ void FileInput::prepare(void) } } -ssize_t FileInput::read(uint8_t* buf, size_t length) +bool FileInput::read_source(size_t num_bytes) { - ssize_t pcmread; + vector samplebuf(num_bytes); + + ssize_t ret = 0; if (m_raw_input) { - if (fread(buf, length, 1, m_in_fh) == 1) { - pcmread = length; - } - else { - //fprintf(stderr, "Unable to read from input!\n"); - return 0; - } + ret = fread(samplebuf.data(), 1, num_bytes, m_in_fh); } else { - pcmread = wav_read_data(m_wav, buf, length); + ret = wav_read_data(m_wav, samplebuf.data(), num_bytes); } - return pcmread; -} + if (ret > 0) { + m_queue.push(samplebuf.data(), ret); + } -int FileInput::eof() -{ - int eof = feof(m_in_fh); - clearerr(m_in_fh); - return eof; -} + if (ret < num_bytes) { + if (m_raw_input) { + if (ferror(m_in_fh)) { + return false; + } + + if (feof(m_in_fh)) { + if (m_continue_after_eof) { + clearerr(m_in_fh); + } + else { + return false; + } + } + } + else { + // the wavfile input doesn't support the continuation after EOF + return false; + } + } + return true; +} -- cgit v1.2.3