MythTV  master
audiooutputalsa.h
Go to the documentation of this file.
1 #ifndef AUDIOOUTPUTALSA
2 #define AUDIOOUTPUTALSA
3 
4 #define ALSA_PCM_NEW_HW_PARAMS_API
5 #define ALSA_PCM_NEW_SW_PARAMS_API
6 #include <alsa/asoundlib.h>
7 
8 #include <QMap>
9 
10 #include "audiooutputbase.h"
11 
13 {
14  public:
15  explicit AudioOutputALSA(const AudioSettings &settings);
16  ~AudioOutputALSA() override;
17 
18  // Volume control
19  int GetVolumeChannel(int channel) const override; // VolumeBase
20  void SetVolumeChannel(int channel, int volume) override; // VolumeBase
21  static QMap<QString, QString> *GetDevices(const char *type);
22 
23  protected:
24  // You need to implement the following functions
25  bool OpenDevice(void) override; // AudioOutputBase
26  void CloseDevice(void) override; // AudioOutputBase
27  void WriteAudio(unsigned char *aubuf, int size) override; // AudioOutputBase
28  int GetBufferedOnSoundcard(void) const override; // AudioOutputBase
29  AudioOutputSettings* GetOutputSettings(bool passthrough) override; // AudioOutputBase
30 
31  private:
32  int TryOpenDevice(int open_mode, bool try_ac3);
33  int GetPCMInfo(int &card, int &device, int &subdevice);
34  bool IncPreallocBufferSize(int requested, int buffer_time);
35  inline int SetParameters(snd_pcm_t *handle, snd_pcm_format_t format,
36  uint channels, uint rate, uint buffer_time,
37  uint period_time);
38  static QByteArray *GetELD(int card, int device, int subdevice);
39  // Volume related
40  bool OpenMixer(void);
41 
42  private:
43  snd_pcm_t *m_pcmHandle {nullptr};
44  int m_pbufSize {-1};
45  int m_card {-1};
46  int m_device {-1};
47  int m_subdevice {-1};
49  QString m_lastDevice;
50 
51  struct {
52  QString device;
53  QString control;
54  snd_mixer_t* handle { nullptr };
55  snd_mixer_elem_t* elem { nullptr };
56  long volmin { 0L };
57  long volmax { 0L };
58  long volrange { 0L };
59  } m_mixer;
60 
61 };
62 #endif
AudioOutputALSA::elem
snd_mixer_elem_t * elem
Definition: audiooutputalsa.h:55
AudioOutputALSA::WriteAudio
void WriteAudio(unsigned char *aubuf, int size) override
Definition: audiooutputalsa.cpp:545
AudioOutputALSA::~AudioOutputALSA
~AudioOutputALSA() override
Definition: audiooutputalsa.cpp:99
AudioOutputALSA::SetParameters
int SetParameters(snd_pcm_t *handle, snd_pcm_format_t format, uint channels, uint rate, uint buffer_time, uint period_time)
Set the various ALSA audio parameters.
Definition: audiooutputalsa.cpp:655
AudioOutputALSA
Definition: audiooutputalsa.h:12
AudioOutputALSA::GetOutputSettings
AudioOutputSettings * GetOutputSettings(bool passthrough) override
Definition: audiooutputalsa.cpp:315
AudioOutputALSA::CloseDevice
void CloseDevice(void) override
Definition: audiooutputalsa.cpp:499
AudioOutputALSA::GetPCMInfo
int GetPCMInfo(int &card, int &device, int &subdevice)
Definition: audiooutputalsa.cpp:139
AudioOutputALSA::OpenDevice
bool OpenDevice(void) override
Definition: audiooutputalsa.cpp:448
AudioOutputALSA::GetDevices
static QMap< QString, QString > * GetDevices(const char *type)
Definition: audiooutputalsa.cpp:986
AudioOutputALSA::IncPreallocBufferSize
bool IncPreallocBufferSize(int requested, int buffer_time)
Definition: audiooutputalsa.cpp:179
AudioOutputALSA::volrange
long volrange
Definition: audiooutputalsa.h:58
AudioSettings
Definition: audiosettings.h:28
AudioOutputALSA::m_mixer
struct AudioOutputALSA::@0 m_mixer
AudioOutputBase
Definition: audiooutputbase.h:49
AudioOutputALSA::GetBufferedOnSoundcard
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
Definition: audiooutputalsa.cpp:629
AudioOutputALSA::SetVolumeChannel
void SetVolumeChannel(int channel, int volume) override
Definition: audiooutputalsa.cpp:860
AudioOutputALSA::OpenMixer
bool OpenMixer(void)
Definition: audiooutputalsa.cpp:881
uint
unsigned int uint
Definition: compat.h:140
AudioOutputALSA::handle
snd_mixer_t * handle
Definition: audiooutputalsa.h:54
AudioOutputALSA::device
QString device
Definition: audiooutputalsa.h:52
AudioOutputALSA::m_device
int m_device
Definition: audiooutputalsa.h:46
AudioOutputALSA::TryOpenDevice
int TryOpenDevice(int open_mode, bool try_ac3)
Definition: audiooutputalsa.cpp:104
audiooutputbase.h
AudioOutputALSA::m_killAudioLock
QMutex m_killAudioLock
Definition: audiooutputalsa.h:48
AudioOutputALSA::control
QString control
Definition: audiooutputalsa.h:53
AudioOutputALSA::AudioOutputALSA
AudioOutputALSA(const AudioSettings &settings)
Definition: audiooutputalsa.cpp:31
AudioOutputALSA::m_pcmHandle
snd_pcm_t * m_pcmHandle
Definition: audiooutputalsa.h:43
AudioOutputALSA::m_pbufSize
int m_pbufSize
Definition: audiooutputalsa.h:44
AudioOutputALSA::m_subdevice
int m_subdevice
Definition: audiooutputalsa.h:47
AudioOutputALSA::GetVolumeChannel
int GetVolumeChannel(int channel) const override
Definition: audiooutputalsa.cpp:827
AudioOutputSettings
Definition: audiooutputsettings.h:49
AudioOutputALSA::volmax
long volmax
Definition: audiooutputalsa.h:57
AudioOutputALSA::m_lastDevice
QString m_lastDevice
Definition: audiooutputalsa.h:49
AudioOutputALSA::m_card
int m_card
Definition: audiooutputalsa.h:45
AudioOutputALSA::GetELD
static QByteArray * GetELD(int card, int device, int subdevice)
Definition: audiooutputalsa.cpp:237
AudioOutputALSA::volmin
long volmin
Definition: audiooutputalsa.h:56