Skip to content

Commit 7d7a97c

Browse files
committed
[*] update normally
1 parent 199b6b5 commit 7d7a97c

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

lib/recorder/src/h264_writer.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,6 @@ use std::{
99
time::Duration,
1010
};
1111

12-
/// Maximum queue size for H.264 writer to prevent memory overflow.
13-
///
14-
/// This constant defines the maximum number of encoded frames that can be
15-
/// queued for writing to disk. If the queue fills up, older frames may be
16-
/// dropped to maintain real-time performance.
17-
///
18-
/// # Examples
19-
///
20-
/// ```no_run
21-
/// use recorder::{H264Writer, MAX_H264_WRITER_QUEUE_SIZE};
22-
///
23-
/// let writer = H264Writer::new("output.h264".into(), MAX_H264_WRITER_QUEUE_SIZE);
24-
/// ```
25-
pub const MAX_H264_WRITER_QUEUE_SIZE: usize = 64;
26-
2712
/// H.264 file writer that handles frame queuing and file output.
2813
///
2914
/// This struct manages the writing of encoded H.264 frames to disk using
@@ -41,9 +26,9 @@ pub const MAX_H264_WRITER_QUEUE_SIZE: usize = 64;
4126
/// # Examples
4227
///
4328
/// ```no_run
44-
/// use recorder::{H264Writer, EncodedFrame, MAX_H264_WRITER_QUEUE_SIZE};
29+
/// use recorder::{H264Writer, EncodedFrame};
4530
///
46-
/// let writer = H264Writer::new("output.h264".into(), MAX_H264_WRITER_QUEUE_SIZE);
31+
/// let writer = H264Writer::new("output.h264".into(), 2);
4732
///
4833
/// // Write frames as they become available
4934
/// // writer.write_frame(encoded_frame);
@@ -70,26 +55,25 @@ impl H264Writer {
7055
/// # Arguments
7156
///
7257
/// * `output_path` - Path where the H.264 file will be created
73-
/// * `queue_size` - Maximum number of frames to queue (must be > 0 and ≤ MAX_H264_WRITER_QUEUE_SIZE)
58+
/// * `queue_size` - Maximum number of frames to queue (must be > 0)
7459
///
7560
/// # Returns
7661
///
7762
/// A new `H264Writer` instance ready to receive frames.
7863
///
7964
/// # Panics
8065
///
81-
/// Panics if `queue_size` is 0 or exceeds `MAX_H264_WRITER_QUEUE_SIZE`.
66+
/// Panics if `queue_size` is 0.
8267
///
8368
/// # Examples
8469
///
8570
/// ```no_run
86-
/// use recorder::{H264Writer, MAX_H264_WRITER_QUEUE_SIZE};
71+
/// use recorder::{H264Writer};
8772
///
88-
/// let writer = H264Writer::new("recording.h264".into(), 1024);
73+
/// let writer = H264Writer::new("recording.h264".into(), 8);
8974
/// ```
9075
pub fn new(output_path: PathBuf, queue_size: usize) -> Self {
9176
assert!(queue_size > 0);
92-
assert!(queue_size <= MAX_H264_WRITER_QUEUE_SIZE);
9377

9478
let (frame_sender, frame_receiver) = bounded::<EncodedFrame>(queue_size);
9579

@@ -142,6 +126,11 @@ impl H264Writer {
142126
log::info!("Creating H.264 file: {}", output_path.display());
143127

144128
while let Ok(frame) = frame_receiver.recv() {
129+
log::debug!(
130+
"h264 writer thread frame receiver remained: {}",
131+
frame_receiver.capacity().unwrap_or_default() - frame_receiver.len()
132+
);
133+
145134
match frame {
146135
EncodedFrame::Frame((_frame_index, frame_data)) => {
147136
if let Err(e) = h264_file.write_all(&frame_data) {

lib/recorder/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub use mp4_ffmpeg::{combine_tracks, is_ffmpeg_installed};
8383

8484
pub use audio_level::*;
8585
pub use crossbeam::channel::{Receiver, Sender, bounded};
86-
pub use h264_writer::{H264Writer, MAX_H264_WRITER_QUEUE_SIZE};
86+
pub use h264_writer::H264Writer;
8787
pub use record_audio::{
8888
AudioConfig, AudioDeviceInfo, AudioError, AudioFileWriter, AudioRecorder,
8989
AudioRecordingSession, StreamingAudioRecorder,

lib/recorder/src/recorder.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const SPEAKER_AUDIO_EXTENSION: &str = "speaker.wav";
3030
const TMP_OUTPUT_VIDEO_EXTENSION: &str = "tmp.mp4";
3131

3232
const USER_CHANNEL_SIZE: usize = 3;
33-
const RESIZE_WORKER_CHANNEL_SIZE: usize = 16;
34-
pub const ENCODER_WORKER_CHANNEL_SIZE: usize = 32;
33+
const RESIZE_WORKER_CHANNEL_SIZE: usize = 8;
34+
const ENCODER_WORKER_CHANNEL_SIZE: usize = 64;
3535

3636
static CAPTURE_MEAN_TIME: Lazy<Mutex<Option<Duration>>> = Lazy::new(|| Mutex::new(None));
3737

@@ -708,6 +708,18 @@ impl RecordingSession {
708708
}
709709
}
710710

711+
{
712+
let mut s = String::default();
713+
for (index, sender) in resize_senders.iter().enumerate() {
714+
s.push_str(&format!(
715+
"send[{index}] remained: {}. ",
716+
sender.capacity().unwrap_or_default() - sender.len()
717+
));
718+
}
719+
720+
log::debug!("{s}");
721+
}
722+
711723
let sender = resize_senders
712724
.iter()
713725
.min_by(|a, b| a.len().cmp(&b.len()))

lib/recorder/src/video_encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl VideoEncoder {
252252
// Calculate timestamp in milliseconds (frame_index * 1000 / fps)
253253
let timestamp_ms = (self.frame_index * 1000) / self.fps.to_u32() as u64;
254254

255-
// Encode frame
255+
// NOTE: It will eat your memory (about 1G)
256256
let (data, _) = self
257257
.encoder
258258
.encode(timestamp_ms as i64, image)

0 commit comments

Comments
 (0)