diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index 22d873dd..52d60778 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -757,8 +757,6 @@ void CameraBinSession::load() setStatus(QCamera::LoadingStatus); - gst_element_set_state(m_camerabin, GST_STATE_NULL); - if (!setupCameraBin()) { setError(QCamera::CameraError, QStringLiteral("No camera source available")); return; @@ -785,22 +783,16 @@ void CameraBinSession::unload() if (m_status == QCamera::UnloadedStatus || m_status == QCamera::UnloadingStatus) return; + // We save the recording state in case something reacted to setStatus() and + // stopped recording. + bool wasRecording = m_recordingActive; + setStatus(QCamera::UnloadingStatus); if (m_recordingActive) stopVideoRecording(); - - if (m_viewfinderInterface) - m_viewfinderInterface->stopRenderer(); - - gst_element_set_state(m_camerabin, GST_STATE_NULL); - - if (m_busy) - emit busyChanged(m_busy = false); - - m_supportedViewfinderSettings.clear(); - - setStatus(QCamera::UnloadedStatus); + else if (!wasRecording) + handleBusyChanged(false); } void CameraBinSession::start() @@ -860,7 +852,7 @@ void CameraBinSession::updateBusyStatus(GObject *o, GParamSpec *p, gpointer d) if (session->m_busy != busy) { session->m_busy = busy; - QMetaObject::invokeMethod(session, "busyChanged", + QMetaObject::invokeMethod(session, "handleBusyChanged", Qt::QueuedConnection, Q_ARG(bool, busy)); } @@ -1509,4 +1501,28 @@ void CameraBinSession::elementRemoved(GstBin *, GstElement *element, CameraBinSe session->m_muxer = 0; } +void CameraBinSession::handleBusyChanged(bool busy) +{ + // don't do anything if we are not unloading. + // It could be that the camera is starting again while it is being unloaded + if (m_status != QCamera::UnloadingStatus) { + if (m_busy != busy) + emit busyChanged(m_busy = busy); + return; + } + + // Now we can really stop + if (m_viewfinderInterface) + m_viewfinderInterface->stopRenderer(); + + gst_element_set_state(m_camerabin, GST_STATE_NULL); + + if (m_busy != busy) + emit busyChanged(m_busy = busy); + + m_supportedViewfinderSettings.clear(); + + setStatus(QCamera::UnloadedStatus); +} + QT_END_NAMESPACE diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.h b/src/plugins/gstreamer/camerabin/camerabinsession.h index ade8916b..f25a8474 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.h +++ b/src/plugins/gstreamer/camerabin/camerabinsession.h @@ -180,6 +180,7 @@ public slots: private slots: void handleViewfinderChange(); void setupCaptureResolution(); + void handleBusyChanged(bool busy); private: void load();