DirectShow: fix setting volume when a media is not loaded.
Store the pending volume and apply it once the media is loaded. Change-Id: I6998e9139aa3680220faa871b3116409855a1b35 Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
@@ -73,7 +73,8 @@ DirectShowPlayerControl::DirectShowPlayerControl(DirectShowPlayerService *servic
|
|||||||
, m_status(QMediaPlayer::NoMedia)
|
, m_status(QMediaPlayer::NoMedia)
|
||||||
, m_error(QMediaPlayer::NoError)
|
, m_error(QMediaPlayer::NoError)
|
||||||
, m_streamTypes(0)
|
, m_streamTypes(0)
|
||||||
, m_muteVolume(-1)
|
, m_volume(100)
|
||||||
|
, m_muted(false)
|
||||||
, m_position(0)
|
, m_position(0)
|
||||||
, m_pendingPosition(-1)
|
, m_pendingPosition(-1)
|
||||||
, m_duration(0)
|
, m_duration(0)
|
||||||
@@ -125,63 +126,47 @@ void DirectShowPlayerControl::setPosition(qint64 position)
|
|||||||
|
|
||||||
int DirectShowPlayerControl::volume() const
|
int DirectShowPlayerControl::volume() const
|
||||||
{
|
{
|
||||||
if (m_muteVolume >= 0) {
|
return m_volume;
|
||||||
return m_muteVolume;
|
|
||||||
} else if (m_audio) {
|
|
||||||
long dB = 0;
|
|
||||||
|
|
||||||
m_audio->get_Volume(&dB);
|
|
||||||
|
|
||||||
return decibelsToVolume(dB);
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectShowPlayerControl::setVolume(int volume)
|
void DirectShowPlayerControl::setVolume(int volume)
|
||||||
{
|
{
|
||||||
int boundedVolume = qBound(0, volume, 100);
|
int boundedVolume = qBound(0, volume, 100);
|
||||||
|
|
||||||
if (m_muteVolume >= 0) {
|
if (m_volume == boundedVolume)
|
||||||
m_muteVolume = boundedVolume;
|
return;
|
||||||
|
|
||||||
emit volumeChanged(m_muteVolume);
|
m_volume = boundedVolume;
|
||||||
} else if (m_audio) {
|
|
||||||
m_audio->put_Volume(volumeToDecibels(volume));
|
|
||||||
|
|
||||||
emit volumeChanged(boundedVolume);
|
if (!m_muted)
|
||||||
}
|
setVolumeHelper(m_volume);
|
||||||
|
|
||||||
|
emit volumeChanged(m_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DirectShowPlayerControl::isMuted() const
|
bool DirectShowPlayerControl::isMuted() const
|
||||||
{
|
{
|
||||||
return m_muteVolume >= 0;
|
return m_muted;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectShowPlayerControl::setMuted(bool muted)
|
void DirectShowPlayerControl::setMuted(bool muted)
|
||||||
{
|
{
|
||||||
if (muted && m_muteVolume < 0) {
|
if (m_muted == muted)
|
||||||
if (m_audio) {
|
return;
|
||||||
long dB = 0;
|
|
||||||
|
|
||||||
m_audio->get_Volume(&dB);
|
m_muted = muted;
|
||||||
|
|
||||||
m_muteVolume = decibelsToVolume(dB);
|
setVolumeHelper(m_muted ? 0 : m_volume);
|
||||||
|
|
||||||
m_audio->put_Volume(-10000);
|
emit mutedChanged(m_muted);
|
||||||
} else {
|
}
|
||||||
m_muteVolume = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
emit mutedChanged(muted);
|
void DirectShowPlayerControl::setVolumeHelper(int volume)
|
||||||
} else if (!muted && m_muteVolume >= 0) {
|
{
|
||||||
if (m_audio) {
|
if (!m_audio)
|
||||||
m_audio->put_Volume(volumeToDecibels(m_muteVolume));
|
return;
|
||||||
}
|
|
||||||
m_muteVolume = -1;
|
|
||||||
|
|
||||||
emit mutedChanged(muted);
|
m_audio->put_Volume(volumeToDecibels(volume));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DirectShowPlayerControl::bufferStatus() const
|
int DirectShowPlayerControl::bufferStatus() const
|
||||||
@@ -389,6 +374,7 @@ void DirectShowPlayerControl::updateAudioOutput(IBaseFilter *filter)
|
|||||||
m_audio->Release();
|
m_audio->Release();
|
||||||
|
|
||||||
m_audio = com_cast<IBasicAudio>(filter, IID_IBasicAudio);
|
m_audio = com_cast<IBasicAudio>(filter, IID_IBasicAudio);
|
||||||
|
setVolumeHelper(m_muted ? 0 : m_volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirectShowPlayerControl::updateError(QMediaPlayer::Error error, const QString &errorString)
|
void DirectShowPlayerControl::updateError(QMediaPlayer::Error error, const QString &errorString)
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ private:
|
|||||||
|
|
||||||
void scheduleUpdate(int properties);
|
void scheduleUpdate(int properties);
|
||||||
void emitPropertyChanges();
|
void emitPropertyChanges();
|
||||||
|
void setVolumeHelper(int volume);
|
||||||
|
|
||||||
DirectShowPlayerService *m_service;
|
DirectShowPlayerService *m_service;
|
||||||
IBasicAudio *m_audio;
|
IBasicAudio *m_audio;
|
||||||
@@ -125,7 +126,8 @@ private:
|
|||||||
QMediaPlayer::MediaStatus m_status;
|
QMediaPlayer::MediaStatus m_status;
|
||||||
QMediaPlayer::Error m_error;
|
QMediaPlayer::Error m_error;
|
||||||
int m_streamTypes;
|
int m_streamTypes;
|
||||||
int m_muteVolume;
|
int m_volume;
|
||||||
|
bool m_muted;
|
||||||
qint64 m_position;
|
qint64 m_position;
|
||||||
qint64 m_pendingPosition;
|
qint64 m_pendingPosition;
|
||||||
qint64 m_duration;
|
qint64 m_duration;
|
||||||
|
|||||||
Reference in New Issue
Block a user