1/* ---------------------------------------------------------------------------
2** This software is in the public domain, furnished "as is", without technical
3** support, and with no warranty, express or implied, as to its usefulness for
4** any purpose.
5**
6** ALSACapture.h
7**
8** V4L2 RTSP streamer
9**
10** ALSA capture overide of V4l2Capture
11**
12** -------------------------------------------------------------------------*/
13
14#ifndef ALSA_CAPTURE
15#define ALSA_CAPTURE
16
17#include <list>
18
19#include <alsa/asoundlib.h>
20#include "logger.h"
21
22struct ALSACaptureParameters
23{
24 ALSACaptureParameters(const char* devname, const std::list<snd_pcm_format_t> & formatList, unsigned int sampleRate, unsigned int channels, int verbose) :
25 m_devName(devname), m_formatList(formatList), m_sampleRate(sampleRate), m_channels(channels), m_verbose(verbose) {
26
27 }
28
29 std::string m_devName;
30 std::list<snd_pcm_format_t> m_formatList;
31 unsigned int m_sampleRate;
32 unsigned int m_channels;
33 int m_verbose;
34};
35
36class ALSACapture
37{
38 public:
39 static ALSACapture* createNew(const ALSACaptureParameters & params) ;
40 virtual ~ALSACapture();
41 void close();
42
43 protected:
44 ALSACapture(const ALSACaptureParameters & params);
45 int configureFormat(snd_pcm_hw_params_t *hw_params);
46
47 public:
48 virtual size_t read(char* buffer, size_t bufferSize);
49 virtual int getFd();
50
51 virtual unsigned long getBufferSize() { return m_bufferSize; };
52 virtual int getWidth() {return -1;}
53 virtual int getHeight() {return -1;}
54 virtual int getCaptureFormat() {return -1;}
55
56 unsigned long getSampleRate() { return m_params.m_sampleRate; }
57 unsigned long getChannels () { return m_params.m_channels; }
58 snd_pcm_format_t getFormat () { return m_fmt; }
59
60 private:
61 snd_pcm_t* m_pcm;
62 unsigned long m_bufferSize;
63 unsigned long m_periodSize;
64 ALSACaptureParameters m_params;
65 snd_pcm_format_t m_fmt;
66};
67
68#endif
69
70
71