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  QByteArray *GetELD(int card, int device, int subdevice);
39  // Volume related
40  bool OpenMixer(void);
41 
42  private:
43  snd_pcm_t *m_pcm_handle {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;
55  snd_mixer_elem_t* elem;
56  long volmin;
57  long volmax;
58  long volrange;
59  } m_mixer;
60 
61 };
62 #endif
bool IncPreallocBufferSize(int requested, int buffer_time)
struct AudioOutputALSA::@0 m_mixer
AudioOutputALSA(const AudioSettings &settings)
void SetVolumeChannel(int channel, int volume) override
~AudioOutputALSA() override
static QMap< QString, QString > * GetDevices(const char *type)
void CloseDevice(void) override
unsigned int uint
Definition: compat.h:140
AudioOutputSettings * GetOutputSettings(bool passthrough) override
snd_mixer_elem_t * elem
int GetVolumeChannel(int channel) const override
bool OpenDevice(void) override
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
QByteArray * GetELD(int card, int device, int subdevice)
int GetPCMInfo(int &card, int &device, int &subdevice)
int TryOpenDevice(int open_mode, bool try_ac3)
snd_pcm_t * m_pcm_handle
snd_mixer_t * handle
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.
void WriteAudio(unsigned char *aubuf, int size) override