     // device orientation
     var deviceOrientation = UIDeviceOrientation.portrait {
         didSet {
+            guard (deviceOrientation != oldValue) else { return }
+
             switch deviceOrientation {
             case .portrait,
                  .portraitUpsideDown,
                  .landscapeLeft,
                  .landscapeRight:
                 sessionQueue.async {
+                    guard self.isConfigured else { return }
+
+                    let sessionIsRunning = self.session.isRunning
+                    if sessionIsRunning {
+                        self.session.stopRunning()
+                    }
+
                     self.setVideoOrientation()
+
+                    if sessionIsRunning {
+                        self.session.startRunning()
+                    }
                 }
             default:
+                deviceOrientation = oldValue
                 break
             }
         }


                self.setVideoOrientation()
                self.setVideoMirrored()
            }
        }
    }

            sessionQueue.async {
                guard self.isConfigured else { return }

                let sessionIsRunning = self.session.isRunning
                if sessionIsRunning {
                    self.session.stopRunning()
                }

                guard self.setSessionInput() else {
                    print("[Error] setSessionInput failed")
                    return
