55//! Decodes the file for a few seconds and reports frame rate, timing, and the
66//! backend actually used - no Wayland or GPU required.
77
8+ use std:: process:: ExitCode ;
89use std:: time:: { Duration , Instant } ;
9- use wallr_core:: video:: { HwAccel , VideoDecoder } ;
10+ use wallr_core:: video:: { DecoderState , HwAccel , VideoDecoder } ;
1011
11- fn main ( ) {
12+ fn main ( ) -> ExitCode {
1213 let mut args = std:: env:: args ( ) . skip ( 1 ) ;
1314 let path = args. next ( ) . expect ( "usage: video_probe <video> [backend]" ) ;
1415 if path == "--capabilities" {
1516 print_capabilities ( ) ;
16- return ;
17+ return ExitCode :: SUCCESS ;
1718 }
1819 let backend = match args. next ( ) . as_deref ( ) {
1920 Some ( "vaapi" ) => HwAccel :: Vaapi ,
@@ -26,7 +27,7 @@ fn main() {
2627 Ok ( d) => d,
2728 Err ( e) => {
2829 eprintln ! ( "failed to init decoder: {e}" ) ;
29- std :: process :: exit ( 1 ) ;
30+ return ExitCode :: FAILURE ;
3031 }
3132 } ;
3233
@@ -69,14 +70,38 @@ fn main() {
6970 "decoded {count} frames in {elapsed:?} ({fps:.1} fps, {} idle polls)" ,
7071 dropped
7172 ) ;
73+ let state = decoder. decoder_state ( ) ;
7274 println ! (
7375 "active backend: {} (state: {}, dropped frames: {})" ,
7476 decoder. hw_accel_in_use( ) . name( ) ,
75- decoder . decoder_state ( ) . name( ) ,
77+ state . name( ) ,
7678 decoder. dropped_frames( )
7779 ) ;
7880 println ! ( "fallback occurred: {}" , decoder. fallback_occurred( ) ) ;
79- println ! ( "result: {}" , if count > 30 { "PASS" } else { "FAIL" } ) ;
81+ let passed = probe_passed ( count, state) ;
82+ println ! ( "result: {}" , if passed { "PASS" } else { "FAIL" } ) ;
83+ if passed {
84+ ExitCode :: SUCCESS
85+ } else {
86+ ExitCode :: FAILURE
87+ }
88+ }
89+
90+ fn probe_passed ( count : u64 , state : DecoderState ) -> bool {
91+ count > 30 && state != DecoderState :: Failed
92+ }
93+
94+ #[ cfg( test) ]
95+ mod tests {
96+ use super :: * ;
97+
98+ #[ test]
99+ fn failed_decoder_cannot_pass_after_producing_frames ( ) {
100+ assert ! ( !probe_passed( 300 , DecoderState :: Failed ) ) ;
101+ assert ! ( !probe_passed( 30 , DecoderState :: SoftwareActive ) ) ;
102+ assert ! ( probe_passed( 31 , DecoderState :: SoftwareActive ) ) ;
103+ assert ! ( probe_passed( 300 , DecoderState :: HardwareActive ) ) ;
104+ }
80105}
81106
82107fn print_capabilities ( ) {
0 commit comments