Don't try to reacquire resources if we already have the correct ones
authorMohammed Sameer <msameer@foolab.org>
Mon, 15 Jul 2013 16:37:27 +0000 (19:37 +0300)
committerMohammed Sameer <msameer@foolab.org>
Mon, 15 Jul 2013 20:28:47 +0000 (23:28 +0300)
qml/PipelineManager.qml

index cd33a48..458885a 100644 (file)
@@ -36,6 +36,7 @@ Item {
     property Camera camera: null
     property Item currentItem
     property bool error: false
+    property int currentPolicyMode: CameraResources.None
 
     onCurrentItemChanged: {
         if (state == "on" || state == "policyLost") {
@@ -59,17 +60,22 @@ Item {
     function startCamera() {
         if (error) {
             return
+        } else if ((currentPolicyMode == currentItem.policyMode) && cam.running) {
+            return
         } else if (!policy.acquire(currentItem.policyMode)) {
             console.log("Failed to acquire policy resources")
             return
         } else if (!camera.start()) {
             showError(qsTr("Failed to start camera. Please restart the application."))
+        } else {
+            currentPolicyMode = currentItem.policyMode
         }
     }
 
     function stopCamera() {
         if (camera.stop(false)) {
             policy.acquire(CameraResources.None)
+            currentPolicyMode = CameraResources.None
             error = false
         }
     }
@@ -79,6 +85,7 @@ Item {
         // when they become available
         currentItem.policyLost()
         camera.stop(true)
+        currentPolicyMode = CameraResources.None
         error = false
     }