MythTV  master
audiooutputpulse.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Alan Calvert
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 #ifndef AUDIOOUTPUTPULSE
21 #define AUDIOOUTPUTPULSE
22 
23 #include <pulse/pulseaudio.h>
24 
25 #include "audiooutputbase.h"
26 
28 {
29  public:
30  explicit AudioOutputPulseAudio(const AudioSettings &settings);
31  ~AudioOutputPulseAudio() override;
32 
33  int GetVolumeChannel(int channel) const override; // VolumeBase
34  void SetVolumeChannel(int channel, int volume) override; // VolumeBase
35  void Drain(void) override; // AudioOutputBase
36 
37  protected:
38  AudioOutputSettings* GetOutputSettings(bool digital) override; // AudioOutputBase
39  bool OpenDevice(void) override; // AudioOutputBase
40  void CloseDevice(void) override; // AudioOutputBase
41  void WriteAudio(unsigned char *aubuf, int size) override; // AudioOutputBase
42  int GetBufferedOnSoundcard(void) const override; // AudioOutputBase
43 
44  private:
45  char *ChooseHost(void);
46  bool MapChannels(void);
47  bool ContextConnect(void);
48  bool ConnectPlaybackStream(void);
49  void FlushStream(const char *caller);
50 
51  static void ContextStateCallback(pa_context *c, void *arg);
52  static void StreamStateCallback(pa_stream *s, void *arg);
53  static void OpCompletionCallback(pa_context *c, int ok, void *arg);
54  static void WriteCallback(pa_stream *s, size_t size, void *arg);
55  static void BufferFlowCallback(pa_stream *s, void *tag);
56  static void ServerInfoCallback(pa_context *context,
57  const pa_server_info *inf, void *arg);
58  static void SinkInfoCallback(pa_context *c, const pa_sink_info *info,
59  int eol, void *arg);
60 
61  pa_context *m_pcontext {nullptr};
62  pa_stream *m_pstream {nullptr};
63  pa_threaded_mainloop *m_mainloop {nullptr};
64  pa_sample_spec m_sample_spec {};
65  pa_channel_map m_channel_map {};
66  pa_cvolume m_volume_control {};
67  pa_buffer_attr m_buffer_settings {};
69 };
70 #endif
71 
72 /* vim: set expandtab tabstop=4 shiftwidth=4: */
static void ContextStateCallback(pa_context *c, void *arg)
static void WriteCallback(pa_stream *s, size_t size, void *arg)
static bool eol(char p)
AudioOutputSettings * GetOutputSettings(bool digital) override
int GetVolumeChannel(int channel) const override
void FlushStream(const char *caller)
AudioOutputPulseAudio(const AudioSettings &settings)
static void SinkInfoCallback(pa_context *c, const pa_sink_info *info, int eol, void *arg)
pa_threaded_mainloop * m_mainloop
AudioOutputSettings * m_aosettings
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...
static void OpCompletionCallback(pa_context *c, int ok, void *arg)
static void ServerInfoCallback(pa_context *context, const pa_server_info *inf, void *arg)
static void BufferFlowCallback(pa_stream *s, void *tag)
pa_buffer_attr m_buffer_settings
static void StreamStateCallback(pa_stream *s, void *arg)
void SetVolumeChannel(int channel, int volume) override
void WriteAudio(unsigned char *aubuf, int size) override
void CloseDevice(void) override
pa_sample_spec m_sample_spec
void Drain(void) override
Block until all available frames have been written to the device.
pa_channel_map m_channel_map