-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_avfoundation] fix stopVideoRecording waiting indefinitely and video lag at start #7065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ba64f20
e2161c3
f2d83af
165afc7
05d19ce
0bfce88
1591697
172b3bf
fb3d713
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ @interface FLTCam () <AVCaptureVideoDataOutputSampleBufferDelegate, | |
| @property(strong, nonatomic) AVCaptureVideoDataOutput *videoOutput; | ||
| @property(strong, nonatomic) AVCaptureAudioDataOutput *audioOutput; | ||
| @property(strong, nonatomic) NSString *videoRecordingPath; | ||
| @property(assign, nonatomic) BOOL firstSample; | ||
| @property(assign, nonatomic) BOOL isRecording; | ||
| @property(assign, nonatomic) BOOL isRecordingPaused; | ||
| @property(assign, nonatomic) BOOL videoIsDisconnected; | ||
|
|
@@ -663,15 +664,15 @@ - (void)captureOutput:(AVCaptureOutput *)output | |
|
|
||
| // ignore audio samples until the first video sample arrives to avoid black frames | ||
| // https://github.com/flutter/flutter/issues/57831 | ||
| if (_videoWriter.status != AVAssetWriterStatusWriting && output != _captureVideoOutput) { | ||
| if (_firstSample && output != _captureVideoOutput) { | ||
| return; | ||
| } | ||
|
|
||
| CMTime currentSampleTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); | ||
|
|
||
| if (_videoWriter.status != AVAssetWriterStatusWriting) { | ||
| [_videoWriter startWriting]; | ||
| if (_firstSample) { | ||
| [_videoWriter startSessionAtSourceTime:currentSampleTime]; | ||
| _firstSample = NO; | ||
| } | ||
|
|
||
| if (output == _captureVideoOutput) { | ||
|
|
@@ -826,6 +827,13 @@ - (void)startVideoRecordingWithCompletion:(void (^)(FlutterError *_Nullable))com | |
| details:nil]); | ||
| return; | ||
| } | ||
| // do not call startWriting in didOutputSampleBuffer to prevent state in which | ||
| // stopVideoRecordingWithCompletion does not send completion when _isRecording is | ||
| // YES but _videoWriter.status is AVAssetWriterStatusUnknown and video lag at start | ||
| // https://github.com/flutter/flutter/issues/132016 | ||
| // https://github.com/flutter/flutter/issues/151319 | ||
| [_videoWriter startWriting]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you intend to remove
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| _firstSample = YES; | ||
| _isRecording = YES; | ||
| _isRecordingPaused = NO; | ||
| _videoTimeOffset = CMTimeMake(0, 1); | ||
|
|
@@ -845,19 +853,17 @@ - (void)stopVideoRecordingWithCompletion:(void (^)(NSString *_Nullable, | |
| if (_isRecording) { | ||
| _isRecording = NO; | ||
|
|
||
| if (_videoWriter.status != AVAssetWriterStatusUnknown) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this check removed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where it was not sending completion (in false case) so a dart future never resolved. But now
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually maybe it should check whether status is I also noticed check for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding previous comment, seems |
||
| [_videoWriter finishWritingWithCompletionHandler:^{ | ||
| if (self->_videoWriter.status == AVAssetWriterStatusCompleted) { | ||
| [self updateOrientation]; | ||
| completion(self->_videoRecordingPath, nil); | ||
| self->_videoRecordingPath = nil; | ||
| } else { | ||
| completion(nil, [FlutterError errorWithCode:@"IOError" | ||
| message:@"AVAssetWriter could not finish writing!" | ||
| details:nil]); | ||
| } | ||
| }]; | ||
| } | ||
| [_videoWriter finishWritingWithCompletionHandler:^{ | ||
| if (self->_videoWriter.status == AVAssetWriterStatusCompleted) { | ||
| [self updateOrientation]; | ||
| completion(self->_videoRecordingPath, nil); | ||
| self->_videoRecordingPath = nil; | ||
| } else { | ||
| completion(nil, [FlutterError errorWithCode:@"IOError" | ||
| message:@"AVAssetWriter could not finish writing!" | ||
| details:nil]); | ||
| } | ||
| }]; | ||
| } else { | ||
| NSError *error = | ||
| [NSError errorWithDomain:NSCocoaErrorDomain | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: isFirstSample