diff --git a/kivy/core/camera/camera_avfoundation.pyx b/kivy/core/camera/camera_avfoundation.pyx index f25e01742..1f8b76dc6 100644 --- a/kivy/core/camera/camera_avfoundation.pyx +++ b/kivy/core/camera/camera_avfoundation.pyx @@ -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. diff --git a/kivy/core/camera/camera_avfoundation_implem.m b/kivy/core/camera/camera_avfoundation_implem.m index 46a2166e8..67e40ae18 100644 --- a/kivy/core/camera/camera_avfoundation_implem.m +++ b/kivy/core/camera/camera_avfoundation_implem.m @@ -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;