]> git.nihav.org Git - nihav-player.git/blobdiff - sndplay/src/main.rs
sndplay: support playing AAC with SBR
[nihav-player.git] / sndplay / src / main.rs
index c8e75a420731439355bad5c45ef1e7f432485aa7..4741853702fc81cedb211964d4b4993eade3d25c 100644 (file)
@@ -153,6 +153,9 @@ impl<'a> Decoder<'a> {
                                 if let Some(pts) = frm.ts.get_pts() {
                                     self.samplepos = NATimeInfo::ts_to_time(pts, u64::from(self.arate), frm.ts.tb_num, frm.ts.tb_den);
                                 }
+                                if buf.get_audio_length() == 0 {
+                                    return false;
+                                }
                                 let out_buf = convert_audio_frame(&buf, &self.dst_info, &self.dst_chmap).unwrap();
                                 match out_buf {
                                     NABufferType::AudioI16(abuf) => {
@@ -193,6 +196,7 @@ impl<'a> Decoder<'a> {
     fn seek(&mut self, time: u64) -> bool {
         let ret = self.demuxer.seek(NATimePoint::Milliseconds(time));
 if ret.is_err() { println!(" seek error\n"); }
+        self.decoder.flush();
         ret.is_ok()
     }
 }
@@ -299,8 +303,16 @@ impl Player {
         }
         let (dsupp, decoder) = dec.unwrap();
 
-        let ainfo = ainfo.unwrap().get_properties().get_audio_info().unwrap();
-        let arate = if ainfo.sample_rate > 0 { ainfo.sample_rate } else { 44100 };
+        let info = ainfo.unwrap();
+        let ainfo = info.get_properties().get_audio_info().unwrap();
+        let sbr_hack = info.get_name() == "aac" && ainfo.sample_rate < 32000;
+        let arate = if ainfo.sample_rate > 0 {
+                if !sbr_hack {
+                    ainfo.sample_rate
+                } else {
+                    ainfo.sample_rate * 2
+                }
+            } else { 44100 };
         let ch    = ainfo.channels;
 
         println!("Playing {} [{}Hz {}ch]", name, arate, ch);
@@ -359,7 +371,7 @@ impl Player {
                 }
             }
             std::io::stdout().flush().unwrap();
-            if device.size() < underfill_limit && !self.paused && refill_limit < (1 << 20) {
+            if device.size() < underfill_limit && !self.paused && (refill_limit < (1 << 20)) & !eof {
                 if full_ms > 5000 {
                     println!("underrun!");
                 }