diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-10-31 16:27:36 +0100 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-11-04 15:04:08 +0000 |
commit | 1ed707deeaf91b1b15e3d3175bc5d9f44b585710 (patch) | |
tree | 94d9c9c48900339134f3279d07748af314da8aba /src/plugins | |
parent | 9ebf1265da2c23ec86201d7f521a9352e0762944 (diff) | |
download | qtmultimedia-1ed707deeaf91b1b15e3d3175bc5d9f44b585710.tar.gz |
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>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/directshow/player/directshowplayercontrol.cpp | 60 | ||||
-rw-r--r-- | src/plugins/directshow/player/directshowplayercontrol.h | 4 |
2 files changed, 26 insertions, 38 deletions
diff --git a/src/plugins/directshow/player/directshowplayercontrol.cpp b/src/plugins/directshow/player/directshowplayercontrol.cpp index a5fed4b95..44e67b95e 100644 --- a/src/plugins/directshow/player/directshowplayercontrol.cpp +++ b/src/plugins/directshow/player/directshowplayercontrol.cpp @@ -73,7 +73,8 @@ DirectShowPlayerControl::DirectShowPlayerControl(DirectShowPlayerService *servic , m_status(QMediaPlayer::NoMedia) , m_error(QMediaPlayer::NoError) , m_streamTypes(0) - , m_muteVolume(-1) + , m_volume(100) + , m_muted(false) , m_position(0) , m_pendingPosition(-1) , m_duration(0) @@ -125,63 +126,47 @@ void DirectShowPlayerControl::setPosition(qint64 position) int DirectShowPlayerControl::volume() const { - if (m_muteVolume >= 0) { - return m_muteVolume; - } else if (m_audio) { - long dB = 0; - - m_audio->get_Volume(&dB); - - return decibelsToVolume(dB); - } else { - return 0; - } + return m_volume; } void DirectShowPlayerControl::setVolume(int volume) { int boundedVolume = qBound(0, volume, 100); - if (m_muteVolume >= 0) { - m_muteVolume = boundedVolume; + if (m_volume == boundedVolume) + return; - emit volumeChanged(m_muteVolume); - } else if (m_audio) { - m_audio->put_Volume(volumeToDecibels(volume)); + m_volume = boundedVolume; - emit volumeChanged(boundedVolume); - } + if (!m_muted) + setVolumeHelper(m_volume); + + emit volumeChanged(m_volume); } bool DirectShowPlayerControl::isMuted() const { - return m_muteVolume >= 0; + return m_muted; } void DirectShowPlayerControl::setMuted(bool muted) { - if (muted && m_muteVolume < 0) { - if (m_audio) { - long dB = 0; + if (m_muted == muted) + return; - m_audio->get_Volume(&dB); + m_muted = muted; - m_muteVolume = decibelsToVolume(dB); + setVolumeHelper(m_muted ? 0 : m_volume); - m_audio->put_Volume(-10000); - } else { - m_muteVolume = 0; - } + emit mutedChanged(m_muted); +} - emit mutedChanged(muted); - } else if (!muted && m_muteVolume >= 0) { - if (m_audio) { - m_audio->put_Volume(volumeToDecibels(m_muteVolume)); - } - m_muteVolume = -1; +void DirectShowPlayerControl::setVolumeHelper(int volume) +{ + if (!m_audio) + return; - emit mutedChanged(muted); - } + m_audio->put_Volume(volumeToDecibels(volume)); } int DirectShowPlayerControl::bufferStatus() const @@ -389,6 +374,7 @@ void DirectShowPlayerControl::updateAudioOutput(IBaseFilter *filter) m_audio->Release(); m_audio = com_cast<IBasicAudio>(filter, IID_IBasicAudio); + setVolumeHelper(m_muted ? 0 : m_volume); } void DirectShowPlayerControl::updateError(QMediaPlayer::Error error, const QString &errorString) diff --git a/src/plugins/directshow/player/directshowplayercontrol.h b/src/plugins/directshow/player/directshowplayercontrol.h index a42d3c7b1..d59b8ac28 100644 --- a/src/plugins/directshow/player/directshowplayercontrol.h +++ b/src/plugins/directshow/player/directshowplayercontrol.h @@ -116,6 +116,7 @@ private: void scheduleUpdate(int properties); void emitPropertyChanges(); + void setVolumeHelper(int volume); DirectShowPlayerService *m_service; IBasicAudio *m_audio; @@ -125,7 +126,8 @@ private: QMediaPlayer::MediaStatus m_status; QMediaPlayer::Error m_error; int m_streamTypes; - int m_muteVolume; + int m_volume; + bool m_muted; qint64 m_position; qint64 m_pendingPosition; qint64 m_duration; |