]> git.nihav.org Git - nihav.git/commitdiff
binkvid: allow decoding from inter frame
authorKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 1 Oct 2025 16:45:51 +0000 (18:45 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Wed, 1 Oct 2025 16:47:25 +0000 (18:47 +0200)
The old behaviour may still be enabled with strict_mode option.

nihav-rad/src/codecs/binkvid.rs

index 2694b8d0ed25bcf23a0f4f06a853754020b1bbff..9e0f2383903b12346db7276e35fb8b4c239fde82 100644 (file)
@@ -469,6 +469,8 @@ struct BinkDecoder {
     trees:      BinkTrees,
 
     qmat_b:     QuantMats,
+
+    strict_mode: bool,
 }
 
 fn calc_len(size: usize) -> u8 {
@@ -598,6 +600,13 @@ impl BinkDecoder {
                 poff += pstride;
             }
             Ok(())
+        } else if !self.strict_mode {
+            for line in dst[off..].chunks_mut(stride).take(8) {
+                for pix in line[..8].iter_mut() {
+                    *pix = 0x80;
+                }
+            }
+            Ok(())
         } else {
             Err(DecoderError::MissingReference)
         }
@@ -1205,10 +1214,30 @@ impl NADecoder for BinkDecoder {
     }
 }
 
+const STRICT_MODE_OPTION: &str = "strict_mode";
+
+const BINK_OPTS: &[NAOptionDefinition] = &[
+    NAOptionDefinition {
+        name: STRICT_MODE_OPTION, description: "Error out on recoverable errors",
+        opt_type: NAOptionDefinitionType::Bool },
+];
+
 impl NAOptionHandler for BinkDecoder {
-    fn get_supported_options(&self) -> &[NAOptionDefinition] { &[] }
-    fn set_options(&mut self, _options: &[NAOption]) { }
-    fn query_option_value(&self, _name: &str) -> Option<NAValue> { None }
+    fn get_supported_options(&self) -> &[NAOptionDefinition] { BINK_OPTS }
+    fn set_options(&mut self, options: &[NAOption]) {
+        for option in options.iter() {
+            if let NAOption { name: STRICT_MODE_OPTION, value: NAValue::Bool(ref bval) } = option {
+                self.strict_mode = *bval;
+            }
+        }
+    }
+    fn query_option_value(&self, name: &str) -> Option<NAValue> {
+        if name == STRICT_MODE_OPTION {
+            Some(NAValue::Bool(self.strict_mode))
+        } else {
+            None
+        }
+    }
 }
 
 pub fn get_decoder() -> Box<dyn NADecoder + Send> {