11use crate :: {
22 bitrate:: BitrateManager ,
33 buttons:: BUTTON_PATH_FROM_ID ,
4+ create_recording_file,
45 face_tracking:: FaceTrackingSink ,
56 haptics,
67 sockets:: WelcomeSocket ,
@@ -42,7 +43,7 @@ use std::{
4243 Arc ,
4344 } ,
4445 thread,
45- time:: Duration ,
46+ time:: { Duration , Instant } ,
4647} ;
4748
4849const RETRY_CONNECT_MIN_INTERVAL : Duration = Duration :: from_secs ( 1 ) ;
@@ -1036,7 +1037,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
10361037 }
10371038 }
10381039
1039- if settings. capture . save_video_stream {
1040+ if settings. capture . startup_video_recording {
10401041 crate :: create_recording_file ( ) ;
10411042 }
10421043
@@ -1101,6 +1102,7 @@ fn try_connect(mut client_ips: HashMap<IpAddr, String>) -> ConResult {
11011102pub extern "C" fn send_video ( timestamp_ns : u64 , buffer_ptr : * mut u8 , len : i32 , is_idr : bool ) {
11021103 // start in the corrupts state, the client didn't receive the initial IDR yet.
11031104 static STREAM_CORRUPTED : AtomicBool = AtomicBool :: new ( true ) ;
1105+ static LAST_IDR_INSTANT : Lazy < Mutex < Instant > > = Lazy :: new ( || Mutex :: new ( Instant :: now ( ) ) ) ;
11041106
11051107 if let Some ( sender) = & * VIDEO_CHANNEL_SENDER . lock ( ) {
11061108 let buffer_size = len as usize ;
@@ -1109,6 +1111,22 @@ pub extern "C" fn send_video(timestamp_ns: u64, buffer_ptr: *mut u8, len: i32, i
11091111 STREAM_CORRUPTED . store ( false , Ordering :: SeqCst ) ;
11101112 }
11111113
1114+ if let Switch :: Enabled ( config) = & SERVER_DATA_MANAGER
1115+ . read ( )
1116+ . settings ( )
1117+ . capture
1118+ . rolling_video_files
1119+ {
1120+ if Instant :: now ( ) > * LAST_IDR_INSTANT . lock ( ) + Duration :: from_secs ( config. duration_s ) {
1121+ unsafe { crate :: RequestIDR ( ) } ;
1122+
1123+ if is_idr {
1124+ create_recording_file ( ) ;
1125+ * LAST_IDR_INSTANT . lock ( ) = Instant :: now ( ) ;
1126+ }
1127+ }
1128+ }
1129+
11121130 let timestamp = Duration :: from_nanos ( timestamp_ns) ;
11131131
11141132 let mut payload = vec ! [ 0 ; buffer_size] ;
0 commit comments