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  QString 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_sampleSpec {};
65  pa_channel_map m_channelMap {};
66  pa_cvolume m_volumeControl {};
67  pa_buffer_attr m_bufferSettings {};
69 };
70 #endif
71 
72 /* vim: set expandtab tabstop=4 shiftwidth=4: */
AudioOutputPulseAudio::AudioOutputPulseAudio
AudioOutputPulseAudio(const AudioSettings &settings)
Definition: audiooutputpulse.cpp:33
AudioOutputPulseAudio::SinkInfoCallback
static void SinkInfoCallback(pa_context *c, const pa_sink_info *info, int eol, void *arg)
Definition: audiooutputpulse.cpp:673
AudioOutputPulseAudio::m_volumeControl
pa_cvolume m_volumeControl
Definition: audiooutputpulse.h:66
AudioOutputPulseAudio::m_channelMap
pa_channel_map m_channelMap
Definition: audiooutputpulse.h:65
AudioOutputPulseAudio::BufferFlowCallback
static void BufferFlowCallback(pa_stream *s, void *tag)
Definition: audiooutputpulse.cpp:643
AudioOutputPulseAudio::WriteCallback
static void WriteCallback(pa_stream *s, size_t size, void *arg)
Definition: audiooutputpulse.cpp:637
AudioOutputPulseAudio::m_pstream
pa_stream * m_pstream
Definition: audiooutputpulse.h:62
AudioOutputPulseAudio::m_sampleSpec
pa_sample_spec m_sampleSpec
Definition: audiooutputpulse.h:64
AudioOutputPulseAudio::ChooseHost
QString ChooseHost(void)
Definition: audiooutputpulse.cpp:471
AudioOutputPulseAudio::GetVolumeChannel
int GetVolumeChannel(int channel) const override
Definition: audiooutputpulse.cpp:315
AudioOutputPulseAudio
Definition: audiooutputpulse.h:27
AudioOutputPulseAudio::FlushStream
void FlushStream(const char *caller)
Definition: audiooutputpulse.cpp:591
AudioOutputPulseAudio::m_pcontext
pa_context * m_pcontext
Definition: audiooutputpulse.h:61
AudioOutputPulseAudio::GetOutputSettings
AudioOutputSettings * GetOutputSettings(bool digital) override
Definition: audiooutputpulse.cpp:55
AudioOutputPulseAudio::StreamStateCallback
static void StreamStateCallback(pa_stream *s, void *arg)
Definition: audiooutputpulse.cpp:621
AudioOutputPulseAudio::OpCompletionCallback
static void OpCompletionCallback(pa_context *c, int ok, void *arg)
Definition: audiooutputpulse.cpp:648
AudioSettings
Definition: audiosettings.h:28
AudioOutputBase
Definition: audiooutputbase.h:49
AudioOutputPulseAudio::SetVolumeChannel
void SetVolumeChannel(int channel, int volume) override
Definition: audiooutputpulse.cpp:321
AudioOutputPulseAudio::m_aoSettings
AudioOutputSettings * m_aoSettings
Definition: audiooutputpulse.h:68
AudioOutputPulseAudio::ConnectPlaybackStream
bool ConnectPlaybackStream(void)
Definition: audiooutputpulse.cpp:498
AudioOutputPulseAudio::ServerInfoCallback
static void ServerInfoCallback(pa_context *context, const pa_server_info *inf, void *arg)
Definition: audiooutputpulse.cpp:661
AudioOutputPulseAudio::m_bufferSettings
pa_buffer_attr m_bufferSettings
Definition: audiooutputpulse.h:67
AudioOutputPulseAudio::OpenDevice
bool OpenDevice(void) override
Definition: audiooutputpulse.cpp:122
AudioOutputPulseAudio::ContextConnect
bool ContextConnect(void)
Definition: audiooutputpulse.cpp:395
AudioOutputPulseAudio::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: audiooutputpulse.cpp:282
AudioOutputPulseAudio::WriteAudio
void WriteAudio(unsigned char *aubuf, int size) override
Definition: audiooutputpulse.cpp:222
AudioOutputPulseAudio::CloseDevice
void CloseDevice(void) override
Definition: audiooutputpulse.cpp:193
audiooutputbase.h
AudioOutputSettings
Definition: audiooutputsettings.h:49
AudioOutputPulseAudio::ContextStateCallback
static void ContextStateCallback(pa_context *c, void *arg)
Definition: audiooutputpulse.cpp:603
AudioOutputPulseAudio::~AudioOutputPulseAudio
~AudioOutputPulseAudio() override
Definition: audiooutputpulse.cpp:45
AudioOutputPulseAudio::Drain
void Drain(void) override
Block until all available frames have been written to the device.
Definition: audiooutputpulse.cpp:382
AudioOutputPulseAudio::m_mainloop
pa_threaded_mainloop * m_mainloop
Definition: audiooutputpulse.h:63
AudioOutputPulseAudio::MapChannels
bool MapChannels(void)