|
1 | 1 | use crate::{ |
2 | 2 | AudioError, AudioRecorder, CombineTracksConfig, EncodedFrame, Frame, FrameUser, H264Writer, |
3 | 3 | MAX_H264_WRITER_QUEUE_SIZE, ProgressState, RecorderConfig, RecorderError, Resolution, |
4 | | - SpeakerRecorder, StatsUser, StreamingAudioRecorder, VideoEncoder, combine_tracks, |
| 4 | + SimpleFpsCounter, SpeakerRecorder, StatsUser, StreamingAudioRecorder, VideoEncoder, |
| 5 | + combine_tracks, |
5 | 6 | }; |
6 | 7 | use capture::{Capture, CaptureIterConfig, capture_output_iter}; |
7 | 8 | use crossbeam::channel::{Receiver, Sender, bounded}; |
@@ -82,7 +83,9 @@ static CAPTURE_MEAN_TIME: Lazy<Mutex<Option<Duration>>> = Lazy::new(|| Mutex::ne |
82 | 83 | pub struct RecordingSession { |
83 | 84 | config: RecorderConfig, |
84 | 85 |
|
| 86 | + // statistic |
85 | 87 | start_time: Instant, |
| 88 | + fps_counter: SimpleFpsCounter, |
86 | 89 | total_frame_count: u64, |
87 | 90 | loss_frame_count: Arc<AtomicU64>, |
88 | 91 |
|
@@ -177,9 +180,10 @@ impl RecordingSession { |
177 | 180 | Self { |
178 | 181 | config, |
179 | 182 |
|
| 183 | + start_time: std::time::Instant::now(), |
| 184 | + fps_counter: Default::default(), |
180 | 185 | total_frame_count: 0, |
181 | 186 | loss_frame_count: Arc::new(AtomicU64::new(0)), |
182 | | - start_time: std::time::Instant::now(), |
183 | 187 |
|
184 | 188 | frame_sender: Some(Arc::new(frame_sender)), |
185 | 189 | frame_receiver, |
@@ -359,6 +363,7 @@ impl RecordingSession { |
359 | 363 | if let Some(ref sender) = self.frame_sender_user { |
360 | 364 | let frame_user = FrameUser { |
361 | 365 | stats: StatsUser { |
| 366 | + fps: self.fps_counter.add_frame(frame.timestamp), |
362 | 367 | total_frames: self.total_frame_count, |
363 | 368 | loss_frames: self.loss_frame_count.load(Ordering::Relaxed), |
364 | 369 | }, |
@@ -663,7 +668,7 @@ impl RecordingSession { |
663 | 668 | Ok((total_frame_index, frame)) => { |
664 | 669 | let frame_timestamp = frame.timestamp.duration_since(start_time); |
665 | 670 | log::debug!( |
666 | | - "total frame[{}] thread[{}] thread_frame[{}] capture time: {:.2?}. fps: {:.2}. timestamp: {:.2?}. chanenel remained: {}", |
| 671 | + "total frame[{}] thread[{}] thread_frame[{}] capture time: {:.2?}. thread_fps: {:.2}. timestamp: {:.2?}. chanenel remained: {}", |
667 | 672 | total_frame_index, |
668 | 673 | frame.thread_id, |
669 | 674 | frame.cb_data.frame_index, |
@@ -859,11 +864,12 @@ impl RecordingSession { |
859 | 864 | } |
860 | 865 |
|
861 | 866 | log::info!( |
862 | | - "Total frame: {}. loss frame: {} ({:.2}%)", |
| 867 | + "Total frame: {}. loss frame: {} ({:.2}%). fps: {:.2}", |
863 | 868 | self.total_frame_count, |
864 | 869 | self.loss_frame_count.load(Ordering::Relaxed), |
865 | 870 | self.loss_frame_count.load(Ordering::Relaxed) as f64 * 100.0 |
866 | 871 | / self.total_frame_count.max(1) as f64, |
| 872 | + self.fps_counter.fps, |
867 | 873 | ); |
868 | 874 |
|
869 | 875 | Ok(()) |
|
0 commit comments