Android: Don't delete the media recorder object twice.

In QAndroidCaptureSession::stop() we call restartViewFinder() which
eventually calls QAndroidCaptureSession::stop() again, but this time
the media recorder object is already released.

Task-number: QTBUG-45637
Change-Id: I943c423398a99d98ccda1063fc16e47cba470deb
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
Christian Strømme
2015-04-27 16:24:18 +02:00
committed by Christian Stromme
parent d910b6d63f
commit 0559f645bb
2 changed files with 13 additions and 17 deletions

View File

@@ -151,23 +151,19 @@ void QAndroidCaptureSession::setState(QMediaRecorder::State state)
stop();
break;
case QMediaRecorder::RecordingState:
if (!start())
return;
start();
break;
case QMediaRecorder::PausedState:
// Not supported by Android API
qWarning("QMediaRecorder::PausedState is not supported on Android");
return;
break;
}
m_state = state;
emit stateChanged(m_state);
}
bool QAndroidCaptureSession::start()
void QAndroidCaptureSession::start()
{
if (m_state == QMediaRecorder::RecordingState || m_status != QMediaRecorder::LoadedStatus)
return false;
return;
setStatus(QMediaRecorder::StartingStatus);
@@ -225,13 +221,13 @@ bool QAndroidCaptureSession::start()
if (!m_mediaRecorder->prepare()) {
emit error(QMediaRecorder::FormatError, QLatin1String("Unable to prepare the media recorder."));
restartViewfinder();
return false;
return;
}
if (!m_mediaRecorder->start()) {
emit error(QMediaRecorder::FormatError, QLatin1String("Unable to start the media recorder."));
restartViewfinder();
return false;
return;
}
m_elapsedTime.start();
@@ -241,22 +237,21 @@ bool QAndroidCaptureSession::start()
if (m_cameraSession)
m_cameraSession->setReadyForCapture(false);
return true;
m_state = QMediaRecorder::RecordingState;
emit stateChanged(m_state);
}
void QAndroidCaptureSession::stop(bool error)
{
if (m_state == QMediaRecorder::StoppedState)
if (m_state == QMediaRecorder::StoppedState || m_mediaRecorder == 0)
return;
setStatus(QMediaRecorder::FinalizingStatus);
m_mediaRecorder->stop();
m_notifyTimer.stop();
updateDuration();
m_elapsedTime.invalidate();
m_mediaRecorder->release();
delete m_mediaRecorder;
m_mediaRecorder = 0;
@@ -279,6 +274,9 @@ void QAndroidCaptureSession::stop(bool error)
m_actualOutputLocation = m_usedOutputLocation;
emit actualLocationChanged(m_actualOutputLocation);
}
m_state = QMediaRecorder::StoppedState;
emit stateChanged(m_state);
}
void QAndroidCaptureSession::setStatus(QMediaRecorder::Status status)
@@ -541,8 +539,6 @@ void QAndroidCaptureSession::onError(int what, int extra)
Q_UNUSED(what)
Q_UNUSED(extra)
stop(true);
m_state = QMediaRecorder::StoppedState;
emit stateChanged(m_state);
emit error(QMediaRecorder::ResourceError, QLatin1String("Unknown error."));
}

View File

@@ -130,7 +130,7 @@ private:
CaptureProfile getProfile(int id);
bool start();
void start();
void stop(bool error = false);
void setStatus(QMediaRecorder::Status status);