diff options
Diffstat (limited to 'src/multimedia/platform/windows/player')
4 files changed, 56 insertions, 95 deletions
diff --git a/src/multimedia/platform/windows/player/mfplayercontrol.cpp b/src/multimedia/platform/windows/player/mfplayercontrol.cpp index 117cd402c..e6ac343b3 100644 --- a/src/multimedia/platform/windows/player/mfplayercontrol.cpp +++ b/src/multimedia/platform/windows/player/mfplayercontrol.cpp @@ -126,14 +126,9 @@ QMediaMetaData MFPlayerControl::metaData() const return m_session->metaData(); } -bool MFPlayerControl::setAudioOutput(const QAudioDevice &info) +void MFPlayerControl::setAudioOutput(QPlatformAudioOutput *output) { - return m_session->setAudioOutput(info); -} - -QAudioDevice MFPlayerControl::audioOutput() const -{ - return m_session->audioOutput(); + m_session->setAudioOutput(output); } void MFPlayerControl::setVideoSink(QVideoSink *sink) @@ -254,26 +249,6 @@ void MFPlayerControl::setPosition(qint64 position) m_session->setPosition(position); } -int MFPlayerControl::volume() const -{ - return m_session->volume(); -} - -void MFPlayerControl::setVolume(int volume) -{ - m_session->setVolume(volume); -} - -bool MFPlayerControl::isMuted() const -{ - return m_session->isMuted(); -} - -void MFPlayerControl::setMuted(bool muted) -{ - m_session->setMuted(muted); -} - float MFPlayerControl::bufferProgress() const { return m_session->bufferProgress() / 100.; diff --git a/src/multimedia/platform/windows/player/mfplayercontrol_p.h b/src/multimedia/platform/windows/player/mfplayercontrol_p.h index 8433ae58a..995181626 100644 --- a/src/multimedia/platform/windows/player/mfplayercontrol_p.h +++ b/src/multimedia/platform/windows/player/mfplayercontrol_p.h @@ -75,12 +75,6 @@ public: qint64 position() const override; void setPosition(qint64 position) override; - int volume() const override; - void setVolume(int volume) override; - - bool isMuted() const override; - void setMuted(bool muted) override; - float bufferProgress() const override; bool isAudioAvailable() const override; @@ -105,8 +99,7 @@ public: QMediaMetaData metaData() const override; - bool setAudioOutput(const QAudioDevice &) override; - QAudioDevice audioOutput() const override; + void setAudioOutput(QPlatformAudioOutput *output) override; void setVideoSink(QVideoSink *sink) override; diff --git a/src/multimedia/platform/windows/player/mfplayersession.cpp b/src/multimedia/platform/windows/player/mfplayersession.cpp index b2afca6bf..1fa05c33a 100644 --- a/src/multimedia/platform/windows/player/mfplayersession.cpp +++ b/src/multimedia/platform/windows/player/mfplayersession.cpp @@ -47,6 +47,9 @@ #include <QtCore/qfile.h> #include <QtCore/qbuffer.h> +#include "qplatformaudiooutput_p.h" +#include "qaudiooutput.h" + #include "mfplayercontrol_p.h" #include "mfevrvideowindowcontrol_p.h" #include "mfvideorenderercontrol_p.h" @@ -83,8 +86,6 @@ MFPlayerSession::MFPlayerSession(MFPlayerControl *playerControl) , m_mediaTypes(0) , m_pendingRate(1) , m_status(QMediaPlayer::NoMedia) - , m_volume(100) - , m_muted(false) , m_audioSampleGrabber(0) , m_audioSampleGrabberNode(0) , m_videoProbeMFT(0) @@ -397,34 +398,36 @@ IMFTopologyNode* MFPlayerSession::addOutputNode(MediaType mediaType, IMFTopology IMFActivate *activate = NULL; if (mediaType == Audio) { - HRESULT hr = MFCreateAudioRendererActivate(&activate); - if (FAILED(hr)) { - qWarning() << "Failed to create audio renderer activate"; - node->Release(); - return NULL; - } + if (m_audioOutput) { + HRESULT hr = MFCreateAudioRendererActivate(&activate); + if (FAILED(hr)) { + qWarning() << "Failed to create audio renderer activate"; + node->Release(); + return NULL; + } - if (!m_audioOutput.id().isEmpty()) { - QString s = QString::fromUtf8(m_audioOutput.id()); - hr = activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, (LPCWSTR)s.utf16()); - } else { - //This is the default one that has been inserted in updateEndpoints(), - //so give the activate a hint that we want to use the device for multimedia playback - //then the media foundation will choose an appropriate one. - - //from MSDN: - //The ERole enumeration defines constants that indicate the role that the system has assigned to an audio endpoint device. - //eMultimedia: Music, movies, narration, and live music recording. - hr = activate->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ROLE, eMultimedia); - } + auto id = m_audioOutput->device.id(); + if (!id.isEmpty()) { + QString s = QString::fromUtf8(id); + hr = activate->SetString(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ID, (LPCWSTR)s.utf16()); + } else { + //This is the default one that has been inserted in updateEndpoints(), + //so give the activate a hint that we want to use the device for multimedia playback + //then the media foundation will choose an appropriate one. + + //from MSDN: + //The ERole enumeration defines constants that indicate the role that the system has assigned to an audio endpoint device. + //eMultimedia: Music, movies, narration, and live music recording. + hr = activate->SetUINT32(MF_AUDIO_RENDERER_ATTRIBUTE_ENDPOINT_ROLE, eMultimedia); + } - if (FAILED(hr)) { - qWarning() << "Failed to set attribute for audio device" << m_audioOutput.description(); - activate->Release(); - node->Release(); - return NULL; + if (FAILED(hr)) { + qWarning() << "Failed to set attribute for audio device" << m_audioOutput->device.description(); + activate->Release(); + node->Release(); + return NULL; + } } - } else if (mediaType == Video) { activate = m_videoRendererControl->createActivate(); } else { @@ -1350,12 +1353,7 @@ void MFPlayerSession::scrub(bool enableScrub) } } -int MFPlayerSession::volume() const -{ - return m_volume; -} - -void MFPlayerSession::setVolume(int volume) +void MFPlayerSession::setVolume(float volume) { if (m_volume == volume) return; @@ -1363,13 +1361,6 @@ void MFPlayerSession::setVolume(int volume) if (!m_muted) setVolumeInternal(volume); - - emit volumeChanged(m_volume); -} - -bool MFPlayerSession::isMuted() const -{ - return m_muted; } void MFPlayerSession::setMuted(bool muted) @@ -1379,11 +1370,9 @@ void MFPlayerSession::setMuted(bool muted) m_muted = muted; setVolumeInternal(muted ? 0 : m_volume); - - emit mutedChanged(m_muted); } -void MFPlayerSession::setVolumeInternal(int volume) +void MFPlayerSession::setVolumeInternal(float volume) { if (m_volumeControl) { quint32 channelCount = 0; @@ -1391,9 +1380,8 @@ void MFPlayerSession::setVolumeInternal(int volume) || channelCount == 0) return; - float scaled = volume * 0.01f; for (quint32 i = 0; i < channelCount; ++i) - m_volumeControl->SetChannelVolume(i, scaled); + m_volumeControl->SetChannelVolume(i, volume); } } @@ -1811,15 +1799,23 @@ void MFPlayerSession::clear() } } -bool MFPlayerSession::setAudioOutput(const QAudioDevice &device) +void MFPlayerSession::setAudioOutput(QPlatformAudioOutput *device) { // ### This doesn't yet update the output routing during playback // ie. it currently only works before the first play(). if (m_audioOutput == device) - return true; + return; + + if (m_audioOutput) + m_audioOutput->q->disconnect(this); m_audioOutput = device; - return true; + if (m_audioOutput) { + // #### Implement device changes: connect(m_audioOutput->q, &QAudioOutput::deviceChanged, this, XXXX); + connect(m_audioOutput->q, &QAudioOutput::volumeChanged, this, &MFPlayerSession::setVolume); + connect(m_audioOutput->q, &QAudioOutput::mutedChanged, this, &MFPlayerSession::setMuted); +// connect(m_audioOutput->q, &QAudioOutput::audioRoleChanged, this, &MFPlayerSession::setAudioRole); + } } void MFPlayerSession::setVideoSink(QVideoSink *sink) diff --git a/src/multimedia/platform/windows/player/mfplayersession_p.h b/src/multimedia/platform/windows/player/mfplayersession_p.h index 9f035e4c2..10b424a37 100644 --- a/src/multimedia/platform/windows/player/mfplayersession_p.h +++ b/src/multimedia/platform/windows/player/mfplayersession_p.h @@ -112,10 +112,6 @@ public: void setPosition(qint64 position); qreal playbackRate() const; void setPlaybackRate(qreal rate); - int volume() const; - void setVolume(int volume); - bool isMuted() const; - void setMuted(bool muted); float bufferProgress(); QMediaTimeRange availablePlaybackRanges(); @@ -124,8 +120,7 @@ public: void close(); void clearPlayer() { m_playerControl = nullptr; } - bool setAudioOutput(const QAudioDevice &device); - QAudioDevice audioOutput() const { return m_audioOutput; } + void setAudioOutput(QPlatformAudioOutput *device); QMediaMetaData metaData() const { return m_metaData; } @@ -138,12 +133,14 @@ public: void seekableUpdate(bool seekable) { if (m_playerControl) m_playerControl->handleSeekableUpdate(seekable); } void error(QMediaPlayer::Error error, QString errorString, bool isFatal) { if (m_playerControl) m_playerControl->handleError(error, errorString, isFatal); } void playbackRateChanged(qreal rate) { if (m_playerControl) m_playerControl->playbackRateChanged(rate); } - void volumeChanged(int volume) { if (m_playerControl) m_playerControl->volumeChanged(volume); } - void mutedChanged(bool muted) { if (m_playerControl) m_playerControl->mutedChanged(muted); } void bufferProgressChanged(float percentFilled) { if (m_playerControl) m_playerControl->bufferProgressChanged(percentFilled); } void metaDataChanged() { if (m_playerControl) m_playerControl->metaDataChanged(); } void positionChanged(qint64 position) { if (m_playerControl) m_playerControl->positionChanged(position); } +public Q_SLOTS: + void setVolume(float volume); + void setMuted(bool muted); + Q_SIGNALS: void sessionEvent(IMFMediaEvent *sessionEvent); @@ -224,13 +221,13 @@ private: QMediaPlayer::MediaStatus m_status; bool m_canScrub; - int m_volume; - bool m_muted; + float m_volume = 1.; + bool m_muted = false; - QAudioDevice m_audioOutput; + QPlatformAudioOutput *m_audioOutput = nullptr; QMediaMetaData m_metaData; - void setVolumeInternal(int volume); + void setVolumeInternal(float volume); void createSession(); void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD); |