Miam-Player  0.8.0
A nice music player
QtAV::AudioOutput Class Reference

#include <AudioOutput.h>

Inheritance diagram for QtAV::AudioOutput:
QtAV::AVOutput

Public Types

enum  DeviceFeature { NoFeature = 0, SetVolume = 1, SetMute = 1 << 1, SetSampleRate = 1 << 2 }
 DeviceFeature Feature enum features supported by the audio playback api (we call device or backend here) More...
 

Signals

void volumeChanged (qreal)
 
void muteChanged (bool)
 
void deviceFeaturesChanged ()
 
void backendsChanged ()
 

Public Member Functions

 AudioOutput (QObject *parent=0)
 AudioOutput Audio format set to preferred sample format and channel layout. More...
 
virtual ~AudioOutput ()
 
void setBackends (const QStringList &backendNames=QStringList())
 setBackends set the given backends. More...
 
QStringList backends () const
 
QString backend () const
 backend backend name currently in use More...
 
void flush ()
 flush Play the buffered audio data More...
 
void clear ()
 clear Clear audio buffers and set time to 0. More...
 
bool open ()
 
bool close ()
 
bool isOpen () const
 
bool play (const QByteArray &data, qreal pts=0.0)
 play Play out the given audio data. More...
 
void setAudioFormat (const AudioFormat &format)
 TODO: requestAudioFormat(): check support after open, use the nearest format if not supported. Or use suitableFormat(AudioFormat requestedFmt) if requestedFmt is not supported. More...
 
AudioFormataudioFormat ()
 
const AudioFormataudioFormat () const
 
void setSampleRate (int rate)
 
int sampleRate () const
 
void setChannels (int channels)
 
int channels () const
 
void setVolume (qreal value)
 setVolume Set volume level. More...
 
qreal volume () const
 
void setMute (bool value=true)
 setMute If SetMute feature is not set or not supported, software implemention will be used. More...
 
bool isMute () const
 
void setSpeed (qreal speed)
 setSpeed set audio playing speed Currently only store the value and does nothing else in audio output. More...
 
qreal speed () const
 
bool isSupported (const AudioFormat &format) const
 isSupported check isSupported(format.sampleFormat()) and isSupported(format.channelLayout()) More...
 
bool isSupported (AudioFormat::SampleFormat sampleFormat) const
 
bool isSupported (AudioFormat::ChannelLayout channelLayout) const
 
AudioFormat::SampleFormat preferredSampleFormat () const
 preferredSampleFormat More...
 
AudioFormat::ChannelLayout preferredChannelLayout () const
 preferredChannelLayout More...
 
int bufferSamples () const
 bufferSamples Number of samples that audio output accept in 1 buffer. More...
 
void setBufferSamples (int value)
 
int bufferSize () const
 
int bufferCount () const
 bufferSamples()*bytesPerSample More...
 
void setBufferCount (int value)
 
int bufferSizeTotal () const
 
void setDeviceFeatures (DeviceFeatures value)
 setDeviceFeatures Unsupported features will not be set. More...
 
DeviceFeatures deviceFeatures () const
 deviceFeatures More...
 
DeviceFeatures supportedDeviceFeatures () const
 supportedDeviceFeatures Supported features of the backend, defined by AudioOutput(DeviceFeatures,AudioOutput&,QObject*) in a backend ctor More...
 
qreal timestamp () const
 
- Public Member Functions inherited from QtAV::AVOutput
 AVOutput ()
 
virtual ~AVOutput ()
 
bool isAvailable () const
 
void pause (bool p)
 
bool isPaused () const
 
QList< Filter * > & filters ()
 
bool installFilter (Filter *filter, int index=0x7fffffff)
 installFilter Insert a filter at position 'index' of current filter list. More...
 
bool uninstallFilter (Filter *filter)
 

Static Public Member Functions

static QStringList backendsAvailable ()
 backendsAvailable All registered backends in default priority order More...
 

Protected Member Functions

bool receiveData (const QByteArray &data, qreal pts=0.0)
 
virtual bool waitForNextBuffer ()
 waitForNextBuffer wait until you can feed more data More...
 
- Protected Member Functions inherited from QtAV::AVOutput
 AVOutput (AVOutputPrivate &d)
 
Q_DECL_DEPRECATED bool tryPause ()
 
void addOutputSet (OutputSet *set)
 
void removeOutputSet (OutputSet *set)
 
void attach (OutputSet *set)
 
void detach (OutputSet *set=0)
 
void hanlePendingTasks ()
 

Properties

qreal volume
 
bool mute
 
DeviceFeatures deviceFeatures
 
QStringList backends
 

Friends

class AudioOutputBackend
 

Member Enumeration Documentation

◆ DeviceFeature

DeviceFeature Feature enum features supported by the audio playback api (we call device or backend here)

Enumerator
NoFeature 
SetVolume 
SetMute 

NOT IMPLEMENTED. Use backend volume control api rather than software scale. Ignore if backend does not support.

SetSampleRate 

NOT IMPLEMENTED.

Constructor & Destructor Documentation

◆ AudioOutput()

QtAV::AudioOutput::AudioOutput ( QObject *  parent = 0)

AudioOutput Audio format set to preferred sample format and channel layout.

◆ ~AudioOutput()

virtual QtAV::AudioOutput::~AudioOutput ( )
virtual

Member Function Documentation

◆ audioFormat() [1/2]

AudioFormat& QtAV::AudioOutput::audioFormat ( )

◆ audioFormat() [2/2]

const AudioFormat& QtAV::AudioOutput::audioFormat ( ) const

◆ backend()

QString QtAV::AudioOutput::backend ( ) const

backend backend name currently in use

◆ backends()

QStringList QtAV::AudioOutput::backends ( ) const

◆ backendsAvailable()

static QStringList QtAV::AudioOutput::backendsAvailable ( )
static

backendsAvailable All registered backends in default priority order

Returns

◆ backendsChanged

void QtAV::AudioOutput::backendsChanged ( )
signal

◆ bufferCount()

int QtAV::AudioOutput::bufferCount ( ) const

bufferSamples()*bytesPerSample

bufferCount Total buffer count. If it's not large enough, playing high sample rate audio may be poor. The default value is 16. TODO: depending on audio format(sample rate?) Some backends(OpenAL) are affected significantly by this property

◆ bufferSamples()

int QtAV::AudioOutput::bufferSamples ( ) const

bufferSamples Number of samples that audio output accept in 1 buffer.

Feed the audio output this size of data every time. Smaller buffer samples gives more buffers for a given data to avoid stutter. But if it's too small, the duration of 1 buffer will be too small to play, for example 1ms. Currently the default value is 512. Some backends(OpenAL) are affected significantly by this property

◆ bufferSize()

int QtAV::AudioOutput::bufferSize ( ) const

◆ bufferSizeTotal()

int QtAV::AudioOutput::bufferSizeTotal ( ) const
inline

◆ channels()

int QtAV::AudioOutput::channels ( ) const

◆ clear()

void QtAV::AudioOutput::clear ( )

clear Clear audio buffers and set time to 0.

The default behavior is flush and reset time

◆ close()

bool QtAV::AudioOutput::close ( )

◆ deviceFeatures()

DeviceFeatures QtAV::AudioOutput::deviceFeatures ( ) const

deviceFeatures

Returns
features set by setFeatures() excluding unsupported features

◆ deviceFeaturesChanged

void QtAV::AudioOutput::deviceFeaturesChanged ( )
signal

◆ flush()

void QtAV::AudioOutput::flush ( )

flush Play the buffered audio data

Returns

◆ isMute()

bool QtAV::AudioOutput::isMute ( ) const

◆ isOpen()

bool QtAV::AudioOutput::isOpen ( ) const

◆ isSupported() [1/3]

bool QtAV::AudioOutput::isSupported ( const AudioFormat format) const

isSupported check isSupported(format.sampleFormat()) and isSupported(format.channelLayout())

Parameters
format
Returns
true if format is supported. default is true

◆ isSupported() [2/3]

bool QtAV::AudioOutput::isSupported ( AudioFormat::SampleFormat  sampleFormat) const

◆ isSupported() [3/3]

bool QtAV::AudioOutput::isSupported ( AudioFormat::ChannelLayout  channelLayout) const

◆ muteChanged

void QtAV::AudioOutput::muteChanged ( bool  )
signal

◆ open()

bool QtAV::AudioOutput::open ( )

◆ play()

bool QtAV::AudioOutput::play ( const QByteArray &  data,
qreal  pts = 0.0 
)

play Play out the given audio data.

It may block current thread until the data can be written to audio device for async playback backend, or until the data is completely played for blocking playback backend.

Parameters
dataAudio data to play
ptsTimestamp for this data. Useful if need A/V sync. Ignore it if only play audio
Returns
true if play successfully

◆ preferredChannelLayout()

AudioFormat::ChannelLayout QtAV::AudioOutput::preferredChannelLayout ( ) const

preferredChannelLayout

Returns
the preferred channel layout. default is stereo

◆ preferredSampleFormat()

AudioFormat::SampleFormat QtAV::AudioOutput::preferredSampleFormat ( ) const

preferredSampleFormat

Returns
the preferred sample format. default is signed16 packed If the specified format is not supported, resample to preffered format

◆ receiveData()

bool QtAV::AudioOutput::receiveData ( const QByteArray &  data,
qreal  pts = 0.0 
)
protected

◆ sampleRate()

int QtAV::AudioOutput::sampleRate ( ) const

◆ setAudioFormat()

void QtAV::AudioOutput::setAudioFormat ( const AudioFormat format)

TODO: requestAudioFormat(): check support after open, use the nearest format if not supported. Or use suitableFormat(AudioFormat requestedFmt) if requestedFmt is not supported.

◆ setBackends()

void QtAV::AudioOutput::setBackends ( const QStringList &  backendNames = QStringList())

setBackends set the given backends.

Old backend instance and backend() is updated soon if backendsChanged. It is called internally with a default backend names when AudioOutput is created.

◆ setBufferCount()

void QtAV::AudioOutput::setBufferCount ( int  value)

◆ setBufferSamples()

void QtAV::AudioOutput::setBufferSamples ( int  value)

◆ setChannels()

void QtAV::AudioOutput::setChannels ( int  channels)

◆ setDeviceFeatures()

void QtAV::AudioOutput::setDeviceFeatures ( DeviceFeatures  value)

setDeviceFeatures Unsupported features will not be set.

You can call this in a backend ctor.

◆ setMute()

void QtAV::AudioOutput::setMute ( bool  value = true)

setMute If SetMute feature is not set or not supported, software implemention will be used.

Call this after open(), because it will call backend api if SetMute feature is enabled

◆ setSampleRate()

void QtAV::AudioOutput::setSampleRate ( int  rate)

◆ setSpeed()

void QtAV::AudioOutput::setSpeed ( qreal  speed)

setSpeed set audio playing speed Currently only store the value and does nothing else in audio output.

You may change sample rate to get the same effect. The speed affects the playing only if audio is available and clock type is audio clock. For example, play a video contains audio without special configurations. To change the playing speed in other cases, use AVPlayer::setSpeed(qreal)

Parameters
speedlinear. > 0 TODO: resample internally

◆ setVolume()

void QtAV::AudioOutput::setVolume ( qreal  value)

setVolume Set volume level.

If SetVolume feature is not set or not supported, software implemention will be used. Call this after open(), because it will call backend api if SetVolume feature is enabled

Parameters
volumelinear. 1.0: original volume.

◆ speed()

qreal QtAV::AudioOutput::speed ( ) const

◆ supportedDeviceFeatures()

DeviceFeatures QtAV::AudioOutput::supportedDeviceFeatures ( ) const

supportedDeviceFeatures Supported features of the backend, defined by AudioOutput(DeviceFeatures,AudioOutput&,QObject*) in a backend ctor

◆ timestamp()

qreal QtAV::AudioOutput::timestamp ( ) const

◆ volume()

qreal QtAV::AudioOutput::volume ( ) const

◆ volumeChanged

void QtAV::AudioOutput::volumeChanged ( qreal  )
signal

◆ waitForNextBuffer()

virtual bool QtAV::AudioOutput::waitForNextBuffer ( )
protectedvirtual

waitForNextBuffer wait until you can feed more data

Friends And Related Function Documentation

◆ AudioOutputBackend

friend class AudioOutputBackend
friend

Property Documentation

◆ backends

QStringList QtAV::AudioOutput::backends
readwrite

◆ deviceFeatures

DeviceFeatures QtAV::AudioOutput::deviceFeatures
readwrite

◆ mute

bool QtAV::AudioOutput::mute
readwrite

◆ volume

qreal QtAV::AudioOutput::volume
readwrite

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