diff options
Diffstat (limited to 'src/plugins/android/src/mediaplayer')
13 files changed, 0 insertions, 1899 deletions
diff --git a/src/plugins/android/src/mediaplayer/mediaplayer.pri b/src/plugins/android/src/mediaplayer/mediaplayer.pri deleted file mode 100644 index 3a9cef3a1..000000000 --- a/src/plugins/android/src/mediaplayer/mediaplayer.pri +++ /dev/null @@ -1,17 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/qandroidmediaplayercontrol.h \ - $$PWD/qandroidmediaservice.h \ - $$PWD/qandroidmetadatareadercontrol.h \ - $$PWD/qandroidaudiorolecontrol.h \ - $$PWD/qandroidcustomaudiorolecontrol.h \ - $$PWD/qandroidmediaplayervideorenderercontrol.h - -SOURCES += \ - $$PWD/qandroidmediaplayercontrol.cpp \ - $$PWD/qandroidmediaservice.cpp \ - $$PWD/qandroidmetadatareadercontrol.cpp \ - $$PWD/qandroidaudiorolecontrol.cpp \ - $$PWD/qandroidcustomaudiorolecontrol.cpp \ - $$PWD/qandroidmediaplayervideorenderercontrol.cpp diff --git a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp deleted file mode 100644 index 5879b0cb9..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidaudiorolecontrol.h" - -QT_BEGIN_NAMESPACE - -QAndroidAudioRoleControl::QAndroidAudioRoleControl(QObject *parent) - : QAudioRoleControl(parent) -{ -} - -QAudio::Role QAndroidAudioRoleControl::audioRole() const -{ - return m_role; -} - -void QAndroidAudioRoleControl::setAudioRole(QAudio::Role role) -{ - if (m_role == role) - return; - - m_role = role; - emit audioRoleChanged(m_role); -} - -QList<QAudio::Role> QAndroidAudioRoleControl::supportedAudioRoles() const -{ - return QList<QAudio::Role>() - << QAudio::VoiceCommunicationRole - << QAudio::MusicRole - << QAudio::VideoRole - << QAudio::SonificationRole - << QAudio::AlarmRole - << QAudio::NotificationRole - << QAudio::RingtoneRole - << QAudio::AccessibilityRole - << QAudio::GameRole; -} - -QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h deleted file mode 100644 index 89219e026..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDAUDIOROLECONTROL_H -#define QANDROIDAUDIOROLECONTROL_H - -#include <qaudiorolecontrol.h> - -QT_BEGIN_NAMESPACE - -class QAndroidAudioRoleControl : public QAudioRoleControl -{ - Q_OBJECT -public: - explicit QAndroidAudioRoleControl(QObject *parent = nullptr); - - QAudio::Role audioRole() const override; - void setAudioRole(QAudio::Role role) override; - QList<QAudio::Role> supportedAudioRoles() const override; - -private: - QAudio::Role m_role = QAudio::UnknownRole; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDAUDIOROLECONTROL_H diff --git a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp deleted file mode 100644 index cb7b5d0af..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidcustomaudiorolecontrol.h" - -QT_BEGIN_NAMESPACE - -QAndroidCustomAudioRoleControl::QAndroidCustomAudioRoleControl(QObject *parent) - : QCustomAudioRoleControl(parent) -{ -} - -QString QAndroidCustomAudioRoleControl::customAudioRole() const -{ - return m_role; -} - -void QAndroidCustomAudioRoleControl::setCustomAudioRole(const QString &role) -{ - if (m_role == role) - return; - - m_role = role; - emit customAudioRoleChanged(m_role); -} - -QStringList QAndroidCustomAudioRoleControl::supportedCustomAudioRoles() const -{ - return QStringList() - << "CONTENT_TYPE_MOVIE" - << "CONTENT_TYPE_MUSIC" - << "CONTENT_TYPE_SONIFICATION" - << "CONTENT_TYPE_SPEECH" - << "USAGE_ALARM" - << "USAGE_ASSISTANCE_ACCESSIBILITY" - << "USAGE_ASSISTANCE_NAVIGATION_GUIDANCE" - << "USAGE_ASSISTANCE_SONIFICATION" - << "USAGE_ASSISTANT" - << "USAGE_GAME" - << "USAGE_MEDIA" - << "USAGE_NOTIFICATION" - << "USAGE_NOTIFICATION_COMMUNICATION_DELAYED" - << "USAGE_NOTIFICATION_COMMUNICATION_INSTANT" - << "USAGE_NOTIFICATION_COMMUNICATION_REQUEST" - << "USAGE_NOTIFICATION_EVENT" - << "USAGE_NOTIFICATION_RINGTONE" - << "USAGE_VOICE_COMMUNICATION" - << "USAGE_VOICE_COMMUNICATION_SIGNALLING"; -} - -QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h deleted file mode 100644 index 4604ebe67..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDCUSTOMAUDIOROLECONTROL_H -#define QANDROIDCUSTOMAUDIOROLECONTROL_H - -#include <qcustomaudiorolecontrol.h> - -QT_BEGIN_NAMESPACE - -class QAndroidCustomAudioRoleControl : public QCustomAudioRoleControl -{ - Q_OBJECT -public: - explicit QAndroidCustomAudioRoleControl(QObject *parent = nullptr); - - QString customAudioRole() const override; - void setCustomAudioRole(const QString &role) override; - QStringList supportedCustomAudioRoles() const override; - -private: - QString m_role; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDCUSTOMAUDIOROLECONTROL_H diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp deleted file mode 100644 index 82250b654..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp +++ /dev/null @@ -1,797 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidmediaplayercontrol.h" -#include "androidmediaplayer.h" -#include "qandroidvideooutput.h" - -QT_BEGIN_NAMESPACE - -class StateChangeNotifier -{ -public: - StateChangeNotifier(QAndroidMediaPlayerControl *mp) - : mControl(mp) - , mPreviousState(mp->state()) - , mPreviousMediaStatus(mp->mediaStatus()) - { - ++mControl->mActiveStateChangeNotifiers; - } - - ~StateChangeNotifier() - { - if (--mControl->mActiveStateChangeNotifiers) - return; - - if (mPreviousMediaStatus != mControl->mediaStatus()) - Q_EMIT mControl->mediaStatusChanged(mControl->mediaStatus()); - - if (mPreviousState != mControl->state()) - Q_EMIT mControl->stateChanged(mControl->state()); - } - -private: - QAndroidMediaPlayerControl *mControl; - QMediaPlayer::State mPreviousState; - QMediaPlayer::MediaStatus mPreviousMediaStatus; -}; - - -QAndroidMediaPlayerControl::QAndroidMediaPlayerControl(QObject *parent) - : QMediaPlayerControl(parent), - mMediaPlayer(new AndroidMediaPlayer), - mCurrentState(QMediaPlayer::StoppedState), - mCurrentMediaStatus(QMediaPlayer::NoMedia), - mMediaStream(0), - mVideoOutput(0), - mSeekable(true), - mBufferPercent(-1), - mBufferFilled(false), - mAudioAvailable(false), - mVideoAvailable(false), - mBuffering(false), - mState(AndroidMediaPlayer::Uninitialized), - mPendingState(-1), - mPendingPosition(-1), - mPendingSetMedia(false), - mPendingVolume(-1), - mPendingMute(-1), - mReloadingMedia(false), - mActiveStateChangeNotifiers(0), - mPendingPlaybackRate(1.0), - mHasPendingPlaybackRate(false) -{ - connect(mMediaPlayer,SIGNAL(bufferingChanged(qint32)), - this,SLOT(onBufferingChanged(qint32))); - connect(mMediaPlayer,SIGNAL(info(qint32,qint32)), - this,SLOT(onInfo(qint32,qint32))); - connect(mMediaPlayer,SIGNAL(error(qint32,qint32)), - this,SLOT(onError(qint32,qint32))); - connect(mMediaPlayer,SIGNAL(stateChanged(qint32)), - this,SLOT(onStateChanged(qint32))); - connect(mMediaPlayer,SIGNAL(videoSizeChanged(qint32,qint32)), - this,SLOT(onVideoSizeChanged(qint32,qint32))); - connect(mMediaPlayer,SIGNAL(progressChanged(qint64)), - this,SIGNAL(positionChanged(qint64))); - connect(mMediaPlayer,SIGNAL(durationChanged(qint64)), - this,SIGNAL(durationChanged(qint64))); -} - -QAndroidMediaPlayerControl::~QAndroidMediaPlayerControl() -{ - mMediaPlayer->release(); - delete mMediaPlayer; -} - -QMediaPlayer::State QAndroidMediaPlayerControl::state() const -{ - return mCurrentState; -} - -QMediaPlayer::MediaStatus QAndroidMediaPlayerControl::mediaStatus() const -{ - return mCurrentMediaStatus; -} - -qint64 QAndroidMediaPlayerControl::duration() const -{ - if ((mState & (AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::Stopped - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - return 0; - } - - return mMediaPlayer->getDuration(); -} - -qint64 QAndroidMediaPlayerControl::position() const -{ - if (mCurrentMediaStatus == QMediaPlayer::EndOfMedia) - return duration(); - - if ((mState & (AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted))) { - return mMediaPlayer->getCurrentPosition(); - } - - return (mPendingPosition == -1) ? 0 : mPendingPosition; -} - -void QAndroidMediaPlayerControl::setPosition(qint64 position) -{ - if (!mSeekable) - return; - - const int seekPosition = (position > INT_MAX) ? INT_MAX : position; - - if (seekPosition == this->position()) - return; - - StateChangeNotifier notifier(this); - - if (mCurrentMediaStatus == QMediaPlayer::EndOfMedia) - setMediaStatus(QMediaPlayer::LoadedMedia); - - if ((mState & (AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - mPendingPosition = seekPosition; - } else { - mMediaPlayer->seekTo(seekPosition); - - if (mPendingPosition != -1) { - mPendingPosition = -1; - } - } - - Q_EMIT positionChanged(seekPosition); -} - -int QAndroidMediaPlayerControl::volume() const -{ - return (mPendingVolume == -1) ? mMediaPlayer->volume() : mPendingVolume; -} - -void QAndroidMediaPlayerControl::setVolume(int volume) -{ - if ((mState & (AndroidMediaPlayer::Idle - | AndroidMediaPlayer::Initialized - | AndroidMediaPlayer::Stopped - | AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - if (mPendingVolume != volume) { - mPendingVolume = volume; - Q_EMIT volumeChanged(volume); - } - return; - } - - mMediaPlayer->setVolume(volume); - - if (mPendingVolume != -1) { - mPendingVolume = -1; - return; - } - - Q_EMIT volumeChanged(volume); -} - -bool QAndroidMediaPlayerControl::isMuted() const -{ - return (mPendingMute == -1) ? mMediaPlayer->isMuted() : (mPendingMute == 1); -} - -void QAndroidMediaPlayerControl::setMuted(bool muted) -{ - if ((mState & (AndroidMediaPlayer::Idle - | AndroidMediaPlayer::Initialized - | AndroidMediaPlayer::Stopped - | AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - if (mPendingMute != muted) { - mPendingMute = muted; - Q_EMIT mutedChanged(muted); - } - return; - } - - mMediaPlayer->setMuted(muted); - - if (mPendingMute != -1) { - mPendingMute = -1; - return; - } - - Q_EMIT mutedChanged(muted); -} - -void QAndroidMediaPlayerControl::setAudioRole(QAudio::Role role) -{ - mMediaPlayer->setAudioRole(role); -} - -void QAndroidMediaPlayerControl::setCustomAudioRole(const QString &role) -{ - mMediaPlayer->setCustomAudioRole(role); -} - -int QAndroidMediaPlayerControl::bufferStatus() const -{ - return mBufferFilled ? 100 : 0; -} - -bool QAndroidMediaPlayerControl::isAudioAvailable() const -{ - return mAudioAvailable; -} - -bool QAndroidMediaPlayerControl::isVideoAvailable() const -{ - return mVideoAvailable; -} - -bool QAndroidMediaPlayerControl::isSeekable() const -{ - return mSeekable; -} - -QMediaTimeRange QAndroidMediaPlayerControl::availablePlaybackRanges() const -{ - return mAvailablePlaybackRange; -} - -void QAndroidMediaPlayerControl::updateAvailablePlaybackRanges() -{ - if (mBuffering) { - const qint64 pos = position(); - const qint64 end = (duration() / 100) * mBufferPercent; - mAvailablePlaybackRange.addInterval(pos, end); - } else if (mSeekable) { - mAvailablePlaybackRange = QMediaTimeRange(0, duration()); - } else { - mAvailablePlaybackRange = QMediaTimeRange(); - } - - Q_EMIT availablePlaybackRangesChanged(mAvailablePlaybackRange); -} - -qreal QAndroidMediaPlayerControl::playbackRate() const -{ - if (mHasPendingPlaybackRate || - (mState & (AndroidMediaPlayer::Initialized - | AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted - | AndroidMediaPlayer::Error)) == 0) { - return mPendingPlaybackRate; - } - - return mMediaPlayer->playbackRate(); -} - -void QAndroidMediaPlayerControl::setPlaybackRate(qreal rate) -{ - if ((mState & (AndroidMediaPlayer::Initialized - | AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted - | AndroidMediaPlayer::Error)) == 0) { - if (mPendingPlaybackRate != rate) { - mPendingPlaybackRate = rate; - mHasPendingPlaybackRate = true; - Q_EMIT playbackRateChanged(rate); - } - return; - } - - bool succeeded = mMediaPlayer->setPlaybackRate(rate); - - if (mHasPendingPlaybackRate) { - mHasPendingPlaybackRate = false; - mPendingPlaybackRate = qreal(1.0); - if (!succeeded) - Q_EMIT playbackRateChanged(playbackRate()); - } else if (succeeded) { - Q_EMIT playbackRateChanged(rate); - } -} - -QMediaContent QAndroidMediaPlayerControl::media() const -{ - return mMediaContent; -} - -const QIODevice *QAndroidMediaPlayerControl::mediaStream() const -{ - return mMediaStream; -} - -void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent, - QIODevice *stream) -{ - StateChangeNotifier notifier(this); - - mReloadingMedia = (mMediaContent == mediaContent) && !mPendingSetMedia; - - if (!mReloadingMedia) { - mMediaContent = mediaContent; - mMediaStream = stream; - } - - // Release the mediaplayer if it's not in in Idle or Uninitialized state - if ((mState & (AndroidMediaPlayer::Idle | AndroidMediaPlayer::Uninitialized)) == 0) - mMediaPlayer->release(); - - if (mediaContent.isNull()) { - setMediaStatus(QMediaPlayer::NoMedia); - } else { - if (mVideoOutput && !mVideoOutput->isReady()) { - // if a video output is set but the video texture is not ready, delay loading the media - // since it can cause problems on some hardware - mPendingSetMedia = true; - return; - } - - if (mVideoSize.isValid() && mVideoOutput) - mVideoOutput->setVideoSize(mVideoSize); - - if ((mMediaPlayer->display() == 0) && mVideoOutput) - mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture()); - mMediaPlayer->setDataSource(mediaContent.request()); - mMediaPlayer->prepareAsync(); - } - - if (!mReloadingMedia) - Q_EMIT mediaChanged(mMediaContent); - - resetBufferingProgress(); - - mReloadingMedia = false; -} - -void QAndroidMediaPlayerControl::setVideoOutput(QAndroidVideoOutput *videoOutput) -{ - if (mVideoOutput) { - mMediaPlayer->setDisplay(0); - mVideoOutput->stop(); - mVideoOutput->reset(); - } - - mVideoOutput = videoOutput; - - if (!mVideoOutput) - return; - - if (mVideoOutput->isReady()) - mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture()); - - connect(videoOutput, SIGNAL(readyChanged(bool)), this, SLOT(onVideoOutputReady(bool))); -} - -void QAndroidMediaPlayerControl::play() -{ - StateChangeNotifier notifier(this); - - // We need to prepare the mediaplayer again. - if ((mState & AndroidMediaPlayer::Stopped) && !mMediaContent.isNull()) { - setMedia(mMediaContent, mMediaStream); - } - - if (!mMediaContent.isNull()) - setState(QMediaPlayer::PlayingState); - - if ((mState & (AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - mPendingState = QMediaPlayer::PlayingState; - return; - } - - mMediaPlayer->play(); -} - -void QAndroidMediaPlayerControl::pause() -{ - StateChangeNotifier notifier(this); - - setState(QMediaPlayer::PausedState); - - if ((mState & (AndroidMediaPlayer::Started - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - mPendingState = QMediaPlayer::PausedState; - return; - } - - mMediaPlayer->pause(); -} - -void QAndroidMediaPlayerControl::stop() -{ - StateChangeNotifier notifier(this); - - setState(QMediaPlayer::StoppedState); - - if ((mState & (AndroidMediaPlayer::Prepared - | AndroidMediaPlayer::Started - | AndroidMediaPlayer::Stopped - | AndroidMediaPlayer::Paused - | AndroidMediaPlayer::PlaybackCompleted)) == 0) { - if ((mState & (AndroidMediaPlayer::Idle | AndroidMediaPlayer::Uninitialized | AndroidMediaPlayer::Error)) == 0) - mPendingState = QMediaPlayer::StoppedState; - return; - } - - mMediaPlayer->stop(); -} - -void QAndroidMediaPlayerControl::onInfo(qint32 what, qint32 extra) -{ - StateChangeNotifier notifier(this); - - Q_UNUSED(extra); - switch (what) { - case AndroidMediaPlayer::MEDIA_INFO_UNKNOWN: - break; - case AndroidMediaPlayer::MEDIA_INFO_VIDEO_TRACK_LAGGING: - // IGNORE - break; - case AndroidMediaPlayer::MEDIA_INFO_VIDEO_RENDERING_START: - break; - case AndroidMediaPlayer::MEDIA_INFO_BUFFERING_START: - mPendingState = mCurrentState; - setState(QMediaPlayer::PausedState); - setMediaStatus(QMediaPlayer::StalledMedia); - break; - case AndroidMediaPlayer::MEDIA_INFO_BUFFERING_END: - if (mCurrentState != QMediaPlayer::StoppedState) - flushPendingStates(); - break; - case AndroidMediaPlayer::MEDIA_INFO_BAD_INTERLEAVING: - break; - case AndroidMediaPlayer::MEDIA_INFO_NOT_SEEKABLE: - setSeekable(false); - break; - case AndroidMediaPlayer::MEDIA_INFO_METADATA_UPDATE: - Q_EMIT metaDataUpdated(); - break; - } -} - -void QAndroidMediaPlayerControl::onError(qint32 what, qint32 extra) -{ - StateChangeNotifier notifier(this); - - QString errorString; - QMediaPlayer::Error error = QMediaPlayer::ResourceError; - - switch (what) { - case AndroidMediaPlayer::MEDIA_ERROR_UNKNOWN: - errorString = QLatin1String("Error:"); - break; - case AndroidMediaPlayer::MEDIA_ERROR_SERVER_DIED: - errorString = QLatin1String("Error: Server died"); - error = QMediaPlayer::ServiceMissingError; - break; - case AndroidMediaPlayer::MEDIA_ERROR_INVALID_STATE: - errorString = QLatin1String("Error: Invalid state"); - error = QMediaPlayer::ServiceMissingError; - break; - } - - switch (extra) { - case AndroidMediaPlayer::MEDIA_ERROR_IO: // Network OR file error - errorString += QLatin1String(" (I/O operation failed)"); - error = QMediaPlayer::NetworkError; - setMediaStatus(QMediaPlayer::InvalidMedia); - break; - case AndroidMediaPlayer::MEDIA_ERROR_MALFORMED: - errorString += QLatin1String(" (Malformed bitstream)"); - error = QMediaPlayer::FormatError; - setMediaStatus(QMediaPlayer::InvalidMedia); - break; - case AndroidMediaPlayer::MEDIA_ERROR_UNSUPPORTED: - errorString += QLatin1String(" (Unsupported media)"); - error = QMediaPlayer::FormatError; - setMediaStatus(QMediaPlayer::InvalidMedia); - break; - case AndroidMediaPlayer::MEDIA_ERROR_TIMED_OUT: - errorString += QLatin1String(" (Timed out)"); - break; - case AndroidMediaPlayer::MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK: - errorString += QLatin1String(" (Unable to start progressive playback')"); - error = QMediaPlayer::FormatError; - setMediaStatus(QMediaPlayer::InvalidMedia); - break; - case AndroidMediaPlayer::MEDIA_ERROR_BAD_THINGS_ARE_GOING_TO_HAPPEN: - errorString += QLatin1String(" (Unknown error/Insufficient resources)"); - error = QMediaPlayer::ServiceMissingError; - break; - } - - Q_EMIT QMediaPlayerControl::error(error, errorString); -} - -void QAndroidMediaPlayerControl::onBufferingChanged(qint32 percent) -{ - StateChangeNotifier notifier(this); - - mBuffering = percent != 100; - mBufferPercent = percent; - - updateAvailablePlaybackRanges(); - - if (mCurrentState != QMediaPlayer::StoppedState) - setMediaStatus(mBuffering ? QMediaPlayer::BufferingMedia : QMediaPlayer::BufferedMedia); -} - -void QAndroidMediaPlayerControl::onVideoSizeChanged(qint32 width, qint32 height) -{ - QSize newSize(width, height); - - if (width == 0 || height == 0 || newSize == mVideoSize) - return; - - setVideoAvailable(true); - mVideoSize = newSize; - - if (mVideoOutput) - mVideoOutput->setVideoSize(mVideoSize); -} - -void QAndroidMediaPlayerControl::onStateChanged(qint32 state) -{ - // If reloading, don't report state changes unless the new state is Prepared or Error. - if ((mState & AndroidMediaPlayer::Stopped) - && (state & (AndroidMediaPlayer::Prepared | AndroidMediaPlayer::Error | AndroidMediaPlayer::Uninitialized)) == 0) { - return; - } - - StateChangeNotifier notifier(this); - - mState = state; - switch (mState) { - case AndroidMediaPlayer::Idle: - break; - case AndroidMediaPlayer::Initialized: - break; - case AndroidMediaPlayer::Preparing: - if (!mReloadingMedia) - setMediaStatus(QMediaPlayer::LoadingMedia); - break; - case AndroidMediaPlayer::Prepared: - setMediaStatus(QMediaPlayer::LoadedMedia); - if (mBuffering) { - setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia - : QMediaPlayer::BufferingMedia); - } else { - onBufferingChanged(100); - } - Q_EMIT metaDataUpdated(); - setAudioAvailable(true); - flushPendingStates(); - break; - case AndroidMediaPlayer::Started: - setState(QMediaPlayer::PlayingState); - if (mBuffering) { - setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia - : QMediaPlayer::BufferingMedia); - } else { - setMediaStatus(QMediaPlayer::BufferedMedia); - } - Q_EMIT positionChanged(position()); - break; - case AndroidMediaPlayer::Paused: - setState(QMediaPlayer::PausedState); - break; - case AndroidMediaPlayer::Error: - setState(QMediaPlayer::StoppedState); - setMediaStatus(QMediaPlayer::UnknownMediaStatus); - mMediaPlayer->release(); - Q_EMIT positionChanged(0); - break; - case AndroidMediaPlayer::Stopped: - setState(QMediaPlayer::StoppedState); - setMediaStatus(QMediaPlayer::LoadedMedia); - Q_EMIT positionChanged(0); - break; - case AndroidMediaPlayer::PlaybackCompleted: - setState(QMediaPlayer::StoppedState); - setMediaStatus(QMediaPlayer::EndOfMedia); - break; - case AndroidMediaPlayer::Uninitialized: - // reset some properties (unless we reload the same media) - if (!mReloadingMedia) { - resetBufferingProgress(); - mPendingPosition = -1; - mPendingSetMedia = false; - mPendingState = -1; - - Q_EMIT durationChanged(0); - Q_EMIT positionChanged(0); - - setAudioAvailable(false); - setVideoAvailable(false); - setSeekable(true); - } - break; - default: - break; - } - - if ((mState & (AndroidMediaPlayer::Stopped | AndroidMediaPlayer::Uninitialized)) != 0) { - mMediaPlayer->setDisplay(0); - if (mVideoOutput) { - mVideoOutput->stop(); - mVideoOutput->reset(); - } - } -} - -void QAndroidMediaPlayerControl::onVideoOutputReady(bool ready) -{ - if ((mMediaPlayer->display() == 0) && mVideoOutput && ready) - mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture()); - - flushPendingStates(); -} - -void QAndroidMediaPlayerControl::setState(QMediaPlayer::State state) -{ - if (mCurrentState == state) - return; - - if (mCurrentState == QMediaPlayer::StoppedState && state == QMediaPlayer::PausedState) - return; - - mCurrentState = state; -} - -void QAndroidMediaPlayerControl::setMediaStatus(QMediaPlayer::MediaStatus status) -{ - if (mCurrentMediaStatus == status) - return; - - mCurrentMediaStatus = status; - - if (status == QMediaPlayer::NoMedia || status == QMediaPlayer::InvalidMedia) - Q_EMIT durationChanged(0); - - if (status == QMediaPlayer::EndOfMedia) - Q_EMIT positionChanged(position()); - - updateBufferStatus(); -} - -void QAndroidMediaPlayerControl::setSeekable(bool seekable) -{ - if (mSeekable == seekable) - return; - - mSeekable = seekable; - Q_EMIT seekableChanged(mSeekable); -} - -void QAndroidMediaPlayerControl::setAudioAvailable(bool available) -{ - if (mAudioAvailable == available) - return; - - mAudioAvailable = available; - Q_EMIT audioAvailableChanged(mAudioAvailable); -} - -void QAndroidMediaPlayerControl::setVideoAvailable(bool available) -{ - if (mVideoAvailable == available) - return; - - if (!available) - mVideoSize = QSize(); - - mVideoAvailable = available; - Q_EMIT videoAvailableChanged(mVideoAvailable); -} - -void QAndroidMediaPlayerControl::resetBufferingProgress() -{ - mBuffering = false; - mBufferPercent = 0; - mAvailablePlaybackRange = QMediaTimeRange(); -} - -void QAndroidMediaPlayerControl::flushPendingStates() -{ - if (mPendingSetMedia) { - setMedia(mMediaContent, 0); - mPendingSetMedia = false; - return; - } - - const int newState = mPendingState; - mPendingState = -1; - - if (mPendingPosition != -1) - setPosition(mPendingPosition); - if (mPendingVolume != -1) - setVolume(mPendingVolume); - if (mPendingMute != -1) - setMuted((mPendingMute == 1)); - if (mHasPendingPlaybackRate) - setPlaybackRate(mPendingPlaybackRate); - - switch (newState) { - case QMediaPlayer::PlayingState: - play(); - break; - case QMediaPlayer::PausedState: - pause(); - break; - case QMediaPlayer::StoppedState: - stop(); - break; - default: - break; - } -} - -void QAndroidMediaPlayerControl::updateBufferStatus() -{ - bool bufferFilled = (mCurrentMediaStatus == QMediaPlayer::BufferedMedia - || mCurrentMediaStatus == QMediaPlayer::BufferingMedia); - - if (mBufferFilled != bufferFilled) { - mBufferFilled = bufferFilled; - Q_EMIT bufferStatusChanged(bufferStatus()); - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h deleted file mode 100644 index 35f56145f..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDMEDIAPLAYERCONTROL_H -#define QANDROIDMEDIAPLAYERCONTROL_H - -#include <qglobal.h> -#include <QMediaPlayerControl> -#include <qsize.h> - -QT_BEGIN_NAMESPACE - -class AndroidMediaPlayer; -class QAndroidVideoOutput; - -class QAndroidMediaPlayerControl : public QMediaPlayerControl -{ - Q_OBJECT -public: - explicit QAndroidMediaPlayerControl(QObject *parent = 0); - ~QAndroidMediaPlayerControl() override; - - QMediaPlayer::State state() const override; - QMediaPlayer::MediaStatus mediaStatus() const override; - qint64 duration() const override; - qint64 position() const override; - int volume() const override; - bool isMuted() const override; - int bufferStatus() const override; - bool isAudioAvailable() const override; - bool isVideoAvailable() const override; - bool isSeekable() const override; - QMediaTimeRange availablePlaybackRanges() const override; - qreal playbackRate() const override; - void setPlaybackRate(qreal rate) override; - QMediaContent media() const override; - const QIODevice *mediaStream() const override; - void setMedia(const QMediaContent &mediaContent, QIODevice *stream) override; - - void setVideoOutput(QAndroidVideoOutput *videoOutput); - -Q_SIGNALS: - void metaDataUpdated(); - -public Q_SLOTS: - void setPosition(qint64 position) override; - void play() override; - void pause() override; - void stop() override; - void setVolume(int volume) override; - void setMuted(bool muted) override; - void setAudioRole(QAudio::Role role); - void setCustomAudioRole(const QString &role); - -private Q_SLOTS: - void onVideoOutputReady(bool ready); - void onError(qint32 what, qint32 extra); - void onInfo(qint32 what, qint32 extra); - void onBufferingChanged(qint32 percent); - void onVideoSizeChanged(qint32 width, qint32 height); - void onStateChanged(qint32 state); - -private: - AndroidMediaPlayer *mMediaPlayer; - QMediaPlayer::State mCurrentState; - QMediaPlayer::MediaStatus mCurrentMediaStatus; - QMediaContent mMediaContent; - QIODevice *mMediaStream; - QAndroidVideoOutput *mVideoOutput; - bool mSeekable; - int mBufferPercent; - bool mBufferFilled; - bool mAudioAvailable; - bool mVideoAvailable; - QSize mVideoSize; - bool mBuffering; - QMediaTimeRange mAvailablePlaybackRange; - int mState; - int mPendingState; - qint64 mPendingPosition; - bool mPendingSetMedia; - int mPendingVolume; - int mPendingMute; - bool mReloadingMedia; - int mActiveStateChangeNotifiers; - qreal mPendingPlaybackRate; - bool mHasPendingPlaybackRate; // we need this because the rate can theoretically be negative - - void setState(QMediaPlayer::State state); - void setMediaStatus(QMediaPlayer::MediaStatus status); - void setSeekable(bool seekable); - void setAudioAvailable(bool available); - void setVideoAvailable(bool available); - void updateAvailablePlaybackRanges(); - void resetBufferingProgress(); - void flushPendingStates(); - void updateBufferStatus(); - - friend class StateChangeNotifier; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDMEDIAPLAYERCONTROL_H diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp deleted file mode 100644 index 5252d60ad..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidmediaplayervideorenderercontrol.h" - -#include "qandroidmediaplayercontrol.h" -#include "qandroidvideooutput.h" -#include <qabstractvideosurface.h> - -QT_BEGIN_NAMESPACE - -QAndroidMediaPlayerVideoRendererControl::QAndroidMediaPlayerVideoRendererControl(QAndroidMediaPlayerControl *mediaPlayer, QObject *parent) - : QVideoRendererControl(parent) - , m_mediaPlayerControl(mediaPlayer) - , m_surface(0) - , m_textureOutput(new QAndroidTextureVideoOutput(this)) -{ - m_mediaPlayerControl->setVideoOutput(m_textureOutput); -} - -QAndroidMediaPlayerVideoRendererControl::~QAndroidMediaPlayerVideoRendererControl() -{ - m_mediaPlayerControl->setVideoOutput(0); -} - -QAbstractVideoSurface *QAndroidMediaPlayerVideoRendererControl::surface() const -{ - return m_surface; -} - -void QAndroidMediaPlayerVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - if (m_surface == surface) - return; - - m_surface = surface; - m_textureOutput->setSurface(m_surface); -} - -QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h deleted file mode 100644 index ef213cc57..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayervideorenderercontrol.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDMEDIAPLAYERVIDEORENDERERCONTROL_H -#define QANDROIDMEDIAPLAYERVIDEORENDERERCONTROL_H - -#include <qvideorenderercontrol.h> - -QT_BEGIN_NAMESPACE - -class QAndroidMediaPlayerControl; -class QAndroidTextureVideoOutput; - -class QAndroidMediaPlayerVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT -public: - QAndroidMediaPlayerVideoRendererControl(QAndroidMediaPlayerControl *mediaPlayer, QObject *parent = 0); - ~QAndroidMediaPlayerVideoRendererControl() override; - - QAbstractVideoSurface *surface() const override; - void setSurface(QAbstractVideoSurface *surface) override; - -private: - QAndroidMediaPlayerControl *m_mediaPlayerControl; - QAbstractVideoSurface *m_surface; - QAndroidTextureVideoOutput *m_textureOutput; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDMEDIAPLAYERVIDEORENDERERCONTROL_H diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp deleted file mode 100644 index c057f530a..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidmediaservice.h" - -#include "qandroidmediaplayercontrol.h" -#include "qandroidmetadatareadercontrol.h" -#include "qandroidaudiorolecontrol.h" -#include "qandroidcustomaudiorolecontrol.h" -#include "qandroidmediaplayervideorenderercontrol.h" - -QT_BEGIN_NAMESPACE - -QAndroidMediaService::QAndroidMediaService(QObject *parent) - : QMediaService(parent) - , mAudioRoleControl(nullptr) - , mCustomAudioRoleControl(nullptr) - , mVideoRendererControl(0) -{ - mMediaControl = new QAndroidMediaPlayerControl; - mMetadataControl = new QAndroidMetaDataReaderControl; - mAudioRoleControl = new QAndroidAudioRoleControl; - mCustomAudioRoleControl = new QAndroidCustomAudioRoleControl; - connect(mAudioRoleControl, &QAndroidAudioRoleControl::audioRoleChanged, - mMediaControl, &QAndroidMediaPlayerControl::setAudioRole); - connect(mCustomAudioRoleControl, &QAndroidCustomAudioRoleControl::customAudioRoleChanged, - mMediaControl, &QAndroidMediaPlayerControl::setCustomAudioRole); - connect(mMediaControl, SIGNAL(mediaChanged(QMediaContent)), - mMetadataControl, SLOT(onMediaChanged(QMediaContent))); - connect(mMediaControl, SIGNAL(metaDataUpdated()), - mMetadataControl, SLOT(onUpdateMetaData())); -} - -QAndroidMediaService::~QAndroidMediaService() -{ - delete mVideoRendererControl; - delete mCustomAudioRoleControl; - delete mAudioRoleControl; - delete mMetadataControl; - delete mMediaControl; -} - -QMediaControl *QAndroidMediaService::requestControl(const char *name) -{ - if (qstrcmp(name, QMediaPlayerControl_iid) == 0) - return mMediaControl; - - if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) - return mMetadataControl; - - if (qstrcmp(name, QAudioRoleControl_iid) == 0) - return mAudioRoleControl; - - if (qstrcmp(name, QCustomAudioRoleControl_iid) == 0) - return mCustomAudioRoleControl; - - if (qstrcmp(name, QVideoRendererControl_iid) == 0) { - if (!mVideoRendererControl) { - mVideoRendererControl = new QAndroidMediaPlayerVideoRendererControl(mMediaControl); - return mVideoRendererControl; - } - } - - return 0; -} - -void QAndroidMediaService::releaseControl(QMediaControl *control) -{ - if (control == mVideoRendererControl) { - delete mVideoRendererControl; - mVideoRendererControl = 0; - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h b/src/plugins/android/src/mediaplayer/qandroidmediaservice.h deleted file mode 100644 index 788c11098..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDMEDIASERVICE_H -#define QANDROIDMEDIASERVICE_H - -#include <QMediaService> - -QT_BEGIN_NAMESPACE - -class QAndroidMediaPlayerControl; -class QAndroidMetaDataReaderControl; -class QAndroidAudioRoleControl; -class QAndroidCustomAudioRoleControl; -class QAndroidMediaPlayerVideoRendererControl; - -class QAndroidMediaService : public QMediaService -{ - Q_OBJECT -public: - explicit QAndroidMediaService(QObject *parent = 0); - ~QAndroidMediaService() override; - - QMediaControl* requestControl(const char *name) override; - void releaseControl(QMediaControl *control) override; - -private: - QAndroidMediaPlayerControl *mMediaControl; - QAndroidMetaDataReaderControl *mMetadataControl; - QAndroidAudioRoleControl *mAudioRoleControl; - QAndroidCustomAudioRoleControl *mCustomAudioRoleControl; - QAndroidMediaPlayerVideoRendererControl *mVideoRendererControl; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDMEDIASERVICE_H diff --git a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp deleted file mode 100644 index d2e097895..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qandroidmetadatareadercontrol.h" - -#include "androidmediametadataretriever.h" -#include <QtMultimedia/qmediametadata.h> -#include <qsize.h> -#include <QDate> -#include <QtCore/qlist.h> -#include <QtConcurrent/qtconcurrentrun.h> - -QT_BEGIN_NAMESPACE - -// Genre name ordered by ID -// see: http://id3.org/id3v2.3.0#Appendix_A_-_Genre_List_from_ID3v1 -static const char* qt_ID3GenreNames[] = -{ - "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", "Hip-Hop", "Jazz", - "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", "Rap", "Reggae", "Rock", "Techno", - "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", - "Ambient", "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", "Instrumental", - "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", "AlternRock", "Bass", "Soul", "Punk", - "Space", "Meditative", "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", - "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", - "Cult", "Gangsta", "Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American", - "Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", - "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", - "Folk-Rock", "National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival", "Celtic", - "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", "Psychedelic Rock", - "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour", - "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", - "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", "Folklore", "Ballad", - "Power Ballad", "Rhythmic Soul", "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A capella", - "Euro-House", "Dance Hall" -}; - -typedef QList<QAndroidMetaDataReaderControl *> AndroidMetaDataReaders; -Q_GLOBAL_STATIC(AndroidMetaDataReaders, g_metaDataReaders) -Q_GLOBAL_STATIC(QMutex, g_metaDataReadersMtx) - -QAndroidMetaDataReaderControl::QAndroidMetaDataReaderControl(QObject *parent) - : QMetaDataReaderControl(parent) - , m_available(false) -{ -} - -QAndroidMetaDataReaderControl::~QAndroidMetaDataReaderControl() -{ - QMutexLocker l(g_metaDataReadersMtx()); - const int idx = g_metaDataReaders->indexOf(this); - if (idx != -1) - g_metaDataReaders->remove(idx); -} - -bool QAndroidMetaDataReaderControl::isMetaDataAvailable() const -{ - const QMutexLocker l(&m_mtx); - return m_available && !m_metadata.isEmpty(); -} - -QVariant QAndroidMetaDataReaderControl::metaData(const QString &key) const -{ - const QMutexLocker l(&m_mtx); - return m_metadata.value(key); -} - -QStringList QAndroidMetaDataReaderControl::availableMetaData() const -{ - const QMutexLocker l(&m_mtx); - return m_metadata.keys(); -} - -void QAndroidMetaDataReaderControl::onMediaChanged(const QMediaContent &media) -{ - const QMutexLocker l(&m_mtx); - m_metadata.clear(); - m_mediaContent = media; -} - -void QAndroidMetaDataReaderControl::onUpdateMetaData() -{ - { - const QMutexLocker l(g_metaDataReadersMtx()); - if (!g_metaDataReaders->contains(this)) - g_metaDataReaders->append(this); - } - - const QMutexLocker ml(&m_mtx); - if (m_mediaContent.isNull()) - return; - - const QUrl &url = m_mediaContent.request().url(); - QtConcurrent::run(&extractMetadata, this, url); -} - -void QAndroidMetaDataReaderControl::updateData(const QVariantMap &metadata, const QUrl &url) -{ - const QMutexLocker l(&m_mtx); - - if (m_mediaContent.request().url() != url) - return; - - const bool oldAvailable = m_available; - m_metadata = metadata; - m_available = !m_metadata.isEmpty(); - - if (m_available != oldAvailable) - Q_EMIT metaDataAvailableChanged(m_available); - - Q_EMIT metaDataChanged(); -} - -void QAndroidMetaDataReaderControl::extractMetadata(QAndroidMetaDataReaderControl *caller, - const QUrl &url) -{ - QVariantMap metadata; - - if (!url.isEmpty()) { - AndroidMediaMetadataRetriever retriever; - if (!retriever.setDataSource(url)) - return; - - QString mimeType = retriever.extractMetadata(AndroidMediaMetadataRetriever::MimeType); - if (!mimeType.isNull()) - metadata.insert(QMediaMetaData::MediaType, mimeType); - - bool isVideo = !retriever.extractMetadata(AndroidMediaMetadataRetriever::HasVideo).isNull() - || mimeType.startsWith(QStringLiteral("video")); - - QString string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Album); - if (!string.isNull()) - metadata.insert(QMediaMetaData::AlbumTitle, string); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::AlbumArtist); - if (!string.isNull()) - metadata.insert(QMediaMetaData::AlbumArtist, string); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Artist); - if (!string.isNull()) { - metadata.insert(isVideo ? QMediaMetaData::LeadPerformer - : QMediaMetaData::ContributingArtist, - string.split('/', Qt::SkipEmptyParts)); - } - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Author); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Author, string.split('/', Qt::SkipEmptyParts)); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Bitrate); - if (!string.isNull()) { - metadata.insert(isVideo ? QMediaMetaData::VideoBitRate - : QMediaMetaData::AudioBitRate, - string.toInt()); - } - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::CDTrackNumber); - if (!string.isNull()) - metadata.insert(QMediaMetaData::TrackNumber, string.toInt()); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Composer); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Composer, string.split('/', Qt::SkipEmptyParts)); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Date); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Date, QDateTime::fromString(string, QStringLiteral("yyyyMMddTHHmmss.zzzZ")).date()); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Duration); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Duration, string.toLongLong()); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Genre); - if (!string.isNull()) { - // The genre can be returned as an ID3v2 id, get the name for it in that case - if (string.startsWith('(') && string.endsWith(')')) { - bool ok = false; - const int genreId = QStringView{string}.mid(1, string.length() - 2).toInt(&ok); - if (ok && genreId >= 0 && genreId <= 125) - string = QLatin1String(qt_ID3GenreNames[genreId]); - } - metadata.insert(QMediaMetaData::Genre, string); - } - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Title); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Title, string); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::VideoHeight); - if (!string.isNull()) { - const int height = string.toInt(); - const int width = retriever.extractMetadata(AndroidMediaMetadataRetriever::VideoWidth).toInt(); - metadata.insert(QMediaMetaData::Resolution, QSize(width, height)); - } - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Writer); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Writer, string.split('/', Qt::SkipEmptyParts)); - - string = retriever.extractMetadata(AndroidMediaMetadataRetriever::Year); - if (!string.isNull()) - metadata.insert(QMediaMetaData::Year, string.toInt()); - } - - const QMutexLocker lock(g_metaDataReadersMtx()); - if (!g_metaDataReaders->contains(caller)) - return; - - caller->updateData(metadata, url); -} - -QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h deleted file mode 100644 index f2b1b47f1..000000000 --- a/src/plugins/android/src/mediaplayer/qandroidmetadatareadercontrol.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QANDROIDMETADATAREADERCONTROL_H -#define QANDROIDMETADATAREADERCONTROL_H - -#include <QMetaDataReaderControl> -#include <qmediacontent.h> -#include <QMutex> - -QT_BEGIN_NAMESPACE - -class AndroidMediaMetadataRetriever; - -class QAndroidMetaDataReaderControl : public QMetaDataReaderControl -{ - Q_OBJECT -public: - explicit QAndroidMetaDataReaderControl(QObject *parent = 0); - ~QAndroidMetaDataReaderControl() override; - - bool isMetaDataAvailable() const override; - - QVariant metaData(const QString &key) const override; - QStringList availableMetaData() const override; - -public Q_SLOTS: - void onMediaChanged(const QMediaContent &media); - void onUpdateMetaData(); - -private: - void updateData(const QVariantMap &metadata, const QUrl &url); - static void extractMetadata(QAndroidMetaDataReaderControl *caller, const QUrl &url); - - mutable QMutex m_mtx; - QMediaContent m_mediaContent; - bool m_available; - QVariantMap m_metadata; -}; - -QT_END_NAMESPACE - -#endif // QANDROIDMETADATAREADERCONTROL_H |