Repository navigation
[camera_android_x] implement CameraX RecordingStats and VideoRecordEvent APIs - #13330
auto-submit[bot] merged 7 commits into
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the Android CameraX implementation to resolve video recording discrepancies. It introduces Pigeon bindings for RecordingStats and VideoRecordEventStatus, and adds error-checking methods to VideoRecordEventFinalize. In AndroidCameraCameraX, startVideoCapturing now waits for the first frame to be recorded by monitoring status events, throwing a CameraException if finalization occurs prematurely. Additionally, stopVideoRecording now checks for finalization errors and throws a CameraException if any are found. Unit and integration tests have been updated to cover these new behaviors. There are no review comments to evaluate, and I have no feedback to provide.
There was a problem hiding this comment.
Code Review
This pull request addresses video recording duration discrepancies and short recording failures in the CameraX Android implementation. It introduces RecordingStats and VideoRecordEventStatus to wait for the first recorded frame before completing startVideoCapturing, and validates errors during finalization. Feedback suggests recreating the StreamQueue at the start of each recording session to prevent leftover finalize events from previous sessions from causing immediate failures, and defining error and hasError in VideoRecordEventFinalize as fields rather than asynchronous methods to avoid platform channel overhead.
| abstract class VideoRecordEventFinalize extends VideoRecordEvent { | ||
| /// The error code of the finalization. | ||
| /// | ||
| /// See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#getError(). | ||
| int getError(); | ||
|
|
||
| /// Whether the recording finalized with an error. | ||
| /// | ||
| /// See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#hasError(). | ||
| bool hasError(); | ||
| } |
There was a problem hiding this comment.
Since VideoRecordEventFinalize is an immutable event, its error and hasError properties are constant once the event is created. Instead of defining them as asynchronous methods (getError() and hasError()), which require asynchronous platform channel calls every time they are accessed, you can define them as fields (similar to how you did for RecordingStats). This avoids unnecessary asynchronous IPC overhead and allows synchronous access to these properties in Dart (e.g., event.hasError and event.error instead of await event.hasError() and await event.getError()).
abstract class VideoRecordEventFinalize extends VideoRecordEvent {
/// The error code of the finalization.
///
/// See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#getError().
late int error;
/// Whether the recording finalized with an error.
///
/// See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#hasError().
late bool hasError;
}There was a problem hiding this comment.
Looks like there is an established pattern for doing this, so I'm pro. Is there some reason we can't do this here?
There was a problem hiding this comment.
No issues with that. I'll make the change.
camsim99
left a comment
There was a problem hiding this comment.
Overall this LGTM! This will be a great improvement for the plugin and its testing :)
One thing I'll point out is that ideally, we fix the issue of not knowing the video duration so we don't have to guess the delay in tests. flutter/flutter#101785 seems to cover that, which I'd be interested in prioritizing (bumped P3 --> P2). I'm ok with doing that here, though ideally, we plan for the smallest delay we can (left a comment about this re:350)
| abstract class VideoRecordEventFinalize extends VideoRecordEvent { | ||
| /// The error code of the finalization. | ||
| /// | ||
| /// See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#getError(). | ||
| int getError(); | ||
|
|
||
| /// Whether the recording finalized with an error. | ||
| /// | ||
| /// See https://developer.android.com/reference/androidx/camera/video/VideoRecordEvent.Finalize#hasError(). | ||
| bool hasError(); | ||
| } |
There was a problem hiding this comment.
Looks like there is an established pattern for doing this, so I'm pro. Is there some reason we can't do this here?
| expect(duration, lessThan(postStopTime)); | ||
| expect(duration, greaterThan(1700)); | ||
| final int delta = (duration - 2000).abs(); | ||
| expect(delta, lessThan(350)); |
There was a problem hiding this comment.
Why 350? Is this the lowest value you found experimentally?
There was a problem hiding this comment.
Can you also leave a comment about the value you pick and link to flutter/flutter#101785?
There was a problem hiding this comment.
Actually, 350 ms isn't the lowest value observed experimentally. I tested this on my S23 and measured intervals of around 100–200 ms. I chose 350 ms to leave some headroom for timer jitter and dropped frames, and avoid flakiness on CI.
There was a problem hiding this comment.
I'll add a code comment to clarify this.
…properties synchronously via pigeon
I can take on flutter/flutter#101785 next. It'll be next in my queue, and I enjoy working on native code, so I'm happy to pick this one up. |
… integration test
camsim99
left a comment
There was a problem hiding this comment.
Thanks for the quick updates :) and your interest in flutter/flutter#101785!!
Fixes flutter/flutter#148138
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2