From: Kostya Shishkov Date: Thu, 9 Oct 2025 16:19:11 +0000 (+0200) Subject: videoplayer: add a rudimentary support for rcfile X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=HEAD;p=nihav-player.git videoplayer: add a rudimentary support for rcfile --- diff --git a/videoplayer/src/main.rs b/videoplayer/src/main.rs index 7008460..12438b4 100644 --- a/videoplayer/src/main.rs +++ b/videoplayer/src/main.rs @@ -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::(), dim[1].parse::()) { + 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() {