]> git.nihav.org Git - nihav-player.git/commitdiff
improve error reporting in audio decoder part
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 18 Jun 2023 14:10:39 +0000 (16:10 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 18 Jun 2023 14:10:39 +0000 (16:10 +0200)
videoplayer/src/audiodec.rs

index 3ed639881d56c241f9fab18b6e3f2e36d81466e3..bddec5745a6dce2df1eae5cfffb84e8d6fde039b 100644 (file)
@@ -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<DecoderStuff>, ainfo: Option<NAAudioInfo>, asystem: &AudioSubsystem) -> Self {
         let (apsend, aprecv) = std::sync::mpsc::sync_channel::<PktSendEvent>(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))
             };