AVFoundation: Cleanup AVCaptureSession with proper reference counting

The reference counting was not being done for AVCaptureSession so it was
being destroyed before we got a chance to properly clean it up (which
lead to crashes).  We also make sure to remove any observers from
AVCaptureSession now before destroying it.

Task-number: QTBUG-37109
Task-number: QTBUG-29955
Change-Id: Ia9b49ad1eab01b4f7424e2a1c699d903cd9bf902
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
Andy Nichols
2014-03-04 14:11:01 +01:00
committed by The Qt Project
parent 9a55f5ce57
commit 1286300a4c

View File

@@ -85,6 +85,7 @@ QMap<QByteArray, AVFCameraInfo> AVFCameraSession::m_cameraInfo;
self->m_session = session; self->m_session = session;
self->m_captureSession = session->captureSession(); self->m_captureSession = session->captureSession();
[m_captureSession retain];
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processRuntimeError:) selector:@selector(processRuntimeError:)
name:AVCaptureSessionRuntimeErrorNotification name:AVCaptureSessionRuntimeErrorNotification
@@ -103,6 +104,22 @@ QMap<QByteArray, AVFCameraInfo> AVFCameraSession::m_cameraInfo;
return self; return self;
} }
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVCaptureSessionRuntimeErrorNotification
object:m_captureSession];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVCaptureSessionDidStartRunningNotification
object:m_captureSession];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVCaptureSessionDidStopRunningNotification
object:m_captureSession];
[m_captureSession release];
[super dealloc];
}
- (void) processRuntimeError:(NSNotification *)notification - (void) processRuntimeError:(NSNotification *)notification
{ {