diff options
author | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2019-02-06 15:35:04 +0100 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2019-02-08 09:57:53 +0000 |
commit | 054a8f3b1f692d14687ce14fa8d143edc8f988f0 (patch) | |
tree | ba7238afa2e8a5467d89c2967e054940c053617a /src/plugins/android/src/mediaplayer | |
parent | 5fa4b2e448734da65ec24f2ce8234a4d3e4a832e (diff) |
Android: Implement audio roles
Introduced custom and standard audio role controls using MediaPlayer.setAudioAttributes(AudioAttributes)
which added in API level 21.
Custom audio roles might contain a list of roles separated by comma.
E.g "CONTENT_TYPE_MOVIE,USAGE_ALARM", which means content type is movie
and usage is alarm.
[ChangeLog][Platform Specific Changes][Android] Implemented audio roles.
Task-number: QTBUG-73119
Change-Id: I281d1ce899d29f54d271516a1fca5f11c897fc90
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/android/src/mediaplayer')
9 files changed, 328 insertions, 0 deletions
diff --git a/src/plugins/android/src/mediaplayer/mediaplayer.pri b/src/plugins/android/src/mediaplayer/mediaplayer.pri index 9f758a993..3a9cef3a1 100644 --- a/src/plugins/android/src/mediaplayer/mediaplayer.pri +++ b/src/plugins/android/src/mediaplayer/mediaplayer.pri @@ -4,10 +4,14 @@ 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 new file mode 100644 index 000000000..5879b0cb9 --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 000000000..89219e026 --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 000000000..cb7b5d0af --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 new file mode 100644 index 000000000..4604ebe67 --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 index df1463a87..4bfcce5bc 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp +++ b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp @@ -250,6 +250,16 @@ void QAndroidMediaPlayerControl::setMuted(bool muted) 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; diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h index 119add7f8..35f56145f 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h +++ b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h @@ -85,6 +85,8 @@ public Q_SLOTS: 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); diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp index 2688f3550..c057f530a 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp +++ b/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp @@ -41,16 +41,26 @@ #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()), @@ -60,6 +70,8 @@ QAndroidMediaService::QAndroidMediaService(QObject *parent) QAndroidMediaService::~QAndroidMediaService() { delete mVideoRendererControl; + delete mCustomAudioRoleControl; + delete mAudioRoleControl; delete mMetadataControl; delete mMediaControl; } @@ -72,6 +84,12 @@ QMediaControl *QAndroidMediaService::requestControl(const char *name) 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); diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h b/src/plugins/android/src/mediaplayer/qandroidmediaservice.h index f78d05ddd..788c11098 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h +++ b/src/plugins/android/src/mediaplayer/qandroidmediaservice.h @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE class QAndroidMediaPlayerControl; class QAndroidMetaDataReaderControl; +class QAndroidAudioRoleControl; +class QAndroidCustomAudioRoleControl; class QAndroidMediaPlayerVideoRendererControl; class QAndroidMediaService : public QMediaService @@ -61,6 +63,8 @@ public: private: QAndroidMediaPlayerControl *mMediaControl; QAndroidMetaDataReaderControl *mMetadataControl; + QAndroidAudioRoleControl *mAudioRoleControl; + QAndroidCustomAudioRoleControl *mCustomAudioRoleControl; QAndroidMediaPlayerVideoRendererControl *mVideoRendererControl; }; |