summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation/camera/avfmediaassetwriter.h
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2016-07-22 14:29:45 +0200
committerTimur Pocheptsov <timur.pocheptsov@theqtcompany.com>2016-07-26 13:01:56 +0000
commit7788feea5d55418ab61681e122c1d2d29f7bddce (patch)
tree7e79602d22aef1bb079b70b55ffca2ea54a888f4 /src/plugins/avfoundation/camera/avfmediaassetwriter.h
parentab940d8fe9affd2ae1bb9cdf0e3f9d41fa49a662 (diff)
AVFMediaAssetWriter - fix race conditions
Apple recommends starting/setting up a session (AVCaptureSession) on a special queue and in the past we did this on the writer's queue. Unfortunately, we also can access the same session from a different thread and this results in race conditions and different weird crashes, for example, we're calling start/stopRunning from the writer's queue, while the session is being configured (in between beginConfiguration/commitConfiguration on the recorder control's thread). So we have to limit access to the session by the control's thread. Apple docs say we have to ensure all appendSampleBuffer calls done _before_ finishWriting. We ensure this by dispatching_sync an empty block on the writer's queue after store-release of m_state. We also do the same with video queue to ensure it does not try to access viewfinder's data after stop/abort executed. All these changes also make lock/mutex unneeded. Task-number: QTBUG-54890 Change-Id: I38e86c879b6b62306bdfbeade65405d6ac3be9f3 Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
Diffstat (limited to 'src/plugins/avfoundation/camera/avfmediaassetwriter.h')
-rw-r--r--src/plugins/avfoundation/camera/avfmediaassetwriter.h13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/plugins/avfoundation/camera/avfmediaassetwriter.h b/src/plugins/avfoundation/camera/avfmediaassetwriter.h
index 77e2a2f32..c36caee8b 100644
--- a/src/plugins/avfoundation/camera/avfmediaassetwriter.h
+++ b/src/plugins/avfoundation/camera/avfmediaassetwriter.h
@@ -38,7 +38,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qatomic.h>
-#include <QtCore/qmutex.h>
#include <AVFoundation/AVFoundation.h>
@@ -63,12 +62,12 @@ QT_END_NAMESPACE
QT_PREPEND_NAMESPACE(AVFScopedPointer)<AVAssetWriterInput> m_audioWriterInput;
AVCaptureDevice *m_audioCaptureDevice;
+ // Queue to write sample buffers:
+ QT_PREPEND_NAMESPACE(AVFScopedPointer)<dispatch_queue_t> m_writerQueue;
// High priority serial queue for video output:
QT_PREPEND_NAMESPACE(AVFScopedPointer)<dispatch_queue_t> m_videoQueue;
// Serial queue for audio output:
QT_PREPEND_NAMESPACE(AVFScopedPointer)<dispatch_queue_t> m_audioQueue;
- // Queue to write sample buffers:
- QT_PREPEND_NAMESPACE(AVFScopedPointer)<dispatch_queue_t> m_writerQueue;
QT_PREPEND_NAMESPACE(AVFScopedPointer)<AVAssetWriter> m_assetWriter;
@@ -77,7 +76,6 @@ QT_END_NAMESPACE
bool m_setStartTime;
QT_PREPEND_NAMESPACE(QAtomicInt) m_state;
- QT_PREPEND_NAMESPACE(QMutex) m_writerMutex;
@public
QT_PREPEND_NAMESPACE(AVFAtomicInt64) m_durationInMs;
@private
@@ -88,8 +86,7 @@ QT_END_NAMESPACE
NSDictionary *m_videoSettings;
}
-- (id)initWithQueue:(dispatch_queue_t)writerQueue
- delegate:(QT_PREPEND_NAMESPACE(AVFMediaRecorderControlIOS) *)delegate;
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(AVFMediaRecorderControlIOS) *)delegate;
- (bool)setupWithFileURL:(NSURL *)fileURL
cameraService:(QT_PREPEND_NAMESPACE(AVFCameraService) *)service
@@ -97,10 +94,10 @@ QT_END_NAMESPACE
videoSettings:(NSDictionary *)videoSettings
transform:(CGAffineTransform)transform;
+// This to be called from the recorder control's thread:
- (void)start;
- (void)stop;
-// This to be called if control's dtor gets called,
-// on the control's thread.
+// This to be called from the recorder control's dtor:
- (void)abort;
@end