From 9caee039533168fbb546b563859770414e54fc94 Mon Sep 17 00:00:00 2001
From: VaL Doroshchuk <valentyn.doroshchuk@qt.io>
Date: Fri, 27 Oct 2017 14:02:14 +0200
Subject: [PATCH] GStreamer: Prevent calling CameraBinSession::setStateHelper
 twice

Since CameraBinSession::setStateHelper() is supposed to handle
only pending states, added a fix to prevent calling it twice.
Otherwise CameraBinSession::load() can be called few times
which might lead an error from gstreamer.

Possible call stack:
CameraBinSession::setState()
CameraBinSession::setStateHelper()
CameraBinSession::load()
CameraBinSession::setStatus()
CameraBinSession::setStateHelper()
CameraBinSession::load() << gst_element_set_state is called also twice

Task-number: QTBUG-53204
Change-Id: I00c66f91cd3b885c70848245da725ff68943fad2
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
---
 src/plugins/gstreamer/camerabin/camerabinsession.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp
index 4941c6ef6..f06d95ea3 100644
--- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp
+++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp
@@ -729,18 +729,21 @@ void CameraBinSession::setState(QCamera::State newState)
     if (newState == m_pendingState)
         return;
 
-    m_pendingState = newState;
-    emit pendingStateChanged(m_pendingState);
+    emit pendingStateChanged(newState);
 
 #if CAMERABIN_DEBUG
     qDebug() << Q_FUNC_INFO << newState;
 #endif
 
     setStateHelper(newState);
+    m_pendingState = newState;
 }
 
 void CameraBinSession::setStateHelper(QCamera::State state)
 {
+    if (state == m_pendingState)
+        return;
+
     switch (state) {
     case QCamera::UnloadedState:
         unload();
-- 
GitLab