[camera_avfoundation] fix stopVideoRecording waiting indefinitely and video lag at start#7065
Conversation
1815a2a to
83cef95
Compare
|
Btw integration tests fail on my side with flutter packages main branch because here |
83cef95 to
ba64f20
Compare
| @property(strong, nonatomic) AVCaptureVideoDataOutput *videoOutput; | ||
| @property(strong, nonatomic) AVCaptureAudioDataOutput *audioOutput; | ||
| @property(strong, nonatomic) NSString *videoRecordingPath; | ||
| @property(assign, nonatomic) BOOL firstSample; |
| if (_isRecording) { | ||
| _isRecording = NO; | ||
|
|
||
| if (_videoWriter.status != AVAssetWriterStatusUnknown) { |
There was a problem hiding this comment.
why is this check removed?
There was a problem hiding this comment.
This is where it was not sending completion (in false case) so a dart future never resolved. But now startWriting is called at the same time as _isRecording is set to YES so finishWritingWithCompletionHandler in stopVideoRecordingWithCompletion can be called only after was called startWriting which sets _videoWriter.status to AVAssetWriterStatusWriting so that check is redundant (and again it would just indicate false possibility of not calling completion).
There was a problem hiding this comment.
Actually maybe it should check whether status is AVAssetWriterStatusWriting and complete with error otherwise because it can be for example AVAssetWriterStatusFailed here (I suppose finishWritingWithCompletionHandler would just crash in that case). But this situation is nothing new introduced with this PR as before there was just check status != unknown which would pass failed to finishWritingWithCompletionHandler.
I also noticed check for AVAssetWriterStatusFailed in didOutputSampleBuffer where is called [self reportErrorMessage] but when I tried to force call reportErrorMessage I did not see this error report anywhere.
There was a problem hiding this comment.
Regarding previous comment, seems finishWritingWithCompletionHandler is ok with AVAssetWriterStatusFailed it will just pass it to handler so there is no need to check whether is status not failed before calling it, it only has problem with AVAssetWriterStatusCancelled but there is no call to cancelWriting, AVAssetWriterStatusCompleted and AVAssetWriterStatusUnknown but these two also cannot happen.
| // 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]; |
There was a problem hiding this comment.
do you intend to remove startWriting from didOutputSampleBuffer?
Seems reasonable to allow both jpg and jpeg to pass |
# Conflicts: # packages/camera/camera_avfoundation/CHANGELOG.md # packages/camera/camera_avfoundation/example/ios/RunnerTests/FLTCamSampleBufferTests.m # packages/camera/camera_avfoundation/ios/Classes/FLTCam.m # packages/camera/camera_avfoundation/pubspec.yaml
hellohuanlin
left a comment
There was a problem hiding this comment.
I think it's reasonable change. Just some nit to make it easier for future readers.
| @property(strong, nonatomic) AVCaptureVideoDataOutput *videoOutput; | ||
| @property(strong, nonatomic) AVCaptureAudioDataOutput *audioOutput; | ||
| @property(strong, nonatomic) NSString *videoRecordingPath; | ||
| @property(assign, nonatomic) BOOL isFirstSample; |
There was a problem hiding this comment.
Should this be isFirstVideoSample?
| details:nil]); | ||
| return; | ||
| } | ||
| // do not call startWriting in didOutputSampleBuffer to prevent state in which |
There was a problem hiding this comment.
nit: "do not move startWriting call to didOutputSampleBuffer... "
Because there should only be 1 place to call startWriting.
| } | ||
| // 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 |
There was a problem hiding this comment.
can you also explain that this happens when stop video is called immediately after start, before the first video sample is arrived (if i understand correctly)
| if (_isRecording) { | ||
| _isRecording = NO; | ||
|
|
||
| if (_videoWriter.status != AVAssetWriterStatusUnknown) { |
There was a problem hiding this comment.
can you add a comment explaining that it's not necessary to check AVAssetWriterStatusUnknown anymore since we call startWriting immediately, even before video sample callback (please rephrase this).
There was a problem hiding this comment.
ok, but such a comment loses context here because in sources it is not visible that there was such a check, only in this diff
| } | ||
| // when _isRecording is YES startWriting was already called so _videoWriter.status | ||
| // is always either AVAssetWriterStatusWriting or AVAssetWriterStatusFailed and | ||
| // finishWritingWithCompletionHandler does not throw exception |
There was a problem hiding this comment.
nit: "so there's no need to check _videoWriter.status before finish writing"
|
Btw does this also require a second review? |
Only first time contributors require a second review, so you are good to go. But feel free to tag more people as you see fit. |
|
Oh ok (there are comments in my 2nd and 3rd PR that second reviews are required, but I did my first some year ago). |
7c5ef79 to
fb3d713
Compare
Sorry I was terribly wrong - we need a second reviewer to land this. |
|
For the curious, from https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#getting-a-code-review
|
|
There's also a process to become a member: https://github.com/flutter/flutter/blob/master/docs/contributing/Contributor-access.md If you are interested, I'm more than happy to sponsor it. |
…tely and video lag at start (flutter/packages#7065)
flutter/packages@cc9ff47...82e8d1e 2024-08-04 engine-flutter-autoroll@skia.org Manual roll Flutter from f10a497 to cbfb222 (23 revisions) (flutter/packages#7298) 2024-08-04 30872003+misos1@users.noreply.github.com [camera_avfoundation] dealloc camera on dispose (flutter/packages#7211) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 4ff9462 to f10a497 (22 revisions) (flutter/packages#7297) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 85960d2 to 4ff9462 (45 revisions) (flutter/packages#7296) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 9d5ede0 to 85960d2 (24 revisions) (flutter/packages#7295) 2024-08-02 stuartmorgan@google.com Roll to 9d5ede0, disabling impeller for google_maps_flutter_android (flutter/packages#7294) 2024-08-02 30872003+misos1@users.noreply.github.com [camera_avfoundation] fix stopVideoRecording waiting indefinitely and video lag at start (flutter/packages#7065) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@cc9ff47...82e8d1e 2024-08-04 engine-flutter-autoroll@skia.org Manual roll Flutter from f10a497 to cbfb222 (23 revisions) (flutter/packages#7298) 2024-08-04 30872003+misos1@users.noreply.github.com [camera_avfoundation] dealloc camera on dispose (flutter/packages#7211) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 4ff9462 to f10a497 (22 revisions) (flutter/packages#7297) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 85960d2 to 4ff9462 (45 revisions) (flutter/packages#7296) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 9d5ede0 to 85960d2 (24 revisions) (flutter/packages#7295) 2024-08-02 stuartmorgan@google.com Roll to 9d5ede0, disabling impeller for google_maps_flutter_android (flutter/packages#7294) 2024-08-02 30872003+misos1@users.noreply.github.com [camera_avfoundation] fix stopVideoRecording waiting indefinitely and video lag at start (flutter/packages#7065) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@cc9ff47...82e8d1e 2024-08-04 engine-flutter-autoroll@skia.org Manual roll Flutter from f10a497 to cbfb222 (23 revisions) (flutter/packages#7298) 2024-08-04 30872003+misos1@users.noreply.github.com [camera_avfoundation] dealloc camera on dispose (flutter/packages#7211) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 4ff9462 to f10a497 (22 revisions) (flutter/packages#7297) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 85960d2 to 4ff9462 (45 revisions) (flutter/packages#7296) 2024-08-03 engine-flutter-autoroll@skia.org Manual roll Flutter from 9d5ede0 to 85960d2 (24 revisions) (flutter/packages#7295) 2024-08-02 stuartmorgan@google.com Roll to 9d5ede0, disabling impeller for google_maps_flutter_android (flutter/packages#7294) 2024-08-02 30872003+misos1@users.noreply.github.com [camera_avfoundation] fix stopVideoRecording waiting indefinitely and video lag at start (flutter/packages#7065) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
|
@hellohuanlin Ok so let's try it. |
Call to
startWritingwas moved tostartVideoRecordingWithCompletionto fix situation when completion is not called when_isRecordingisYESbut_videoWriter.statusisAVAssetWriterStatusUnknowninstopVideoRecordingWithCompletionwhich can happen ifstopVideoRecordingWithCompletionis called right afterstartVideoRecordingWithCompletionanddidOutputSampleBufferhad no chance to callstartWritingin meantime and to avoid lag which happens when is calledstartWritingbetween first frame creation and its appending.Fixes flutter/flutter#132016
Fixes flutter/flutter#151319
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.