add flush() to decoder interface
[nihav.git] / nihav-realmedia / src / codecs / cook.rs
index ec59b638d84b1e5d5d88c5648672a9d4a4c4b40d..a1a32e48788592214f4c39475c095c1868e37a51 100644 (file)
@@ -17,8 +17,8 @@ enum Mode {
 }
 
 impl Mode {
-    fn get_channels(&self) -> usize {
-        match *self {
+    fn get_channels(self) -> usize {
+        match self {
             Mode::Mono  => 1,
             _           => 2,
         }
@@ -74,9 +74,9 @@ impl Codebooks {
                      Codebook::new(&mut vq5, CodebookMode::MSB).unwrap(),
                      Codebook::new(&mut vq6, CodebookMode::MSB).unwrap()];
         Codebooks {
-            cpl_cb:     cpl_cb,
-            quant_cb:   quant_cb,
-            vq_cb:      vq_cb,
+            cpl_cb,
+            quant_cb,
+            vq_cb,
         }
     }
 }
@@ -111,7 +111,7 @@ impl CookDSP {
             gain_tab[i] = pow_tab[i + 53].powf(8.0 / fsamples);
         }
         let size = samples;
-        CookDSP { imdct: IMDCT::new(samples*2, false), window: window, out: [0.0; 2048], size, pow_tab, hpow_tab, gain_tab }
+        CookDSP { imdct: IMDCT::new(samples*2, false), window, out: [0.0; 2048], size, pow_tab, hpow_tab, gain_tab }
     }
 }
 
@@ -337,11 +337,11 @@ impl CookChannelPair {
             let cend   = COOK_CPL_BAND[self.subbands - 1] as usize;
             if br.read_bool()? {
                 let cb = &codebooks.cpl_cb[(self.js_bits - 2) as usize];
-                for i in cstart..cend+1 {
+                for i in cstart..=cend {
                     self.decouple[i]                    = br.read_cb(cb)? as u8;
                 }
             } else {
-                for i in cstart..cend+1 {
+                for i in cstart..=cend {
                     self.decouple[i]                    = br.read(self.js_bits)? as u8;
                 }
             }
@@ -669,9 +669,14 @@ impl NADecoder for CookDecoder {
         frm.set_keyframe(true);
         Ok(frm.into_ref())
     }
+    fn flush(&mut self) {
+        for pair in self.pairs.iter_mut() {
+            pair.delay = [[0.0; MAX_SAMPLES]; 2];
+        }
+    }
 }
 
-pub fn get_decoder() -> Box<NADecoder> {
+pub fn get_decoder() -> Box<dyn NADecoder> {
     Box::new(CookDecoder::new())
 }
 
@@ -1118,6 +1123,7 @@ const COOK_CPL_BAND: [u8; MAX_SUBBANDS - 1] = [
     19, 19, 19
 ];
 
+#[allow(clippy::approx_constant)]
 const COOK_DITHER_TAB: [f32; 9] = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107, 1.0 ];
 
 const COOK_QUANT_CENTROID: [[f32; 14]; 7] = [