@@ -30,6 +30,10 @@ fn sink_and_decoder(format: &str) -> (Sink, Decoder<impl Read + Seek>) {
30
30
( sink, decoder)
31
31
}
32
32
33
+ // run the following to get the other configuration:
34
+ // cargo test --no-default-features
35
+ // --features symphonia-wav --features symphonia-vorbis
36
+ // --features symphonia-flac --features symphonia-isomp4 --features minimp3
33
37
fn format_decoder_info ( ) -> & ' static [ ( & ' static str , bool , & ' static str ) ] {
34
38
& [
35
39
#[ cfg( feature = "minimp3" ) ]
@@ -42,14 +46,16 @@ fn format_decoder_info() -> &'static [(&'static str, bool, &'static str)] {
42
46
( "wav" , true , "symphonia" ) ,
43
47
#[ cfg( feature = "lewton" ) ]
44
48
( "ogg" , true , "lewton" ) ,
45
- #[ cfg( feature = "symphonia-vorbis" ) ]
46
- ( "ogg" , true , "symphonia" ) ,
49
+ // note: disabled, symphonia returns error unsupported format
50
+ // #[cfg(feature = "symphonia-vorbis")]
51
+ // ("ogg", true, "symphonia"),
47
52
#[ cfg( feature = "claxon" ) ]
48
53
( "flac" , false , "claxon" ) ,
49
54
#[ cfg( feature = "symphonia-flac" ) ]
50
55
( "flac" , true , "symphonia" ) ,
51
- #[ cfg( feature = "symphonia-isomp4" ) ]
52
- ( "m4a" , true , "_" ) ,
56
+ // note: disabled, symphonia returns error unsupported format
57
+ // #[cfg(feature = "symphonia-isomp4")]
58
+ // ("m4a", true, "symphonia"),
53
59
]
54
60
}
55
61
@@ -64,17 +70,38 @@ fn seek_returns_err_if_unsupported() {
64
70
}
65
71
}
66
72
67
- #[ test]
68
- fn seek_beyond_end_does_not_crash ( ) {
73
+ // #[ignore]
74
+ #[ test] // in the future use PR #510 (playback position) to speed this up
75
+ fn seek_beyond_end_saturates ( ) {
69
76
for ( format, _, decoder_name) in format_decoder_info ( )
70
77
. iter ( )
71
78
. cloned ( )
72
79
. filter ( |( _, supported, _) | * supported)
73
80
{
74
81
let ( sink, decoder) = sink_and_decoder ( format) ;
75
- println ! ( "seeking beyond end in: {format}\t decoded by: {decoder_name}" ) ;
76
82
sink. append ( decoder) ;
77
- sink. try_seek ( Duration :: from_secs ( 999 ) ) . unwrap ( ) ;
83
+
84
+ println ! ( "seeking beyond end for: {format}\t decoded by: {decoder_name}" ) ;
85
+ let res = sink. try_seek ( Duration :: from_secs ( 999 ) ) ;
86
+ assert ! ( res. is_ok( ) ) ;
87
+
88
+ let now = Instant :: now ( ) ;
89
+ sink. sleep_until_end ( ) ;
90
+ let elapsed = now. elapsed ( ) ;
91
+ assert ! ( elapsed. as_secs( ) < 1 ) ;
92
+ }
93
+ }
94
+
95
+ fn total_duration ( format : & ' static str ) -> Duration {
96
+ let ( sink, decoder) = sink_and_decoder ( format) ;
97
+ match decoder. total_duration ( ) {
98
+ Some ( d) => d,
99
+ None => {
100
+ let now = Instant :: now ( ) ;
101
+ sink. append ( decoder) ;
102
+ sink. sleep_until_end ( ) ;
103
+ now. elapsed ( )
104
+ }
78
105
}
79
106
}
80
107
@@ -86,33 +113,26 @@ fn seek_results_in_correct_remaining_playtime() {
86
113
. cloned ( )
87
114
. filter ( |( _, supported, _) | * supported)
88
115
{
89
- let ( sink, decoder) = sink_and_decoder ( format) ;
90
- println ! ( "checking seek time in: {format}\t decoded by: {decoder_name}" ) ;
91
- let total_duration = match decoder. total_duration ( ) {
92
- Some ( d) => d,
93
- None => {
94
- let now = Instant :: now ( ) ;
95
- sink. append ( decoder) ;
96
- sink. sleep_until_end ( ) ;
97
- now. elapsed ( )
98
- }
99
- } ;
116
+ println ! ( "checking seek duration for: {format}\t decoded by: {decoder_name}" ) ;
100
117
101
118
let ( sink, decoder) = sink_and_decoder ( format) ;
102
119
sink. append ( decoder) ;
103
120
104
121
const SEEK_BEFORE_END : Duration = Duration :: from_secs ( 5 ) ;
105
- sink. try_seek ( total_duration - SEEK_BEFORE_END ) . unwrap ( ) ;
122
+ sink. try_seek ( total_duration ( format) - SEEK_BEFORE_END )
123
+ . unwrap ( ) ;
106
124
107
125
let now = Instant :: now ( ) ;
108
126
sink. sleep_until_end ( ) ;
109
127
let elapsed = now. elapsed ( ) ;
110
128
let expected = SEEK_BEFORE_END ;
111
129
112
130
if elapsed. as_millis ( ) . abs_diff ( expected. as_millis ( ) ) > 250 {
113
- panic ! ( "Seek did not result in expected leftover playtime
131
+ panic ! (
132
+ "Seek did not result in expected leftover playtime
114
133
leftover time: {elapsed:?}
115
- expected time left in source: {SEEK_BEFORE_END:?}" ) ;
134
+ expected time left in source: {SEEK_BEFORE_END:?}"
135
+ ) ;
116
136
}
117
137
}
118
138
}
0 commit comments