Skip to content

Commit

Permalink
GPUImageMovieWriter: finishRecordingWithCompletionHandler must happen…
Browse files Browse the repository at this point in the history
… synchronously on video processing queue too

finishRecording runs synchronously, but if you call the method with a completion handler you don't. This results in a race condition to finish recording.
  • Loading branch information
Karl von Randow committed Jul 7, 2013
1 parent 8986763 commit 60f44bd
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions framework/Source/iOS/GPUImageMovieWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,42 +271,42 @@ - (void)cancelRecording;

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

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

isRecording = NO;
runOnMainQueueWithoutDeadlocking(^{
[assetWriterVideoInput markAsFinished];
[assetWriterAudioInput markAsFinished];
isRecording = NO;
runOnMainQueueWithoutDeadlocking(^{
[assetWriterVideoInput markAsFinished];
[assetWriterAudioInput markAsFinished];
#if (!defined(__IPHONE_6_0) || (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_6_0))
// Not iOS 6 SDK
[assetWriter finishWriting];
if (handler) handler();
// Not iOS 6 SDK
[assetWriter finishWriting];
if (handler) handler();
#else
// iOS 6 SDK
if ([assetWriter respondsToSelector:@selector(finishWritingWithCompletionHandler:)]) {
// Running iOS 6
[assetWriter finishWritingWithCompletionHandler:(handler ?: ^{ })];
}
else {
// Not running iOS 6
// iOS 6 SDK
if ([assetWriter respondsToSelector:@selector(finishWritingWithCompletionHandler:)]) {
// Running iOS 6
[assetWriter finishWritingWithCompletionHandler:(handler ?: ^{ })];
}
else {
// Not running iOS 6
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[assetWriter finishWriting];
[assetWriter finishWriting];
#pragma clang diagnostic pop
if (handler) handler();
}
if (handler) handler();
}
#endif
});
});
}

Expand Down

0 comments on commit 60f44bd

Please sign in to comment.