Added QMediaRecorder::actualLocation property

To report the actual location file was written.

Change-Id: Ibb56a720a258a1e5cedceaf0f9bcea73fb93bc96
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
Dmytro Poplavskiy
2012-01-31 13:20:17 +10:00
committed by Qt by Nokia
parent a26bf6c8b6
commit ba37f73d44
7 changed files with 76 additions and 1 deletions

View File

@@ -111,7 +111,9 @@ QMediaRecorderControl::~QMediaRecorderControl()
The \a location can be relative or empty; The \a location can be relative or empty;
in this case the service should use the system specific place and file naming scheme. in this case the service should use the system specific place and file naming scheme.
After recording has stated, QMediaRecorderControl::outputLocation() should return the actual output location.
After recording has started, the backend should report the actual file location
with actualLocationChanged() signal.
*/ */
/*! /*!
@@ -184,6 +186,13 @@ QMediaRecorderControl::~QMediaRecorderControl()
Signals that the \a muted state of a media recorder has changed. Signals that the \a muted state of a media recorder has changed.
*/ */
/*!
\fn void QMediaRecorderControl::actualLocationChanged(const QUrl &location)
Signals that the actual media \a location has changed.
This signal should be emitted at start of recording.
*/
/*! /*!
\fn void QMediaRecorderControl::error(int error, const QString &errorString) \fn void QMediaRecorderControl::error(int error, const QString &errorString)

View File

@@ -78,6 +78,7 @@ Q_SIGNALS:
void stateChanged(QMediaRecorder::State state); void stateChanged(QMediaRecorder::State state);
void durationChanged(qint64 position); void durationChanged(qint64 position);
void mutedChanged(bool muted); void mutedChanged(bool muted);
void actualLocationChanged(const QUrl &location);
void error(int error, const QString &errorString); void error(int error, const QString &errorString);
public Q_SLOTS: public Q_SLOTS:

View File

@@ -145,6 +145,14 @@ void QMediaRecorderPrivate::_q_serviceDestroyed()
metaDataControl = 0; metaDataControl = 0;
} }
void QMediaRecorderPrivate::_q_updateActualLocation(const QUrl &location)
{
if (actualLocation != location) {
actualLocation = location;
emit q_func()->actualLocationChanged(actualLocation);
}
}
void QMediaRecorderPrivate::_q_notify() void QMediaRecorderPrivate::_q_notify()
{ {
emit q_func()->durationChanged(q_func()->duration()); emit q_func()->durationChanged(q_func()->duration());
@@ -257,6 +265,9 @@ bool QMediaRecorder::setMediaObject(QMediaObject *object)
disconnect(d->control, SIGNAL(durationChanged(qint64)), disconnect(d->control, SIGNAL(durationChanged(qint64)),
this, SIGNAL(durationChanged(qint64))); this, SIGNAL(durationChanged(qint64)));
disconnect(d->control, SIGNAL(actualLocationChanged(QUrl)),
this, SLOT(_q_updateActualLocation(QUrl)));
disconnect(d->control, SIGNAL(error(int,QString)), disconnect(d->control, SIGNAL(error(int,QString)),
this, SLOT(_q_error(int,QString))); this, SLOT(_q_error(int,QString)));
} }
@@ -338,6 +349,9 @@ bool QMediaRecorder::setMediaObject(QMediaObject *object)
connect(d->control, SIGNAL(durationChanged(qint64)), connect(d->control, SIGNAL(durationChanged(qint64)),
this, SIGNAL(durationChanged(qint64))); this, SIGNAL(durationChanged(qint64)));
connect(d->control, SIGNAL(actualLocationChanged(QUrl)),
this, SLOT(_q_updateActualLocation(QUrl)));
connect(d->control, SIGNAL(error(int,QString)), connect(d->control, SIGNAL(error(int,QString)),
this, SLOT(_q_error(int,QString))); this, SLOT(_q_error(int,QString)));
@@ -371,6 +385,14 @@ bool QMediaRecorder::setMediaObject(QMediaObject *object)
After recording has stated, QMediaRecorder::outputLocation() returns the actual output location. After recording has stated, QMediaRecorder::outputLocation() returns the actual output location.
*/ */
/*!
\property QMediaRecorder::actualLocation
\brief the actual location of the last media content.
The actual location is usually available after recording starts,
and reset when new location is set or new recording starts.
*/
/*! /*!
Returns true if media recorder service ready to use. Returns true if media recorder service ready to use.
*/ */
@@ -401,9 +423,15 @@ QUrl QMediaRecorder::outputLocation() const
bool QMediaRecorder::setOutputLocation(const QUrl &location) bool QMediaRecorder::setOutputLocation(const QUrl &location)
{ {
Q_D(QMediaRecorder); Q_D(QMediaRecorder);
d->actualLocation.clear();
return d->control ? d->control->setOutputLocation(location) : false; return d->control ? d->control->setOutputLocation(location) : false;
} }
QUrl QMediaRecorder::actualLocation() const
{
return d_func()->actualLocation;
}
/*! /*!
Returns the current media recorder state. Returns the current media recorder state.
@@ -743,6 +771,8 @@ void QMediaRecorder::record()
{ {
Q_D(QMediaRecorder); Q_D(QMediaRecorder);
d->actualLocation.clear();
if (d->settingsChanged) if (d->settingsChanged)
d->_q_applySettings(); d->_q_applySettings();
@@ -804,6 +834,13 @@ void QMediaRecorder::stop()
Signals that the \a duration of the recorded media has changed. Signals that the \a duration of the recorded media has changed.
*/ */
/*!
\fn QMediaRecorder::actualLocationChanged(const QUrl &location)
Signals that the actual \a location of the recorded media has changed.
This signal is usually emitted when recording starts.
*/
/*! /*!
\fn QMediaRecorder::error(QMediaRecorder::Error error) \fn QMediaRecorder::error(QMediaRecorder::Error error)

View File

@@ -75,6 +75,7 @@ class Q_MULTIMEDIA_EXPORT QMediaRecorder : public QObject, public QMediaBindable
Q_ENUMS(Error) Q_ENUMS(Error)
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
Q_PROPERTY(QUrl outputLocation READ outputLocation WRITE setOutputLocation) Q_PROPERTY(QUrl outputLocation READ outputLocation WRITE setOutputLocation)
Q_PROPERTY(QUrl actualLocation READ actualLocation NOTIFY actualLocationChanged)
Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(bool metaDataAvailable READ isMetaDataAvailable NOTIFY metaDataAvailableChanged) Q_PROPERTY(bool metaDataAvailable READ isMetaDataAvailable NOTIFY metaDataAvailableChanged)
Q_PROPERTY(bool metaDataWritable READ isMetaDataWritable NOTIFY metaDataWritableChanged) Q_PROPERTY(bool metaDataWritable READ isMetaDataWritable NOTIFY metaDataWritableChanged)
@@ -105,6 +106,8 @@ public:
QUrl outputLocation() const; QUrl outputLocation() const;
bool setOutputLocation(const QUrl &location); bool setOutputLocation(const QUrl &location);
QUrl actualLocation() const;
State state() const; State state() const;
Error error() const; Error error() const;
@@ -161,6 +164,7 @@ Q_SIGNALS:
void stateChanged(QMediaRecorder::State state); void stateChanged(QMediaRecorder::State state);
void durationChanged(qint64 duration); void durationChanged(qint64 duration);
void mutedChanged(bool muted); void mutedChanged(bool muted);
void actualLocationChanged(const QUrl &location);
void error(QMediaRecorder::Error error); void error(QMediaRecorder::Error error);
@@ -180,6 +184,7 @@ private:
Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &)) Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &))
Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed()) Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
Q_PRIVATE_SLOT(d_func(), void _q_notify()) Q_PRIVATE_SLOT(d_func(), void _q_notify())
Q_PRIVATE_SLOT(d_func(), void _q_updateActualLocation(const QUrl &))
Q_PRIVATE_SLOT(d_func(), void _q_updateNotifyInterval(int)) Q_PRIVATE_SLOT(d_func(), void _q_updateNotifyInterval(int))
Q_PRIVATE_SLOT(d_func(), void _q_applySettings()) Q_PRIVATE_SLOT(d_func(), void _q_applySettings())
}; };

View File

@@ -44,6 +44,7 @@
#include "qmediarecorder.h" #include "qmediarecorder.h"
#include "qmediaobject_p.h" #include "qmediaobject_p.h"
#include <QtCore/qurl.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -80,10 +81,12 @@ public:
QMediaRecorder::State state; QMediaRecorder::State state;
QMediaRecorder::Error error; QMediaRecorder::Error error;
QString errorString; QString errorString;
QUrl actualLocation;
void _q_stateChanged(QMediaRecorder::State state); void _q_stateChanged(QMediaRecorder::State state);
void _q_error(int error, const QString &errorString); void _q_error(int error, const QString &errorString);
void _q_serviceDestroyed(); void _q_serviceDestroyed();
void _q_updateActualLocation(const QUrl &);
void _q_notify(); void _q_notify();
void _q_updateNotifyInterval(int ms); void _q_updateNotifyInterval(int ms);
void _q_applySettings(); void _q_applySettings();

View File

@@ -210,6 +210,7 @@ void tst_QMediaRecorder::testNullControls()
recorder.setOutputLocation(QUrl("file://test/save/file.mp4")); recorder.setOutputLocation(QUrl("file://test/save/file.mp4"));
QCOMPARE(recorder.outputLocation(), QUrl()); QCOMPARE(recorder.outputLocation(), QUrl());
QCOMPARE(recorder.actualLocation(), QUrl());
QAudioEncoderSettings audio; QAudioEncoderSettings audio;
audio.setCodec(id); audio.setCodec(id);
@@ -285,6 +286,22 @@ void tst_QMediaRecorder::testSink()
capture->setOutputLocation(QUrl("test.tmp")); capture->setOutputLocation(QUrl("test.tmp"));
QUrl s = capture->outputLocation(); QUrl s = capture->outputLocation();
QCOMPARE(s.toString(), QString("test.tmp")); QCOMPARE(s.toString(), QString("test.tmp"));
QCOMPARE(capture->actualLocation(), QUrl());
//the actual location is available after record
capture->record();
QCOMPARE(capture->actualLocation().toString(), QString("test.tmp"));
capture->stop();
QCOMPARE(capture->actualLocation().toString(), QString("test.tmp"));
//setOutputLocation resets the actual location
capture->setOutputLocation(QUrl());
QCOMPARE(capture->actualLocation(), QUrl());
capture->record();
QCOMPARE(capture->actualLocation(), QUrl::fromLocalFile("default_name.mp4"));
capture->stop();
QCOMPARE(capture->actualLocation(), QUrl::fromLocalFile("default_name.mp4"));
} }
void tst_QMediaRecorder::testRecord() void tst_QMediaRecorder::testRecord()

View File

@@ -100,6 +100,9 @@ public slots:
m_position=1; m_position=1;
emit stateChanged(m_state); emit stateChanged(m_state);
emit durationChanged(m_position); emit durationChanged(m_position);
QUrl actualLocation = m_sink.isEmpty() ? QUrl::fromLocalFile("default_name.mp4") : m_sink;
emit actualLocationChanged(actualLocation);
} }
void pause() void pause()