]> git.nihav.org Git - nihav-player.git/commitdiff
videoplayer: add a rudimentary support for rcfile master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 9 Oct 2025 16:19:11 +0000 (18:19 +0200)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Thu, 9 Oct 2025 16:32:49 +0000 (18:32 +0200)
videoplayer/src/main.rs

index 7008460a1d702b1894a5aadf48e94ad071bba6fc..12438b465653bd909cc6d041985117c229349be0 100644 (file)
@@ -5,6 +5,8 @@ extern crate nihav_allstuff;
 
 use std::env;
 use std::fs::File;
+#[cfg(not(target_os = "windows"))]
+use std::io::{BufRead, BufReader};
 use std::io::Write;
 use std::path::Path;
 use std::time::{Duration, Instant};
@@ -365,6 +367,9 @@ struct Player {
     acontrol:       AudioControl,
     vcontrol:       VideoControl,
 
+    thr_w:          usize,
+    thr_h:          usize,
+
     play_video:     bool,
     play_audio:     bool,
     has_video:      bool,
@@ -407,6 +412,9 @@ impl Player {
 
             acontrol, vcontrol,
 
+            thr_w:          384,
+            thr_h:          288,
+
             play_video:     true,
             play_audio:     true,
             has_video:      false,
@@ -841,12 +849,13 @@ impl Player {
         }
 
         match self.sc_size {
-            ScaleSize::Auto => {
-                while (width <= 384) && (height <= 288) {
+            ScaleSize::Auto if self.thr_w > 0 && self.thr_h > 0 => {
+                while (width <= self.thr_w) && (height <= self.thr_h) {
                     width <<= 1;
                     height <<= 1;
                 }
             },
+            ScaleSize::Auto => {},
             ScaleSize::Times(factor) => {
                 let nw = ((width  as f32) * factor).ceil() as usize;
                 let nh = ((height as f32) * factor).ceil() as usize;
@@ -1035,6 +1044,51 @@ fn main() {
     let mut builder = player.vsystem.window("NihAV Player", 640, 480);
     let mut window = builder.position_centered().hidden().build().expect("should be able to centre window");
 
+    #[cfg(not(target_os = "windows"))]
+    #[allow(deprecated)]
+    if let Some(home_path) = std::env::home_dir() {
+        let mut rcfile = home_path.into_os_string();
+        rcfile.push(std::path::MAIN_SEPARATOR_STR);
+        rcfile.push(".naplayerrc");
+        debug_log!(self; {format!("opening settings file {rcfile}")});
+        if let Ok(file) = File::open(rcfile) {
+            let br = BufReader::new(file);
+            for (n, line) in br.lines().enumerate() {
+                if let Ok(line) = line {
+                    let mut words: Vec<&str> = line.split_ascii_whitespace().collect();
+                    if words.is_empty() || words[0].starts_with('#') {
+                        continue;
+                    }
+                    if words.len() == 1 && words[0].contains('=') {
+                        words = words[0].split('=').collect();
+                    }
+                    if words.is_empty() {
+                        continue;
+                    }
+                    if words[0] == "scale_thr" {
+                        let last_arg = words[words.len() - 1];
+                        let dim: Vec<&str> = last_arg.split(['x', 'X']).collect();
+                        if dim.len() != 2 {
+                            println!("    expected 'scale_thr=WxH', got 'scale_thr={last_arg}'");
+                            continue;
+                        }
+                        if let (Ok(thr_w), Ok(thr_h)) = (dim[0].parse::<usize>(), dim[1].parse::<usize>()) {
+                            debug_log!(self; {format!(" set autoscale threshold to {thr_w}x{thr_h}")});
+                            player.thr_w = thr_w;
+                            player.thr_h = thr_h;
+                        } else {
+                            println!("    expected 'scale_thr=WxH', got 'scale_thr={last_arg}'");
+                            continue;
+                        }
+                    }
+                } else {
+                    println!("    error at line {n}");
+                    break;
+                }
+            }
+        }
+    }
+
     let mut aiter = args.iter().skip(1);
     let mut seek_time = NATimePoint::None;
     while let Some(arg) = aiter.next() {