summaryrefslogtreecommitdiffstats
path: root/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
diff options
context:
space:
mode:
authorDmytro Poplavskiy <dmytro.poplavskiy@nokia.com>2012-05-01 13:10:33 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-02 03:15:01 +0200
commitb7935a84d71b479f5320e5b062274d344835ba26 (patch)
treee72ac1774590d91f621ed9b21cf0c0ab2c87903b /src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
parentaf932e8653b024c93ed49ba30d6f06839ecfced6 (diff)
Added QMediaRecorder::status property
QMediaRecorder::state property represents the user request and changed synchronously during record(), pause() or stop() calls. Recorder status is changed asynchronously and represents the actual status of media recorder. This also makes API more consistent with QMediaPlayer and QCamera. Change-Id: I80b4aaa70bb88e555c492908da8c29d0fc5ed5ea Reviewed-by: Ling Hu <ling.hu@nokia.com>
Diffstat (limited to 'src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp')
-rw-r--r--src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp74
1 files changed, 61 insertions, 13 deletions
diff --git a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp b/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
index c9e8d454..700517a1 100644
--- a/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
+++ b/src/plugins/gstreamer/mediacapture/qgstreamerrecordercontrol.cpp
@@ -46,10 +46,13 @@
#include <QtCore/QDebug>
QGstreamerRecorderControl::QGstreamerRecorderControl(QGstreamerCaptureSession *session)
- :QMediaRecorderControl(session), m_session(session), m_state(QMediaRecorder::StoppedState)
+ :QMediaRecorderControl(session),
+ m_session(session),
+ m_state(QMediaRecorder::StoppedState),
+ m_status(QMediaRecorder::UnloadedStatus)
{
- connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)), SLOT(updateState()));
- connect(m_session, SIGNAL(error(int,QString)), SIGNAL(error(int,QString)));
+ connect(m_session, SIGNAL(stateChanged(QGstreamerCaptureSession::State)), SLOT(updateStatus()));
+ connect(m_session, SIGNAL(error(int,QString)), SLOT(handleSessionError(int,QString)));
connect(m_session, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64)));
connect(m_session, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool)));
m_hasPreviewState = m_session->captureMode() != QGstreamerCaptureSession::Audio;
@@ -74,29 +77,50 @@ bool QGstreamerRecorderControl::setOutputLocation(const QUrl &sink)
QMediaRecorder::State QGstreamerRecorderControl::state() const
{
+ return m_state;
+}
+
+QMediaRecorder::Status QGstreamerRecorderControl::status() const
+{
+ static QMediaRecorder::Status statusTable[3][3] = {
+ //Stopped recorder state:
+ { QMediaRecorder::LoadedStatus, QMediaRecorder::FinalizingStatus, QMediaRecorder::FinalizingStatus },
+ //Recording recorder state:
+ { QMediaRecorder::StartingStatus, QMediaRecorder::RecordingStatus, QMediaRecorder::PausedStatus },
+ //Paused recorder state:
+ { QMediaRecorder::StartingStatus, QMediaRecorder::RecordingStatus, QMediaRecorder::PausedStatus }
+ };
+
+ QMediaRecorder::State sessionState = QMediaRecorder::StoppedState;
+
switch ( m_session->state() ) {
case QGstreamerCaptureSession::RecordingState:
- return QMediaRecorder::RecordingState;
+ sessionState = QMediaRecorder::RecordingState;
case QGstreamerCaptureSession::PausedState:
- return QMediaRecorder::PausedState;
+ sessionState = QMediaRecorder::PausedState;
case QGstreamerCaptureSession::PreviewState:
case QGstreamerCaptureSession::StoppedState:
- return QMediaRecorder::StoppedState;
+ sessionState = QMediaRecorder::StoppedState;
}
- return QMediaRecorder::StoppedState;
-
+ return statusTable[m_state][sessionState];
}
-void QGstreamerRecorderControl::updateState()
+void QGstreamerRecorderControl::updateStatus()
{
- QMediaRecorder::State newState = state();
- if (m_state != newState) {
- m_state = newState;
- emit stateChanged(m_state);
+ QMediaRecorder::Status newStatus = status();
+ if (m_status != newStatus) {
+ m_status = newStatus;
+ emit statusChanged(m_status);
}
}
+void QGstreamerRecorderControl::handleSessionError(int code, const QString &description)
+{
+ emit error(code, description);
+ stop();
+}
+
qint64 QGstreamerRecorderControl::duration() const
{
return m_session->duration();
@@ -104,6 +128,11 @@ qint64 QGstreamerRecorderControl::duration() const
void QGstreamerRecorderControl::record()
{
+ if (m_state == QMediaRecorder::RecordingState)
+ return;
+
+ m_state = QMediaRecorder::RecordingState;
+
if (m_outputLocation.isEmpty()) {
QString container = m_session->mediaContainerControl()->containerExtension();
if (container.isEmpty())
@@ -119,25 +148,44 @@ void QGstreamerRecorderControl::record()
emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
m_session->dumpGraph("after-record");
+
+ emit stateChanged(m_state);
+ updateStatus();
}
void QGstreamerRecorderControl::pause()
{
+ if (m_state == QMediaRecorder::PausedState)
+ return;
+
+ m_state = QMediaRecorder::PausedState;
+
m_session->dumpGraph("before-pause");
if (!m_hasPreviewState || m_session->state() != QGstreamerCaptureSession::StoppedState) {
m_session->setState(QGstreamerCaptureSession::PausedState);
} else
emit error(QMediaRecorder::ResourceError, tr("Service has not been started"));
+
+ emit stateChanged(m_state);
+ updateStatus();
}
void QGstreamerRecorderControl::stop()
{
+ if (m_state == QMediaRecorder::StoppedState)
+ return;
+
+ m_state = QMediaRecorder::StoppedState;
+
if (!m_hasPreviewState) {
m_session->setState(QGstreamerCaptureSession::StoppedState);
} else {
if (m_session->state() != QGstreamerCaptureSession::StoppedState)
m_session->setState(QGstreamerCaptureSession::PreviewState);
}
+
+ emit stateChanged(m_state);
+ updateStatus();
}
void QGstreamerRecorderControl::applySettings()