Skip to content

Commit

Permalink
GPUImageMovieWriter: synchronise finishRecording with the movieWritin…
Browse files Browse the repository at this point in the history
…gQueue

As the AVAssetWriter gets started on the movieWritingQueue.

Also ensure that the handler is called async, otherwise it is called on the movieWritingQueue, which is dispatch_sync from the video processing queue, so if the user-code in the handler calls anything that dispatch_syncs to the video processing queue: deadlock.
  • Loading branch information
karlvr committed Sep 11, 2013
1 parent 961c103 commit 23991bd
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions framework/Source/iOS/GPUImageMovieWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,22 @@ - (void)cancelRecording;

- (void)finishRecording;
{
[self finishRecordingWithCompletionHandler:nil];
[self finishRecordingWithCompletionHandler:NULL];
}

- (void)finishRecordingWithCompletionHandler:(void (^)(void))handler;
{
runSynchronouslyOnVideoProcessingQueue(^{
if (assetWriter.status == AVAssetWriterStatusCompleted || assetWriter.status == AVAssetWriterStatusCancelled
|| assetWriter.status == AVAssetWriterStatusUnknown)
{
return;
}

isRecording = NO;

dispatch_sync(movieWritingQueue, ^{
isRecording = NO;

if (assetWriter.status == AVAssetWriterStatusCompleted || assetWriter.status == AVAssetWriterStatusCancelled || assetWriter.status == AVAssetWriterStatusUnknown)
{
if (handler)
runAsynchronouslyOnVideoProcessingQueue(handler);
return;
}
if( assetWriter.status == AVAssetWriterStatusWriting && ! videoEncodingIsFinished )
{
videoEncodingIsFinished = YES;
Expand All @@ -329,7 +331,8 @@ - (void)finishRecordingWithCompletionHandler:(void (^)(void))handler;
#if (!defined(__IPHONE_6_0) || (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_6_0))
// Not iOS 6 SDK
[assetWriter finishWriting];
if (handler) handler();
if (handler)
runAsynchronouslyOnVideoProcessingQueue(handler);
#else
// iOS 6 SDK
if ([assetWriter respondsToSelector:@selector(finishWritingWithCompletionHandler:)]) {
Expand All @@ -342,7 +345,8 @@ - (void)finishRecordingWithCompletionHandler:(void (^)(void))handler;
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[assetWriter finishWriting];
#pragma clang diagnostic pop
if (handler) handler();
if (handler)
runAsynchronouslyOnVideoProcessingQueue(handler);
}
#endif
});
Expand Down

0 comments on commit 23991bd

Please sign in to comment.