File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -373,8 +373,9 @@ pub unsafe fn copy_to_rust(ccx_s_options: *const ccx_s_options) -> Options {
373373 options. live_stream = if ( * ccx_s_options) . live_stream < 0 {
374374 None
375375 } else {
376+ // C stores the timeout in seconds
376377 Some ( Timestamp :: from_millis (
377- ( ( * ccx_s_options) . live_stream ) as i64 ,
378+ 1000 * ( ( * ccx_s_options) . live_stream ) as i64 ,
378379 ) )
379380 } ;
380381
@@ -1206,3 +1207,25 @@ impl CType<avc_ctx> for AvcContextRust {
12061207 }
12071208 }
12081209}
1210+
1211+ #[ cfg( test) ]
1212+ mod tests {
1213+ use super :: * ;
1214+
1215+ #[ test]
1216+ fn test_live_stream_seconds_round_trip ( ) {
1217+ // C keeps the --stream timeout in seconds; the Rust Options keep a Timestamp
1218+ let options = Options {
1219+ live_stream : Some ( Timestamp :: from_millis ( 2000 ) ) ,
1220+ ..Default :: default ( )
1221+ } ;
1222+ unsafe {
1223+ let mut c_options: ccx_s_options = std:: mem:: zeroed ( ) ;
1224+ copy_from_rust ( & mut c_options, options) ;
1225+ assert_eq ! ( c_options. live_stream, 2 ) ;
1226+
1227+ let back = copy_to_rust ( & c_options) ;
1228+ assert_eq ! ( back. live_stream. map( |t| t. seconds( ) ) , Some ( 2 ) ) ;
1229+ }
1230+ }
1231+ }
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ pub fn sleepandchecktimeout(start: u64, ccx_options: &mut Options) {
134134
135135 if let Some ( live_stream) = ccx_options. live_stream {
136136 if live_stream. seconds ( ) != 0 {
137- if current_time > start + live_stream. millis ( ) as u64 {
137+ if current_time > start + live_stream. seconds ( ) as u64 {
138138 // Timeout elapsed
139139 ccx_options. live_stream = Option :: from ( Timestamp :: from_millis ( 0 ) ) ;
140140 } else {
@@ -884,6 +884,22 @@ mod tests {
884884 assert ! ( ( null_mut:: <* mut u8 >( ) ) . is_null( ) ) ;
885885 }
886886 }
887+ #[ test]
888+ fn test_sleepandchecktimeout_timeout_elapsed ( ) {
889+ // --stream 2: the file stopped growing 10 seconds ago, so the timeout has passed
890+ let mut ccx_options = Options :: default ( ) ;
891+ ccx_options. input_source = DataSource :: File ;
892+ ccx_options. live_stream = Some ( Timestamp :: from_millis ( 2000 ) ) ;
893+ let now = SystemTime :: now ( )
894+ . duration_since ( UNIX_EPOCH )
895+ . unwrap ( )
896+ . as_secs ( ) ;
897+
898+ sleepandchecktimeout ( now - 10 , & mut ccx_options) ;
899+
900+ assert_eq ! ( ccx_options. live_stream. unwrap( ) . millis( ) , 0 ) ;
901+ }
902+
887903 // #[test] // Uncomment to run, needs real file
888904 #[ allow( unused) ]
889905 fn test_switch_to_next_file_success ( ) {
You can’t perform that action at this time.
0 commit comments