Skip to content

Commit 51acc39

Browse files
committed
skip over packets without frames when initializing the decoder
1 parent 59893b8 commit 51acc39

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/decoder/symphonia.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ impl SymphoniaDecoder {
113113
continue;
114114
}
115115

116-
match decoder.decode(&current_span) {
117-
Ok(decoded) => break decoded,
116+
let decoded = match decoder.decode(&current_span) {
117+
Ok(decoded) => decoded,
118118
Err(e) => match e {
119119
Error::DecodeError(_) => {
120120
// Decode errors are intentionally ignored with no retry limit.
@@ -124,6 +124,15 @@ impl SymphoniaDecoder {
124124
}
125125
_ => return Err(e),
126126
},
127+
};
128+
129+
// Loop until we get a packet with audio frames. This is necessary because some
130+
// formats can have packets with only metadata, particularly when rewinding, in
131+
// which case the iterator would otherwise end with `None`.
132+
// Note: checking `decoded.frames()` is more reliable than `packet.dur()`, which
133+
// can resturn non-zero durations for packets without audio frames.
134+
if decoded.frames() > 0 {
135+
break decoded;
127136
}
128137
};
129138
let spec = decoded.spec().to_owned();

0 commit comments

Comments
 (0)