Skip to content
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

Use CameraX's recordedDuration in status event for video recorder's timer #438

Merged
merged 3 commits into from
Jul 28, 2024

Conversation

MHShetty
Copy link
Member

This would help us in displaying a more accurate timer while the video recording takes place, for example in cases when the user pauses the recording or when an unexpected occasional delay occurs before the recording actually starts

@muhomorr
Copy link
Member

This change occasionally causes video recording duration to be stuck at "0:00", not clear why. Saving the recording doesn't work produces the "this recording is too short to be saved" error.

@MHShetty MHShetty force-pushed the camerax_timer branch 3 times, most recently from c55b496 to 485fff2 Compare June 25, 2024 09:39
@MHShetty
Copy link
Member Author

This change occasionally causes video recording duration to be stuck at "0:00", not clear why. Saving the recording doesn't work produces the "this recording is too short to be saved" error.

Yes actually this happens because the recording does not directly start as soon as we call PendingRecording.start but rather a short while after that. This PR was made to address the recorded time not being in sync with the timer displayed by the app.

I have pushed some changes to only animate the UI when the recording starts, while the sound plays as the way it used to before PendingRecording.start is called, to show a more accurate time state.

If the recording is less than a second or half a second, it would most likely lead to an error like that. However, if it still happens after the latest changes (i.e. animating the UI and timer after CameraX notifies us about the recording starting), it could be a bug that might need to be reported

@MHShetty MHShetty requested a review from muhomorr June 25, 2024 10:01
@muhomorr
Copy link
Member

Found a bug with latest changes, not sure if it's the same as the previous bug:

  • clear storage of Camera app to reset its permissions
  • open Camera, grant it camera pemission
  • switch to video mode, tap "start recording" button
  • allow microphone permission
  • observe that recording appears to have been started, but the counter is not counting. Tapping "finish recording" button shows "recording is too short" message

@MHShetty
Copy link
Member Author

MHShetty commented Jun 27, 2024

If the 00:00 red indicator shows up and then doesn't update later, this could be a bug of CameraX. It implies that VideoRecordEvent.Start event was called but not the VideoRecordEvent.Status which could mean that the recorder isn't recording even after starting. Could you please share the logs specific to the app while reproducing this issue?

For me, it's showing the counter as expected on first launch/attempt to record the video, but then end up with the same "recording is too short" error. The subsequent recording attempts seem to work as expected even for durations shorter than a second although.

Edit: I'm able to reproduce it just as you right now, neither the Start nor Status event seems to get trigged and we end up with the "recording too short" error, while the recording attempts ahead work as expected. I'll just look into the logs to see if we find something and report it to the CameraX team soon

@MHShetty
Copy link
Member Author

In the first attempt of recording the video we have,

2024-06-27 13:56:55.480 19719-19719 Recorder                app.grapheneos.camera.dev            D  Transitioning Recorder internal state: CONFIGURING --> PENDING_RECORDING
2024-06-27 13:57:04.114 19719-19719 Recorder                app.grapheneos.camera.dev            D  Transitioning Recorder internal state: PENDING_RECORDING --> CONFIGURING

This stays almost forever after that, until we attempt to stop recording which then just logs

> 2024-06-27 13:57:04.117 19719-19719 Recorder                app.grapheneos.camera.dev            D  Sending VideoRecordEvent Finalize [error: ERROR_NO_VALID_DATA]

In the second attempt, however,

2024-06-27 13:57:17.181 19719-19719 Recorder                app.grapheneos.camera.dev            D  Transitioning Recorder internal state: IDLING --> PENDING_RECORDING
2024-06-27 13:57:17.183 19719-20009 Recorder                app.grapheneos.camera.dev            D  Transitioning Recorder internal state: PENDING_RECORDING --> RECORDING

(rest of the logs as expected and the recording works)

The main difference seems to be between the transition in the internal state (between the logs of the two case), one transitions to CONFIGURING state whereas the other transitions to RECORDING state directly

@MHShetty
Copy link
Member Author

This happens specifically when the recording starts right after the recording permission is given, possibly related to the different flows that are taken when audio permission is not already present and when it is

@MHShetty
Copy link
Member Author

MHShetty commented Jun 27, 2024

The bug occurs because when audio permission an audio permission is completed, a callback is invoked that causes the videoCapturer.startRecording() to get called.

    private val restartRecordingWithAudioPermissionLauncher = registerForActivityResult(
        ActivityResultContracts.RequestPermission()
    ) { granted ->
        if (granted) {
            videoCapturer.startRecording()
            return@registerForActivityResult
        }
        showAudioPermissionDeniedDialog {
            videoCapturer.startRecording()
        }
    }

However, the issue is that onResume gets called after the activity result gets complete, causing the camera to re-initialize completely. This causes the UI and sounds changes to execute as expected, whereas the Recorder attempts to wait for frames from the old inactive camera instance

This regression seems to have occurred at some point while refactoring the code that was previously used to restart the camera after audio permission was granted/audio was disabled

@MHShetty
Copy link
Member Author

Hey @muhomorr,

Could you please test the latest revision of this branch for this issue?

Thanks a lot for your time and help!

@MHShetty MHShetty force-pushed the camerax_timer branch 3 times, most recently from b98ad8b to 7324d47 Compare July 12, 2024 11:25
@thestinger thestinger merged commit b664d89 into GrapheneOS:main Jul 28, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants