summaryrefslogtreecommitdiffstats
path: root/src/FileInput.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-10-07 11:47:05 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-10-07 11:51:46 +0200
commit84febca8b268129cdd79ff0d1c4f8eeed092c5fb (patch)
tree3e75880241e0fcd2951c04aad77d7077b4ec130c /src/FileInput.cpp
parent9c2615425bb4f35a417eb04b1ceebfc77d8e2c8b (diff)
downloadODR-AudioEnc-84febca8b268129cdd79ff0d1c4f8eeed092c5fb.tar.gz
ODR-AudioEnc-84febca8b268129cdd79ff0d1c4f8eeed092c5fb.tar.bz2
ODR-AudioEnc-84febca8b268129cdd79ff0d1c4f8eeed092c5fb.zip
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.
Diffstat (limited to 'src/FileInput.cpp')
-rw-r--r--src/FileInput.cpp49
1 files changed, 31 insertions, 18 deletions
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<uint8_t> 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;
+}