-
Notifications
You must be signed in to change notification settings - Fork 922
Hold camera and mic locks while recording is active #1162
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,8 @@ use cap_project::{ | |||||||||||
| cursor::CursorEvents, | ||||||||||||
| }; | ||||||||||||
| use cap_recording::PipelineDoneError; | ||||||||||||
| use cap_recording::feeds::camera::CameraFeedLock; | ||||||||||||
| use cap_recording::feeds::microphone::MicrophoneFeedLock; | ||||||||||||
| use cap_recording::{ | ||||||||||||
| RecordingError, RecordingMode, | ||||||||||||
| feeds::{camera, microphone}, | ||||||||||||
|
|
@@ -53,20 +55,24 @@ use crate::{ | |||||||||||
| windows::{CapWindowId, ShowCapWindow}, | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| pub struct InProgressRecordingCommon { | ||||||||||||
| pub target_name: String, | ||||||||||||
| pub inputs: StartRecordingInputs, | ||||||||||||
| pub recording_dir: PathBuf, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| pub enum InProgressRecording { | ||||||||||||
| Instant { | ||||||||||||
| target_name: String, | ||||||||||||
| handle: instant_recording::ActorHandle, | ||||||||||||
| progressive_upload: InstantMultipartUpload, | ||||||||||||
| video_upload_info: VideoUploadInfo, | ||||||||||||
| inputs: StartRecordingInputs, | ||||||||||||
| recording_dir: PathBuf, | ||||||||||||
| common: InProgressRecordingCommon, | ||||||||||||
| // camera isn't used as part of recording pipeline so we hold lock here | ||||||||||||
| camera_feed: Option<Arc<CameraFeedLock>>, | ||||||||||||
|
Comment on lines
+69
to
+71
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. Remove the comment to comply with coding guidelines. The inline comment violates the guideline: "Do not add inline, block, or docstring comments in any language; code must be self-explanatory." Apply this diff: common: InProgressRecordingCommon,
- // camera isn't used as part of recording pipeline so we hold lock here
camera_feed: Option<Arc<CameraFeedLock>>,As per coding guidelines 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| }, | ||||||||||||
| Studio { | ||||||||||||
| target_name: String, | ||||||||||||
| handle: studio_recording::ActorHandle, | ||||||||||||
| inputs: StartRecordingInputs, | ||||||||||||
| recording_dir: PathBuf, | ||||||||||||
| common: InProgressRecordingCommon, | ||||||||||||
| }, | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -80,8 +86,8 @@ impl InProgressRecording { | |||||||||||
|
|
||||||||||||
| pub fn inputs(&self) -> &StartRecordingInputs { | ||||||||||||
| match self { | ||||||||||||
| Self::Instant { inputs, .. } => inputs, | ||||||||||||
| Self::Studio { inputs, .. } => inputs, | ||||||||||||
| Self::Instant { common, .. } => &common.inputs, | ||||||||||||
| Self::Studio { common, .. } => &common.inputs, | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -101,8 +107,8 @@ impl InProgressRecording { | |||||||||||
|
|
||||||||||||
| pub fn recording_dir(&self) -> &PathBuf { | ||||||||||||
| match self { | ||||||||||||
| Self::Instant { recording_dir, .. } => recording_dir, | ||||||||||||
| Self::Studio { recording_dir, .. } => recording_dir, | ||||||||||||
| Self::Instant { common, .. } => &common.recording_dir, | ||||||||||||
| Self::Studio { common, .. } => &common.recording_dir, | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -112,21 +118,17 @@ impl InProgressRecording { | |||||||||||
| handle, | ||||||||||||
| progressive_upload, | ||||||||||||
| video_upload_info, | ||||||||||||
| target_name, | ||||||||||||
| common, | ||||||||||||
| .. | ||||||||||||
| } => CompletedRecording::Instant { | ||||||||||||
| recording: handle.stop().await?, | ||||||||||||
| progressive_upload, | ||||||||||||
| video_upload_info, | ||||||||||||
| target_name, | ||||||||||||
| target_name: common.target_name, | ||||||||||||
| }, | ||||||||||||
| Self::Studio { | ||||||||||||
| handle, | ||||||||||||
| target_name, | ||||||||||||
| .. | ||||||||||||
| } => CompletedRecording::Studio { | ||||||||||||
| Self::Studio { handle, common, .. } => CompletedRecording::Studio { | ||||||||||||
| recording: handle.stop().await?, | ||||||||||||
| target_name, | ||||||||||||
| target_name: common.target_name, | ||||||||||||
| }, | ||||||||||||
| }) | ||||||||||||
| } | ||||||||||||
|
|
@@ -449,6 +451,12 @@ pub async fn start_recording( | |||||||||||
| .map_err(|e| format!("GetShareableContent: {e}"))? | ||||||||||||
| .ok_or_else(|| format!("GetShareableContent/NotAvailable"))?; | ||||||||||||
|
|
||||||||||||
| let common = InProgressRecordingCommon { | ||||||||||||
| target_name, | ||||||||||||
| inputs: inputs.clone(), | ||||||||||||
| recording_dir: recording_dir.clone(), | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| let actor = match inputs.mode { | ||||||||||||
| RecordingMode::Studio => { | ||||||||||||
| let mut builder = studio_recording::Actor::builder( | ||||||||||||
|
|
@@ -481,12 +489,7 @@ pub async fn start_recording( | |||||||||||
| e.to_string() | ||||||||||||
| })?; | ||||||||||||
|
|
||||||||||||
| InProgressRecording::Studio { | ||||||||||||
| handle, | ||||||||||||
| target_name, | ||||||||||||
| inputs, | ||||||||||||
| recording_dir: recording_dir.clone(), | ||||||||||||
| } | ||||||||||||
| InProgressRecording::Studio { handle, common } | ||||||||||||
| } | ||||||||||||
| RecordingMode::Instant => { | ||||||||||||
| let Some(video_upload_info) = video_upload_info.clone() else { | ||||||||||||
|
|
@@ -526,9 +529,8 @@ pub async fn start_recording( | |||||||||||
| handle, | ||||||||||||
| progressive_upload, | ||||||||||||
| video_upload_info, | ||||||||||||
| target_name, | ||||||||||||
| inputs, | ||||||||||||
| recording_dir: recording_dir.clone(), | ||||||||||||
| common, | ||||||||||||
| camera_feed, | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| }; | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| use crate::{ | ||||||
| RecordingBaseInputs, | ||||||
| capture_pipeline::{MakeCapturePipeline, ScreenCaptureMethod, Stop, create_screen_capture}, | ||||||
| feeds::microphone::MicrophoneFeedLock, | ||||||
| feeds::{camera::CameraFeedLock, microphone::MicrophoneFeedLock}, | ||||||
|
Check warning on line 4 in crates/recording/src/instant_recording.rs
|
||||||
|
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. Unused import:
Apply this diff to remove the unused import: - feeds::{camera::CameraFeedLock, microphone::MicrophoneFeedLock},
+ feeds::microphone::MicrophoneFeedLock,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| output_pipeline::{self, OutputPipeline}, | ||||||
| sources::screen_capture::{ScreenCaptureConfig, ScreenCaptureTarget}, | ||||||
| }; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,24 +7,24 @@ use cap_media_info::AudioInfo; | |||||
| use futures::{SinkExt, channel::mpsc}; | ||||||
| use std::sync::Arc; | ||||||
|
|
||||||
| pub struct Microphone(AudioInfo); | ||||||
| pub struct Microphone(AudioInfo, Arc<MicrophoneFeedLock>); | ||||||
|
|
||||||
| impl AudioSource for Microphone { | ||||||
| type Config = Arc<MicrophoneFeedLock>; | ||||||
|
|
||||||
| fn setup( | ||||||
| config: Self::Config, | ||||||
| feed_lock: Self::Config, | ||||||
| mut audio_tx: mpsc::Sender<AudioFrame>, | ||||||
| _: &mut crate::SetupCtx, | ||||||
| ) -> impl Future<Output = anyhow::Result<Self>> + 'static | ||||||
| where | ||||||
| Self: Sized, | ||||||
| { | ||||||
| async move { | ||||||
| let audio_info = config.audio_info(); | ||||||
| let audio_info = feed_lock.audio_info(); | ||||||
| let (tx, rx) = flume::bounded(8); | ||||||
|
|
||||||
| config | ||||||
| feed_lock | ||||||
| .ask(microphone::AddSender(tx)) | ||||||
| .await | ||||||
| .map_err(|e| anyhow!("Failed to add camera sender: {e}"))?; | ||||||
|
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. Fix error message to reference microphone instead of camera. The error message mentions "camera sender" but this code is for the microphone source. Apply this diff to fix the message: - .map_err(|e| anyhow!("Failed to add camera sender: {e}"))?;
+ .map_err(|e| anyhow!("Failed to add microphone sender: {e}"))?;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
@@ -40,7 +40,7 @@ impl AudioSource for Microphone { | |||||
| } | ||||||
| }); | ||||||
|
|
||||||
| Ok(Self(audio_info)) | ||||||
| Ok(Self(audio_info, feed_lock)) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
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.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Verify that the imports are actually needed.
The imports for
CameraFeedLockandMicrophoneFeedLockare not explicitly referenced by name in the code shown (types are inferred at lines 436 and 442). These might be unused imports unless they're needed elsewhere in the file.Run the following script to check if these types are explicitly used:
🏁 Script executed:
Length of output: 182
Remove unused imports of
CameraFeedLockandMicrophoneFeedLockNeither type is referenced anywhere in
apps/desktop/src-tauri/src/recording.rs; these imports can be deleted.🤖 Prompt for AI Agents