Split QMediaRecorder::setEncodingSettings to separate setters.
It's easier to change only the necessary part of encoding settings. The settings are applied during the next event loop or before recording starts. Change-Id: Ia2b5c93826a302212aa7f79a0c75e4cbaaf1dd7a Reviewed-by: Ling Hu <ling.hu@nokia.com> Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
9d3102efe2
commit
a22a0195f1
@@ -113,7 +113,7 @@ void MediaExample::EncoderSettings()
|
||||
audioSettings.setCodec("audio/mpeg");
|
||||
audioSettings.setChannelCount(2);
|
||||
|
||||
recorder->setEncodingSettings(audioSettings);
|
||||
recorder->setAudioSettings(audioSettings);
|
||||
//! [Audio encoder settings]
|
||||
|
||||
//! [Video encoder settings]
|
||||
@@ -121,7 +121,7 @@ void MediaExample::EncoderSettings()
|
||||
videoSettings.setCodec("video/mpeg2");
|
||||
videoSettings.setResolution(640, 480);
|
||||
|
||||
recorder->setEncodingSettings(audioSettings, videoSettings);
|
||||
recorder->setVideoSettings(videoSettings);
|
||||
//! [Video encoder settings]
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ void MediaExample::MediaRecorder()
|
||||
audioSettings.setCodec("audio/amr");
|
||||
audioSettings.setQuality(QtMultimedia::HighQuality);
|
||||
|
||||
recorder->setEncodingSettings(audioSettings);
|
||||
recorder->setAudioSettings(audioSettings);
|
||||
|
||||
recorder->setOutputLocation(QUrl::fromLocalFile(fileName));
|
||||
recorder->record();
|
||||
|
||||
@@ -94,7 +94,7 @@ void QDeclarativeCameraRecorder::setCaptureResolution(const QSize &resolution)
|
||||
{
|
||||
if (resolution != captureResolution()) {
|
||||
m_videoSettings.setResolution(resolution);
|
||||
applySettings();
|
||||
m_recorder->setVideoSettings(m_videoSettings);
|
||||
emit captureResolutionChanged(resolution);
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ void QDeclarativeCameraRecorder::setAudioCodec(const QString &codec)
|
||||
{
|
||||
if (codec != audioCodec()) {
|
||||
m_audioSettings.setCodec(codec);
|
||||
applySettings();
|
||||
m_recorder->setAudioSettings(m_audioSettings);
|
||||
emit audioCodecChanged(codec);
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ void QDeclarativeCameraRecorder::setVideoCodec(const QString &codec)
|
||||
{
|
||||
if (codec != videoCodec()) {
|
||||
m_videoSettings.setCodec(codec);
|
||||
applySettings();
|
||||
m_recorder->setVideoSettings(m_videoSettings);
|
||||
emit videoCodecChanged(codec);
|
||||
}
|
||||
}
|
||||
@@ -121,18 +121,11 @@ void QDeclarativeCameraRecorder::setMediaContainer(const QString &container)
|
||||
{
|
||||
if (container != m_mediaContainer) {
|
||||
m_mediaContainer = container;
|
||||
applySettings();
|
||||
m_recorder->setContainerFormat(container);
|
||||
emit mediaContainerChanged(container);
|
||||
}
|
||||
}
|
||||
|
||||
void QDeclarativeCameraRecorder::applySettings()
|
||||
{
|
||||
m_recorder->setEncodingSettings(m_audioSettings,
|
||||
m_videoSettings,
|
||||
m_mediaContainer);
|
||||
}
|
||||
|
||||
QMediaRecorder::Error QDeclarativeCameraRecorder::error() const
|
||||
{
|
||||
return m_recorder->error();
|
||||
|
||||
@@ -144,8 +144,6 @@ private:
|
||||
friend class QDeclarativeCamera;
|
||||
QDeclarativeCameraRecorder(QCamera *camera, QObject *parent = 0);
|
||||
|
||||
void applySettings();
|
||||
|
||||
QMediaRecorder *m_recorder;
|
||||
|
||||
QAudioEncoderSettings m_audioSettings;
|
||||
|
||||
@@ -101,21 +101,21 @@ QMediaContainerControl::~QMediaContainerControl()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMediaContainerControl::containerMimeType() const
|
||||
\fn QMediaContainerControl::containerFormat() const
|
||||
|
||||
Returns the MIME type of the selected container format.
|
||||
Returns the selected container format.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMediaContainerControl::setContainerMimeType(const QString &mimeType)
|
||||
\fn QMediaContainerControl::setContainerFormat(const QString &format)
|
||||
|
||||
Sets the current container format to the format identified by the given \a mimeType.
|
||||
Sets the current container \a format.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QMediaContainerControl::containerDescription(const QString &mimeType) const
|
||||
\fn QMediaContainerControl::containerDescription(const QString &format) const
|
||||
|
||||
Returns a description of the container format identified by the given \a mimeType.
|
||||
Returns a description of the container \a format.
|
||||
*/
|
||||
|
||||
#include "moc_qmediacontainercontrol.cpp"
|
||||
|
||||
@@ -60,8 +60,8 @@ public:
|
||||
virtual ~QMediaContainerControl();
|
||||
|
||||
virtual QStringList supportedContainers() const = 0;
|
||||
virtual QString containerMimeType() const = 0;
|
||||
virtual void setContainerMimeType(const QString &formatMimeType) = 0;
|
||||
virtual QString containerFormat() const = 0;
|
||||
virtual void setContainerFormat(const QString &format) = 0;
|
||||
|
||||
virtual QString containerDescription(const QString &formatMimeType) const = 0;
|
||||
|
||||
|
||||
@@ -155,6 +155,34 @@ void QMediaRecorderPrivate::_q_updateNotifyInterval(int ms)
|
||||
notifyTimer->setInterval(ms);
|
||||
}
|
||||
|
||||
void QMediaRecorderPrivate::applySettingsLater()
|
||||
{
|
||||
if (control && !settingsChanged) {
|
||||
settingsChanged = true;
|
||||
QMetaObject::invokeMethod(q_func(), "_q_applySettings", Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void QMediaRecorderPrivate::_q_applySettings()
|
||||
{
|
||||
if (control && settingsChanged) {
|
||||
settingsChanged = false;
|
||||
control->applySettings();
|
||||
}
|
||||
}
|
||||
|
||||
void QMediaRecorderPrivate::restartCamera()
|
||||
{
|
||||
//restart camera if it can't apply new settings in the Active state
|
||||
QCamera *camera = qobject_cast<QCamera*>(mediaObject);
|
||||
if (camera && camera->captureMode() == QCamera::CaptureVideo) {
|
||||
QMetaObject::invokeMethod(camera,
|
||||
"_q_preparePropertyChange",
|
||||
Qt::DirectConnection,
|
||||
Q_ARG(int, QCameraControl::VideoEncodingSettings));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Constructs a media recorder which records the media produced by \a mediaObject.
|
||||
@@ -316,6 +344,8 @@ bool QMediaRecorder::setMediaObject(QMediaObject *object)
|
||||
connect(service, SIGNAL(destroyed()), this, SLOT(_q_serviceDestroyed()));
|
||||
|
||||
|
||||
d->applySettingsLater();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -438,7 +468,7 @@ void QMediaRecorder::setMuted(bool muted)
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a list of MIME types of supported container formats.
|
||||
Returns a list of supported container formats.
|
||||
*/
|
||||
QStringList QMediaRecorder::supportedContainers() const
|
||||
{
|
||||
@@ -447,22 +477,22 @@ QStringList QMediaRecorder::supportedContainers() const
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a description of a container format \a mimeType.
|
||||
Returns a description of a container \a format.
|
||||
*/
|
||||
QString QMediaRecorder::containerDescription(const QString &mimeType) const
|
||||
QString QMediaRecorder::containerDescription(const QString &format) const
|
||||
{
|
||||
return d_func()->formatControl ?
|
||||
d_func()->formatControl->containerDescription(mimeType) : QString();
|
||||
d_func()->formatControl->containerDescription(format) : QString();
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the MIME type of the selected container format.
|
||||
Returns the selected container format.
|
||||
*/
|
||||
|
||||
QString QMediaRecorder::containerMimeType() const
|
||||
QString QMediaRecorder::containerFormat() const
|
||||
{
|
||||
return d_func()->formatControl ?
|
||||
d_func()->formatControl->containerMimeType() : QString();
|
||||
d_func()->formatControl->containerFormat() : QString();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -593,18 +623,92 @@ QVideoEncoderSettings QMediaRecorder::videoSettings() const
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \a audio and \a video encoder settings and \a container format MIME type.
|
||||
Sets the audio encoder \a settings.
|
||||
|
||||
If some parameters are not specified, or null settings are passed, the
|
||||
encoder will choose default encoding parameters, depending on media
|
||||
source properties.
|
||||
While setEncodingSettings is optional, the backend can preload
|
||||
encoding pipeline to improve recording startup time.
|
||||
|
||||
It's only possible to change settings when the encoder is in the
|
||||
QMediaEncoder::StoppedState state.
|
||||
|
||||
\sa audioSettings(), videoSettings(), containerMimeType()
|
||||
\sa audioSettings(), videoSettings(), containerFormat()
|
||||
*/
|
||||
|
||||
void QMediaRecorder::setAudioSettings(const QAudioEncoderSettings &settings)
|
||||
{
|
||||
Q_D(QMediaRecorder);
|
||||
|
||||
//restart camera if it can't apply new settings in the Active state
|
||||
d->restartCamera();
|
||||
|
||||
if (d->audioControl) {
|
||||
d->audioControl->setAudioSettings(settings);
|
||||
d->applySettingsLater();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the video encoder \a settings.
|
||||
|
||||
If some parameters are not specified, or null settings are passed, the
|
||||
encoder will choose default encoding parameters, depending on media
|
||||
source properties.
|
||||
|
||||
It's only possible to change settings when the encoder is in the
|
||||
QMediaEncoder::StoppedState state.
|
||||
|
||||
\sa audioSettings(), videoSettings(), containerFormat()
|
||||
*/
|
||||
|
||||
void QMediaRecorder::setVideoSettings(const QVideoEncoderSettings &settings)
|
||||
{
|
||||
Q_D(QMediaRecorder);
|
||||
|
||||
d->restartCamera();
|
||||
|
||||
if (d->videoControl) {
|
||||
d->videoControl->setVideoSettings(settings);
|
||||
d->applySettingsLater();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the media \a container format.
|
||||
|
||||
If the container format is not specified, the
|
||||
encoder will choose format, depending on media source properties
|
||||
and encoding settings selected.
|
||||
|
||||
It's only possible to change settings when the encoder is in the
|
||||
QMediaEncoder::StoppedState state.
|
||||
|
||||
\sa audioSettings(), videoSettings(), containerFormat()
|
||||
*/
|
||||
|
||||
void QMediaRecorder::setContainerFormat(const QString &container)
|
||||
{
|
||||
Q_D(QMediaRecorder);
|
||||
|
||||
d->restartCamera();
|
||||
|
||||
if (d->formatControl) {
|
||||
d->formatControl->setContainerFormat(container);
|
||||
d->applySettingsLater();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets the \a audio and \a video encoder settings and \a container format.
|
||||
|
||||
If some parameters are not specified, or null settings are passed, the
|
||||
encoder will choose default encoding parameters, depending on media
|
||||
source properties.
|
||||
|
||||
It's only possible to change settings when the encoder is in the
|
||||
QMediaEncoder::StoppedState state.
|
||||
|
||||
\sa audioSettings(), videoSettings(), containerFormat()
|
||||
*/
|
||||
|
||||
void QMediaRecorder::setEncodingSettings(const QAudioEncoderSettings &audio,
|
||||
@@ -613,13 +717,7 @@ void QMediaRecorder::setEncodingSettings(const QAudioEncoderSettings &audio,
|
||||
{
|
||||
Q_D(QMediaRecorder);
|
||||
|
||||
QCamera *camera = qobject_cast<QCamera*>(d->mediaObject);
|
||||
if (camera && camera->captureMode() == QCamera::CaptureVideo) {
|
||||
QMetaObject::invokeMethod(camera,
|
||||
"_q_preparePropertyChange",
|
||||
Qt::DirectConnection,
|
||||
Q_ARG(int, QCameraControl::VideoEncodingSettings));
|
||||
}
|
||||
d->restartCamera();
|
||||
|
||||
if (d->audioControl)
|
||||
d->audioControl->setAudioSettings(audio);
|
||||
@@ -628,13 +726,11 @@ void QMediaRecorder::setEncodingSettings(const QAudioEncoderSettings &audio,
|
||||
d->videoControl->setVideoSettings(video);
|
||||
|
||||
if (d->formatControl)
|
||||
d->formatControl->setContainerMimeType(container);
|
||||
d->formatControl->setContainerFormat(container);
|
||||
|
||||
if (d->control)
|
||||
d->control->applySettings();
|
||||
d->applySettingsLater();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Start recording.
|
||||
|
||||
@@ -647,6 +743,9 @@ void QMediaRecorder::record()
|
||||
{
|
||||
Q_D(QMediaRecorder);
|
||||
|
||||
if (d->settingsChanged)
|
||||
d->_q_applySettings();
|
||||
|
||||
// reset error
|
||||
d->error = NoError;
|
||||
d->errorString = QString();
|
||||
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
bool isMuted() const;
|
||||
|
||||
QStringList supportedContainers() const;
|
||||
QString containerDescription(const QString &containerMimeType) const;
|
||||
QString containerDescription(const QString &format) const;
|
||||
|
||||
QStringList supportedAudioCodecs() const;
|
||||
QString audioCodecDescription(const QString &codecName) const;
|
||||
@@ -134,13 +134,16 @@ public:
|
||||
|
||||
QAudioEncoderSettings audioSettings() const;
|
||||
QVideoEncoderSettings videoSettings() const;
|
||||
QString containerMimeType() const;
|
||||
QString containerFormat() const;
|
||||
|
||||
void setAudioSettings(const QAudioEncoderSettings &audioSettings);
|
||||
void setVideoSettings(const QVideoEncoderSettings &videoSettings);
|
||||
void setContainerFormat(const QString &container);
|
||||
|
||||
void setEncodingSettings(const QAudioEncoderSettings &audioSettings,
|
||||
const QVideoEncoderSettings &videoSettings = QVideoEncoderSettings(),
|
||||
const QString &containerMimeType = QString());
|
||||
|
||||
|
||||
bool isMetaDataAvailable() const;
|
||||
bool isMetaDataWritable() const;
|
||||
|
||||
@@ -178,6 +181,7 @@ private:
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_serviceDestroyed())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_notify())
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_updateNotifyInterval(int))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_applySettings())
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@@ -62,6 +62,9 @@ public:
|
||||
QMediaRecorderPrivate();
|
||||
virtual ~QMediaRecorderPrivate() {}
|
||||
|
||||
void applySettingsLater();
|
||||
void restartCamera();
|
||||
|
||||
QMediaObject *mediaObject;
|
||||
|
||||
QMediaRecorderControl *control;
|
||||
@@ -70,6 +73,8 @@ public:
|
||||
QVideoEncoderControl *videoControl;
|
||||
QMetaDataWriterControl *metaDataControl;
|
||||
|
||||
bool settingsChanged;
|
||||
|
||||
QTimer* notifyTimer;
|
||||
|
||||
QMediaRecorder::State state;
|
||||
@@ -81,6 +86,7 @@ public:
|
||||
void _q_serviceDestroyed();
|
||||
void _q_notify();
|
||||
void _q_updateNotifyInterval(int ms);
|
||||
void _q_applySettings();
|
||||
|
||||
QMediaRecorder *q_ptr;
|
||||
};
|
||||
|
||||
@@ -146,7 +146,7 @@ QString AudioCaptureSession::containerDescription(const QString &formatMimeType)
|
||||
return QString();
|
||||
}
|
||||
|
||||
void AudioCaptureSession::setContainerMimeType(const QString &formatMimeType)
|
||||
void AudioCaptureSession::setContainerFormat(const QString &formatMimeType)
|
||||
{
|
||||
if (!formatMimeType.contains(QLatin1String("audio/x-wav")) &&
|
||||
!formatMimeType.contains(QLatin1String("audio/pcm")) &&
|
||||
@@ -167,7 +167,7 @@ void AudioCaptureSession::setContainerMimeType(const QString &formatMimeType)
|
||||
}
|
||||
}
|
||||
|
||||
QString AudioCaptureSession::containerMimeType() const
|
||||
QString AudioCaptureSession::containerFormat() const
|
||||
{
|
||||
if(wavFile)
|
||||
return QString("audio/x-wav");
|
||||
|
||||
@@ -69,8 +69,8 @@ public:
|
||||
bool isFormatSupported(const QAudioFormat &format) const;
|
||||
bool setFormat(const QAudioFormat &format);
|
||||
QStringList supportedContainers() const;
|
||||
QString containerMimeType() const;
|
||||
void setContainerMimeType(const QString &formatMimeType);
|
||||
QString containerFormat() const;
|
||||
void setContainerFormat(const QString &formatMimeType);
|
||||
QString containerDescription(const QString &formatMimeType) const;
|
||||
|
||||
QUrl outputLocation() const;
|
||||
|
||||
@@ -57,14 +57,14 @@ QStringList AudioContainerControl::supportedContainers() const
|
||||
return m_session->supportedContainers();
|
||||
}
|
||||
|
||||
QString AudioContainerControl::containerMimeType() const
|
||||
QString AudioContainerControl::containerFormat() const
|
||||
{
|
||||
return m_session->containerMimeType();
|
||||
return m_session->containerFormat();
|
||||
}
|
||||
|
||||
void AudioContainerControl::setContainerMimeType(const QString &formatMimeType)
|
||||
void AudioContainerControl::setContainerFormat(const QString &formatMimeType)
|
||||
{
|
||||
m_session->setContainerMimeType(formatMimeType);
|
||||
m_session->setContainerFormat(formatMimeType);
|
||||
}
|
||||
|
||||
QString AudioContainerControl::containerDescription(const QString &formatMimeType) const
|
||||
|
||||
@@ -59,8 +59,8 @@ public:
|
||||
virtual ~AudioContainerControl();
|
||||
|
||||
QStringList supportedContainers() const;
|
||||
QString containerMimeType() const;
|
||||
void setContainerMimeType(const QString &formatMimeType);
|
||||
QString containerFormat() const;
|
||||
void setContainerFormat(const QString &formatMimeType);
|
||||
QString containerDescription(const QString &formatMimeType) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -101,7 +101,7 @@ QGstreamerMediaContainerControl::QGstreamerMediaContainerControl(QObject *parent
|
||||
}
|
||||
|
||||
//if (!m_supportedContainers.isEmpty())
|
||||
// setContainerMimeType(m_supportedContainers[0]);
|
||||
// setContainerFormat(m_supportedContainers[0]);
|
||||
}
|
||||
|
||||
QSet<QString> QGstreamerMediaContainerControl::supportedStreamTypes(GstElementFactory *factory, GstPadDirection direction)
|
||||
|
||||
@@ -59,12 +59,12 @@ public:
|
||||
virtual ~QGstreamerMediaContainerControl() {};
|
||||
|
||||
virtual QStringList supportedContainers() const { return m_supportedContainers; }
|
||||
virtual QString containerMimeType() const { return m_format; }
|
||||
virtual void setContainerMimeType(const QString &formatMimeType) { m_format = formatMimeType; }
|
||||
virtual QString containerFormat() const { return m_format; }
|
||||
virtual void setContainerFormat(const QString &formatMimeType) { m_format = formatMimeType; }
|
||||
|
||||
virtual QString containerDescription(const QString &formatMimeType) const { return m_containerDescriptions.value(formatMimeType); }
|
||||
|
||||
QByteArray formatElementName() const { return m_elementNames.value(containerMimeType()); }
|
||||
QByteArray formatElementName() const { return m_elementNames.value(containerFormat()); }
|
||||
|
||||
QSet<QString> supportedStreamTypes(const QString &container) const;
|
||||
|
||||
|
||||
@@ -152,10 +152,10 @@ void QGstreamerRecorderControl::applySettings()
|
||||
bool needVideo = m_session->captureMode() & QGstreamerCaptureSession::Video;
|
||||
|
||||
QStringList containerCandidates;
|
||||
if (mediaContainerControl->containerMimeType().isEmpty())
|
||||
if (mediaContainerControl->containerFormat().isEmpty())
|
||||
containerCandidates = mediaContainerControl->supportedContainers();
|
||||
else
|
||||
containerCandidates << mediaContainerControl->containerMimeType();
|
||||
containerCandidates << mediaContainerControl->containerFormat();
|
||||
|
||||
|
||||
QStringList audioCandidates;
|
||||
@@ -221,7 +221,7 @@ void QGstreamerRecorderControl::applySettings()
|
||||
if (container.isEmpty()) {
|
||||
emit error(QMediaRecorder::FormatError, tr("Not compatible codecs and container format."));
|
||||
} else {
|
||||
mediaContainerControl->setContainerMimeType(container);
|
||||
mediaContainerControl->setContainerFormat(container);
|
||||
|
||||
if (needAudio) {
|
||||
QAudioEncoderSettings audioSettings = audioEncodeControl->audioSettings();
|
||||
|
||||
@@ -66,9 +66,9 @@ private slots:
|
||||
QVERIFY(strlist[1]==strlist1[1]); //checking with "mp3" mime type
|
||||
QVERIFY(strlist[2]==strlist1[2]); //checking with "mov" mime type
|
||||
|
||||
control.setContainerMimeType("wav");
|
||||
control.setContainerFormat("wav");
|
||||
const QString str("wav");
|
||||
QVERIFY2(control.containerMimeType() == str,"Failed");
|
||||
QVERIFY2(control.containerFormat() == str,"Failed");
|
||||
|
||||
const QString str1("WAV format");
|
||||
QVERIFY2(control.containerDescription("wav") == str1,"FAILED");
|
||||
|
||||
@@ -83,6 +83,7 @@ private slots:
|
||||
void testEncodingSettings();
|
||||
void testAudioSettings();
|
||||
void testVideoSettings();
|
||||
void testSettingsApplied();
|
||||
|
||||
void nullMetaDataControl();
|
||||
void isMetaDataAvailable();
|
||||
@@ -171,7 +172,7 @@ void tst_QMediaRecorder::testNullService()
|
||||
QCOMPARE(continuous, false);
|
||||
QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings());
|
||||
QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings());
|
||||
QCOMPARE(recorder.containerMimeType(), QString());
|
||||
QCOMPARE(recorder.containerFormat(), QString());
|
||||
QVERIFY(!recorder.isMuted());
|
||||
recorder.setMuted(true);
|
||||
QVERIFY(!recorder.isMuted());
|
||||
@@ -205,7 +206,7 @@ void tst_QMediaRecorder::testNullControls()
|
||||
QCOMPARE(continuous, false);
|
||||
QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings());
|
||||
QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings());
|
||||
QCOMPARE(recorder.containerMimeType(), QString());
|
||||
QCOMPARE(recorder.containerFormat(), QString());
|
||||
|
||||
recorder.setOutputLocation(QUrl("file://test/save/file.mp4"));
|
||||
QCOMPARE(recorder.outputLocation(), QUrl());
|
||||
@@ -222,7 +223,7 @@ void tst_QMediaRecorder::testNullControls()
|
||||
|
||||
QCOMPARE(recorder.audioSettings(), QAudioEncoderSettings());
|
||||
QCOMPARE(recorder.videoSettings(), QVideoEncoderSettings());
|
||||
QCOMPARE(recorder.containerMimeType(), QString());
|
||||
QCOMPARE(recorder.containerFormat(), QString());
|
||||
|
||||
QSignalSpy spy(&recorder, SIGNAL(stateChanged(QMediaRecorder::State)));
|
||||
|
||||
@@ -410,7 +411,7 @@ void tst_QMediaRecorder::testEncodingSettings()
|
||||
QCOMPARE(videoSettings.quality(), QtMultimedia::NormalQuality);
|
||||
QCOMPARE(videoSettings.encodingMode(), QtMultimedia::ConstantQualityEncoding);
|
||||
|
||||
QString format = capture->containerMimeType();
|
||||
QString format = capture->containerFormat();
|
||||
QCOMPARE(format, QString());
|
||||
|
||||
audioSettings.setCodec("audio/mpeg");
|
||||
@@ -428,11 +429,13 @@ void tst_QMediaRecorder::testEncodingSettings()
|
||||
|
||||
format = QString("mov");
|
||||
|
||||
capture->setEncodingSettings(audioSettings,videoSettings,format);
|
||||
capture->setAudioSettings(audioSettings);
|
||||
capture->setVideoSettings(videoSettings);
|
||||
capture->setContainerFormat(format);
|
||||
|
||||
QCOMPARE(capture->audioSettings(), audioSettings);
|
||||
QCOMPARE(capture->videoSettings(), videoSettings);
|
||||
QCOMPARE(capture->containerMimeType(), format);
|
||||
QCOMPARE(capture->containerFormat(), format);
|
||||
}
|
||||
|
||||
void tst_QMediaRecorder::testAudioSettings()
|
||||
@@ -688,6 +691,47 @@ void tst_QMediaRecorder::testVideoSettings()
|
||||
QVERIFY(settings1 != settings2);
|
||||
}
|
||||
|
||||
void tst_QMediaRecorder::testSettingsApplied()
|
||||
{
|
||||
MockMediaRecorderControl recorderControl(0);
|
||||
MockMediaRecorderService service(0, &recorderControl);
|
||||
MockMediaObject object(0, &service);
|
||||
|
||||
//if the media recorder is not configured after construction
|
||||
//the settings are applied in the next event loop
|
||||
QMediaRecorder recorder(&object);
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 0);
|
||||
QTest::qWait(10);
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 1);
|
||||
|
||||
QVideoEncoderSettings videoSettings;
|
||||
videoSettings.setResolution(640,480);
|
||||
recorder.setVideoSettings(videoSettings);
|
||||
|
||||
QAudioEncoderSettings audioSettings;
|
||||
audioSettings.setQuality(QtMultimedia::HighQuality);
|
||||
recorder.setAudioSettings(audioSettings);
|
||||
|
||||
recorder.setContainerFormat("mkv");
|
||||
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 1);
|
||||
QTest::qWait(10);
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 2);
|
||||
|
||||
//encoder settings are applied before recording if changed
|
||||
audioSettings.setQuality(QtMultimedia::VeryHighQuality);
|
||||
recorder.setAudioSettings(audioSettings);
|
||||
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 2);
|
||||
recorder.record();
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 3);
|
||||
|
||||
recorder.stop();
|
||||
|
||||
//applySettings is not called if setting has not changes
|
||||
recorder.record();
|
||||
QCOMPARE(recorderControl.m_settingAppliedCount, 3);
|
||||
}
|
||||
|
||||
void tst_QMediaRecorder::nullMetaDataControl()
|
||||
{
|
||||
|
||||
@@ -72,12 +72,12 @@ public:
|
||||
return m_supportedContainers;
|
||||
}
|
||||
|
||||
QString containerMimeType() const
|
||||
QString containerFormat() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
|
||||
void setContainerMimeType(const QString &formatMimeType)
|
||||
void setContainerFormat(const QString &formatMimeType)
|
||||
{
|
||||
if (m_supportedContainers.contains(formatMimeType))
|
||||
m_format = formatMimeType;
|
||||
|
||||
@@ -53,9 +53,12 @@ class MockMediaRecorderControl : public QMediaRecorderControl
|
||||
public:
|
||||
MockMediaRecorderControl(QObject *parent = 0):
|
||||
QMediaRecorderControl(parent),
|
||||
m_state(QMediaRecorder::StoppedState),
|
||||
m_position(0),
|
||||
m_muted(false) {}
|
||||
m_state(QMediaRecorder::StoppedState),
|
||||
m_position(0),
|
||||
m_muted(false),
|
||||
m_settingAppliedCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
QUrl outputLocation() const
|
||||
{
|
||||
@@ -83,7 +86,10 @@ public:
|
||||
return m_muted;
|
||||
}
|
||||
|
||||
void applySettings() {}
|
||||
void applySettings()
|
||||
{
|
||||
m_settingAppliedCount++;
|
||||
}
|
||||
|
||||
using QMediaRecorderControl::error;
|
||||
|
||||
@@ -120,6 +126,7 @@ public:
|
||||
QMediaRecorder::State m_state;
|
||||
qint64 m_position;
|
||||
bool m_muted;
|
||||
int m_settingAppliedCount;
|
||||
};
|
||||
|
||||
#endif // MOCKRECORDERCONTROL_H
|
||||
|
||||
Reference in New Issue
Block a user