v4l2rtspserver/inc/ALSACapture.h

69 lines
2.0 KiB
C
Raw Normal View History

2016-06-19 17:15:51 +00:00
/* ---------------------------------------------------------------------------
** This software is in the public domain, furnished "as is", without technical
** support, and with no warranty, express or implied, as to its usefulness for
** any purpose.
**
2017-07-30 17:37:39 +00:00
** ALSACapture.h
2016-06-19 17:15:51 +00:00
**
** V4L2 RTSP streamer
**
** ALSA capture overide of V4l2Capture
**
** -------------------------------------------------------------------------*/
2016-09-18 19:57:53 +00:00
#ifndef ALSA_CAPTURE
#define ALSA_CAPTURE
2018-01-20 12:11:58 +00:00
#include <list>
2016-06-19 17:15:51 +00:00
#include <alsa/asoundlib.h>
#include "logger.h"
2016-06-19 17:15:51 +00:00
2016-09-18 19:57:53 +00:00
struct ALSACaptureParameters
{
2018-01-20 12:11:58 +00:00
ALSACaptureParameters(const char* devname, const std::list<snd_pcm_format_t> & formatList, unsigned int sampleRate, unsigned int channels, int verbose) :
m_devName(devname), m_formatList(formatList), m_sampleRate(sampleRate), m_channels(channels), m_verbose(verbose) {
}
2016-09-18 19:57:53 +00:00
std::string m_devName;
2018-01-20 12:11:58 +00:00
std::list<snd_pcm_format_t> m_formatList;
unsigned int m_sampleRate;
unsigned int m_channels;
int m_verbose;
2016-09-18 19:57:53 +00:00
};
class ALSACapture
2016-06-19 17:15:51 +00:00
{
public:
2017-07-30 17:37:39 +00:00
static ALSACapture* createNew(const ALSACaptureParameters & params) ;
virtual ~ALSACapture();
void close();
2016-06-19 17:15:51 +00:00
protected:
2017-07-30 17:37:39 +00:00
ALSACapture(const ALSACaptureParameters & params);
2018-01-20 12:11:58 +00:00
int configureFormat(snd_pcm_hw_params_t *hw_params);
2016-06-19 17:15:51 +00:00
public:
2017-07-30 17:37:39 +00:00
virtual size_t read(char* buffer, size_t bufferSize);
virtual int getFd();
2016-09-18 19:57:53 +00:00
2017-06-25 14:58:37 +00:00
virtual unsigned long getBufferSize() { return m_bufferSize; };
virtual int getWidth() {return -1;}
virtual int getHeight() {return -1;}
unsigned long getSampleRate() { return m_params.m_sampleRate; };
unsigned long getChannels () { return m_params.m_channels; };
2016-06-19 17:15:51 +00:00
private:
snd_pcm_t* m_pcm;
unsigned long m_bufferSize;
unsigned long m_periodSize;
ALSACaptureParameters m_params;
2018-01-20 12:11:58 +00:00
snd_pcm_format_t m_fmt;
2016-06-19 17:15:51 +00:00
};
2016-09-18 19:57:53 +00:00
#endif