diff options
author | Ling Hu <ling.hu@nokia.com> | 2012-03-21 14:25:23 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-23 09:53:49 +0100 |
commit | 138242fb2dc19438a0ead34b36af848800e27190 (patch) | |
tree | c053d748c3854cad15c66c2b706eb90db496f4cc /src/plugins/gstreamer/mediaplayer | |
parent | 655408bced62c5fa490f8f4f260aefd164b870ee (diff) |
Added resource policy support though internal plugin system
Change-Id: I374be17d49b6a5eed0b1ed94d0b9ca5f9a2caa9b
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
Diffstat (limited to 'src/plugins/gstreamer/mediaplayer')
5 files changed, 12 insertions, 277 deletions
diff --git a/src/plugins/gstreamer/mediaplayer/mediaplayer.pri b/src/plugins/gstreamer/mediaplayer/mediaplayer.pri index 92cd79086..fcfbd063b 100644 --- a/src/plugins/gstreamer/mediaplayer/mediaplayer.pri +++ b/src/plugins/gstreamer/mediaplayer/mediaplayer.pri @@ -7,15 +7,13 @@ HEADERS += \ $$PWD/qgstreamerplayerservice.h \ $$PWD/qgstreamerplayersession.h \ $$PWD/qgstreamerstreamscontrol.h \ - $$PWD/qgstreamermetadataprovider.h \ - $$PWD/playerresourcepolicy.h + $$PWD/qgstreamermetadataprovider.h SOURCES += \ $$PWD/qgstreamerplayercontrol.cpp \ $$PWD/qgstreamerplayerservice.cpp \ $$PWD/qgstreamerplayersession.cpp \ $$PWD/qgstreamerstreamscontrol.cpp \ - $$PWD/qgstreamermetadataprovider.cpp \ - $$PWD/playerresourcepolicy.cpp + $$PWD/qgstreamermetadataprovider.cpp diff --git a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.cpp b/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.cpp deleted file mode 100644 index bd2431b7e..000000000 --- a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "playerresourcepolicy.h" - -//#define DEBUG_RESOURCE_POLICY -#include <QtCore/qdebug.h> - -#ifdef HAVE_RESOURCE_POLICY -#include <policy/resource.h> -#include <policy/resources.h> -#include <policy/resource-set.h> -#endif - -PlayerResourcePolicy::PlayerResourcePolicy(QObject *parent) : - QObject(parent), - m_videoEnabled(true), - m_resourceSet(0), - m_status(PlayerResourcePolicy::Initial) -{ -#ifdef HAVE_RESOURCE_POLICY - m_resourceSet = new ResourcePolicy::ResourceSet("player", this); - m_resourceSet->setAlwaysReply(); - - ResourcePolicy::AudioResource *audioResource = new ResourcePolicy::AudioResource("player"); - audioResource->setProcessID(QCoreApplication::applicationPid()); - audioResource->setStreamTag("media.name", "*"); - m_resourceSet->addResourceObject(audioResource); - - m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType); - m_resourceSet->update(); - - connect(m_resourceSet, SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType>)), - this, SLOT(handleResourcesGranted())); - connect(m_resourceSet, SIGNAL(resourcesDenied()), - this, SLOT(handleResourcesDenied())); - connect(m_resourceSet, SIGNAL(lostResources()), - this, SLOT(handleResourcesLost())); - connect(m_resourceSet, SIGNAL(resourcesReleasedByManager()), - this, SLOT(handleResourcesLost())); -#endif -} - -PlayerResourcePolicy::~PlayerResourcePolicy() -{ -} - -bool PlayerResourcePolicy::isVideoEnabled() const -{ - return m_videoEnabled; -} - -void PlayerResourcePolicy::setVideoEnabled(bool enabled) -{ - if (m_videoEnabled != enabled) { - m_videoEnabled = enabled; - -#ifdef HAVE_RESOURCE_POLICY - if (enabled) - m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType); - else - m_resourceSet->deleteResource(ResourcePolicy::VideoPlaybackType); - - m_resourceSet->update(); -#endif - } -} - -void PlayerResourcePolicy::acquire() -{ -#ifdef HAVE_RESOURCE_POLICY - -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Acquire resource"; -#endif - m_status = RequestedResource; - m_resourceSet->acquire(); -#else - m_status = GrantedResource; -#endif -} - -void PlayerResourcePolicy::release() -{ -#ifdef HAVE_RESOURCE_POLICY - -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Release resource"; -#endif - - m_resourceSet->release(); -#endif - m_status = Initial; - -} - -bool PlayerResourcePolicy::isGranted() const -{ - return m_status == GrantedResource; -} - -bool PlayerResourcePolicy::isRequested() const -{ - return m_status == RequestedResource; -} - -void PlayerResourcePolicy::handleResourcesGranted() -{ - m_status = GrantedResource; -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Resource granted"; -#endif - emit resourcesGranted(); -} - -void PlayerResourcePolicy::handleResourcesDenied() -{ - m_status = Initial; -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Resource denied"; -#endif - emit resourcesDenied(); -} - -void PlayerResourcePolicy::handleResourcesLost() -{ -#ifdef DEBUG_RESOURCE_POLICY - qDebug() << Q_FUNC_INFO << "Resource lost"; -#endif - if (m_status != Initial) { - m_status = Initial; - emit resourcesLost(); - } - -#ifdef HAVE_RESOURCE_POLICY - m_resourceSet->release(); -#endif -} diff --git a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.h b/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.h deleted file mode 100644 index 66a0ed931..000000000 --- a/src/plugins/gstreamer/mediaplayer/playerresourcepolicy.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PLAYERRESOURCEPOLICY_H -#define PLAYERRESOURCEPOLICY_H - -#include <QtCore/qobject.h> - -namespace ResourcePolicy { -class ResourceSet; -}; - -class PlayerResourcePolicy : public QObject -{ - Q_OBJECT -public: - PlayerResourcePolicy(QObject *parent = 0); - ~PlayerResourcePolicy(); - - bool isVideoEnabled() const; - bool isGranted() const; - bool isRequested() const; - -Q_SIGNALS: - void resourcesDenied(); - void resourcesGranted(); - void resourcesLost(); - -public Q_SLOTS: - void acquire(); - void release(); - - void setVideoEnabled(bool enabled); - -private Q_SLOTS: - void handleResourcesGranted(); - void handleResourcesDenied(); - void handleResourcesLost(); - -private: - enum ResourceStatus { - Initial = 0, - RequestedResource, - GrantedResource - }; - - bool m_videoEnabled; - ResourcePolicy::ResourceSet *m_resourceSet; - ResourceStatus m_status; -}; - -#endif diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp index 19e261a16..19476b497 100644 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp +++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp @@ -41,10 +41,10 @@ #include "qgstreamerplayercontrol.h" #include "qgstreamerplayersession.h" -#include "playerresourcepolicy.h" #include <private/qmediaplaylistnavigator_p.h> - +#include <private/qmediaresourcepolicy_p.h> +#include <private/qmediaresourceset_p.h> #include <QtCore/qdir.h> #include <QtCore/qsocketnotifier.h> @@ -78,7 +78,8 @@ QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *sessio m_fifoFd[0] = -1; m_fifoFd[1] = -1; - m_resources = new PlayerResourcePolicy(this); + m_resources = QMediaResourcePolicy::createResourceSet<QMediaPlayerResourceSetInterface>(QMediaPlayerResourceSetInterface_iid); + Q_ASSERT(m_resources); connect(m_session, SIGNAL(positionChanged(qint64)), this, SLOT(updatePosition(qint64))); @@ -116,6 +117,8 @@ QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *sessio QGstreamerPlayerControl::~QGstreamerPlayerControl() { + QMediaResourcePolicy::destroyResourceSet(m_resources); + if (m_fifoFd[0] >= 0) { ::close(m_fifoFd[0]); ::close(m_fifoFd[1]); @@ -243,7 +246,7 @@ void QGstreamerPlayerControl::playOrPause(QMediaPlayer::State newState) m_seekToStartPending = true; } - if (!m_resources->isGranted() && !m_resources->isRequested()) + if (!m_resources->isGranted()) m_resources->acquire(); if (m_resources->isGranted()) { @@ -350,7 +353,7 @@ void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice * m_session->showPrerollFrames(false); // do not show prerolled frames until pause() or play() explicitly called if (!content.isNull() || stream) { - if (!m_resources->isRequested() && !m_resources->isGranted()) + if (!m_resources->isGranted()) m_resources->acquire(); if (!m_resources->isGranted()) { diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h b/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h index 5d976dbb4..b575d1d1b 100644 --- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h +++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.h @@ -50,7 +50,7 @@ #include <limits.h> -class PlayerResourcePolicy; +class QMediaPlayerResourceSetInterface; QT_BEGIN_NAMESPACE class QMediaPlaylist; @@ -151,7 +151,7 @@ private: int m_bufferOffset; char m_buffer[PIPE_BUF]; - PlayerResourcePolicy *m_resources; + QMediaPlayerResourceSetInterface *m_resources; }; QT_END_NAMESPACE |