From 54ede18180302b14e7de9cc033d1be66592db796 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sun, 18 Jun 2023 16:10:39 +0200 Subject: [PATCH] improve error reporting in audio decoder part --- videoplayer/src/audiodec.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/videoplayer/src/audiodec.rs b/videoplayer/src/audiodec.rs index 3ed6398..bddec57 100644 --- a/videoplayer/src/audiodec.rs +++ b/videoplayer/src/audiodec.rs @@ -122,7 +122,7 @@ impl AudioCallback for AudioOutput { type Channel = i16; fn callback(&mut self, out: &mut [Self::Channel]) { - let mut queue = self.queue.lock().unwrap(); + let mut queue = self.queue.lock().expect("audio queue should be accessible"); let dstlen = out.len(); let copylen = queue.fill().min(dstlen); let volume = AUDIO_VOLUME.load(Ordering::Relaxed) as i32; @@ -183,9 +183,9 @@ fn start_audio_decoding(asystem: &AudioSubsystem, ainfo: NAAudioInfo, mut audio_ let adec = if let DecoderType::Audio(ref mut dec) = audio_dec.dec { dec } else { panic!("not an audio decoder!"); }; let mut samplepos = 0usize; let dst_chmap = if dst_info.channels == 2 { - NAChannelMap::from_str("L,R").unwrap() + NAChannelMap::from_str("L,R").expect("should be able to create stereo channel map") } else { - NAChannelMap::from_str("C").unwrap() + NAChannelMap::from_str("C").expect("should be able to create single-channel map") }; ADEC_STATE.set_state(DecodingState::Normal); loop { @@ -208,12 +208,12 @@ fn start_audio_decoding(asystem: &AudioSubsystem, ainfo: NAAudioInfo, mut audio_ if let Ok(out_buf) = convert_audio_frame(&buf, &dst_info, &dst_chmap) { match out_buf { NABufferType::AudioI16(abuf) => { - let mut qdata = queue.lock().unwrap(); + let mut qdata = queue.lock().expect("audio queue should be accessible"); qdata.add(abuf.get_data(), samplepos); drop(qdata); }, NABufferType::AudioPacked(abuf) => { - let mut qdata = queue.lock().unwrap(); + let mut qdata = queue.lock().expect("audio queue should be accessible"); qdata.add_bytes(abuf.get_data(), samplepos); drop(qdata); }, @@ -226,13 +226,13 @@ fn start_audio_decoding(asystem: &AudioSubsystem, ainfo: NAAudioInfo, mut audio_ Ok(PktSendEvent::GetFrames) => {}, Ok(PktSendEvent::Flush) => { adec.flush(); - let mut qdata = queue.lock().unwrap(); + let mut qdata = queue.lock().expect("audio queue should be accessible"); qdata.flush(); ADEC_STATE.set_state(DecodingState::Waiting); }, Ok(PktSendEvent::End) => break, Ok(PktSendEvent::ImmediateEnd) => { - let mut qdata = queue.lock().unwrap(); + let mut qdata = queue.lock().expect("audio queue should be accessible"); qdata.flush(); break; }, @@ -243,7 +243,7 @@ fn start_audio_decoding(asystem: &AudioSubsystem, ainfo: NAAudioInfo, mut audio_ }; } loop { - let qdata = queue.lock().unwrap(); + let qdata = queue.lock().expect("audio queue should be accessible"); if qdata.fill() == 0 || ADEC_STATE.is_flushing() { break; } @@ -263,7 +263,7 @@ impl AudioControl { pub fn new(audio_dec: Option, ainfo: Option, asystem: &AudioSubsystem) -> Self { let (apsend, aprecv) = std::sync::mpsc::sync_channel::(20); let (adevice, athread) = if let Some(audio_dec) = audio_dec { - start_audio_decoding(asystem, ainfo.unwrap(), audio_dec, aprecv) + start_audio_decoding(asystem, ainfo.expect("audio info should be present"), audio_dec, aprecv) } else { (None, dummy_audio_thread(aprecv)) }; -- 2.39.5