]> git.nihav.org Git - nihav-encoder.git/commitdiff
allow custom stream tags
authorKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 9 Jun 2026 16:57:22 +0000 (18:57 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Tue, 9 Jun 2026 16:57:22 +0000 (18:57 +0200)
src/transcoder.rs

index 01b939934c29ce17e887fdc808d0141b2994b849..d087a277039ae51ad393bb7bc52a576c20269b33 100644 (file)
@@ -538,6 +538,53 @@ impl OutputQueue {
     }
 }
 
+fn format_stream_tag(streamno: u32, arg: &str) -> Result<String, ()> {
+    let mut dst = format!("stream{streamno}tag");
+
+    let src = arg.as_bytes();
+    let mut idx = 0;
+    while idx < src.len() {
+        match src[idx] {
+            b'\\' => {
+                idx += 1;
+
+                if idx >= src.len() {
+                    return Err(());
+                }
+                match src[idx] {
+                    b'0' => {
+                        dst += "00";
+                        idx += 1;
+                    },
+                    b'x' => {
+                        idx += 1;
+                        if idx + 1 >= src.len() {
+                            return Err(());
+                        }
+                        let c0 = src[idx];
+                        let c1 = src[idx + 1];
+                        idx += 2;
+                        if c0.is_ascii_hexdigit() && c1.is_ascii_hexdigit() {
+                            dst.push(c0.to_ascii_uppercase() as char);
+                            dst.push(c1.to_ascii_uppercase() as char);
+                        } else {
+                            return Err(());
+                        }
+                    },
+                    _ => return Err(()),
+                }
+            },
+            b' '..=0x7E => {
+                dst += format!("{:02X}", src[idx]).as_str();
+                idx += 1;
+            },
+            _ => return Err(()),
+        }
+    }
+
+    Ok(dst)
+}
+
 #[derive(Default)]
 pub struct QuirkSupport {
     pub calc_len:       bool,
@@ -844,6 +891,13 @@ impl Transcoder {
                             println!("invalid volume");
                         }
                     },
+                    "stream_tag" => {
+                        if let Ok(tag) = format_stream_tag(streamno, oval[1]) {
+                            self.mux_opts.push(OptionArgs{ name: "stream_tag".to_string(), value: Some(tag) });
+                        } else {
+                            println!("invalid stream tag");
+                        }
+                    },
                     _ => {
                         ostr.enc_opts.push(OptionArgs{ name: oval[0].to_string(), value: Some(oval[1].to_string()) });
                     },