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
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user