case QCamera::LoadedState:
switch (sessionState) {
case QCamera::UnloadedState:
- m_status = QCamera::LoadingStatus;
+ m_status = m_resourcePolicy->isResourcesGranted()
+ ? QCamera::LoadingStatus
+ : QCamera::UnavailableStatus;
break;
case QCamera::LoadedState:
m_status = QCamera::LoadedStatus;
case QCamera::ActiveState:
switch (sessionState) {
case QCamera::UnloadedState:
- m_status = QCamera::LoadingStatus;
+ m_status = m_resourcePolicy->isResourcesGranted()
+ ? QCamera::LoadingStatus
+ : QCamera::UnavailableStatus;
break;
case QCamera::LoadedState:
m_status = QCamera::StartingStatus;
bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const;
bool viewfinderColorSpaceConversion() const;
+ CamerabinResourcePolicy *resourcePolicy() { return m_resourcePolicy; }
+
public slots:
void reloadLater();
void setViewfinderColorSpaceConversion(bool enabled);
****************************************************************************/
#include "camerabinimagecapture.h"
+#include "camerabincontrol.h"
#include "camerabincapturedestination.h"
#include "camerabincapturebufferformat.h"
#include "camerabinsession.h"
+#include "camerabinresourcepolicy.h"
#include <private/qgstvideobuffer_p.h>
#include <private/qvideosurfacegstsink_p.h>
#include <private/qgstutils_p.h>
connect(m_session, SIGNAL(stateChanged(QCamera::State)), SLOT(updateState()));
connect(m_session, SIGNAL(imageExposed(int)), this, SIGNAL(imageExposed(int)));
connect(m_session, SIGNAL(imageCaptured(int,QImage)), this, SIGNAL(imageCaptured(int,QImage)));
+ connect(m_session->cameraControl()->resourcePolicy(), SIGNAL(canCaptureChanged()), this, SLOT(updateState()));
m_session->bus()->installMessageFilter(this);
}
void CameraBinImageCapture::updateState()
{
- bool ready = m_session->state() == QCamera::ActiveState;
+ bool ready = m_session->state() == QCamera::ActiveState
+ && m_session->cameraControl()->resourcePolicy()->canCapture();
if (m_ready != ready) {
#ifdef DEBUG_CAPTURE
qDebug() << "readyForCaptureChanged" << ready;
****************************************************************************/
#include "camerabinrecorder.h"
+#include "camerabincontrol.h"
+#include "camerabinresourcepolicy.h"
#include "camerabinaudioencoder.h"
#include "camerabinvideoencoder.h"
#include "camerabincontainer.h"
connect(m_session, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool)));
+ connect(m_session->cameraControl()->resourcePolicy(), SIGNAL(canCaptureChanged()),
+ this, SLOT(updateStatus()));
}
CameraBinRecorder::~CameraBinRecorder()
if (sessionState == QCamera::ActiveState &&
m_session->captureMode().testFlag(QCamera::CaptureVideo)) {
- if (m_state == QMediaRecorder::RecordingState) {
+ if (!m_session->cameraControl()->resourcePolicy()->canCapture()) {
+ m_status = QMediaRecorder::UnavailableStatus;
+ m_state = QMediaRecorder::StoppedState;
+ m_session->stopVideoRecording();
+ } else if (m_state == QMediaRecorder::RecordingState) {
m_status = QMediaRecorder::RecordingStatus;
} else {
m_status = m_session->isBusy() ?
emit error(QMediaRecorder::ResourceError, tr("QMediaRecorder::pause() is not supported by camerabin2."));
break;
case QMediaRecorder::RecordingState:
- if (m_session->state() == QCamera::ActiveState) {
+
+ if (m_session->state() != QCamera::ActiveState) {
+ emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
+ } else if (!m_session->cameraControl()->resourcePolicy()->canCapture()) {
+ emit error(QMediaRecorder::ResourceError, tr("Recording permissions are not available"));
+ } else {
m_session->recordVideo();
m_state = state;
m_status = QMediaRecorder::RecordingStatus;
emit actualLocationChanged(m_session->outputLocation());
- } else {
- emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
}
}
void setMuted(bool);
void setVolume(qreal volume);
-private slots:
void updateStatus();
private:
CamerabinResourcePolicy::CamerabinResourcePolicy(QObject *parent) :
QObject(parent),
m_resourceSet(NoResources),
- m_releasingResources(false)
+ m_releasingResources(false),
+ m_canCapture(false)
{
#ifdef HAVE_RESOURCE_POLICY
//loaded resource set is also kept requested for image and video capture sets
m_resource->initAndConnect();
connect(m_resource, SIGNAL(resourcesGranted(const QList<ResourcePolicy::ResourceType>)),
- SIGNAL(resourcesGranted()));
+ SLOT(handleResourcesGranted()));
connect(m_resource, SIGNAL(resourcesDenied()), SIGNAL(resourcesDenied()));
- connect(m_resource, SIGNAL(lostResources()), SIGNAL(resourcesLost()));
+ connect(m_resource, SIGNAL(lostResources()), SLOT(handleResourcesLost()));
connect(m_resource, SIGNAL(resourcesReleased()), SLOT(handleResourcesReleased()));
+ connect(m_resource, SIGNAL(resourcesBecameAvailable(QList<ResourcePolicy::ResourceType>)),
+ this, SLOT(resourcesAvailable()));
+ connect(m_resource, SIGNAL(updateOK()), this, SLOT(updateCanCapture()));
#endif
}
break;
case LoadedResources:
requestedTypes << ResourcePolicy::LensCoverType //to detect lens cover is opened/closed
- << ResourcePolicy::VideoRecorderType //to open camera device
- << ResourcePolicy::SnapButtonType; //to detect capture button events
+ << ResourcePolicy::VideoRecorderType; //to open camera device
break;
case ImageCaptureResources:
requestedTypes << ResourcePolicy::LensCoverType
<< ResourcePolicy::VideoPlaybackType
<< ResourcePolicy::VideoRecorderType
- << ResourcePolicy::AudioPlaybackType
- << ResourcePolicy::ScaleButtonType
- << ResourcePolicy::LedsType
- << ResourcePolicy::SnapButtonType;
+ << ResourcePolicy::LedsType;
break;
case VideoCaptureResources:
requestedTypes << ResourcePolicy::LensCoverType
<< ResourcePolicy::VideoRecorderType
<< ResourcePolicy::AudioPlaybackType
<< ResourcePolicy::AudioRecorderType
- << ResourcePolicy::ScaleButtonType
- << ResourcePolicy::LedsType
- << ResourcePolicy::SnapButtonType;
+ << ResourcePolicy::LedsType;
break;
}
ResourcePolicy::LensCoverResource *lensCoverResource = new ResourcePolicy::LensCoverResource;
lensCoverResource->setOptional(true);
m_resource->addResourceObject(lensCoverResource);
+ } else if (resourceType == ResourcePolicy::AudioPlaybackType) {
+ ResourcePolicy::Resource *resource = new ResourcePolicy::AudioResource;
+ resource->setOptional(true);
+ m_resource->addResourceObject(resource);
+ } else if (resourceType == ResourcePolicy::AudioRecorderType) {
+ ResourcePolicy::Resource *resource = new ResourcePolicy::AudioRecorderResource;
+ resource->setOptional(true);
+ m_resource->addResourceObject(resource);
} else {
m_resource->addResource(resourceType);
}
}
#else
Q_UNUSED(oldSet);
+ updateCanCapture();
#endif
}
return true;
}
+void CamerabinResourcePolicy::handleResourcesLost()
+{
+ updateCanCapture();
+ emit resourcesLost();
+}
+
+void CamerabinResourcePolicy::handleResourcesGranted()
+{
+ updateCanCapture();
+ emit resourcesGranted();
+}
+
void CamerabinResourcePolicy::handleResourcesReleased()
{
#ifdef HAVE_RESOURCE_POLICY
#endif
m_releasingResources = false;
#endif
+ updateCanCapture();
+}
+
+void CamerabinResourcePolicy::resourcesAvailable()
+{
+#ifdef HAVE_RESOURCE_POLICY
+ if (m_resourceSet != NoResources) {
+ m_resource->acquire();
+ }
+#endif
+}
+
+bool CamerabinResourcePolicy::canCapture() const
+{
+ return m_canCapture;
+}
+
+void CamerabinResourcePolicy::updateCanCapture()
+{
+ const bool wasAbleToRecord = m_canCapture;
+ m_canCapture = (m_resourceSet == VideoCaptureResources) || (m_resourceSet == ImageCaptureResources);
+#ifdef HAVE_RESOURCE_POLICY
+ foreach (ResourcePolicy::Resource *resource, m_resource->resources()) {
+ if (resource->type() != ResourcePolicy::LensCoverType)
+ m_canCapture = m_canCapture && resource->isGranted();
+ }
+#endif
+ if (wasAbleToRecord != m_canCapture)
+ emit canCaptureChanged();
}
QT_END_NAMESPACE
bool isResourcesGranted() const;
+ bool canCapture() const;
+
Q_SIGNALS:
void resourcesDenied();
void resourcesGranted();
void resourcesLost();
+ void canCaptureChanged();
private Q_SLOTS:
+ void handleResourcesLost();
+ void handleResourcesGranted();
void handleResourcesReleased();
+ void resourcesAvailable();
+ void updateCanCapture();
+
private:
ResourceSet m_resourceSet;
ResourcePolicy::ResourceSet *m_resource;
bool m_releasingResources;
+ bool m_canCapture;
};
QT_END_NAMESPACE
QMediaService(parent)
{
m_captureSession = 0;
- m_cameraControl = 0;
m_metaDataControl = 0;
m_audioInputSelector = 0;
if (service == Q_MEDIASERVICE_CAMERA) {
m_captureSession = new CameraBinSession(this);
- m_cameraControl = new CameraBinControl(m_captureSession);
m_videoInputDevice = new QGstreamerVideoInputDeviceControl(
m_captureSession->buildCameraSource(), m_captureSession);
m_imageCaptureControl = new CameraBinImageCapture(m_captureSession);
return m_captureSession->mediaContainerControl();
if (qstrcmp(name,QCameraControl_iid) == 0)
- return m_cameraControl;
+ return m_captureSession->cameraControl();
if (qstrcmp(name,QMetaDataWriterControl_iid) == 0)
return m_metaDataControl;
void setAudioPreview(GstElement*);
CameraBinSession *m_captureSession;
- CameraBinControl *m_cameraControl;
CameraBinMetaData *m_metaDataControl;
QAudioInputSelectorControl *m_audioInputSelector;
**
****************************************************************************/
#include "camerabinsession.h"
+#include "camerabincontrol.h"
#include "camerabinrecorder.h"
#include "camerabincontainer.h"
#include "camerabinaudioencoder.h"
m_busHelper = new QGstreamerBusHelper(m_bus, this);
m_busHelper->installMessageFilter(this);
+ m_cameraControl = new CameraBinControl(this);
m_audioEncodeControl = new CameraBinAudioEncoder(this);
m_videoEncodeControl = new CameraBinVideoEncoder(this);
m_imageEncodeControl = new CameraBinImageEncoder(this);
g_object_set(m_camerabin, MODE_PROPERTY, CAMERABIN_VIDEO_MODE, NULL);
break;
}
+
+ m_recorderControl->updateStatus();
}
QUrl CameraBinSession::outputLocation() const
class QGstreamerMessage;
class QGstreamerBusHelper;
+class CameraBinControl;
class CameraBinAudioEncoder;
class CameraBinVideoEncoder;
class CameraBinImageEncoder;
GstElement *buildCameraSource();
+ CameraBinControl *cameraControl() const { return m_cameraControl; }
CameraBinAudioEncoder *audioEncodeControl() const { return m_audioEncodeControl; }
CameraBinVideoEncoder *videoEncodeControl() const { return m_videoEncodeControl; }
CameraBinImageEncoder *imageEncodeControl() const { return m_imageEncodeControl; }
QObject *m_viewfinder;
QGstreamerVideoRendererInterface *m_viewfinderInterface;
+ CameraBinControl *m_cameraControl;
CameraBinAudioEncoder *m_audioEncodeControl;
CameraBinVideoEncoder *m_videoEncodeControl;
CameraBinImageEncoder *m_imageEncodeControl;
ResourcePolicyImpl::ResourcePolicyImpl(QObject *parent)
: QMediaPlayerResourceSetInterface(parent)
+ , m_status(Initial)
+ , m_videoEnabled(false)
{
m_resourceSet = new ResourcePolicy::ResourceSet("player", this);
m_resourceSet->setAlwaysReply();
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>)),