summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVal Doroshchuk <valentyn.doroshchuk@qt.io>2017-11-09 15:26:49 +0100
committerVaL Doroshchuk <valentyn.doroshchuk@qt.io>2017-11-10 09:05:26 +0000
commitb0c352054e64b0fc64e547bf54dad1bdeaee283a (patch)
tree091f53857cae141432438e2a2e05629e6e37af56
parentb42659eb8baa384e329e6af6afea89bb4005fb46 (diff)
downloadqtmultimedia-b0c352054e64b0fc64e547bf54dad1bdeaee283a.tar.gz
Fix crash when an app is sent to background while capturing an image
Since the native notify* methods for QtCameraListener.java are executed on different thread, there is a potential for a race condition when the applicationStateChanged is received before the notify* signals, which leads to the camera being release before the slots are executed. Task-number: QTBUG-52366 Change-Id: Ifc82f3a75a7e88e4e76fac3edbf16bb9f138fde7 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r--src/plugins/android/src/mediacapture/qandroidcamerasession.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
index a7f0254ee..15aa027e4 100644
--- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
+++ b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp
@@ -697,7 +697,7 @@ void QAndroidCameraSession::onCameraTakePictureFailed()
void QAndroidCameraSession::onCameraPictureExposed()
{
- if (m_captureCanceled)
+ if (m_captureCanceled || !m_camera)
return;
emit imageExposed(m_currentImageCaptureId);
@@ -706,7 +706,7 @@ void QAndroidCameraSession::onCameraPictureExposed()
void QAndroidCameraSession::onLastPreviewFrameFetched(const QVideoFrame &frame)
{
- if (m_captureCanceled)
+ if (m_captureCanceled || !m_camera)
return;
QtConcurrent::run(this, &QAndroidCameraSession::processPreviewImage,
@@ -730,6 +730,9 @@ void QAndroidCameraSession::processPreviewImage(int id, const QVideoFrame &frame
void QAndroidCameraSession::onNewPreviewFrame(const QVideoFrame &frame)
{
+ if (!m_camera)
+ return;
+
m_videoProbesMutex.lock();
for (QAndroidMediaVideoProbeControl *probe : qAsConst(m_videoProbes))
@@ -756,7 +759,8 @@ void QAndroidCameraSession::onCameraPictureCaptured(const QByteArray &data)
m_captureCanceled = false;
// Preview needs to be restarted after taking a picture
- m_camera->startPreview();
+ if (m_camera)
+ m_camera->startPreview();
}
void QAndroidCameraSession::onCameraPreviewStarted()