aboutsummaryrefslogtreecommitdiffstats
path: root/src/AlsaInput.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/AlsaInput.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/AlsaInput.cpp')
-rw-r--r--src/AlsaInput.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/AlsaInput.cpp b/src/AlsaInput.cpp
index af3c284..747814f 100644
--- a/src/AlsaInput.cpp
+++ b/src/AlsaInput.cpp
@@ -137,6 +137,12 @@ void AlsaInputThreaded::prepare()
}
}
+bool AlsaInputThreaded::read_source(size_t num_bytes)
+{
+ // Reading done in separate thread, no normal termination condition possible
+ return true;
+}
+
void AlsaInputThreaded::process()
{
uint8_t samplebuf[NUM_SAMPLES_PER_CALL * BYTES_PER_SAMPLE * m_channels];
@@ -158,14 +164,19 @@ void AlsaInputDirect::prepare()
m_init_alsa();
}
-ssize_t AlsaInputDirect::read(uint8_t* buf, size_t length)
+bool AlsaInputDirect::read_source(size_t num_bytes)
{
- int bytes_per_frame = m_channels * BYTES_PER_SAMPLE;
- assert(length % bytes_per_frame == 0);
+ const int bytes_per_frame = m_channels * BYTES_PER_SAMPLE;
+ assert(num_bytes % bytes_per_frame == 0);
- ssize_t read = m_read(buf, length / bytes_per_frame);
+ const size_t num_frames = num_bytes / bytes_per_frame;
+ vector<uint8_t> buf(num_bytes);
+ ssize_t ret = m_read(buf.data(), num_frames);
- return (read > 0) ? read * bytes_per_frame : read;
+ if (ret > 0) {
+ m_queue.push(buf.data(), ret * bytes_per_frame);
+ }
+ return ret == num_frames;
}
#endif // HAVE_ALSA