MythTV  master
audioinputalsa.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Anand K. Mistry
3  * Copyright (C) 2008 Alan Calvert
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  */
20 
21 #ifndef AUDIOINPUTALSA_H
22 #define AUDIOINPUTALSA_H
23 
24 #include "audioinput.h"
25 
26 #ifdef USING_ALSA
27 #include <alsa/asoundlib.h>
28 #else
29 using snd_pcm_t = int;
30 using snd_pcm_uframes_t = int;
31 #endif // USING_ALSA
32 
33 class AudioInputALSA : public AudioInput
34 {
35  public:
36  explicit AudioInputALSA(const QString &device)
37  : AudioInput(device)
38  , m_alsaDevice(device.right(device.size()-5).toLatin1()) {}
40 
41  bool Open(uint sample_bits, uint sample_rate, uint channels) override; // AudioInput
42  inline bool IsOpen(void) override // AudioInput
43  { return (m_pcmHandle != nullptr); }
44  void Close(void) override; // AudioInput
45 
46  bool Start(void) override // AudioInput
47  { return (m_pcmHandle != nullptr); }
48  bool Stop(void) override; // AudioInput
49 
50  inline int GetBlockSize(void) override // AudioInput
51  { return m_mythBlockBytes; }
52  int GetSamples(void* buf, uint nbytes) override; // AudioInput
53  int GetNumReadyBytes(void) override; // AudioInput
54 
55  private:
56  bool PrepHwParams(void);
57  bool PrepSwParams(void);
58  int PcmRead(void* buf, uint nbytes);
59  bool Recovery(int err);
60  bool AlsaBad(int op_result, const QString& errmsg);
61 
62  QByteArray m_alsaDevice;
63  snd_pcm_t* m_pcmHandle {nullptr};
64  snd_pcm_uframes_t m_periodSize {0};
66 };
67 #endif /* AUDIOINPUTALSA_H */
68 /* vim: set expandtab tabstop=4 shiftwidth=4: */
69 
AudioInputALSA::m_periodSize
snd_pcm_uframes_t m_periodSize
Definition: audioinputalsa.h:64
AudioInputALSA::PrepSwParams
bool PrepSwParams(void)
Definition: audioinputalsa.cpp:215
AudioInputALSA::Recovery
bool Recovery(int err)
Definition: audioinputalsa.cpp:300
AudioInputALSA::IsOpen
bool IsOpen(void) override
Definition: audioinputalsa.h:42
AudioInputALSA::GetBlockSize
int GetBlockSize(void) override
Definition: audioinputalsa.h:50
AudioInput
Definition: audioinput.h:27
AudioInputALSA::m_mythBlockBytes
int m_mythBlockBytes
Definition: audioinputalsa.h:65
AudioInputALSA::m_pcmHandle
snd_pcm_t * m_pcmHandle
Definition: audioinputalsa.h:63
AudioInputALSA::PcmRead
int PcmRead(void *buf, uint nbytes)
Definition: audioinputalsa.cpp:240
AudioInputALSA::AudioInputALSA
AudioInputALSA(const QString &device)
Definition: audioinputalsa.h:36
AudioInputALSA::GetSamples
int GetSamples(void *buf, uint nbytes) override
Definition: audioinputalsa.cpp:79
AudioInputALSA::GetNumReadyBytes
int GetNumReadyBytes(void) override
Definition: audioinputalsa.cpp:113
AudioInputALSA::Stop
bool Stop(void) override
Definition: audioinputalsa.cpp:67
uint
unsigned int uint
Definition: compat.h:79
AudioInputALSA::~AudioInputALSA
~AudioInputALSA() override
Definition: audioinputalsa.h:39
AudioInputALSA::PrepHwParams
bool PrepHwParams(void)
Definition: audioinputalsa.cpp:133
AudioInputALSA::AlsaBad
bool AlsaBad(int op_result, const QString &errmsg)
Definition: audioinputalsa.cpp:336
AudioInputALSA::Close
void Close(void) override
Definition: audioinputalsa.cpp:57
AudioInputALSA
Definition: audioinputalsa.h:33
AudioInputALSA::Start
bool Start(void) override
Definition: audioinputalsa.h:46
AudioInputALSA::m_alsaDevice
QByteArray m_alsaDevice
Definition: audioinputalsa.h:62
audioinput.h
AudioInputALSA::Open
bool Open(uint sample_bits, uint sample_rate, uint channels) override
Definition: audioinputalsa.cpp:28