summaryrefslogtreecommitdiffstats
path: root/src/AlsaInput.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-03-09 16:07:01 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-03-09 16:07:01 +0100
commit9f0159f2327b29dda47735fd69aaf5ce2da20d91 (patch)
tree6eebe0cd2862dc502b501c07fda5e2127890b6f8 /src/AlsaInput.h
parent8e34d9a78752f3a7d8d49adbb219f51da4b2702e (diff)
downloadfdk-aac-9f0159f2327b29dda47735fd69aaf5ce2da20d91.tar.gz
fdk-aac-9f0159f2327b29dda47735fd69aaf5ce2da20d91.tar.bz2
fdk-aac-9f0159f2327b29dda47735fd69aaf5ce2da20d91.zip
Split AlsaInput into two variants (Threaded/Direct)
Diffstat (limited to 'src/AlsaInput.h')
-rw-r--r--src/AlsaInput.h83
1 files changed, 64 insertions, 19 deletions
diff --git a/src/AlsaInput.h b/src/AlsaInput.h
index c1e3e9b..eb02ec1 100644
--- a/src/AlsaInput.h
+++ b/src/AlsaInput.h
@@ -40,22 +40,13 @@ class AlsaInput
public:
AlsaInput(const string& alsa_dev,
unsigned int channels,
- unsigned int rate,
- SampleQueue<uint8_t>& queue) :
- m_running(false),
+ unsigned int rate) :
m_alsa_dev(alsa_dev),
m_channels(channels),
m_rate(rate),
- m_queue(queue),
m_alsa_handle(NULL) { }
- ~AlsaInput()
- {
- if (m_running) {
- m_running = false;
- m_thread.interrupt();
- m_thread.join();
- }
+ ~AlsaInput() {
if (m_alsa_handle) {
snd_pcm_abort(m_alsa_handle);
@@ -63,26 +54,80 @@ class AlsaInput
}
}
+ /* Prepare the audio input */
int prepare();
- void start();
+ virtual void start() = 0;
+
+ protected:
+ size_t m_read(uint8_t* buf, snd_pcm_uframes_t length);
+
+ string m_alsa_dev;
+ unsigned int m_channels;
+ unsigned int m_rate;
+
+ snd_pcm_t *m_alsa_handle;
private:
- AlsaInput(const AlsaInput& other) : m_queue(other.m_queue) {}
+ AlsaInput(const AlsaInput& other) {}
+};
+
+class AlsaInputDirect : public AlsaInput
+{
+ public:
+ AlsaInputDirect(const string& alsa_dev,
+ unsigned int channels,
+ unsigned int rate) :
+ AlsaInput(alsa_dev, channels, rate) { }
+
+ virtual void start() { };
+
+ /* Read length Bytes from from the alsa device.
+ * length must be a multiple of channels * bytes_per_sample.
+ *
+ * Returns the number of bytes read.
+ */
+ size_t read(uint8_t* buf, size_t length);
+
+ private:
+ AlsaInputDirect(const AlsaInputDirect& other) :
+ AlsaInput("", 0, 0) { }
+};
+
+class AlsaInputThreaded : public AlsaInput
+{
+ public:
+ AlsaInputThreaded(const string& alsa_dev,
+ unsigned int channels,
+ unsigned int rate,
+ SampleQueue<uint8_t>& queue) :
+ AlsaInput(alsa_dev, channels, rate),
+ m_running(false),
+ m_queue(queue) { }
+
+ ~AlsaInputThreaded()
+ {
+ if (m_running) {
+ m_running = false;
+ m_thread.interrupt();
+ m_thread.join();
+ }
+ }
+
+ virtual void start();
+
+ private:
+ AlsaInputThreaded(const AlsaInputThreaded& other) :
+ AlsaInput("", 0, 0),
+ m_queue(other.m_queue) {}
- size_t read(uint8_t* buf, snd_pcm_uframes_t length);
void process();
bool m_running;
boost::thread m_thread;
- string m_alsa_dev;
- unsigned int m_channels;
- unsigned int m_rate;
SampleQueue<uint8_t>& m_queue;
- snd_pcm_t *m_alsa_handle;
-
};
#endif