Skip to content

Commit

Permalink
ao: backend reset volume if fail. add backend get volume
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Feb 16, 2015
1 parent f7fa6a8 commit 376fee8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/QtAV/AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ class Q_AV_EXPORT AudioOutput : public QObject, public AVOutput
* \brief setFeatures
* do nothing if onSetFeatures() returns false, which means current api does not support the features
* call this in the ctor of your new backend
* TODO: return features set successfully
*/
void setFeatures(Feature value);
Feature features() const;
void setFeature(Feature value, bool on = true);
bool hasFeatures(Feature value) const;
//TODO: virtual Features supportedFeatures() const;
qreal timestamp() const;
// Internal use since QtAV 1.5
virtual bool play() = 0; //MUST
Expand Down Expand Up @@ -214,7 +216,8 @@ class Q_AV_EXPORT AudioOutput : public QObject, public AVOutput
virtual int getOffset(); // OffsetIndex
virtual int getOffsetByBytes(); // OffsetBytes
// \return false by default
virtual bool onSetFeatures(Feature value, bool set = true);
// TODO: bool onSetFeature(Feature f, bool s);
virtual bool onSetFeatures(Feature value, bool set = true); // TODO: remove
/*!
* \brief deviceSetVolume
* Set volume by backend api. If backend can not set the given volume, or SetVolume feature is not set, software implemention will be used.
Expand All @@ -223,6 +226,7 @@ class Q_AV_EXPORT AudioOutput : public QObject, public AVOutput
* \return true if success
*/
virtual bool deviceSetVolume(qreal value);
virtual qreal deviceGetVolume() const;
virtual bool deviceSetMute(bool value = true);
// reset internal status. MUST call this at the begining of open()
void resetStatus();
Expand Down
14 changes: 12 additions & 2 deletions src/output/audio/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,15 @@ void AudioOutput::setVolume(qreal volume)
d.vol = volume;
emit volumeChanged(d.vol);
d.updateSampleScaleFunc();
if (features() & SetVolume)
if (features() & SetVolume) {
d.sw_volume = !deviceSetVolume(d.vol);
else
//if (!qFuzzyCompare(deviceGetVolume(), d.vol))
// d.sw_volume = true;
if (d.sw_volume)
deviceSetVolume(1.0); // TODO: partial software?
} else {
d.sw_volume = true;
}
}

qreal AudioOutput::volume() const
Expand Down Expand Up @@ -517,6 +522,11 @@ bool AudioOutput::deviceSetVolume(qreal value)
return false;
}

qreal AudioOutput::deviceGetVolume() const
{
return 1.0;
}

bool AudioOutput::deviceSetMute(bool value)
{
Q_UNUSED(value)
Expand Down
13 changes: 13 additions & 0 deletions src/output/audio/AudioOutputOpenAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AudioOutputOpenAL : public AudioOutput
}

virtual bool deviceSetVolume(qreal value);
virtual qreal deviceGetVolume() const;
int getQueued();
};

Expand Down Expand Up @@ -447,6 +448,18 @@ bool AudioOutputOpenAL::deviceSetVolume(qreal value)
return true;
}

qreal AudioOutputOpenAL::deviceGetVolume() const
{
SCOPE_LOCK_CONTEXT();
ALfloat v = 1.0;
alGetListenerf(AL_GAIN, &v);
ALenum err = alGetError();
if (err != AL_NO_ERROR) {
qWarning("AudioOutputOpenAL Error>>> deviceGetVolume (%d) : %s", err, alGetString(err));
}
return v;
}

int AudioOutputOpenAL::getQueued()
{
SCOPE_LOCK_CONTEXT();
Expand Down

0 comments on commit 376fee8

Please sign in to comment.