Skip to content

Commit 5f1b057

Browse files
author
apolunar
committed
improved error handling
1 parent 3bc9647 commit 5f1b057

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/decoder/symphonia.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Duration;
22
use symphonia::{
33
core::{
44
audio::{AudioBufferRef, SampleBuffer, SignalSpec},
5-
codecs::{Decoder, CODEC_TYPE_NULL},
5+
codecs::{Decoder, DecoderOptions, CODEC_TYPE_NULL},
66
errors::Error,
77
formats::{FormatOptions, FormatReader, SeekedTo},
88
io::MediaSourceStream,
@@ -77,13 +77,19 @@ impl SymphoniaDecoder {
7777
};
7878

7979
// Select the first supported track
80-
let track_id = probed
80+
let track_id = match probed
8181
.format
8282
.tracks()
8383
.iter()
8484
.find(|t| t.codec_params.codec != CODEC_TYPE_NULL)
85-
.unwrap()
86-
.id;
85+
{
86+
Some(track) => track.id,
87+
None => {
88+
return Err(symphonia::core::errors::Error::Unsupported(
89+
"No track with supported codec",
90+
))
91+
}
92+
};
8793

8894
let track = probed
8995
.format
@@ -92,8 +98,8 @@ impl SymphoniaDecoder {
9298
.find(|track| track.id == track_id)
9399
.unwrap();
94100

95-
let mut decoder =
96-
symphonia::default::get_codecs().make(&track.codec_params, &Default::default())?;
101+
let mut decoder = symphonia::default::get_codecs()
102+
.make(&track.codec_params, &DecoderOptions::default())?;
97103
let total_duration = stream
98104
.codec_params
99105
.time_base
@@ -104,10 +110,8 @@ impl SymphoniaDecoder {
104110
let decoded = loop {
105111
let current_frame = match probed.format.next_packet() {
106112
Ok(packet) => packet,
107-
Err(e) => match e {
108-
Error::IoError(_) => break decoder.last_decoded(),
109-
_ => return Err(e),
110-
},
113+
Err(Error::IoError(_)) => break decoder.last_decoded(),
114+
Err(e) => return Err(e),
111115
};
112116

113117
// If the packet does not belong to the selected track, skip over it

0 commit comments

Comments
 (0)