summaryrefslogtreecommitdiffstats
path: root/src/plugins/qnx/mediaplayer
diff options
context:
space:
mode:
authorJames McDonnell <jmcdonnell@blackberry.com>2017-03-23 15:36:51 -0400
committerJames McDonnell <jmcdonnell@blackberry.com>2017-03-28 14:26:09 +0000
commit684456d8fbdb80d621e3c4838544c2878e3f2a43 (patch)
tree794b73f6251764aa7952041e45a74e258b41166b /src/plugins/qnx/mediaplayer
parent883df8dfda760fdbe850303383ba098887abbf62 (diff)
Implement QAudioRoleControl for QNX
The system must provide a JSON file that maps Qt audio roles to the system's audio types. This is necessary because QNX doesn't dictate the audio types that a system must use. Anyone creating a QNX system is free to define whatever audio types they deem to be appropriate for that system. Set the audio role for the Qt player example to VideoRole and added code to dump the supported audio roles. Change-Id: I34d2c5da0033f69b9dd476a0eadccf3d87d07bfd Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
Diffstat (limited to 'src/plugins/qnx/mediaplayer')
-rw-r--r--src/plugins/qnx/mediaplayer/mediaplayer.pri2
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp68
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h63
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp17
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h3
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp22
-rw-r--r--src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h2
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendererutil.cpp113
-rw-r--r--src/plugins/qnx/mediaplayer/mmrendererutil.h4
9 files changed, 288 insertions, 6 deletions
diff --git a/src/plugins/qnx/mediaplayer/mediaplayer.pri b/src/plugins/qnx/mediaplayer/mediaplayer.pri
index 756857cce..0871f34bc 100644
--- a/src/plugins/qnx/mediaplayer/mediaplayer.pri
+++ b/src/plugins/qnx/mediaplayer/mediaplayer.pri
@@ -1,6 +1,7 @@
INCLUDEPATH += $$PWD
HEADERS += \
+ $$PWD/mmrendereraudiorolecontrol.h \
$$PWD/mmrenderermediaplayercontrol.h \
$$PWD/mmrenderermediaplayerservice.h \
$$PWD/mmrenderermetadata.h \
@@ -10,6 +11,7 @@ HEADERS += \
$$PWD/mmrenderervideowindowcontrol.h \
$$PWD/ppsmediaplayercontrol.h
SOURCES += \
+ $$PWD/mmrendereraudiorolecontrol.cpp \
$$PWD/mmrenderermediaplayercontrol.cpp \
$$PWD/mmrenderermediaplayerservice.cpp \
$$PWD/mmrenderermetadata.cpp \
diff --git a/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp b/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp
new file mode 100644
index 000000000..e470ed4c5
--- /dev/null
+++ b/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 QNX Software Systems. All rights reserved.
+** 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 "mmrendereraudiorolecontrol.h"
+#include "mmrendererutil.h"
+
+QT_BEGIN_NAMESPACE
+
+MmRendererAudioRoleControl::MmRendererAudioRoleControl(QObject *parent)
+ : QAudioRoleControl(parent)
+ , m_role(QAudio::UnknownRole)
+{
+}
+
+QAudio::Role MmRendererAudioRoleControl::audioRole() const
+{
+ return m_role;
+}
+
+void MmRendererAudioRoleControl::setAudioRole(QAudio::Role role)
+{
+ if (m_role != role) {
+ m_role = role;
+ emit audioRoleChanged(m_role);
+ }
+}
+
+QList<QAudio::Role> MmRendererAudioRoleControl::supportedAudioRoles() const
+{
+ return qnxSupportedAudioRoles();
+}
+
+QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h b/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h
new file mode 100644
index 000000000..7458d3512
--- /dev/null
+++ b/src/plugins/qnx/mediaplayer/mmrendereraudiorolecontrol.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 QNX Software Systems. All rights reserved.
+** 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 MMRENDERERAUDIOROLECONTROL_H
+#define MMRENDERERAUDIOROLECONTROL_H
+
+#include <qaudiorolecontrol.h>
+
+QT_BEGIN_NAMESPACE
+
+class MmRendererAudioRoleControl : public QAudioRoleControl
+{
+ Q_OBJECT
+public:
+ explicit MmRendererAudioRoleControl(QObject *parent = 0);
+
+ QAudio::Role audioRole() const Q_DECL_OVERRIDE;
+ void setAudioRole(QAudio::Role role) Q_DECL_OVERRIDE;
+
+ QList<QAudio::Role> supportedAudioRoles() const Q_DECL_OVERRIDE;
+
+private:
+ QAudio::Role m_role;
+};
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp b/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp
index 5cd3bc3d2..b07a18f4f 100644
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp
+++ b/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.cpp
@@ -36,6 +36,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include "mmrendereraudiorolecontrol.h"
#include "mmrenderermediaplayercontrol.h"
#include "mmrenderermetadatareadercontrol.h"
#include "mmrendererplayervideorenderercontrol.h"
@@ -197,6 +198,17 @@ void MmRendererMediaPlayerControl::attach()
return;
}
+ if (m_audioId != -1 && m_audioRoleControl) {
+ QString audioType = qnxAudioType(m_audioRoleControl->audioRole());
+ QByteArray latin1AudioType = audioType.toLatin1();
+ if (!audioType.isEmpty() && latin1AudioType == audioType) {
+ strm_dict_t *dict = strm_dict_new();
+ dict = strm_dict_set(dict, "audio_type", latin1AudioType.constData());
+ if (mmr_output_parameters(m_context, m_audioId, dict) != 0)
+ emitMmError("mmr_output_parameters: Setting audio_type failed");
+ }
+ }
+
const QByteArray resourcePath = resourcePathForUrl(m_media.canonicalUrl());
if (resourcePath.isEmpty()) {
detach();
@@ -561,6 +573,11 @@ void MmRendererMediaPlayerControl::setMetaDataReaderControl(MmRendererMetaDataRe
m_metaDataReaderControl = metaDataReaderControl;
}
+void MmRendererMediaPlayerControl::setAudioRoleControl(MmRendererAudioRoleControl *audioRoleControl)
+{
+ m_audioRoleControl = audioRoleControl;
+}
+
void MmRendererMediaPlayerControl::setMmPosition(qint64 newPosition)
{
if (newPosition != 0 && newPosition != m_position) {
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h b/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h
index 00f70db34..f3d81461c 100644
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h
+++ b/src/plugins/qnx/mediaplayer/mmrenderermediaplayercontrol.h
@@ -51,6 +51,7 @@ typedef struct mmrenderer_monitor mmrenderer_monitor_t;
QT_BEGIN_NAMESPACE
+class MmRendererAudioRoleControl;
class MmRendererMetaDataReaderControl;
class MmRendererPlayerVideoRendererControl;
class MmRendererVideoWindowControl;
@@ -102,6 +103,7 @@ public:
MmRendererVideoWindowControl *videoWindowControl() const;
void setVideoWindowControl(MmRendererVideoWindowControl *videoControl);
void setMetaDataReaderControl(MmRendererMetaDataReaderControl *metaDataReaderControl);
+ void setAudioRoleControl(MmRendererAudioRoleControl *audioRoleControl);
protected:
virtual void startMonitoring(int contextId, const QString &contextName) = 0;
@@ -154,6 +156,7 @@ private:
QPointer<MmRendererPlayerVideoRendererControl> m_videoRendererControl;
QPointer<MmRendererVideoWindowControl> m_videoWindowControl;
QPointer<MmRendererMetaDataReaderControl> m_metaDataReaderControl;
+ QPointer<MmRendererAudioRoleControl> m_audioRoleControl;
MmRendererMetaData m_metaData;
int m_id;
qint64 m_position;
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp b/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp
index e253c68d8..6136f9465 100644
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp
+++ b/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "mmrenderermediaplayerservice.h"
+#include "mmrendereraudiorolecontrol.h"
#include "mmrenderermediaplayercontrol.h"
#include "mmrenderermetadatareadercontrol.h"
#include "mmrendererplayervideorenderercontrol.h"
@@ -66,6 +67,7 @@ MmRendererMediaPlayerService::~MmRendererMediaPlayerService()
delete m_videoWindowControl;
delete m_mediaPlayerControl;
delete m_metaDataReaderControl;
+ delete m_audioRoleControl;
}
QMediaControl *MmRendererMediaPlayerService::requestControl(const char *name)
@@ -76,15 +78,19 @@ QMediaControl *MmRendererMediaPlayerService::requestControl(const char *name)
updateControls();
}
return m_mediaPlayerControl;
- }
- else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
+ } else if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) {
if (!m_metaDataReaderControl) {
m_metaDataReaderControl = new MmRendererMetaDataReaderControl();
updateControls();
}
return m_metaDataReaderControl;
- }
- else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
+ } else if (qstrcmp(name, QAudioRoleControl_iid) == 0) {
+ if (!m_audioRoleControl) {
+ m_audioRoleControl = new MmRendererAudioRoleControl();
+ updateControls();
+ }
+ return m_audioRoleControl;
+ } else if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
if (!m_appHasDrmPermissionChecked) {
m_appHasDrmPermission = checkForDrmPermission();
m_appHasDrmPermissionChecked = true;
@@ -102,8 +108,7 @@ QMediaControl *MmRendererMediaPlayerService::requestControl(const char *name)
updateControls();
}
return m_videoRendererControl;
- }
- else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
+ } else if (qstrcmp(name, QVideoWindowControl_iid) == 0) {
if (!m_videoWindowControl) {
m_videoWindowControl = new MmRendererVideoWindowControl();
updateControls();
@@ -123,6 +128,8 @@ void MmRendererMediaPlayerService::releaseControl(QMediaControl *control)
m_mediaPlayerControl = 0;
if (control == m_metaDataReaderControl)
m_metaDataReaderControl = 0;
+ if (control == m_audioRoleControl)
+ m_audioRoleControl = 0;
delete control;
}
@@ -136,6 +143,9 @@ void MmRendererMediaPlayerService::updateControls()
if (m_metaDataReaderControl && m_mediaPlayerControl)
m_mediaPlayerControl->setMetaDataReaderControl(m_metaDataReaderControl);
+
+ if (m_audioRoleControl && m_mediaPlayerControl)
+ m_mediaPlayerControl->setAudioRoleControl(m_audioRoleControl);
}
QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h b/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h
index de85293cb..9434b85b2 100644
--- a/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h
+++ b/src/plugins/qnx/mediaplayer/mmrenderermediaplayerservice.h
@@ -44,6 +44,7 @@
QT_BEGIN_NAMESPACE
+class MmRendererAudioRoleControl;
class MmRendererMediaPlayerControl;
class MmRendererMetaDataReaderControl;
class MmRendererPlayerVideoRendererControl;
@@ -66,6 +67,7 @@ private:
QPointer<MmRendererVideoWindowControl> m_videoWindowControl;
QPointer<MmRendererMediaPlayerControl> m_mediaPlayerControl;
QPointer<MmRendererMetaDataReaderControl> m_metaDataReaderControl;
+ QPointer<MmRendererAudioRoleControl> m_audioRoleControl;
bool m_appHasDrmPermission : 1;
bool m_appHasDrmPermissionChecked : 1;
diff --git a/src/plugins/qnx/mediaplayer/mmrendererutil.cpp b/src/plugins/qnx/mediaplayer/mmrendererutil.cpp
index 239d9d52e..7a9f6393b 100644
--- a/src/plugins/qnx/mediaplayer/mmrendererutil.cpp
+++ b/src/plugins/qnx/mediaplayer/mmrendererutil.cpp
@@ -41,6 +41,11 @@
#include <QDebug>
#include <QDir>
#include <QFile>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QMutex>
+#include <QMutex>
#include <QString>
#include <QXmlStreamReader>
@@ -85,6 +90,91 @@ static const MmError mmErrors[] = {
};
static const unsigned int numMmErrors = sizeof(mmErrors) / sizeof(MmError);
+static QBasicMutex roleMapMutex;
+static bool roleMapInitialized = false;
+static QString roleMap[QAudio::GameRole + 1];
+
+template <typename T, size_t N>
+constexpr size_t countof(T (&)[N])
+{
+ return N;
+}
+
+constexpr bool inBounds(QAudio::Role r)
+{
+ return r >= 0 && r < countof(roleMap);
+}
+
+QString keyValueMapsLocation()
+{
+ QByteArray qtKeyValueMaps = qgetenv("QT_KEY_VALUE_MAPS");
+ if (qtKeyValueMaps.isNull())
+ return QStringLiteral("/etc/qt/keyvaluemaps");
+ else
+ return qtKeyValueMaps;
+}
+
+QJsonObject loadMapObject(const QString &keyValueMapPath)
+{
+ QFile mapFile(keyValueMapsLocation() + keyValueMapPath);
+ if (mapFile.open(QIODevice::ReadOnly)) {
+ QByteArray mapFileContents = mapFile.readAll();
+ QJsonDocument mapDocument = QJsonDocument::fromJson(mapFileContents);
+ if (mapDocument.isObject()) {
+ QJsonObject mapObject = mapDocument.object();
+ return mapObject;
+ }
+ }
+ return QJsonObject();
+}
+
+static void loadRoleMap()
+{
+ QMutexLocker locker(&roleMapMutex);
+
+ if (!roleMapInitialized) {
+ QJsonObject mapObject = loadMapObject("/QAudio/Role.json");
+ if (!mapObject.isEmpty()) {
+ // Wrapping the loads in a switch like this ensures that anyone adding
+ // a new enumerator will be notified that this code must be updated. A
+ // compile error will occur because the enumerator is missing from the
+ // switch. A compile error will also occur if the enumerator used to
+ // size the mapping table isn't updated when a new enumerator is added.
+ // One or more enumerators will be outside the bounds of the array when
+ // the wrong enumerator is used to size the array.
+ //
+ // The code loads a mapping for each enumerator because role is set
+ // to UnknownRole and all the cases drop through to the next case.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic error "-Wswitch"
+#define loadRoleMapping(r) \
+ case QAudio::r: \
+ static_assert(inBounds(QAudio::r), #r " out-of-bounds." \
+ " Do you need to change the enumerator used to size the mapping table" \
+ " because you added new QAudio::Role enumerators?"); \
+ roleMap[QAudio::r] = mapObject.value(QLatin1String(#r)).toString();
+
+ QAudio::Role role = QAudio::UnknownRole;
+ switch (role) {
+ loadRoleMapping(UnknownRole);
+ loadRoleMapping(MusicRole);
+ loadRoleMapping(VideoRole);
+ loadRoleMapping(VoiceCommunicationRole);
+ loadRoleMapping(AlarmRole);
+ loadRoleMapping(NotificationRole);
+ loadRoleMapping(RingtoneRole);
+ loadRoleMapping(AccessibilityRole);
+ loadRoleMapping(SonificationRole);
+ loadRoleMapping(GameRole);
+ }
+#undef loadRoleMapping
+#pragma GCC diagnostic pop
+ }
+
+ roleMapInitialized = true;
+ }
+}
+
QString mmErrorMessage(const QString &msg, mmr_context_t *context, int *errorCode)
{
const mmr_error_info_t * const mmError = mmr_error_info(context);
@@ -124,4 +214,27 @@ bool checkForDrmPermission()
return false;
}
+QString qnxAudioType(QAudio::Role role)
+{
+ loadRoleMap();
+
+ if (role >= 0 && role < countof(roleMap))
+ return roleMap[role];
+ else
+ return QString();
+}
+
+QList<QAudio::Role> qnxSupportedAudioRoles()
+{
+ loadRoleMap();
+
+ QList<QAudio::Role> result;
+ for (size_t i = 0; i < countof(roleMap); ++i) {
+ if (!roleMap[i].isEmpty() || (i == QAudio::UnknownRole))
+ result.append(static_cast<QAudio::Role>(i));
+ }
+
+ return result;
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/qnx/mediaplayer/mmrendererutil.h b/src/plugins/qnx/mediaplayer/mmrendererutil.h
index 8017b2690..ac6f73a7d 100644
--- a/src/plugins/qnx/mediaplayer/mmrendererutil.h
+++ b/src/plugins/qnx/mediaplayer/mmrendererutil.h
@@ -40,6 +40,7 @@
#define MMRENDERERUTIL_H
#include <QtCore/qglobal.h>
+#include <QtMultimedia/qaudio.h>
typedef struct mmr_context mmr_context_t;
@@ -51,6 +52,9 @@ QString mmErrorMessage(const QString &msg, mmr_context_t *context, int * errorCo
bool checkForDrmPermission();
+QString qnxAudioType(QAudio::Role role);
+QList<QAudio::Role> qnxSupportedAudioRoles();
+
QT_END_NAMESPACE
#endif