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

#include <audiooutputalsa.h>

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

Public Member Functions

 AudioOutputALSA (const AudioSettings &settings)
 
 ~AudioOutputALSA () override
 
int GetVolumeChannel (int channel) const override
 
void SetVolumeChannel (int channel, int volume) override
 
- Public Member Functions inherited from AudioOutputBase
const char * quality_string (int q)
 
 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, int64_t timecode) override
 Add frames to the audiobuffer and perform any required processing. More...
 
bool AddData (void *buffer, int len, int64_t timecode, int frames) override
 Add data to the audiobuffer and perform any required processing. More...
 
bool NeedDecodingBeforePassthrough () const override
 
int64_t LengthLastData (void) const override
 
void SetTimecode (int64_t 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
 
void Drain (void) override
 Block until all available frames have been written to the device. More...
 
int64_t GetAudiotime (void) override
 Calculate the timecode of the samples that are about to become audible. More...
 
int64_t 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, int max_length) override
 
- Public Member Functions inherited from AudioOutput
 AudioOutput ()=default
 
 ~AudioOutput () override
 
QString GetError (void) const
 
QString GetWarning (void) const
 
bool PulseStatus (void)
 
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
 
virtual ~OutputListeners ()=default
 
bool hasVisual (void)
 
void addVisual (MythTV::Visual *)
 
void removeVisual (MythTV::Visual *)
 
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 ()
 
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=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 (unsigned long time=ULONG_MAX)
 Wait for the MThread to exit, with a maximum timeout. More...
 

Static Public Member Functions

static QMap< QString, QString > * GetDevices (const char *type)
 
- Static Public Member Functions inherited from AudioOutput
static void Cleanup (void)
 
static ADCVectGetOutputList (void)
 
static AudioDeviceConfigGetAudioDeviceConfig (QString &name, 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 &)
 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)
 

Protected Member Functions

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...
 
AudioOutputSettingsGetOutputSettings (bool passthrough) override
 
- 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...
 
int 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, unsigned long written, 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

int TryOpenDevice (int open_mode, bool try_ac3)
 
int GetPCMInfo (int &card, int &device, int &subdevice)
 
bool IncPreallocBufferSize (int requested, int buffer_time)
 
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. More...
 
QByteArray * GetELD (int card, int device, int subdevice)
 
bool OpenMixer (void)
 

Private Attributes

snd_pcm_t * m_pcm_handle {nullptr}
 
int m_pbufsize {-1}
 
int m_card {-1}
 
int m_device {-1}
 
int m_subdevice {-1}
 
QMutex m_killAudioLock
 
QString m_lastdevice
 
struct {
   QString   device
 
   QString   control
 
   snd_mixer_t *   handle
 
   snd_mixer_elem_t *   elem
 
   long   volmin
 
   long   volmax
 
   long   volrange
 
m_mixer
 

Additional Inherited Members

- Public Types inherited from AudioOutput
typedef QVector< AudioDeviceConfigADCVect
 
- 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 MAX_SIZE_BUFFER = 384000
 MAX_SIZE_BUFFER is the maximum size of a buffer to be used with DecodeAudio. More...
 
- Static Public Attributes inherited from MThread
static const int kDefaultStartTimeout
 
- 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 sleep (unsigned long time)
 
static void msleep (unsigned long time)
 
static void usleep (unsigned long time)
 
- Protected Attributes inherited from AudioOutputBase
int m_channels {-1}
 
AVCodecID m_codec {AV_CODEC_ID_NONE}
 
int m_bytes_per_frame {0}
 
int m_output_bytes_per_frame {0}
 
AudioFormat m_format {FORMAT_NONE}
 
AudioFormat m_output_format {FORMAT_NONE}
 
int m_samplerate {-1}
 
int m_effdsp {0}
 
int m_fragment_size {0}
 
long m_soundcard_buffer_size {0}
 
QString m_main_device
 
QString m_passthru_device
 
bool m_discretedigital {false}
 
bool m_passthru {false}
 
bool m_enc {false}
 
bool m_reenc {false}
 
float m_stretchfactor {1.0F}
 
int m_eff_stretchfactor {100000}
 
AudioOutputSource source
 
bool m_killaudio {false}
 
bool m_pauseaudio {false}
 
bool m_actually_paused {false}
 
bool m_was_paused {false}
 
bool m_unpause_when_ready {false}
 
bool m_set_initial_vol
 
bool m_buffer_output_data_for_use {false}
 
int m_configured_channels {0}
 
int m_max_channels {0}
 
int m_src_quality {QUALITY_MEDIUM}
 
long m_source_bitrate {-1}
 
int m_source_samplerate {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 internal_vol {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_prolog_executed {true}
 
bool m_epilog_executed {true}
 

Detailed Description

Definition at line 12 of file audiooutputalsa.h.

Constructor & Destructor Documentation

◆ AudioOutputALSA()

AudioOutputALSA::AudioOutputALSA ( const AudioSettings settings)
explicit

Definition at line 33 of file audiooutputalsa.cpp.

◆ ~AudioOutputALSA()

AudioOutputALSA::~AudioOutputALSA ( )
override

Definition at line 104 of file audiooutputalsa.cpp.

Member Function Documentation

◆ GetVolumeChannel()

int AudioOutputALSA::GetVolumeChannel ( int  channel) const
overridevirtual

Implements VolumeBase.

Definition at line 822 of file audiooutputalsa.cpp.

◆ SetVolumeChannel()

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

Implements VolumeBase.

Definition at line 857 of file audiooutputalsa.cpp.

Referenced by OpenMixer().

◆ GetDevices()

QMap< QString, QString > * AudioOutputALSA::GetDevices ( const char *  type)
static

◆ OpenDevice()

bool AudioOutputALSA::OpenDevice ( void  )
overrideprotectedvirtual

Implements AudioOutputBase.

Definition at line 447 of file audiooutputalsa.cpp.

◆ CloseDevice()

void AudioOutputALSA::CloseDevice ( void  )
overrideprotectedvirtual

Implements AudioOutputBase.

Definition at line 498 of file audiooutputalsa.cpp.

Referenced by OpenDevice().

◆ WriteAudio()

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

Implements AudioOutputBase.

Definition at line 542 of file audiooutputalsa.cpp.

◆ GetBufferedOnSoundcard()

int AudioOutputALSA::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 627 of file audiooutputalsa.cpp.

◆ GetOutputSettings()

AudioOutputSettings * AudioOutputALSA::GetOutputSettings ( bool  passthrough)
overrideprotectedvirtual

Reimplemented from AudioOutputBase.

Definition at line 318 of file audiooutputalsa.cpp.

◆ TryOpenDevice()

int AudioOutputALSA::TryOpenDevice ( int  open_mode,
bool  try_ac3 
)
private

Definition at line 109 of file audiooutputalsa.cpp.

Referenced by GetOutputSettings(), and OpenDevice().

◆ GetPCMInfo()

int AudioOutputALSA::GetPCMInfo ( int &  card,
int &  device,
int &  subdevice 
)
private

Definition at line 145 of file audiooutputalsa.cpp.

Referenced by GetOutputSettings(), and IncPreallocBufferSize().

◆ IncPreallocBufferSize()

bool AudioOutputALSA::IncPreallocBufferSize ( int  requested,
int  buffer_time 
)
private

Definition at line 187 of file audiooutputalsa.cpp.

Referenced by SetParameters().

◆ SetParameters()

int AudioOutputALSA::SetParameters ( snd_pcm_t *  handle,
snd_pcm_format_t  format,
uint  channels,
uint  rate,
uint  buffer_time,
uint  period_time 
)
inlineprivate

Set the various ALSA audio parameters.

Returns: < 0 : an error occurred 0 : Succeeded

0 : Buffer timelength returned by ALSA which is less than what we asked for

Definition at line 653 of file audiooutputalsa.cpp.

Referenced by OpenDevice().

◆ GetELD()

QByteArray * AudioOutputALSA::GetELD ( int  card,
int  device,
int  subdevice 
)
private

Definition at line 243 of file audiooutputalsa.cpp.

Referenced by GetOutputSettings().

◆ OpenMixer()

bool AudioOutputALSA::OpenMixer ( void  )
private

Definition at line 878 of file audiooutputalsa.cpp.

Referenced by OpenDevice().

Member Data Documentation

◆ m_pcm_handle

snd_pcm_t* AudioOutputALSA::m_pcm_handle {nullptr}
private

◆ m_pbufsize

int AudioOutputALSA::m_pbufsize {-1}
private

Definition at line 44 of file audiooutputalsa.h.

Referenced by IncPreallocBufferSize(), and SetParameters().

◆ m_card

int AudioOutputALSA::m_card {-1}
private

Definition at line 45 of file audiooutputalsa.h.

Referenced by GetPCMInfo().

◆ m_device

int AudioOutputALSA::m_device {-1}
private

Definition at line 46 of file audiooutputalsa.h.

Referenced by GetPCMInfo().

◆ m_subdevice

int AudioOutputALSA::m_subdevice {-1}
private

Definition at line 47 of file audiooutputalsa.h.

Referenced by GetPCMInfo().

◆ m_killAudioLock

QMutex AudioOutputALSA::m_killAudioLock
private

Definition at line 48 of file audiooutputalsa.h.

◆ m_lastdevice

QString AudioOutputALSA::m_lastdevice
private

Definition at line 49 of file audiooutputalsa.h.

Referenced by GetOutputSettings(), OpenDevice(), and TryOpenDevice().

◆ device

QString AudioOutputALSA::device

Definition at line 52 of file audiooutputalsa.h.

Referenced by GetELD(), GetOutputSettings(), GetPCMInfo(), and IncPreallocBufferSize().

◆ control

QString AudioOutputALSA::control

Definition at line 53 of file audiooutputalsa.h.

Referenced by GetELD().

◆ handle

snd_mixer_t* AudioOutputALSA::handle

Definition at line 54 of file audiooutputalsa.h.

Referenced by SetParameters().

◆ elem

snd_mixer_elem_t* AudioOutputALSA::elem

Definition at line 55 of file audiooutputalsa.h.

Referenced by GetELD().

◆ volmin

long AudioOutputALSA::volmin

Definition at line 56 of file audiooutputalsa.h.

◆ volmax

long AudioOutputALSA::volmax

Definition at line 57 of file audiooutputalsa.h.

◆ volrange

long AudioOutputALSA::volrange

Definition at line 58 of file audiooutputalsa.h.

◆ m_mixer

struct { ... } AudioOutputALSA::m_mixer

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