]> git.nihav.org Git - nihav-player.git/commitdiff
videoplayer: add option for debugging scaler
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 8 Mar 2026 16:39:33 +0000 (17:39 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 8 Mar 2026 16:39:33 +0000 (17:39 +0100)
videoplayer/src/main.rs
videoplayer/src/videodec.rs

index 836001ea4edc1163bb3e9a6f2a1afe9a5f0dae77..a40c495c5c1201df6b4621e437325938a3ed1057 100644 (file)
@@ -454,6 +454,7 @@ struct Player {
     audio_str:      u32,
     force_astr:     Option<u32>,
     sc_size:        ScaleSize,
+    sc_dbg:         bool,
 
     vthreads:       usize,
     use_mt:         bool,
@@ -484,7 +485,7 @@ impl Player {
         let asystem = sdl_context.audio().expect("audio subsystem init failure");
         vsystem.disable_screen_saver();
         let acontrol = AudioControl::new(None, None, false, &asystem);
-        let vcontrol = VideoControl::new(None, 0, 0, 0, 0);
+        let vcontrol = VideoControl::new(None, 0, 0, 0, 0, false);
         Self {
             sdl_context, asystem, vsystem,
 
@@ -504,6 +505,7 @@ impl Player {
             audio_str:      0,
             force_astr:     None,
             sc_size:        ScaleSize::Auto,
+            sc_dbg:         false,
 
             vthreads:       3,
             use_mt:         true,
@@ -971,7 +973,7 @@ impl Player {
         };
 
         // prepare playback structure
-        let mut new_vcontrol = VideoControl::new(video_dec, width, height, tb_num, tb_den);
+        let mut new_vcontrol = VideoControl::new(video_dec, width, height, tb_num, tb_den, self.sc_dbg);
         std::mem::swap(&mut self.vcontrol, &mut new_vcontrol);
 
         let mut new_acontrol = AudioControl::new(audio_dec, ainfo, sbr_hack, &self.asystem);
@@ -1284,6 +1286,9 @@ fn main() {
                     }
                 }
             },
+            "-scale-debug" => {
+                player.sc_dbg = true;
+            },
             "-quiet" => {
                 player.quiet = true;
             },
index 4ed9b9516afb465fe08fd4df63983bf9d0610a32..1e68cd26e962b1427f7e328507e900a0fddccaca 100644 (file)
@@ -35,10 +35,11 @@ pub struct VideoDecoder {
     ofmt_yuv:   ScaleInfo,
     oinfo_yuv:  NAVideoInfo,
     oinfo_rgb:  NAVideoInfo,
+    sc_dbg:     bool,
 }
 
 impl VideoDecoder {
-    pub fn new(width: usize, height: usize, tb_num: u32, tb_den: u32, dec: DecoderStuff) -> Self {
+    pub fn new(width: usize, height: usize, tb_num: u32, tb_den: u32, dec: DecoderStuff, sc_dbg: bool) -> Self {
         let ofmt_rgb = ScaleInfo { width, height, fmt: SDL_RGB_FMT };
         let ofmt_yuv = ScaleInfo { width, height, fmt: YUV420_FORMAT };
         let oinfo_rgb = NAVideoInfo { width, height, flipped: false, format: SDL_RGB_FMT, bits: 24 };
@@ -50,6 +51,7 @@ impl VideoDecoder {
             dec, ofmt_yuv, ofmt_rgb, oinfo_yuv, oinfo_rgb,
             scaler:     NAScale::new(ofmt_rgb, ofmt_rgb).expect("creating scaler failed"),
             ifmt:       NAVideoInfo { width: 0, height: 0, flipped: false, format: SDL_RGB_FMT, bits: 24 },
+            sc_dbg,
         }
     }
     fn convert_buf(&mut self, bt: NABufferType, ts: u64) -> Option<FrameRecord> {
@@ -58,10 +60,14 @@ impl VideoDecoder {
             self.ifmt.get_height() != vinfo.get_height() ||
             self.ifmt.get_format() != vinfo.get_format() {
             self.ifmt = vinfo;
+            let mut sc_opts = Vec::with_capacity(1);
+            if self.sc_dbg {
+                sc_opts.push(("debug".to_string(), String::new()));
+            }
             let sc_ifmt = ScaleInfo { width: self.ifmt.get_width(), height: self.ifmt.get_height(), fmt: self.ifmt.get_format() };
             let do_yuv = self.ifmt.get_format().get_model().is_yuv();
             let ofmt = if do_yuv { self.ofmt_yuv } else { self.ofmt_rgb };
-            self.scaler = NAScale::new(sc_ifmt, ofmt).expect("scaling should not fail");
+            self.scaler = NAScale::new_with_options(sc_ifmt, ofmt, &sc_opts).expect("scaling should not fail");
         }
         let mut opic = if let ColorModel::YUV(_) = self.ifmt.get_format().get_model() {
                 self.yuv_pool.prealloc_video(self.oinfo_yuv, 2).expect("video frame pool allocation failure");
@@ -261,10 +267,10 @@ impl VideoDecoder {
     }
 }
 
-fn start_video_decoding(width: usize, height: usize, tb_num: u32, tb_den: u32, video_dec: DecoderStuff, vprecv: Receiver<PktSendEvent>, vfsend: SyncSender<(NABufferType, u64)>) -> JoinHandle<()> {
+fn start_video_decoding(width: usize, height: usize, tb_num: u32, tb_den: u32, video_dec: DecoderStuff, vprecv: Receiver<PktSendEvent>, vfsend: SyncSender<(NABufferType, u64)>, sc_dbg: bool) -> JoinHandle<()> {
     std::thread::Builder::new().name("vdecoder".to_string()).spawn(move ||{
             VDEC_STATE.set_state(DecodingState::Waiting);
-            let mut vdec = VideoDecoder::new(width, height, tb_num, tb_den, video_dec);
+            let mut vdec = VideoDecoder::new(width, height, tb_num, tb_den, video_dec, sc_dbg);
             let mut skip_mode = FrameSkipMode::None;
             loop {
                 match vprecv.recv() {
@@ -360,14 +366,14 @@ pub struct VideoControl {
 }
 
 impl VideoControl {
-    pub fn new(video_dec: Option<DecoderStuff>, width: usize, height: usize, tb_num: u32, tb_den: u32) -> Self {
+    pub fn new(video_dec: Option<DecoderStuff>, width: usize, height: usize, tb_num: u32, tb_den: u32, sc_dbg: bool) -> Self {
         let (vpsend, vprecv) = std::sync::mpsc::sync_channel::<PktSendEvent>(0);
         let (vfsend, vfrecv) = std::sync::mpsc::sync_channel::<FrameRecord>(FRAME_QUEUE_SIZE - 1);
 
         VDEC_STATE.set_state(DecodingState::Normal);
 
         let vthread = if let Some(video_dec) = video_dec {
-                start_video_decoding(width, height, tb_num, tb_den, video_dec, vprecv, vfsend)
+                start_video_decoding(width, height, tb_num, tb_den, video_dec, vprecv, vfsend, sc_dbg)
             } else {
                 thread::Builder::new().name("vdecoder-dummy".to_string()).spawn(move ||{
                         loop {