vdr-plugin-softhddevice-drm-gles 1.6.7
cAlsaDevice Class Reference

Alsa Interface. More...

#include <alsadevice.h>

Public Member Functions

 cAlsaDevice (cSoftHdConfig *)
 
bool Init (void)
 Initialize the ALSA audio output module.
 
void Exit (void)
 Cleanup the ALSA audio output module.
 
int Setup (int, int, bool, int)
 Setup ALSA audio for requested format.
 
int Write (const void *, int)
 Write data to the output device.
 
void FlushBuffers (bool)
 Flush ALSA buffers internally.
 
bool HandleError (int)
 Handle an alsa error.
 
void SetVolume (int)
 Set alsa mixer volume (0-1000)
 
int WaitUntilReady (void)
 Wait until data can be written or read to/from the device (Timeout is 150ms currently)
 
bool CheckWrittenFrames (int, int)
 Check, if all frames have been written.
 
int GetHwDelayFrames (void)
 Return the current hardware audio delay in frames.
 
int GetAvailableBufferFrames (bool)
 Get the number of frames that could be written to the device.
 
std::vector< std::string > GetChannelLayoutAsArray (void)
 Put ALSA channel layout in a dynamic array of strings.
 
int GetBufferSizeFrames (void)
 
int GetDownmix (void)
 
int GetHwNumChannels (void)
 
int GetHwSampleRate (void)
 
bool IsRunning (void)
 
bool IsPassthroughActive (void)
 
void SetPassthroughMask (int mask)
 
int GetPassthroughMask (void) const
 
void SetAutoAES (bool appendAes)
 
void SetDownmix (int downMix)
 
size_t FramesToBytes (int frames)
 
int BytesToFrames (size_t bytes)
 
int64_t PtsToMs (int64_t pts, double timebase)
 
int64_t MsToPts (int64_t ptsMs, double timebase)
 
int MsToFrames (int milliseconds)
 
int FramesToMs (int frames)
 
int64_t FramesToPts (int frames, double timebase)
 
double FramesToMsDouble (int frames)
 

Private Member Functions

bool ShouldAppendAES (void)
 
charOpenDevice (const char *)
 Open an ALSA device.
 
charFindDevice (const char *, const char *)
 Find alsa device giving some search hints.
 
bool InitDevice (void)
 Search for an alsa pcm device and open it.
 
void InitMixer (void)
 Initialize the ALSA mixer.
 

Private Attributes

const charm_pPCMDevice
 Alsa PCM device name.
 
snd_pcm_tm_pPCMHandle = nullptr
 alsa pcm handle
 
const charm_pMixerDevice = nullptr
 mixer device name (not used)
 
const charm_pMixerChannel
 mixer channel name
 
snd_mixer_tm_pMixer = nullptr
 alsa mixer handle
 
snd_mixer_elem_tm_pMixerElem = nullptr
 alsa mixer element
 
snd_pcm_uframes_t m_bufferSizeFrames = 0
 alsa buffer size in frames
 
int m_ratio
 internal -> mixer ratio * 1000
 
bool m_appendAES
 flag to automatic append AES
 
int m_passthroughMask
 passthrough mask
 
std::atomic< boolm_passthroughActive = false
 set, if passthrough is active
 
unsigned int m_hwSampleRate = 0
 hardware sample rate in Hz
 
unsigned int m_hwNumChannels = 0
 number of hardware channels
 
int m_downmix
 set stereo downmix
 
bool m_useMmap
 use mmap
 

Detailed Description

Alsa Interface.

Definition at line 36 of file alsadevice.h.

Constructor & Destructor Documentation

◆ cAlsaDevice()

cAlsaDevice::cAlsaDevice ( cSoftHdConfig m_pConfig)

Definition at line 39 of file alsadevice.cpp.

Member Function Documentation

◆ BytesToFrames()

◆ CheckWrittenFrames()

bool cAlsaDevice::CheckWrittenFrames ( int  framesWritten,
int  framesToWrite 
)

Check, if all frames have been written.

Return values
true,ifall frames have been written or we should try again later
false,ifnot all frames have been written or an error occured

Definition at line 454 of file alsadevice.cpp.

References LOGERROR, LOGWARNING, and m_pPCMHandle.

Referenced by cSoftHdAudio::SendAudio(), and cSoftHdAudio::SendPause().

◆ Exit()

void cAlsaDevice::Exit ( void  )

Cleanup the ALSA audio output module.

Definition at line 73 of file alsadevice.cpp.

References m_pMixer, m_pMixerElem, and m_pPCMHandle.

Referenced by cSoftHdAudio::Exit().

◆ FindDevice()

char * cAlsaDevice::FindDevice ( const char devname,
const char hint 
)
private

Find alsa device giving some search hints.

Parameters
devnameinterface identification (e.g. "pcm")
hintstring to compare with device name hints
Returns
an opened alsa device name if successful, NULL otherwise NOTE: Returned string is allocated and must be freed by caller

Definition at line 141 of file alsadevice.cpp.

References LOGWARNING, and OpenDevice().

Referenced by InitDevice().

◆ FlushBuffers()

void cAlsaDevice::FlushBuffers ( bool  drop)

Flush ALSA buffers internally.

Parameters
dropforce a snd_pcm_drop of the audio frames already in the kernel

Definition at line 479 of file alsadevice.cpp.

References L_SOUND, LOGDEBUG2, LOGERROR, m_passthroughActive, and m_pPCMHandle.

Referenced by cSoftHdAudio::DropAlsaBuffers(), and cSoftHdAudio::FlushAlsaBuffers().

◆ FramesToBytes()

size_t cAlsaDevice::FramesToBytes ( int  frames)
inline

◆ FramesToMs()

◆ FramesToMsDouble()

double cAlsaDevice::FramesToMsDouble ( int  frames)
inline

Definition at line 74 of file alsadevice.h.

References m_hwSampleRate.

Referenced by cSoftHdAudio::ClockDriftCompensation().

◆ FramesToPts()

int64_t cAlsaDevice::FramesToPts ( int  frames,
double  timebase 
)
inline

Definition at line 73 of file alsadevice.h.

References m_hwSampleRate, and MsToPts().

Referenced by cSoftHdAudio::Enqueue().

◆ GetAvailableBufferFrames()

int cAlsaDevice::GetAvailableBufferFrames ( bool  sync)

Get the number of frames that could be written to the device.

Parameters
syncsynchronize with hardware first
Returns
number of frames, that could be written or negative error code in case of an error

Definition at line 554 of file alsadevice.cpp.

References L_SOUND, LOGDEBUG2, LOGWARNING, and m_pPCMHandle.

Referenced by cSoftHdAudio::ClockDriftCompensation(), and cSoftHdAudio::CyclicCall().

◆ GetBufferSizeFrames()

int cAlsaDevice::GetBufferSizeFrames ( void  )
inline

Definition at line 55 of file alsadevice.h.

References m_bufferSizeFrames.

Referenced by cSoftHdAudio::ClockDriftCompensation().

◆ GetDownmix()

int cAlsaDevice::GetDownmix ( void  )
inline

Definition at line 56 of file alsadevice.h.

References m_downmix.

Referenced by cSoftHdAudio::InitFilter(), and cSoftHdAudio::Setup().

◆ GetHwDelayFrames()

int cAlsaDevice::GetHwDelayFrames ( void  )

Return the current hardware audio delay in frames.

Definition at line 516 of file alsadevice.cpp.

References m_pPCMHandle.

Referenced by cSoftHdAudio::GetHardwareOutputDelayMs(), cSoftHdAudio::GetHardwareOutputPtsMs(), and cSoftHdAudio::SetHwDelayBaseline().

◆ GetHwNumChannels()

int cAlsaDevice::GetHwNumChannels ( void  )
inline

Definition at line 57 of file alsadevice.h.

References m_hwNumChannels.

Referenced by cSoftHdAudio::InitFilter(), cSoftHdAudio::Setup(), and cSoftHdAudio::SetVolume().

◆ GetHwSampleRate()

int cAlsaDevice::GetHwSampleRate ( void  )
inline

Definition at line 58 of file alsadevice.h.

References m_hwSampleRate.

Referenced by cSoftHdAudio::InitFilter(), and cSoftHdAudio::Setup().

◆ GetPassthroughMask()

int cAlsaDevice::GetPassthroughMask ( void  ) const
inline

Definition at line 62 of file alsadevice.h.

References m_passthroughMask.

Referenced by cSoftHdAudio::GetPassthroughMask().

◆ HandleError()

bool cAlsaDevice::HandleError ( int  error)

Handle an alsa error.

Returns
true, if an audio underrun happened, false otherwise

Definition at line 531 of file alsadevice.cpp.

References LOGERROR, m_passthroughActive, and m_pPCMHandle.

Referenced by cSoftHdAudio::CyclicCall().

◆ Init()

bool cAlsaDevice::Init ( void  )

Initialize the ALSA audio output module.

Returns
true, if device init was successful

Definition at line 53 of file alsadevice.cpp.

References AlsaNoopCallback(), InitDevice(), and InitMixer().

Referenced by cSoftHdAudio::LazyInit().

◆ InitDevice()

bool cAlsaDevice::InitDevice ( void  )
private

Search for an alsa pcm device and open it.

Returns
true, if a device could be opened

Definition at line 179 of file alsadevice.cpp.

References FindDevice(), L_SOUND, LOGDEBUG2, LOGERROR, LOGINFO, LOGWARNING, m_pPCMDevice, m_pPCMHandle, and OpenDevice().

Referenced by Init().

◆ InitMixer()

void cAlsaDevice::InitMixer ( void  )
private

Initialize the ALSA mixer.

Definition at line 248 of file alsadevice.cpp.

References L_SOUND, LOGDEBUG2, LOGERROR, m_pMixer, m_pMixerChannel, m_pMixerDevice, m_pMixerElem, and m_ratio.

Referenced by Init().

◆ IsPassthroughActive()

◆ IsRunning()

bool cAlsaDevice::IsRunning ( void  )
inline

◆ MsToFrames()

int cAlsaDevice::MsToFrames ( int  milliseconds)
inline

Definition at line 71 of file alsadevice.h.

References m_hwSampleRate.

Referenced by cSoftHdAudio::DropSamplesOlderThanPtsMs().

◆ MsToPts()

int64_t cAlsaDevice::MsToPts ( int64_t  ptsMs,
double  timebase 
)
inline

Definition at line 70 of file alsadevice.h.

Referenced by FramesToPts(), and cSoftHdAudio::GetHardwareOutputPtsTimebaseUnits().

◆ OpenDevice()

char * cAlsaDevice::OpenDevice ( const char device)
private

Open an ALSA device.

Parameters
devicealsa device to be opened
Returns
the alsa device if successful, NULL otherwise

Definition at line 93 of file alsadevice.cpp.

References L_SOUND, LOGDEBUG2, LOGWARNING, m_pPCMHandle, and ShouldAppendAES().

Referenced by FindDevice(), and InitDevice().

◆ PtsToMs()

int64_t cAlsaDevice::PtsToMs ( int64_t  pts,
double  timebase 
)
inline

◆ SetAutoAES()

void cAlsaDevice::SetAutoAES ( bool  appendAes)
inline

Definition at line 63 of file alsadevice.h.

References m_appendAES.

Referenced by cSoftHdAudio::SetAutoAES().

◆ SetDownmix()

void cAlsaDevice::SetDownmix ( int  downMix)
inline

Definition at line 64 of file alsadevice.h.

References m_downmix.

Referenced by cSoftHdAudio::SetDownmix().

◆ SetPassthroughMask()

void cAlsaDevice::SetPassthroughMask ( int  mask)
inline

Definition at line 61 of file alsadevice.h.

References m_passthroughMask.

Referenced by cSoftHdAudio::SetPassthroughMask().

◆ Setup()

int cAlsaDevice::Setup ( int  channels,
int  sample_rate,
bool  passthrough,
int  downmix 
)

Setup ALSA audio for requested format.

Parameters
channelsChannels requested
sample_rateSampleRate requested
passthroughuse pass-through (AC-3, ...) device
Return values
0everything ok
-1something gone wrong

Definition at line 307 of file alsadevice.cpp.

References GetChannelLayoutAsArray(), L_SOUND, LOGDEBUG2, LOGERROR, LOGINFO, LOGWARNING, m_bufferSizeFrames, m_downmix, m_hwNumChannels, m_hwSampleRate, m_passthroughActive, m_pPCMHandle, and m_useMmap.

Referenced by cSoftHdAudio::Setup().

◆ SetVolume()

void cAlsaDevice::SetVolume ( int  volume)

Set alsa mixer volume (0-1000)

Parameters
volumevolume (0 .. 1000)

Definition at line 577 of file alsadevice.cpp.

References m_pMixer, m_pMixerElem, and m_ratio.

Referenced by cSoftHdAudio::SetVolume().

◆ ShouldAppendAES()

bool cAlsaDevice::ShouldAppendAES ( void  )
inlineprivate

Definition at line 96 of file alsadevice.h.

References m_appendAES, and m_passthroughMask.

Referenced by OpenDevice().

◆ WaitUntilReady()

int cAlsaDevice::WaitUntilReady ( void  )

Wait until data can be written or read to/from the device (Timeout is 150ms currently)

Returns
0, if timeout occured 1, if device is ready negative error code, in case of an error

Definition at line 417 of file alsadevice.cpp.

References L_SOUND, LOGDEBUG2, LOGERROR, and m_pPCMHandle.

Referenced by cSoftHdAudio::CyclicCall().

◆ Write()

int cAlsaDevice::Write ( const void data,
int  framesToWrite 
)

Write data to the output device.

Returns
number of written frames, or negative error code in case of an error

Definition at line 440 of file alsadevice.cpp.

References m_pPCMHandle, and m_useMmap.

Referenced by cSoftHdAudio::SendAudio(), and cSoftHdAudio::SendPause().

Member Data Documentation

◆ m_appendAES

bool cAlsaDevice::m_appendAES
private

flag to automatic append AES

Definition at line 88 of file alsadevice.h.

Referenced by SetAutoAES(), and ShouldAppendAES().

◆ m_bufferSizeFrames

snd_pcm_uframes_t cAlsaDevice::m_bufferSizeFrames = 0
private

alsa buffer size in frames

Definition at line 86 of file alsadevice.h.

Referenced by GetBufferSizeFrames(), and Setup().

◆ m_downmix

int cAlsaDevice::m_downmix
private

set stereo downmix

Definition at line 93 of file alsadevice.h.

Referenced by GetDownmix(), SetDownmix(), and Setup().

◆ m_hwNumChannels

unsigned int cAlsaDevice::m_hwNumChannels = 0
private

number of hardware channels

Definition at line 92 of file alsadevice.h.

Referenced by GetHwNumChannels(), and Setup().

◆ m_hwSampleRate

unsigned int cAlsaDevice::m_hwSampleRate = 0
private

hardware sample rate in Hz

Definition at line 91 of file alsadevice.h.

Referenced by FramesToMs(), FramesToMsDouble(), FramesToPts(), GetHwSampleRate(), IsRunning(), MsToFrames(), and Setup().

◆ m_passthroughActive

std::atomic<bool> cAlsaDevice::m_passthroughActive = false
private

set, if passthrough is active

Definition at line 90 of file alsadevice.h.

Referenced by FlushBuffers(), HandleError(), IsPassthroughActive(), and Setup().

◆ m_passthroughMask

int cAlsaDevice::m_passthroughMask
private

passthrough mask

Definition at line 89 of file alsadevice.h.

Referenced by GetPassthroughMask(), SetPassthroughMask(), and ShouldAppendAES().

◆ m_pMixer

snd_mixer_t* cAlsaDevice::m_pMixer = nullptr
private

alsa mixer handle

Definition at line 83 of file alsadevice.h.

Referenced by Exit(), InitMixer(), and SetVolume().

◆ m_pMixerChannel

const char* cAlsaDevice::m_pMixerChannel
private

mixer channel name

Definition at line 82 of file alsadevice.h.

Referenced by InitMixer().

◆ m_pMixerDevice

const char* cAlsaDevice::m_pMixerDevice = nullptr
private

mixer device name (not used)

Definition at line 81 of file alsadevice.h.

Referenced by InitMixer().

◆ m_pMixerElem

snd_mixer_elem_t* cAlsaDevice::m_pMixerElem = nullptr
private

alsa mixer element

Definition at line 84 of file alsadevice.h.

Referenced by Exit(), InitMixer(), and SetVolume().

◆ m_pPCMDevice

const char* cAlsaDevice::m_pPCMDevice
private

Alsa PCM device name.

Definition at line 77 of file alsadevice.h.

Referenced by InitDevice().

◆ m_pPCMHandle

◆ m_ratio

int cAlsaDevice::m_ratio
private

internal -> mixer ratio * 1000

Definition at line 87 of file alsadevice.h.

Referenced by InitMixer(), and SetVolume().

◆ m_useMmap

bool cAlsaDevice::m_useMmap
private

use mmap

Definition at line 94 of file alsadevice.h.

Referenced by Setup(), and Write().


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