fix(android): treat ERROR_SOURCE_INACTIVE as a successful finish (don't discard a valid file)#4042
Open
radko93 wants to merge 1 commit into
Open
Conversation
CameraX finalizes a valid file on ERROR_SOURCE_INACTIVE (the frames recorded before the source went inactive — e.g. the Activity is stopped/destroyed mid-recording), unlike ERROR_NO_VALID_DATA. Routing it to onRecordingError discards usable footage, so map it to onRecordingFinished(STOPPED) instead, matching expo-camera's handling. ERROR_NO_VALID_DATA stays fatal. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@radko93 is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Android, when a recording finalizes with
VideoRecordEvent.Finalize.ERROR_SOURCE_INACTIVE,HybridVideoRecorderreports it viaonRecordingError, so callers treat the recording as failed and discard it.But
ERROR_SOURCE_INACTIVEis not a no-output error. CameraX finalizes a valid, playable file (containing every frame produced before the source went inactive) before delivering theFinalizeevent. This commonly fires when the hostActivityis stopped/destroyed mid-recording during normal app lifecycle (backgrounding, deep-link relaunch, config change) — so the user did record usable footage, and it's being thrown away.Evidence it produces a usable file
Per the CameraX
VideoRecordEvent.Finalizereference:ERROR_SOURCE_INACTIVE: "The recording failed because the source becomes inactive and stops sending frames. One case is that if camera is closed due to lifecycle stopped, the active recording will be finalized with this error, and the output will be generated, containing the frames produced before camera closing."ERROR_NO_VALID_DATA: "… The application will need to clean up the output file, such as deleting the file."So
ERROR_SOURCE_INACTIVE⇒ usable file;ERROR_NO_VALID_DATA⇒ no usable file.Precedent
expo-cameratreatsERROR_SOURCE_INACTIVEas a success and resolves withevent.outputResults.outputUri— seeExpoCameraView.ktL382-L394. This change brings VisionCamera in line with that contract.The intent to keep the file even predates the Nitro rewrite. VisionCamera v4's
VideoRecordEvent+toCameraError.ktL13-L20 grouped this code under a comment that reads "errors where the recording still gets saved (so we can probably ignore them)" — but mapped it toNoDataError(cause)(wasVideoRecorded = false), soCameraSession+Video.ktL67-L76 still took the fatal branch and dropped the file. The Nitro rewrite collapsed thewasVideoRecordeddistinction, so the file is lost either way — this PR realizes the originally-intended behavior.Change
Map
ERROR_SOURCE_INACTIVEto a successful finish (RecordingFinishedReason.STOPPED).ERROR_NO_VALID_DATAand other no-output errors stay on the error path.Testing
ERROR_SOURCE_INACTIVEis delivered by CameraX when the frame source dies, which is impractical to trigger deterministically in the unit harness (needs a real camera/lifecycle teardown). Verified manually on devices (Android 12–16): backgrounding to destroy the Activity mid-recording previously hitonRecordingErrorwith a valid file left on disk; with this change the file is delivered viaonRecordingFinished. Happy to add a harness test if you can point me at the right seam to inject aFinalizeevent with a given error code.bun run lint-kotlinproduces no diff.