Skip to content

Commit ca22a4f

Browse files
committed
[*] update normally
1 parent db2b82a commit ca22a4f

File tree

11 files changed

+91
-36
lines changed

11 files changed

+91
-36
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ desktop-debug:
3535
desktop-debug-winit:
3636
SLINT_BACKEND=winit-femtovg $(desktop-build-env) $(run-env) cargo run --bin ${app-name} --no-default-features --features=desktop
3737

38+
desktop-run-release:
39+
$(desktop-build-env) $(run-env) cargo run --release --bin ${app-name} --no-default-features --features=desktop
40+
41+
3842
web-build:
3943
cd $(app-name) && $(web-build-env) wasm-pack build --no-opt --dev --target web --out-dir ./web/pkg --no-default-features --features=web
4044

lib/capture/examples/capture_mean_time_demo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use capture::capture_mean_time;
1+
use capture::{available_screens, capture_mean_time};
22

33
fn main() -> Result<(), Box<dyn std::error::Error>> {
4-
if let Some(avg_time) = capture_mean_time(10) {
4+
let screen_infos = available_screens()?;
5+
if let Ok(avg_time) = capture_mean_time(&screen_infos[0].name, 10) {
56
println!("Average capture time: {:.2?}", avg_time);
67
} else {
78
println!("Failed to measure capture time");

lib/capture/src/capture.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,24 +412,35 @@ fn captures_to_buffer(output_infos: &[backend::OutputInfo]) -> Result<Capture, E
412412
/// ```no_run
413413
/// use lib::capture::capture_output_mean_time;
414414
///
415-
/// if let Some(avg_time) = capture_mean_time(10) {
415+
/// if let Some(avg_time) = capture_mean_time("eDP-1", 10) {
416416
/// println!("Average capture time: {:?}", avg_time);
417417
/// } else {
418418
/// println!("Failed to measure capture time");
419419
/// }
420420
/// ```
421-
pub fn capture_mean_time(counts: u32) -> Option<Duration> {
422-
let Ok(screen_infos) = available_screens() else {
423-
return None;
424-
};
421+
pub fn capture_mean_time(screen_name: &str, counts: u32) -> Result<Duration, Error> {
422+
assert!(counts > 0);
423+
424+
let screen_infos = available_screens()?;
425+
if screen_infos.is_empty() {
426+
return Err(crate::Error::NoOutput(
427+
"available screen no found".to_string(),
428+
));
429+
}
425430

426-
if counts == 0 || screen_infos.is_empty() {
427-
return None;
431+
if screen_infos
432+
.iter()
433+
.find(|item| item.name == screen_name)
434+
.is_none()
435+
{
436+
return Err(crate::Error::NoOutput(format!(
437+
"{screen_name} is not in available screen list"
438+
)));
428439
}
429440

430441
let start = Instant::now();
431442
for _ in 0..counts {
432-
_ = capture_output(&screen_infos[0].name, true);
443+
_ = capture_output(screen_name, true);
433444
}
434-
Some(start.elapsed() / counts)
445+
Ok(start.elapsed() / counts)
435446
}

lib/recorder/examples/recording_10m_demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1919
default_input.default_config
2020
);
2121

22-
RecordingSession::init()?;
23-
2422
let screen_infos = capture::available_screens()?;
2523
assert!(!screen_infos.is_empty());
2624

2725
log::debug!("screen_infos: {screen_infos:?}");
2826

27+
RecordingSession::init(&screen_infos[0].name)?;
28+
2929
let config = RecorderConfig::new(
3030
screen_infos[0].name.clone(),
3131
screen_infos[0].logical_size.clone(),

lib/recorder/examples/recording_1s_demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99

1010
log::debug!("Recording for exactly 5 seconds...");
1111

12-
RecordingSession::init()?;
13-
1412
let screen_infos = capture::available_screens()?;
1513
assert!(!screen_infos.is_empty());
1614

1715
log::debug!("screen_infos: {screen_infos:?}");
1816

17+
RecordingSession::init(&screen_infos[0].name)?;
18+
1919
let config = RecorderConfig::new(
2020
screen_infos[0].name.clone(),
2121
screen_infos[0].logical_size.clone(),

lib/recorder/examples/recording_5s_demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1919
default_input.default_config
2020
);
2121

22-
RecordingSession::init()?;
23-
2422
let screen_infos = capture::available_screens()?;
2523
assert!(!screen_infos.is_empty());
2624

25+
RecordingSession::init(&screen_infos[0].name)?;
26+
2727
log::debug!("screen_infos: {screen_infos:?}");
2828

2929
let config = RecorderConfig::new(

lib/recorder/examples/recording_demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
66

77
log::debug!("Press Ctrl-C to stop recording.");
88

9-
RecordingSession::init()?;
10-
119
let screen_infos = capture::available_screens()?;
1210
assert!(!screen_infos.is_empty());
1311

12+
RecordingSession::init(&screen_infos[0].name)?;
13+
1414
let config = RecorderConfig::new(
1515
screen_infos[0].name.clone(),
1616
screen_infos[0].logical_size.clone(),

lib/recorder/src/recorder.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static CAPTURE_MEAN_TIME: Lazy<Mutex<Option<Duration>>> = Lazy::new(|| Mutex::ne
3939
///
4040
/// # Lifecycle
4141
///
42-
/// 1. **Initialize**: Call `RecordingSession::init()` once at application startup
42+
/// 1. **Initialize**: Call `RecordingSession::init("eDP-1")` once at application startup
4343
/// 2. **Create**: Create a new session with `RecordingSession::new(config)`
4444
/// 3. **Start**: Begin recording with `session.start()`
4545
/// 4. **Wait**: Process frames and wait for completion with `session.wait()`
@@ -53,7 +53,7 @@ static CAPTURE_MEAN_TIME: Lazy<Mutex<Option<Duration>>> = Lazy::new(|| Mutex::ne
5353
/// use std::path::PathBuf;
5454
///
5555
/// // Initialize once at application startup
56-
/// RecordingSession::init().unwrap();
56+
/// RecordingSession::init("eDP-1").unwrap();
5757
///
5858
/// // Create configuration
5959
/// let config = RecorderConfig::new(
@@ -119,19 +119,24 @@ impl RecordingSession {
119119
/// use recorder::RecordingSession;
120120
///
121121
/// // Initialize once at application startup
122-
/// RecordingSession::init().unwrap();
122+
/// RecordingSession::init("eDP-1").unwrap();
123123
/// ```
124-
pub fn init() -> Result<(), RecorderError> {
125-
let mean_time = capture::capture_mean_time(10).expect("can not evaluate capture mean time");
124+
pub fn init(screen_name: &str) -> Result<(), RecorderError> {
125+
let mean_time = capture::capture_mean_time(screen_name, 10)
126+
.expect("can not evaluate capture mean time");
126127
{
127128
*CAPTURE_MEAN_TIME.lock().unwrap() = Some(mean_time);
128129
}
129130

130-
log::debug!("capture_mean_time: {mean_time:.2?}");
131+
log::info!("capture_mean_time: {mean_time:.2?}");
131132

132133
Ok(())
133134
}
134135

136+
pub fn init_finished() -> bool {
137+
CAPTURE_MEAN_TIME.lock().unwrap().is_some()
138+
}
139+
135140
/// Create a new recording session with the given configuration.
136141
///
137142
/// This constructor sets up the internal channels and state for recording
@@ -388,6 +393,12 @@ impl RecordingSession {
388393
})
389394
.map_err(|e: AudioError| RecorderError::AudioError(e.to_string()))?;
390395

396+
let audio_recorder = if self.config.audio_amplification.is_some() {
397+
audio_recorder.with_amplification(self.config.audio_amplification.clone().unwrap())
398+
} else {
399+
audio_recorder
400+
};
401+
391402
let audio_file_path = self
392403
.config
393404
.output_path
@@ -420,11 +431,18 @@ impl RecordingSession {
420431
(None, None)
421432
};
422433

434+
let amplification = self.config.speaker_amplification.clone();
423435
let enable_preview_mode = self.config.enable_preview_mode;
424436
let handle = thread::spawn(move || {
425437
let recorder = SpeakerRecorder::new(save_path, stop_sig, sender, enable_preview_mode)
426438
.map_err(|e| RecorderError::SpeakerError(e.to_string()))?;
427439

440+
let recorder = if amplification.is_some() {
441+
recorder.with_amplification(amplification.unwrap())
442+
} else {
443+
recorder
444+
};
445+
428446
recorder
429447
.start_recording()
430448
.map_err(|e| RecorderError::SpeakerError(e.to_string()))?;

lib/recorder/src/recorder_config.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ use crate::{recorder_error::RecorderError, resolution::Resolution};
22
use capture::LogicalSize;
33
use chrono::Local;
44
use derive_setters::Setters;
5-
use std::path::{Path, PathBuf};
5+
use std::{
6+
path::{Path, PathBuf},
7+
sync::{Arc, atomic::AtomicI32},
8+
};
69

710
/// Supported frame rates for screen recording.
811
///
@@ -129,6 +132,12 @@ pub struct RecorderConfig {
129132
pub enable_speaker_channel_user: bool,
130133
/// Enable preview mode (process frames without writing to file)
131134
pub enable_preview_mode: bool,
135+
136+
#[setters(strip_option)]
137+
pub audio_amplification: Option<Arc<AtomicI32>>,
138+
139+
#[setters(strip_option)]
140+
pub speaker_amplification: Option<Arc<AtomicI32>>,
132141
}
133142

134143
impl RecorderConfig {
@@ -182,6 +191,8 @@ impl RecorderConfig {
182191
enable_audio_channel_user: false,
183192
enable_speaker_channel_user: false,
184193
enable_preview_mode: false,
194+
audio_amplification: None,
195+
speaker_amplification: None,
185196
}
186197
}
187198

lib/recorder/src/recorder_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use thiserror::Error;
1212
/// ```no_run
1313
/// use recorder::{RecordingSession, RecorderError};
1414
///
15-
/// match RecordingSession::init() {
15+
/// match RecordingSession::init("eDP-1") {
1616
/// Ok(()) => println!("Initialization successful"),
1717
/// Err(RecorderError::CaptureFailed(e)) => eprintln!("Capture failed: {}", e),
1818
/// Err(RecorderError::VideoEncodingFailed(msg)) => eprintln!("Encoding failed: {}", msg),

0 commit comments

Comments
 (0)