Giter Site home page Giter Site logo

Comments (12)

s4cha avatar s4cha commented on May 10, 2024 1

PR here : #26
I'll take time tomorrow to issue a new version with the fix :)

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024 1

https://github.com/Yummypets/YPImagePicker/releases/tag/2.5.1
:)

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024

@viktorgardart,
First thanks a ton for taking the time to open an issue for this.
I had the issue before on and off, on my side the issue was quite hard to reproduce, it seemed to happen more often in release configuration.
I came to the conclusion that this was thread related, something like a data race for instance.
This would explain the freeze and the randomness of the issue.
This is quite annoying :/
I'm going to look into it again but if you want to instrument as well I could definitely use some help :) We'll report our findings here .

Cheers,

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024

@viktorgardart oO i'Ve found :) thanks so much for bringing this up I had gave up earlier :)

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024

will post the fix

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024
diff --git a/Source/Camera/YPCameraVC.swift b/Source/Camera/YPCameraVC.swift
index 2c82c30..8ee1238 100644
--- a/Source/Camera/YPCameraVC.swift
+++ b/Source/Camera/YPCameraVC.swift
@@ -13,7 +13,7 @@ import Photos
 public class YPCameraVC: UIViewController, UIGestureRecognizerDelegate, PermissionCheckable {
     
     public var didCapturePhoto: ((UIImage) -> Void)?
-    private let sessionQueue = DispatchQueue(label: "YPCameraVCSerialQueue")
+    private let sessionQueue = DispatchQueue(label: "YPCameraVCSerialQueue", qos: .background)
     let session = AVCaptureSession()
     var device: AVCaptureDevice? {
         return videoInput?.device
@@ -49,21 +49,27 @@ public class YPCameraVC: UIViewController, UIGestureRecognizerDelegate, Permissi
     
     public override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
+        refreshFlashButton()
+    }
+    
+    func tryToSetupPreview() {
         if !isPreviewSetup {
             setupPreview()
             isPreviewSetup = true
         }
-        refreshFlashButton()
     }
     
     func setupPreview() {
         let videoLayer = AVCaptureVideoPreviewLayer(session: session)
-        videoLayer.frame = v.previewViewContainer.bounds
-        videoLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
-        v.previewViewContainer.layer.addSublayer(videoLayer)
-        let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(focusTapped(_:)))
-        tapRecognizer.delegate = self
-        v.previewViewContainer.addGestureRecognizer(tapRecognizer)
+        
+        DispatchQueue.main.async {
+            videoLayer.frame = self.v.previewViewContainer.bounds
+            videoLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
+            self.v.previewViewContainer.layer.addSublayer(videoLayer)
+            let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.focusTapped(_:)))
+            tapRecognizer.delegate = self
+            self.v.previewViewContainer.addGestureRecognizer(tapRecognizer)
+        }
     }
     
     private func setupCaptureSession() {
@@ -120,6 +126,7 @@ public class YPCameraVC: UIViewController, UIGestureRecognizerDelegate, Permissi
                     self.session.stopRunning()
                 case .authorized:
                     self.session.startRunning()
+                    self.tryToSetupPreview()
                 }
             }
         }

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024

Something that is very strange though concerning the dispatchQueue

DispatchQueue(label: "YPCameraVCSerialQueue") // SLOW
DispatchQueue(label: "YPCameraVCSerialQueue", qos: .userInitiated) // SLOW
DispatchQueue(label: "YPCameraVCSerialQueue", qos: .userInteractive) // SLOW
DispatchQueue(label: "YPCameraVCSerialQueue", qos: .utility) // SLOW
DispatchQueue(label: "YPCameraVCSerialQueue", qos: .default) // SLOW
DispatchQueue(label: "YPCameraVCSerialQueue", qos: .background) // FAST

From what I believed, userInteractive should've been the fastest but somehow that's not the case :/

The second part of the fix is doing let videoLayer = AVCaptureVideoPreviewLayer(session: session)
in the session queue.

from ypimagepicker.

viktorgardart avatar viktorgardart commented on May 10, 2024

Thanks a lot for the quick reply, I’ll check out the fix later today/tomorrow! 🙂

Sent with GitHawk

from ypimagepicker.

viktorgardart avatar viktorgardart commented on May 10, 2024

Works! 💃 Thanks @s4cha

from ypimagepicker.

viktorgardart avatar viktorgardart commented on May 10, 2024

Or.. hmm 🤔
It went from always being slow to being slow sometimes. 😕

from ypimagepicker.

s4cha avatar s4cha commented on May 10, 2024

mm that's V weird :/ not happening anymore on my side what device are you testing on?

from ypimagepicker.

viktorgardart avatar viktorgardart commented on May 10, 2024

The same device as previously, but haven't seen it since.. Closing for now and reopening if I find anything new!

from ypimagepicker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.