summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/avfoundation/mediaplayer/mediaplayer.pro13
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinfocus.cpp136
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinfocus.h10
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinsession.h1
-rw-r--r--src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp1
-rw-r--r--src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp1
-rw-r--r--src/plugins/plugins.pro9
-rw-r--r--src/plugins/resourcepolicy/resourcepolicy.pro6
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyimpl.cpp85
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyimpl.h17
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyint.cpp311
-rw-r--r--src/plugins/resourcepolicy/resourcepolicyint.h100
12 files changed, 594 insertions, 96 deletions
diff --git a/src/plugins/avfoundation/mediaplayer/mediaplayer.pro b/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
index b5193b73d..2670eceaf 100644
--- a/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
+++ b/src/plugins/avfoundation/mediaplayer/mediaplayer.pro
@@ -49,12 +49,17 @@ OBJECTIVE_SOURCES += \
HEADERS += \
avfvideorenderercontrol.h \
- avfdisplaylink.h \
- avfvideoframerenderer.h
+ avfdisplaylink.h
OBJECTIVE_SOURCES += \
avfvideorenderercontrol.mm \
- avfdisplaylink.mm \
- avfvideoframerenderer.mm
+ avfdisplaylink.mm
+
+ contains(QT_CONFIG, opengl.*) {
+ HEADERS += \
+ avfvideoframerenderer.h
+ OBJECTIVE_SOURCES += \
+ avfvideoframerenderer.mm
+ }
}
OTHER_FILES += \
diff --git a/src/plugins/gstreamer/camerabin/camerabinfocus.cpp b/src/plugins/gstreamer/camerabin/camerabinfocus.cpp
index ed5b483c2..50bc8a44d 100644
--- a/src/plugins/gstreamer/camerabin/camerabinfocus.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinfocus.cpp
@@ -54,10 +54,16 @@ QT_BEGIN_NAMESPACE
CameraBinFocus::CameraBinFocus(CameraBinSession *session)
:QCameraFocusControl(session),
m_session(session),
+ m_cameraState(QCamera::UnloadedState),
m_focusMode(QCameraFocus::AutoFocus),
+ m_focusPointMode(QCameraFocus::FocusPointAuto),
m_focusStatus(QCamera::Unlocked),
- m_focusZoneStatus(QCameraFocusZone::Selected)
+ m_focusZoneStatus(QCameraFocusZone::Selected),
+ m_focusPoint(0.5, 0.5),
+ m_focusRect(0, 0, 0.3, 0.3)
{
+ m_focusRect.moveCenter(m_focusPoint);
+
gst_photography_set_focus_mode(m_session->photography(), GST_PHOTOGRAPHY_FOCUS_MODE_AUTO);
connect(m_session, SIGNAL(stateChanged(QCamera::State)),
@@ -122,32 +128,61 @@ bool CameraBinFocus::isFocusModeSupported(QCameraFocus::FocusModes mode) const
QCameraFocus::FocusPointMode CameraBinFocus::focusPointMode() const
{
- return QCameraFocus::FocusPointAuto;
+ return m_focusPointMode;
}
void CameraBinFocus::setFocusPointMode(QCameraFocus::FocusPointMode mode)
{
Q_UNUSED(mode);
+ if (m_focusPointMode != mode
+ && (mode == QCameraFocus::FocusPointAuto || mode == QCameraFocus::FocusPointCustom)) {
+ m_focusPointMode = mode;
+
+ if (m_focusPointMode == QCameraFocus::FocusPointAuto)
+ resetFocusPoint();
+
+ emit focusPointModeChanged(m_focusPointMode);
+
+ }
}
bool CameraBinFocus::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const
{
- return mode == QCameraFocus::FocusPointAuto;
+ return mode == QCameraFocus::FocusPointAuto || mode == QCameraFocus::FocusPointCustom;
}
QPointF CameraBinFocus::customFocusPoint() const
{
- return QPointF(0.5, 0.5);
+ return m_focusPoint;
}
void CameraBinFocus::setCustomFocusPoint(const QPointF &point)
{
- Q_UNUSED(point);
+ if (m_focusPoint != point) {
+ m_focusPoint = point;
+
+ // Bound the focus point so the focus rect remains entirely within the unit square.
+ m_focusPoint.setX(qBound(m_focusRect.width() / 2, m_focusPoint.x(), 1 - m_focusRect.width() / 2));
+ m_focusPoint.setY(qBound(m_focusRect.height() / 2, m_focusPoint.y(), 1 - m_focusRect.height() / 2));
+
+ if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
+ const QRectF focusRect = m_focusRect;
+ m_focusRect.moveCenter(m_focusPoint);
+
+ updateRegionOfInterest(m_focusRect, 1);
+
+ if (focusRect != m_focusRect) {
+ emit focusZonesChanged();
+ }
+ }
+
+ emit customFocusPointChanged(m_focusPoint);
+ }
}
QCameraFocusZoneList CameraBinFocus::focusZones() const
{
- return QCameraFocusZoneList() << QCameraFocusZone(QRectF(0.35, 0.35, 0.3, 0.3), m_focusZoneStatus);
+ return QCameraFocusZoneList() << QCameraFocusZone(m_focusRect, m_focusZoneStatus);
}
@@ -213,8 +248,29 @@ void CameraBinFocus::_q_setFocusStatus(QCamera::LockStatus status, QCamera::Lock
void CameraBinFocus::_q_handleCameraStateChange(QCamera::State state)
{
- if (state != QCamera::ActiveState)
+ m_cameraState = state;
+ if (state == QCamera::ActiveState) {
+ if (GstPad *pad = gst_element_get_static_pad(m_session->cameraSource(), "vfsrc")) {
+ if (GstCaps *caps = gst_pad_get_negotiated_caps(pad)) {
+ if (GstStructure *structure = gst_caps_get_structure(caps, 0)) {
+ int width = 0;
+ int height = 0;
+ gst_structure_get_int(structure, "width", &width);
+ gst_structure_get_int(structure, "height", &height);
+ setViewfinderResolution(QSize(width, height));
+ }
+ gst_caps_unref(caps);
+ }
+ gst_object_unref(GST_OBJECT(pad));
+ }
+ if (m_focusPointMode == QCameraFocus::FocusPointCustom) {
+ updateRegionOfInterest(m_focusRect, 1);
+ }
+ } else {
_q_setFocusStatus(QCamera::Unlocked, QCamera::LockLost);
+
+ resetFocusPoint();
+ }
}
void CameraBinFocus::_q_startFocusing()
@@ -229,4 +285,70 @@ void CameraBinFocus::_q_stopFocusing()
_q_setFocusStatus(QCamera::Unlocked, QCamera::UserRequest);
}
+void CameraBinFocus::setViewfinderResolution(const QSize &resolution)
+{
+ if (resolution != m_viewfinderResolution) {
+ m_viewfinderResolution = resolution;
+ if (!resolution.isEmpty()) {
+ const QPointF center = m_focusRect.center();
+ m_focusRect.setWidth(m_focusRect.height() * resolution.height() / resolution.width());
+ m_focusRect.moveCenter(center);
+ }
+ }
+}
+
+void CameraBinFocus::resetFocusPoint()
+{
+ const QRectF focusRect = m_focusRect;
+ m_focusPoint = QPointF(0.5, 0.5);
+ m_focusRect.moveCenter(m_focusPoint);
+
+ updateRegionOfInterest(QRectF(0, 0, 0, 0), 0);
+
+ if (focusRect != m_focusRect) {
+ emit customFocusPointChanged(m_focusPoint);
+ emit focusZonesChanged();
+ }
+}
+
+void CameraBinFocus::updateRegionOfInterest(const QRectF &focusRect, int priority)
+{
+ if (m_cameraState != QCamera::ActiveState)
+ return;
+
+ GstElement * const cameraSource = m_session->cameraSource();
+ if (!cameraSource)
+ return;
+
+ GstStructure *region = gst_structure_new(
+ "region",
+ "region-x" , G_TYPE_UINT , uint(m_viewfinderResolution.width() * focusRect.x()),
+ "region-y" , G_TYPE_UINT, uint(m_viewfinderResolution.height() * focusRect.y()),
+ "region-w" , G_TYPE_UINT , uint(m_viewfinderResolution.width() * focusRect.width()),
+ "region-h" , G_TYPE_UINT, uint(m_viewfinderResolution.height() * focusRect.height()),
+ "region-priority" , G_TYPE_UINT, priority,
+ NULL);
+
+ GValue regionValue = G_VALUE_INIT;
+ g_value_init(&regionValue, GST_TYPE_STRUCTURE);
+ gst_value_set_structure(&regionValue, region);
+ gst_structure_free(region);
+
+ GValue regions = G_VALUE_INIT;
+ g_value_init(&regions, GST_TYPE_LIST);
+ gst_value_list_append_value(&regions, &regionValue);
+ g_value_unset(&regionValue);
+
+ GstStructure *regionsOfInterest = gst_structure_new(
+ "regions-of-interest",
+ "frame-width" , G_TYPE_UINT , m_viewfinderResolution.width(),
+ "frame-height" , G_TYPE_UINT, m_viewfinderResolution.height(),
+ NULL);
+ gst_structure_set_value(regionsOfInterest, "regions", &regions);
+ g_value_unset(&regions);
+
+ GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM, regionsOfInterest);
+ gst_element_send_event(cameraSource, event);
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinfocus.h b/src/plugins/gstreamer/camerabin/camerabinfocus.h
index e1f4dcd36..45ca7fcc8 100644
--- a/src/plugins/gstreamer/camerabin/camerabinfocus.h
+++ b/src/plugins/gstreamer/camerabin/camerabinfocus.h
@@ -82,15 +82,25 @@ public Q_SLOTS:
void _q_startFocusing();
void _q_stopFocusing();
+ void setViewfinderResolution(const QSize &resolution);
+
private Q_SLOTS:
void _q_setFocusStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason);
void _q_handleCameraStateChange(QCamera::State state);
private:
+ void resetFocusPoint();
+ void updateRegionOfInterest(const QRectF &focusRect, int priority);
+
CameraBinSession *m_session;
+ QCamera::State m_cameraState;
QCameraFocus::FocusModes m_focusMode;
+ QCameraFocus::FocusPointMode m_focusPointMode;
QCamera::LockStatus m_focusStatus;
QCameraFocusZone::FocusZoneStatus m_focusZoneStatus;
+ QPointF m_focusPoint;
+ QRectF m_focusRect;
+ QSize m_viewfinderResolution;
};
QT_END_NAMESPACE
diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h
index d77217906..54800e9ed 100644
--- a/src/plugins/gstreamer/camerabin/camerabinsession.h
+++ b/src/plugins/gstreamer/camerabin/camerabinsession.h
@@ -103,6 +103,7 @@ public:
GstPhotography *photography();
#endif
GstElement *cameraBin() { return m_camerabin; }
+ GstElement *cameraSource() { return m_videoSrc; }
QGstreamerBusHelper *bus() { return m_busHelper; }
CameraRole cameraRole() const;
diff --git a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp b/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp
index 373dbee77..b61a506dc 100644
--- a/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinviewfindersettings.cpp
@@ -89,6 +89,7 @@ void CameraBinViewfinderSettings::setViewfinderParameter(ViewfinderParameter par
switch (parameter) {
case Resolution:
m_resolution = value.toSize();
+ break;
case PixelAspectRatio:
case MinimumFrameRate:
case MaximumFrameRate:
diff --git a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp
index 87b71d7e2..19fa07881 100644
--- a/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp
+++ b/src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp
@@ -1523,6 +1523,7 @@ void QGstreamerPlayerSession::playbinNotifySource(GObject *o, GParamSpec *p, gpo
//rtspsrc acts like a live source and will therefore only generate data in the PLAYING state.
self->m_sourceType = RTSPSrc;
self->m_isLiveSource = true;
+ g_object_set(G_OBJECT(source), "buffer-mode", 1, NULL);
} else {
self->m_sourceType = UnknownSrc;
self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source));
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
index 2677e269b..45aa95ec7 100644
--- a/src/plugins/plugins.pro
+++ b/src/plugins/plugins.pro
@@ -36,11 +36,8 @@ unix:!mac:!android {
SUBDIRS += audiocapture
}
- config_pulseaudio {
- SUBDIRS += pulseaudio
- } else:config_alsa {
- SUBDIRS += alsa
- }
+ config_pulseaudio: SUBDIRS += pulseaudio
+ config_alsa: SUBDIRS += alsa
# v4l is turned off because it is not supported in Qt 5
# !maemo*:SUBDIRS += v4l
@@ -51,7 +48,7 @@ mac:!simulator {
config_avfoundation: SUBDIRS += avfoundation
- !ios: SUBDIRS += qt7
+ contains(QT_CONFIG, opengl.*):!ios: SUBDIRS += qt7
}
config_resourcepolicy {
diff --git a/src/plugins/resourcepolicy/resourcepolicy.pro b/src/plugins/resourcepolicy/resourcepolicy.pro
index 7aa1ced9f..4805c5250 100644
--- a/src/plugins/resourcepolicy/resourcepolicy.pro
+++ b/src/plugins/resourcepolicy/resourcepolicy.pro
@@ -13,9 +13,11 @@ INCLUDEPATH += $$PWD \
HEADERS += \
$$PWD/resourcepolicyplugin.h \
- $$PWD/resourcepolicyimpl.h
+ $$PWD/resourcepolicyimpl.h \
+ $$PWD/resourcepolicyint.h
SOURCES += \
$$PWD/resourcepolicyplugin.cpp \
- $$PWD/resourcepolicyimpl.cpp
+ $$PWD/resourcepolicyimpl.cpp \
+ $$PWD/resourcepolicyint.cpp
diff --git a/src/plugins/resourcepolicy/resourcepolicyimpl.cpp b/src/plugins/resourcepolicy/resourcepolicyimpl.cpp
index 0acabc001..3ad92fa1f 100644
--- a/src/plugins/resourcepolicy/resourcepolicyimpl.cpp
+++ b/src/plugins/resourcepolicy/resourcepolicyimpl.cpp
@@ -40,99 +40,62 @@
**
****************************************************************************/
+#include <QGlobalStatic>
+
#include <policy/resource.h>
#include <policy/resources.h>
#include <policy/resource-set.h>
#include "resourcepolicyimpl.h"
+#include "resourcepolicyint.h"
+
+Q_GLOBAL_STATIC(ResourcePolicyInt, globalResourcePolicyInt);
ResourcePolicyImpl::ResourcePolicyImpl(QObject *parent)
: QMediaPlayerResourceSetInterface(parent)
- , m_status(Initial)
- , m_videoEnabled(false)
{
- 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->update();
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ set->addClient(this);
+}
- connect(m_resourceSet, SIGNAL(resourcesGranted(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()));
+ResourcePolicyImpl::~ResourcePolicyImpl()
+{
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ set->removeClient(this);
}
bool ResourcePolicyImpl::isVideoEnabled() const
{
- return m_videoEnabled;
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ return set->isVideoEnabled(this);
}
void ResourcePolicyImpl::setVideoEnabled(bool videoEnabled)
{
- if (m_videoEnabled != videoEnabled) {
- m_videoEnabled = videoEnabled;
-
- if (videoEnabled)
- m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType);
- else
- m_resourceSet->deleteResource(ResourcePolicy::VideoPlaybackType);
-
- m_resourceSet->update();
- }
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ set->setVideoEnabled(this, videoEnabled);
}
void ResourcePolicyImpl::acquire()
{
- m_status = RequestedResource;
- m_resourceSet->acquire();
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ set->acquire(this);
}
void ResourcePolicyImpl::release()
{
- m_resourceSet->release();
- m_status = Initial;
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ set->release(this);
}
bool ResourcePolicyImpl::isGranted() const
{
- return m_status == GrantedResource;
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ return set->isGranted(this);
}
bool ResourcePolicyImpl::isAvailable() const
{
- // TODO: is this used? what is it for?
- qWarning() << Q_FUNC_INFO << "Stub";
- return true;
+ ResourcePolicyInt *set = globalResourcePolicyInt;
+ return set->isAvailable();
}
-
-void ResourcePolicyImpl::handleResourcesGranted()
-{
- m_status = GrantedResource;
- emit resourcesGranted();
-}
-
-void ResourcePolicyImpl::handleResourcesDenied()
-{
- m_status = Initial;
- emit resourcesDenied();
-}
-
-void ResourcePolicyImpl::handleResourcesLost()
-{
- if (m_status != Initial) {
- m_status = Initial;
- emit resourcesLost();
- }
-
- m_resourceSet->release();
-}
-
diff --git a/src/plugins/resourcepolicy/resourcepolicyimpl.h b/src/plugins/resourcepolicy/resourcepolicyimpl.h
index 8680df86a..28393b789 100644
--- a/src/plugins/resourcepolicy/resourcepolicyimpl.h
+++ b/src/plugins/resourcepolicy/resourcepolicyimpl.h
@@ -56,6 +56,7 @@ class ResourcePolicyImpl : public QMediaPlayerResourceSetInterface
Q_OBJECT
public:
ResourcePolicyImpl(QObject *parent = 0);
+ ~ResourcePolicyImpl();
bool isVideoEnabled() const;
void setVideoEnabled(bool videoEnabled);
@@ -63,22 +64,6 @@ public:
void release();
bool isGranted() const;
bool isAvailable() const;
-
-private 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 // RESOURCEPOLICYIMPL_H
diff --git a/src/plugins/resourcepolicy/resourcepolicyint.cpp b/src/plugins/resourcepolicy/resourcepolicyint.cpp
new file mode 100644
index 000000000..2fff64bfb
--- /dev/null
+++ b/src/plugins/resourcepolicy/resourcepolicyint.cpp
@@ -0,0 +1,311 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Jolla Ltd, author: <robin.burchell@jollamobile.com>
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <policy/resource.h>
+#include <policy/resources.h>
+#include <policy/resource-set.h>
+
+#include "resourcepolicyint.h"
+#include "resourcepolicyimpl.h"
+
+#include <QMap>
+
+static int clientid = 0;
+
+ResourcePolicyInt::ResourcePolicyInt(QObject *parent)
+ : QObject(parent)
+ , m_acquired(0)
+ , m_status(Initial)
+ , m_video(0)
+ , m_resourceSet(0)
+{
+ 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->update();
+
+ connect(m_resourceSet, SIGNAL(resourcesGranted(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()));
+}
+
+ResourcePolicyInt::~ResourcePolicyInt()
+{
+ delete m_resourceSet;
+ m_resourceSet = 0;
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### Tearing down singleton.";
+#endif
+}
+
+void ResourcePolicyInt::addClient(ResourcePolicyImpl *client)
+{
+ clientEntry entry;
+ entry.id = clientid++;
+ entry.client = client;
+ entry.status = Initial;
+ entry.videoEnabled = false;
+ m_clients.insert(entry.client, entry);
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### Add client " << client << " : " << entry.id;
+#endif
+}
+
+void ResourcePolicyInt::removeClient(ResourcePolicyImpl *client)
+{
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
+ if (i != m_clients.end()) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### Remove client " << client << " : " << i.value().id;
+#endif
+ if (i.value().status == GrantedResource)
+ --m_acquired;
+ m_clients.erase(i);
+ }
+
+ if (m_acquired == 0) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### Remove client, acquired = 0, release";
+#endif
+ m_resourceSet->release();
+ m_status = Initial;
+ }
+}
+
+bool ResourcePolicyInt::isVideoEnabled(const ResourcePolicyImpl *client) const
+{
+ QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
+ if (i != m_clients.constEnd())
+ return i.value().videoEnabled;
+
+ return false;
+}
+
+void ResourcePolicyInt::setVideoEnabled(const ResourcePolicyImpl *client, bool videoEnabled)
+{
+ bool update = false;
+
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
+ if (i != m_clients.end()) {
+ if (videoEnabled == i.value().videoEnabled)
+ return;
+
+ if (videoEnabled) {
+ if (m_video > 0) {
+ i.value().videoEnabled = true;
+ } else {
+ m_resourceSet->addResource(ResourcePolicy::VideoPlaybackType);
+ update = true;
+ }
+ ++m_video;
+ } else {
+ --m_video;
+ i.value().videoEnabled = false;
+ if (m_video == 0) {
+ m_resourceSet->deleteResource(ResourcePolicy::VideoPlaybackType);
+ update = true;
+ }
+ }
+ }
+
+ if (update)
+ m_resourceSet->update();
+}
+
+void ResourcePolicyInt::acquire(const ResourcePolicyImpl *client)
+{
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
+ if (i != m_clients.end()) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": ACQUIRE";
+#endif
+ if (i.value().status == Initial) {
+
+ if (m_status == RequestedResource) {
+ i.value().status = RequestedResource;
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": Already requesting, set client as RequestResource and return";
+#endif
+ return;
+ }
+
+ if (m_status == GrantedResource) {
+ ++m_acquired;
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": Already granted, set as GrantedResource and return";
+#endif
+ i.value().status = GrantedResource;
+ emit i.value().client->resourcesGranted();
+ return;
+ }
+ } else if (i.value().status == RequestedResource) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": Already requesting, return";
+#endif
+ return;
+ } else {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": Already granted, return ";
+#endif
+ return;
+ }
+ i.value().status = RequestedResource;
+ m_status = RequestedResource;
+
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": ACQUIRE call resourceSet->acquire()";
+#endif
+ // If m_status was Initial this is the first time resources are requested,
+ // so let's actually do the acquiring
+ m_resourceSet->acquire();
+ }
+}
+
+void ResourcePolicyInt::release(const ResourcePolicyImpl *client)
+{
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.find(client);
+ if (i != m_clients.end()) {
+ if (i.value().status == GrantedResource) {
+ i.value().status = Initial;
+ --m_acquired;
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": RELEASE, acquired (" << m_acquired << ")";
+#endif
+ }
+ }
+
+ if (m_acquired == 0) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": RELEASE call resourceSet->release()";
+#endif
+ m_resourceSet->release();
+ m_status = Initial;
+ }
+}
+
+bool ResourcePolicyInt::isGranted(const ResourcePolicyImpl *client) const
+{
+ QMap<const ResourcePolicyImpl*, clientEntry>::const_iterator i = m_clients.find(client);
+ if (i != m_clients.constEnd()) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": IS GRANTED, status: " << i.value().status;
+#endif
+ return i.value().status == GrantedResource;
+ }
+
+ return false;
+}
+
+bool ResourcePolicyInt::isAvailable() const
+{
+ // TODO: is this used? what is it for?
+ qWarning() << Q_FUNC_INFO << "Stub";
+ return true;
+}
+
+void ResourcePolicyInt::handleResourcesGranted()
+{
+ m_status = GrantedResource;
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
+ while (i != m_clients.end()) {
+ if (i.value().status == RequestedResource) {
+ ++m_acquired;
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": HANDLE GRANTED, acquired (" << m_acquired << ") emitting resourcesGranted()";
+#endif
+ i.value().status = GrantedResource;
+ emit i.value().client->resourcesGranted();
+ }
+ ++i;
+ }
+}
+
+void ResourcePolicyInt::handleResourcesDenied()
+{
+ m_status = Initial;
+ m_acquired = 0;
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
+ while (i != m_clients.end()) {
+ if (i.value().status == RequestedResource) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": HANDLE DENIED, acquired (" << m_acquired << ") emitting resourcesDenied()";
+#endif
+ i.value().status = Initial;
+ emit i.value().client->resourcesDenied();
+ }
+ // Do we need to act for clients that are in granted state?
+ ++i;
+ }
+}
+
+void ResourcePolicyInt::handleResourcesLost()
+{
+ if (m_status != Initial) {
+ m_status = Initial;
+ }
+
+ m_acquired = 0;
+ m_resourceSet->release();
+
+ QMap<const ResourcePolicyImpl*, clientEntry>::iterator i = m_clients.begin();
+ while (i != m_clients.end()) {
+ if (i.value().status != Initial) {
+#ifdef RESOURCE_DEBUG
+ qDebug() << "##### " << i.value().id << ": HANDLE LOST, acquired (" << m_acquired << ") emitting resourcesLost()";
+#endif
+ i.value().status = Initial;
+ emit i.value().client->resourcesLost();
+ }
+ ++i;
+ }
+}
diff --git a/src/plugins/resourcepolicy/resourcepolicyint.h b/src/plugins/resourcepolicy/resourcepolicyint.h
new file mode 100644
index 000000000..39882b527
--- /dev/null
+++ b/src/plugins/resourcepolicy/resourcepolicyint.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Jolla Ltd, author: <robin.burchell@jollamobile.com>
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/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 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, Digia gives you certain additional
+** rights. These rights are described in the Digia 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef RESOURCEPOLICYINT_H
+#define RESOURCEPOLICYINT_H
+
+#include <QObject>
+#include <QMap>
+
+#include <private/qmediaresourceset_p.h>
+#include "resourcepolicyimpl.h"
+
+namespace ResourcePolicy {
+ class ResourceSet;
+};
+
+enum ResourceStatus {
+ Initial = 0,
+ RequestedResource,
+ GrantedResource
+};
+
+struct clientEntry {
+ int id;
+ ResourcePolicyImpl *client;
+ ResourceStatus status;
+ bool videoEnabled;
+};
+
+class ResourcePolicyInt : public QObject
+{
+ Q_OBJECT
+public:
+ ResourcePolicyInt(QObject *parent = 0);
+ ~ResourcePolicyInt();
+
+ bool isVideoEnabled(const ResourcePolicyImpl *client) const;
+ void setVideoEnabled(const ResourcePolicyImpl *client, bool videoEnabled);
+ void acquire(const ResourcePolicyImpl *client);
+ void release(const ResourcePolicyImpl *client);
+ bool isGranted(const ResourcePolicyImpl *client) const;
+ bool isAvailable() const;
+
+ void addClient(ResourcePolicyImpl *client);
+ void removeClient(ResourcePolicyImpl *client);
+
+private slots:
+ void handleResourcesGranted();
+ void handleResourcesDenied();
+ void handleResourcesLost();
+
+private:
+ QMap<const ResourcePolicyImpl*, clientEntry> m_clients;
+
+ int m_acquired;
+ ResourceStatus m_status;
+ int m_video;
+ ResourcePolicy::ResourceSet *m_resourceSet;
+};
+
+#endif // RESOURCEPOLICYINT_H