Skip to content

Commit 8726ec8

Browse files
committed
[*] update normally
1 parent 4c1e1bf commit 8726ec8

File tree

4 files changed

+12
-71
lines changed

4 files changed

+12
-71
lines changed

lib/recorder/examples/merge_tracks_demo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2828
output_path: output_path.clone(),
2929
fps: FPS::Fps30,
3030
stop_sig: Arc::new(AtomicBool::new(false)),
31+
convert_input_wav_to_mono: false,
3132
};
3233

3334
let now = std::time::Instant::now();

lib/recorder/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ pub use crossbeam::channel::{Receiver, Sender, bounded};
8484
pub use h264_writer::H264Writer;
8585
pub use mp4_ffmpeg::{is_ffmpeg_installed, merge_tracks};
8686
pub use record_audio::{
87-
AudioDeviceInfo, AudioError, AudioFileWriter, AudioRecorder, AudioRecordingSession,
88-
StreamingAudioRecorder,
87+
AudioDeviceInfo, AudioError, AudioFileWriter, AudioRecorder, StreamingAudioRecorder,
8988
};
9089
pub use record_speaker::{SpeakerError, SpeakerRecorder};
9190
pub use recorder::RecordingSession;

lib/recorder/src/record_audio.rs

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl AudioRecorder {
294294
&self,
295295
device_name: &str,
296296
callback: impl FnMut(&[f32], &InputCallbackInfo) + Send + 'static,
297-
) -> Result<AudioRecordingSession, AudioError> {
297+
) -> Result<Arc<Mutex<Option<Stream>>>, AudioError> {
298298
let (stream_config, _) = self.get_config(device_name)?;
299299

300300
let physical_device = self
@@ -319,54 +319,7 @@ impl AudioRecorder {
319319
.play()
320320
.map_err(|e| AudioError::StreamError(e.to_string()))?;
321321

322-
Ok(AudioRecordingSession {
323-
stream: Arc::new(Mutex::new(Some(stream))),
324-
})
325-
}
326-
}
327-
328-
/// Active audio recording session
329-
pub struct AudioRecordingSession {
330-
stream: Arc<Mutex<Option<Stream>>>,
331-
}
332-
333-
impl std::fmt::Debug for AudioRecordingSession {
334-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
335-
f.debug_struct("AudioRecordingSession")
336-
.field("is_active", &self.is_active())
337-
.finish()
338-
}
339-
}
340-
341-
impl AudioRecordingSession {
342-
/// Stop the audio recording session
343-
pub fn stop(&self) -> Result<(), AudioError> {
344-
let mut stream_guard = self
345-
.stream
346-
.lock()
347-
.map_err(|_| AudioError::StreamError("Failed to lock stream".to_string()))?;
348-
349-
if let Some(stream) = stream_guard.take() {
350-
drop(stream);
351-
}
352-
353-
Ok(())
354-
}
355-
356-
/// Check if the recording session is active
357-
pub fn is_active(&self) -> bool {
358-
let stream_guard = match self.stream.lock() {
359-
Ok(guard) => guard,
360-
Err(_) => return false,
361-
};
362-
363-
stream_guard.is_some()
364-
}
365-
}
366-
367-
impl Drop for AudioRecordingSession {
368-
fn drop(&mut self) {
369-
_ = self.stop();
322+
Ok(Arc::new(Mutex::new(Some(stream))))
370323
}
371324
}
372325

@@ -375,14 +328,6 @@ pub struct AudioFileWriter {
375328
writer: Option<WavWriter<BufWriter<File>>>,
376329
}
377330

378-
impl std::fmt::Debug for AudioFileWriter {
379-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
380-
f.debug_struct("AudioFileWriter")
381-
.field("is_active", &self.writer.is_some())
382-
.finish()
383-
}
384-
}
385-
386331
impl AudioFileWriter {
387332
/// Create a new WAV file writer
388333
pub fn new<P: AsRef<Path>>(
@@ -437,10 +382,10 @@ impl Drop for AudioFileWriter {
437382
}
438383

439384
/// Streaming audio recorder that writes to file in real-time
440-
#[derive(Debug)]
385+
// #[derive(Debug)]
441386
pub struct StreamingAudioRecorder {
442387
file_writer: Arc<Mutex<Option<AudioFileWriter>>>,
443-
recording_session: AudioRecordingSession,
388+
recording_session: Arc<Mutex<Option<Stream>>>,
444389
audio_level_receiver: Option<Arc<Receiver<f32>>>,
445390
}
446391

@@ -505,22 +450,19 @@ impl StreamingAudioRecorder {
505450

506451
/// Stop the streaming audio recording
507452
pub fn stop(self) -> Result<(), AudioError> {
508-
self.recording_session.stop()?;
509-
510-
if let Ok(mut writer) = self.file_writer.lock()
511-
&& let Some(ref mut writer) = *writer
512453
{
454+
if let Some(stream) = self.recording_session.lock().unwrap().take() {
455+
drop(stream);
456+
}
457+
}
458+
459+
if let Some(mut writer) = self.file_writer.lock().unwrap().take() {
513460
writer.finalize()?;
514461
}
515462

516463
Ok(())
517464
}
518465

519-
/// Check if the streaming recorder is active
520-
pub fn is_active(&self) -> bool {
521-
self.recording_session.is_active()
522-
}
523-
524466
pub fn get_audio_level_receiver(&self) -> Option<Arc<Receiver<f32>>> {
525467
self.audio_level_receiver.clone()
526468
}

lib/recorder/src/recorder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static CAPTURE_MEAN_TIME: Lazy<Mutex<Option<Duration>>> = Lazy::new(|| Mutex::ne
8383
/// Err(e) => eprintln!("Recording failed: {}", e),
8484
/// }
8585
/// ```
86-
#[derive(Debug)]
8786
pub struct RecordingSession {
8887
config: RecorderConfig,
8988

0 commit comments

Comments
 (0)