mirror of https://github.com/kivy/kivy.git
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:
parent
5e13119137
commit
a0d47e2e64
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue