From: Yoann Lopes Date: Thu, 13 Mar 2014 15:19:04 +0000 (+0100) Subject: Android: correctly report QMediaRecorder status. X-Git-Tag: upstream/5.2.95+rc1~3^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29ba8cf4c417d7c2ff9f2815bdc49c97215283a3;p=platform%2Fupstream%2Fqtmultimedia.git Android: correctly report QMediaRecorder status. QMediaRecorder should have the LoadedStatus before starting recording. When recording the camera, the recorder should be considered loaded when all prerequisites are met (viewfinder started, recording mode set to video and capture ready). Task-number: QTBUG-36828 Change-Id: I3279bdfdc2b361c7e0707c52e74ae47e0bb4a93d Reviewed-by: Christian Stromme --- diff --git a/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp b/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp index f40ec24..fef2a5b 100644 --- a/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp +++ b/src/plugins/android/src/mediacapture/qandroidcapturesession.cpp @@ -65,12 +65,16 @@ QAndroidCaptureSession::QAndroidCaptureSession(QAndroidCameraSession *cameraSess , m_audioEncoder(JMediaRecorder::DefaultAudioEncoder) , m_videoEncoder(JMediaRecorder::DefaultVideoEncoder) { + connect(this, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(updateStatus())); + if (cameraSession) { connect(cameraSession, SIGNAL(opened()), this, SLOT(onCameraOpened())); - connect(cameraSession, SIGNAL(statusChanged(QCamera::Status)), - this, SLOT(onCameraStatusChanged(QCamera::Status))); + connect(cameraSession, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(updateStatus())); connect(cameraSession, SIGNAL(captureModeChanged(QCamera::CaptureModes)), - this, SLOT(onCameraCaptureModeChanged(QCamera::CaptureModes))); + this, SLOT(updateStatus())); + connect(cameraSession, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(updateStatus())); + } else { + updateStatus(); } m_notifyTimer.setInterval(1000); @@ -164,10 +168,10 @@ void QAndroidCaptureSession::setState(QMediaRecorder::State state) bool QAndroidCaptureSession::start() { - if (m_state == QMediaRecorder::RecordingState) + if (m_state == QMediaRecorder::RecordingState || m_status != QMediaRecorder::LoadedStatus) return false; - setStatus(QMediaRecorder::LoadingStatus); + setStatus(QMediaRecorder::StartingStatus); if (m_mediaRecorder) { m_mediaRecorder->release(); @@ -179,17 +183,11 @@ bool QAndroidCaptureSession::start() // Set audio/video sources if (m_cameraSession) { - if (m_cameraSession->status() != QCamera::ActiveStatus) { - emit error(QMediaRecorder::ResourceError, QLatin1String("Camera must be active to record it.")); - setStatus(QMediaRecorder::UnloadedStatus); - return false; - } else { - updateViewfinder(); - m_cameraSession->camera()->unlock(); - m_mediaRecorder->setCamera(m_cameraSession->camera()); - m_mediaRecorder->setAudioSource(JMediaRecorder::Camcorder); - m_mediaRecorder->setVideoSource(JMediaRecorder::Camera); - } + updateViewfinder(); + m_cameraSession->camera()->unlock(); + m_mediaRecorder->setCamera(m_cameraSession->camera()); + m_mediaRecorder->setAudioSource(JMediaRecorder::Camcorder); + m_mediaRecorder->setVideoSource(JMediaRecorder::Camera); } else { m_mediaRecorder->setAudioSource(m_audioSource); } @@ -213,7 +211,6 @@ bool QAndroidCaptureSession::start() m_mediaRecorder->setOrientationHint(m_cameraSession->currentCameraRotation()); } - // Set output file QString filePath = m_mediaStorageLocation.generateFileName( m_requestedOutputLocation.isLocalFile() ? m_requestedOutputLocation.toLocalFile() @@ -236,17 +233,12 @@ bool QAndroidCaptureSession::start() return false; } - setStatus(QMediaRecorder::LoadedStatus); - setStatus(QMediaRecorder::StartingStatus); - if (!m_mediaRecorder->start()) { emit error(QMediaRecorder::FormatError, QLatin1String("Unable to start the media recorder.")); setStatus(QMediaRecorder::UnloadedStatus); return false; } - setStatus(QMediaRecorder::RecordingStatus); - m_elapsedTime.start(); m_notifyTimer.start(); updateDuration(); @@ -292,7 +284,6 @@ void QAndroidCaptureSession::stop(bool error) JMultimediaUtils::registerMediaFile(mediaPath); } - setStatus(QMediaRecorder::UnloadedStatus); } void QAndroidCaptureSession::setStatus(QMediaRecorder::Status status) @@ -513,16 +504,40 @@ QAndroidCaptureSession::CaptureProfile QAndroidCaptureSession::getProfile(int id return profile; } -void QAndroidCaptureSession::onCameraStatusChanged(QCamera::Status status) +void QAndroidCaptureSession::updateStatus() { - if (status == QCamera::StoppingStatus) - setState(QMediaRecorder::StoppedState); -} + if (m_cameraSession) { + // Video recording -void QAndroidCaptureSession::onCameraCaptureModeChanged(QCamera::CaptureModes mode) -{ - if (!mode.testFlag(QCamera::CaptureVideo)) - setState(QMediaRecorder::StoppedState); + // stop recording when stopping the camera + if (m_cameraSession->status() == QCamera::StoppingStatus + || !m_cameraSession->captureMode().testFlag(QCamera::CaptureVideo)) { + setState(QMediaRecorder::StoppedState); + } + + if (m_state == QMediaRecorder::RecordingState) { + setStatus(QMediaRecorder::RecordingStatus); + } else if (m_cameraSession->status() == QCamera::UnavailableStatus) { + setStatus(QMediaRecorder::UnavailableStatus); + } else if (m_cameraSession->captureMode().testFlag(QCamera::CaptureVideo) + && m_cameraSession->isReadyForCapture()) { + if (m_cameraSession->status() == QCamera::StartingStatus) + setStatus(QMediaRecorder::LoadingStatus); + else if (m_cameraSession->status() == QCamera::ActiveStatus) + setStatus(QMediaRecorder::LoadedStatus); + else + setStatus(QMediaRecorder::UnloadedStatus); + } else { + setStatus(QMediaRecorder::UnloadedStatus); + } + + } else { + // Audio-only recording + if (m_state == QMediaRecorder::RecordingState) + setStatus(QMediaRecorder::RecordingStatus); + else + setStatus(QMediaRecorder::LoadedStatus); + } } void QAndroidCaptureSession::onError(int what, int extra) diff --git a/src/plugins/android/src/mediacapture/qandroidcapturesession.h b/src/plugins/android/src/mediacapture/qandroidcapturesession.h index fcd87cd..deee505 100644 --- a/src/plugins/android/src/mediacapture/qandroidcapturesession.h +++ b/src/plugins/android/src/mediacapture/qandroidcapturesession.h @@ -99,8 +99,7 @@ Q_SIGNALS: private Q_SLOTS: void updateDuration(); void onCameraOpened(); - void onCameraStatusChanged(QCamera::Status); - void onCameraCaptureModeChanged(QCamera::CaptureModes mode); + void updateStatus(); void onError(int what, int extra); void onInfo(int what, int extra);