videoplayer: add a hack to play AAC with SBR properly
[nihav-player.git] / videoplayer / src / main.rs
index 674a243ae49ab9d55e9a3198deb63781e6deb01d..e3d2d002a1ddba0514859aada31504f043760825 100644 (file)
@@ -332,7 +332,7 @@ impl Player {
         let vsystem = sdl_context.video().expect("video subsystem init failure");
         let asystem = sdl_context.audio().expect("audio subsystem init failure");
         vsystem.disable_screen_saver();
-        let acontrol = AudioControl::new(None, None, &asystem);
+        let acontrol = AudioControl::new(None, None, false, &asystem);
         let vcontrol = VideoControl::new(None, 0, 0, 0, 0);
         Self {
             sdl_context, asystem, vsystem,
@@ -596,6 +596,7 @@ impl Player {
         let mut tb_num = 0;
         let mut tb_den = 0;
         let mut ainfo: Option<NAAudioInfo> = None;
+        let mut sbr_hack = false;
 
         let mut video_dec: Option<DecoderStuff> = None;
         let mut audio_dec: Option<DecoderStuff> = None;
@@ -677,6 +678,11 @@ impl Player {
                         let mut dec = (decfunc)();
                         let mut dsupp = Box::new(NADecoderSupport::new());
                         ainfo = info.get_properties().get_audio_info();
+                        if let (true, Some(ref ai)) = (info.get_name() == "aac", ainfo) {
+                            if ai.sample_rate < 32000 {
+                                sbr_hack = true;
+                            }
+                        }
                         if dec.init(&mut dsupp, info).is_err() {
                             println!("failed to initialise audio decoder");
                             return;
@@ -706,7 +712,7 @@ impl Player {
         let mut new_vcontrol = VideoControl::new(video_dec, width, height, tb_num, tb_den);
         std::mem::swap(&mut self.vcontrol, &mut new_vcontrol);
 
-        let mut new_acontrol = AudioControl::new(audio_dec, ainfo, &self.asystem);
+        let mut new_acontrol = AudioControl::new(audio_dec, ainfo, sbr_hack, &self.asystem);
         std::mem::swap(&mut self.acontrol, &mut new_acontrol);
 
         if self.mute {