Camera: Fix AVFoundation provider to release the camera, start it async, and check if started before stopping it (#7303)

* Camera: Fix AVCamera to release the camera, start it async, and check if started before stopping it

* Camera: Additional check on storage.camera pre/post deinit
This commit is contained in:
Mirko 2021-01-05 19:06:14 +01:00 committed by GitHub
parent 5e13119137
commit a0d47e2e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -49,11 +49,20 @@ class CameraAVFoundation(CameraBase):
self._framerate = 30
super(CameraAVFoundation, self).__init__(**kwargs)
def __del__(self):
self._release_camera()
def init_camera(self):
cdef _AVStorage storage = <_AVStorage>self._storage
storage.camera = avf_camera_init(
self._index, self.resolution[0], self.resolution[1])
def _release_camera(self):
cdef _AVStorage storage = <_AVStorage>self._storage
if storage.camera != NULL:
avf_camera_deinit(storage.camera)
storage.camera = NULL
@property
def _scheduled_rate(self):
# We're going 4 times faster the framerate to avoid frame skipping.

View File

@ -214,7 +214,9 @@ Camera::Camera(int _cameraNum, int _width, int _height) {
}
Camera::~Camera() {
stopCaptureDevice();
if(started){
stopCaptureDevice();
}
}
bool Camera::grabFrame(double timeOut) {
@ -411,7 +413,9 @@ int Camera::startCaptureDevice() {
#endif
[conn setVideoOrientation:default_orientation];
[mCaptureSession startRunning];
dispatch_async(dispatch_get_main_queue(), ^{
[mCaptureSession startRunning];
});
[localpool drain];
started = 1;