MythTV  master
Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
AudioOutputPulseAudio Class Reference

#include <audiooutputpulse.h>

Inheritance diagram for AudioOutputPulseAudio:
Inheritance graph
[legend]
Collaboration diagram for AudioOutputPulseAudio:
Collaboration graph
[legend]

Public Member Functions

 AudioOutputPulseAudio (const AudioSettings &settings)
 
 ~AudioOutputPulseAudio () override
 
int GetVolumeChannel (int channel) const override
 
void SetVolumeChannel (int channel, int volume) override
 
void Drain (void) override
 Block until all available frames have been written to the device. More...
 
- Public Member Functions inherited from AudioOutputBase
 AudioOutputBase (const AudioSettings &settings)
 
 ~AudioOutputBase () override
 Destructor. More...
 
AudioOutputSettingsGetOutputSettingsCleaned (bool digital=true) override
 Returns capabilities supported by the audio device amended to take into account the digital audio options (AC3, DTS, E-AC3 and TrueHD) More...
 
AudioOutputSettingsGetOutputSettingsUsers (bool digital=false) override
 Returns capabilities supported by the audio device amended to take into account the digital audio options (AC3, DTS, E-AC3 and TrueHD) as well as the user settings. More...
 
void Reconfigure (const AudioSettings &settings) override
 (Re)Configure AudioOutputBase More...
 
void SetEffDsp (int dsprate) override
 Set the effective DSP rate. More...
 
void SetStretchFactor (float factor) override
 Set the timestretch factor. More...
 
float GetStretchFactor (void) const override
 Get the timetretch factor. More...
 
int GetChannels (void) const override
 
AudioFormat GetFormat (void) const override
 
int GetBytesPerFrame (void) const override
 
bool CanPassthrough (int samplerate, int channels, AVCodecID codec, int profile) const override
 Test if we can output digital audio and if sample rate is supported. More...
 
bool CanDownmix (void) const override
 
bool IsUpmixing (void) override
 Source is currently being upmixed. More...
 
bool ToggleUpmix (void) override
 Toggle between stereo and upmixed 5.1 if the source material is stereo. More...
 
bool CanUpmix (void) override
 Upmixing of the current source is available if requested. More...
 
bool CanProcess (AudioFormat) override
 
uint32_t CanProcess (void) override
 
void Reset (void) override
 Reset the audiobuffer, timecode and mythmusic visualisation. More...
 
void SetSWVolume (int new_volume, bool save) override
 Set the volume for software volume control. More...
 
int GetSWVolume (void) override
 Get the volume for software volume control. More...
 
bool AddFrames (void *buffer, int frames, std::chrono::milliseconds timecode) override
 Add frames to the audiobuffer and perform any required processing. More...
 
bool AddData (void *buffer, int len, std::chrono::milliseconds timecode, int frames) override
 Add data to the audiobuffer and perform any required processing. More...
 
bool NeedDecodingBeforePassthrough () const override
 
std::chrono::milliseconds LengthLastData (void) const override
 
void SetTimecode (std::chrono::milliseconds timecode) override
 Set the timecode of the samples most recently added to the audiobuffer. More...
 
bool IsPaused (void) const override
 
void Pause (bool paused) override
 
void PauseUntilBuffered (void) override
 
std::chrono::milliseconds GetAudiotime (void) override
 Calculate the timecode of the samples that are about to become audible. More...
 
std::chrono::milliseconds GetAudioBufferedTime (void) override
 Get the difference in timecode between the samples that are about to become audible and the samples most recently added to the audiobuffer, i.e. More...
 
virtual void Status (void)
 Report status via an OutputEvent. More...
 
void SetSourceBitrate (int rate) override
 Set the bitrate of the source material, reported in periodic OutputEvents. More...
 
void GetBufferStatus (uint &fill, uint &total) override
 Fill in the number of bytes in the audiobuffer and the total size of the audiobuffer. More...
 
void bufferOutputData (bool y) override
 
int readOutputData (unsigned char *read_buffer, size_t max_length) override
 
- Public Member Functions inherited from AudioOutput
 AudioOutput ()=default
 
 ~AudioOutput () override
 
QString GetError (void) const
 
QString GetWarning (void) const
 
bool PulseStatus (void) const
 
virtual int DecodeAudio (AVCodecContext *ctx, uint8_t *buffer, int &data_size, const AVPacket *pkt)
 Utility routine. More...
 
- Public Member Functions inherited from VolumeBase
 VolumeBase ()
 
virtual ~VolumeBase ()=default
 
void SWVolume (bool set)
 
bool SWVolume (void) const
 
virtual uint GetCurrentVolume (void) const
 
virtual void SetCurrentVolume (int value)
 
virtual void AdjustCurrentVolume (int change)
 
virtual void ToggleMute (void)
 
virtual MuteState GetMuteState (void) const
 
virtual MuteState SetMuteState (MuteState)
 
- Public Member Functions inherited from OutputListeners
 OutputListeners ()=default
 
 ~OutputListeners () override=default
 
bool hasVisual (void)
 
void addVisual (MythTV::Visual *v)
 
void removeVisual (MythTV::Visual *v)
 
QMutex * mutex ()
 
void setBufferSize (unsigned int sz)
 
unsigned int bufferSize () const
 
- Public Member Functions inherited from MythObservable
 MythObservable ()
 
virtual ~MythObservable ()
 
void addListener (QObject *listener)
 Add a listener to the observable. More...
 
void removeListener (QObject *listener)
 Remove a listener to the observable. More...
 
void dispatch (const MythEvent &event)
 Dispatch an event to all listeners. More...
 
bool hasListeners (void)
 
- Public Member Functions inherited from MThread
 MThread (const QString &objectName)
 Standard constructor. More...
 
 MThread (const QString &objectName, QRunnable *runnable)
 Use this constructor if you want the default run() method to run the QRunnable's run() method instead of entering the Qt event loop. More...
 
virtual ~MThread ()
 
 MThread (const MThread &)=delete
 
MThreadoperator= (const MThread &)=delete
 
void RunProlog (void)
 Sets up a thread, call this if you reimplement run(). More...
 
void RunEpilog (void)
 Cleans up a thread's resources, call this if you reimplement run(). More...
 
QThread * qthread (void)
 Returns the thread, this will always return the same pointer no matter how often you restart the thread. More...
 
void setObjectName (const QString &name)
 
QString objectName (void) const
 
void setPriority (QThread::Priority priority)
 
QThread::Priority priority (void) const
 
bool isFinished (void) const
 
bool isRunning (void) const
 
void setStackSize (uint stackSize)
 
uint stackSize (void) const
 
void exit (int retcode=0)
 Use this to exit from the thread if you are using a Qt event loop. More...
 
void start (QThread::Priority p=QThread::InheritPriority)
 Tell MThread to start running the thread in the near future. More...
 
void terminate (void)
 Kill a thread unsafely. More...
 
void quit (void)
 calls exit(0) More...
 
bool wait (std::chrono::milliseconds time=std::chrono::milliseconds::max())
 Wait for the MThread to exit, with a maximum timeout. More...
 

Protected Member Functions

AudioOutputSettingsGetOutputSettings (bool digital) override
 
bool OpenDevice (void) override
 
void CloseDevice (void) override
 
void WriteAudio (unsigned char *aubuf, int size) override
 
int GetBufferedOnSoundcard (void) const override
 Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback latency. More...
 
- Protected Member Functions inherited from AudioOutputBase
void InitSettings (const AudioSettings &settings)
 
void KillAudio (void)
 Kill the output thread and cleanup. More...
 
virtual bool StartOutputThread (void)
 
virtual void StopOutputThread (void)
 
int GetAudioData (uchar *buffer, int buf_size, bool full_buffer, volatile uint *local_raud=nullptr)
 Copy frames from the audiobuffer into the buffer provided. More...
 
void OutputAudioLoop (void)
 Run in the output thread, write frames to the output device as they become available and there's space in the device buffer to write them. More...
 
void run () override
 Main routine for the output thread. More...
 
int CheckFreeSpace (int &frames)
 Check that there's enough space in the audiobuffer to write the provided number of frames. More...
 
int audiolen () const
 Get the number of bytes in the audiobuffer. More...
 
int audiofree () const
 Get the free space in the audiobuffer in bytes. More...
 
int audioready () const
 Get the scaled number of bytes in the audiobuffer, i.e. More...
 
void SetStretchFactorLocked (float factor)
 Set the timestretch factor. More...
 
std::chrono::milliseconds GetBaseAudBufTimeCode () const
 
bool usesSpdif () const
 
- Protected Member Functions inherited from AudioOutput
void Error (const QString &msg)
 
void SilentError (const QString &msg)
 
void Warn (const QString &msg)
 
void ClearError (void)
 
void ClearWarning (void)
 
- Protected Member Functions inherited from VolumeBase
void UpdateVolume (void)
 
void SyncVolume (void)
 
void SetChannels (int new_channels)
 
- Protected Member Functions inherited from OutputListeners
void error (const QString &e)
 
void dispatchVisual (uchar *b, unsigned long b_len, std::chrono::milliseconds timecode, int chan, int prec)
 
void prepareVisuals ()
 
- Protected Member Functions inherited from MThread
int exec (void)
 Enters the qt event loop. call exit or quit to exit thread. More...
 

Private Member Functions

QString ChooseHost (void)
 
bool MapChannels (void)
 
bool ContextConnect (void)
 
bool ConnectPlaybackStream (void)
 
void FlushStream (const char *caller)
 

Static Private Member Functions

static void ContextStateCallback (pa_context *c, void *arg)
 
static void StreamStateCallback (pa_stream *s, void *arg)
 
static void OpCompletionCallback (pa_context *c, int ok, void *arg)
 
static void WriteCallback (pa_stream *s, size_t size, void *arg)
 
static void BufferFlowCallback (pa_stream *s, void *tag)
 
static void ServerInfoCallback (pa_context *context, const pa_server_info *inf, void *arg)
 
static void SinkInfoCallback (pa_context *c, const pa_sink_info *info, int eol, void *arg)
 

Private Attributes

pa_context * m_pcontext {nullptr}
 
pa_stream * m_pstream {nullptr}
 
pa_threaded_mainloop * m_mainloop {nullptr}
 
pa_sample_spec m_sampleSpec {}
 
pa_channel_map m_channelMap {}
 
pa_cvolume m_volumeControl {}
 
pa_buffer_attr m_bufferSettings {}
 
AudioOutputSettingsm_aoSettings {nullptr}
 

Additional Inherited Members

- Public Types inherited from AudioOutput
using ADCVect = QVector< AudioDeviceConfig >
 
- Static Public Member Functions inherited from AudioOutputBase
static const char * quality_string (int q)
 
- Static Public Member Functions inherited from AudioOutput
static void Cleanup (void)
 
static ADCVectGetOutputList (void)
 
static AudioDeviceConfigGetAudioDeviceConfig (QString &name, const QString &desc, bool willsuspendpa=false)
 
static AudioOutputOpenAudio (const QString &main_device, const QString &passthru_device, AudioFormat format, int channels, AVCodecID codec, int samplerate, AudioOutputSource source, bool set_initial_vol, bool passthru, int upmixer_startup=0, AudioOutputSettings *custom=nullptr)
 
static AudioOutputOpenAudio (AudioSettings &settings, bool willsuspendpa=true)
 
static AudioOutputOpenAudio (const QString &main_device, const QString &passthru_device=QString(), bool willsuspendpa=true)
 
- Static Public Member Functions inherited from VolumeBase
static MuteState NextMuteState (MuteState)
 
- Static Public Member Functions inherited from MThread
static void ThreadSetup (const QString &name)
 This is to be called on startup in those few threads that haven't been ported to MThread. More...
 
static void ThreadCleanup (void)
 This is to be called on exit in those few threads that haven't been ported to MThread. More...
 
static void Cleanup (void)
 This will print out all the running threads, call exit(1) on each and then wait up to 5 seconds total for all the threads to exit. More...
 
static void GetAllThreadNames (QStringList &list)
 
static void GetAllRunningThreadNames (QStringList &list)
 
- Static Public Attributes inherited from AudioOutputBase
static const uint kAudioSRCInputSize = 16384
 
static const uint kAudioRingBufferSize = 10239936U
 Audio Buffer Size – should be divisible by 32,24,16,12,10,8,6,4,2.. More...
 
- Static Public Attributes inherited from AudioOutput
static const int kMaxSizeBuffer = 384000
 kMaxSizeBuffer is the maximum size of a buffer to be used with DecodeAudio More...
 
- Protected Types inherited from AudioOutputBase
enum  { QUALITY_DISABLED = -1, QUALITY_LOW = 0, QUALITY_MEDIUM = 1, QUALITY_HIGH = 2 }
 
- Static Protected Member Functions inherited from MThread
static void setTerminationEnabled (bool enabled=true)
 
static void usleep (std::chrono::microseconds time)
 
template<typename R , typename P >
static std::enable_if_t< std::chrono::treat_as_floating_point< R >::value, void > usleep (std::chrono::duration< R, P > time)
 
- Protected Attributes inherited from AudioOutputBase
int m_channels {-1}
 
AVCodecID m_codec {AV_CODEC_ID_NONE}
 
int m_bytesPerFrame {0}
 
int m_outputBytesPerFrame {0}
 
AudioFormat m_format {FORMAT_NONE}
 
AudioFormat m_outputFormat {FORMAT_NONE}
 
int m_sampleRate {-1}
 
int m_effDsp {0}
 
int m_fragmentSize {0}
 
long m_soundcardBufferSize {0}
 
QString m_mainDevice
 
QString m_passthruDevice
 
bool m_discreteDigital {false}
 
bool m_passthru {false}
 
bool m_enc {false}
 
bool m_reEnc {false}
 
float m_stretchFactor {1.0F}
 
int m_effStretchFactor {100000}
 
AudioOutputSource m_source
 
bool m_killAudio {false}
 
bool m_pauseAudio {false}
 
bool m_actuallyPaused {false}
 
bool m_wasPaused {false}
 
bool m_unpauseWhenReady {false}
 
bool m_setInitialVol
 
bool m_bufferOutputDataForUse {false}
 
int m_configuredChannels {0}
 
int m_maxChannels {0}
 
int m_srcQuality {QUALITY_MEDIUM}
 
long m_sourceBitRate {-1}
 
int m_sourceSampleRate {0}
 
- Protected Attributes inherited from AudioOutput
QString m_lastError
 
QString m_lastWarn
 
bool m_pulseWasSuspended {false}
 
AVFramem_frame {nullptr}
 
- Protected Attributes inherited from VolumeBase
bool m_internalVol {false}
 
- Protected Attributes inherited from MythObservable
QMutex * m_lock {nullptr}
 
QSet< QObject * > m_listeners
 
- Protected Attributes inherited from MThread
MThreadInternalm_thread {nullptr}
 
QRunnable * m_runnable {nullptr}
 
bool m_prologExecuted {true}
 
bool m_epilogExecuted {true}
 

Detailed Description

Definition at line 27 of file audiooutputpulse.h.

Constructor & Destructor Documentation

◆ AudioOutputPulseAudio()

AudioOutputPulseAudio::AudioOutputPulseAudio ( const AudioSettings settings)
explicit

Definition at line 32 of file audiooutputpulse.cpp.

◆ ~AudioOutputPulseAudio()

AudioOutputPulseAudio::~AudioOutputPulseAudio ( )
override

Definition at line 44 of file audiooutputpulse.cpp.

Member Function Documentation

◆ GetVolumeChannel()

int AudioOutputPulseAudio::GetVolumeChannel ( int  channel) const
overridevirtual

Implements VolumeBase.

Definition at line 314 of file audiooutputpulse.cpp.

◆ SetVolumeChannel()

void AudioOutputPulseAudio::SetVolumeChannel ( int  channel,
int  volume 
)
overridevirtual

Implements VolumeBase.

Definition at line 320 of file audiooutputpulse.cpp.

◆ Drain()

void AudioOutputPulseAudio::Drain ( void  )
overridevirtual

Block until all available frames have been written to the device.

Reimplemented from AudioOutputBase.

Definition at line 380 of file audiooutputpulse.cpp.

◆ GetOutputSettings()

AudioOutputSettings * AudioOutputPulseAudio::GetOutputSettings ( bool  digital)
overrideprotectedvirtual

Reimplemented from AudioOutputBase.

Definition at line 54 of file audiooutputpulse.cpp.

◆ OpenDevice()

bool AudioOutputPulseAudio::OpenDevice ( void  )
overrideprotectedvirtual

Implements AudioOutputBase.

Definition at line 121 of file audiooutputpulse.cpp.

◆ CloseDevice()

void AudioOutputPulseAudio::CloseDevice ( void  )
overrideprotectedvirtual

Implements AudioOutputBase.

Definition at line 192 of file audiooutputpulse.cpp.

◆ WriteAudio()

void AudioOutputPulseAudio::WriteAudio ( unsigned char *  aubuf,
int  size 
)
overrideprotectedvirtual

Implements AudioOutputBase.

Definition at line 221 of file audiooutputpulse.cpp.

◆ GetBufferedOnSoundcard()

int AudioOutputPulseAudio::GetBufferedOnSoundcard ( void  ) const
overrideprotectedvirtual

Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback latency.

Implements AudioOutputBase.

Definition at line 281 of file audiooutputpulse.cpp.

◆ ChooseHost()

QString AudioOutputPulseAudio::ChooseHost ( void  )
private

Definition at line 469 of file audiooutputpulse.cpp.

Referenced by ContextConnect().

◆ MapChannels()

bool AudioOutputPulseAudio::MapChannels ( void  )
private

◆ ContextConnect()

bool AudioOutputPulseAudio::ContextConnect ( void  )
private

Definition at line 393 of file audiooutputpulse.cpp.

Referenced by GetOutputSettings(), and OpenDevice().

◆ ConnectPlaybackStream()

bool AudioOutputPulseAudio::ConnectPlaybackStream ( void  )
private

Definition at line 492 of file audiooutputpulse.cpp.

Referenced by OpenDevice().

◆ FlushStream()

void AudioOutputPulseAudio::FlushStream ( const char *  caller)
private

Definition at line 585 of file audiooutputpulse.cpp.

Referenced by CloseDevice().

◆ ContextStateCallback()

void AudioOutputPulseAudio::ContextStateCallback ( pa_context *  c,
void *  arg 
)
staticprivate

Definition at line 597 of file audiooutputpulse.cpp.

Referenced by ContextConnect().

◆ StreamStateCallback()

void AudioOutputPulseAudio::StreamStateCallback ( pa_stream *  s,
void *  arg 
)
staticprivate

Definition at line 615 of file audiooutputpulse.cpp.

Referenced by ConnectPlaybackStream().

◆ OpCompletionCallback()

void AudioOutputPulseAudio::OpCompletionCallback ( pa_context *  c,
int  ok,
void *  arg 
)
staticprivate

Definition at line 642 of file audiooutputpulse.cpp.

Referenced by SetVolumeChannel().

◆ WriteCallback()

void AudioOutputPulseAudio::WriteCallback ( pa_stream *  s,
size_t  size,
void *  arg 
)
staticprivate

Definition at line 631 of file audiooutputpulse.cpp.

Referenced by ConnectPlaybackStream().

◆ BufferFlowCallback()

void AudioOutputPulseAudio::BufferFlowCallback ( pa_stream *  s,
void *  tag 
)
staticprivate

Definition at line 637 of file audiooutputpulse.cpp.

Referenced by ConnectPlaybackStream().

◆ ServerInfoCallback()

void AudioOutputPulseAudio::ServerInfoCallback ( pa_context *  context,
const pa_server_info *  inf,
void *  arg 
)
staticprivate

Definition at line 655 of file audiooutputpulse.cpp.

Referenced by ContextConnect().

◆ SinkInfoCallback()

void AudioOutputPulseAudio::SinkInfoCallback ( pa_context *  c,
const pa_sink_info *  info,
int  eol,
void *  arg 
)
staticprivate

Definition at line 667 of file audiooutputpulse.cpp.

Referenced by GetOutputSettings().

Member Data Documentation

◆ m_pcontext

pa_context* AudioOutputPulseAudio::m_pcontext {nullptr}
private

◆ m_pstream

pa_stream* AudioOutputPulseAudio::m_pstream {nullptr}
private

◆ m_mainloop

pa_threaded_mainloop* AudioOutputPulseAudio::m_mainloop {nullptr}
private

◆ m_sampleSpec

pa_sample_spec AudioOutputPulseAudio::m_sampleSpec {}
private

Definition at line 64 of file audiooutputpulse.h.

Referenced by ConnectPlaybackStream(), and OpenDevice().

◆ m_channelMap

pa_channel_map AudioOutputPulseAudio::m_channelMap {}
private

Definition at line 65 of file audiooutputpulse.h.

Referenced by ConnectPlaybackStream(), and OpenDevice().

◆ m_volumeControl

pa_cvolume AudioOutputPulseAudio::m_volumeControl {}
private

◆ m_bufferSettings

pa_buffer_attr AudioOutputPulseAudio::m_bufferSettings {}
private

Definition at line 67 of file audiooutputpulse.h.

Referenced by ConnectPlaybackStream().

◆ m_aoSettings

AudioOutputSettings* AudioOutputPulseAudio::m_aoSettings {nullptr}
private

Definition at line 68 of file audiooutputpulse.h.

Referenced by GetOutputSettings().


The documentation for this class was generated from the following files: