]> git.nihav.org Git - nihav-player.git/commitdiff
videoplayer: pass video stream parameters in a structure master
authorKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 8 Mar 2026 16:43:59 +0000 (17:43 +0100)
committerKostya Shishkov <kostya.shishkov@gmail.com>
Sun, 8 Mar 2026 16:43:59 +0000 (17:43 +0100)
This reduces number of arguments to pass through call chain.

videoplayer/src/main.rs
videoplayer/src/videodec.rs

index a40c495c5c1201df6b4621e437325938a3ed1057..35d295f2b13609d68f93b1b349383b553971812a 100644 (file)
@@ -485,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, false);
+        let vcontrol = VideoControl::new(None, VideoParams::default(), false);
         Self {
             sdl_context, asystem, vsystem,
 
@@ -973,7 +973,7 @@ impl Player {
         };
 
         // prepare playback structure
-        let mut new_vcontrol = VideoControl::new(video_dec, width, height, tb_num, tb_den, self.sc_dbg);
+        let mut new_vcontrol = VideoControl::new(video_dec, VideoParams { 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);
index 1e68cd26e962b1427f7e328507e900a0fddccaca..c910d6d00e587d29e0cd0b52a292dcd64148ddab 100644 (file)
@@ -11,6 +11,14 @@ use nihav_core::scale::*;
 
 use super::{DecoderStuff, DecoderType, DecoderState, DecodingState, DispQueue, FrameRecord, PktSendEvent, FRAME_QUEUE_LEN};
 
+#[derive(Clone,Copy,Default)]
+pub struct VideoParams {
+    pub width:      usize,
+    pub height:     usize,
+    pub tb_num:     u32,
+    pub tb_den:     u32,
+}
+
 static VDEC_STATE: DecoderState = DecoderState::new();
 
 pub const FRAME_QUEUE_SIZE: usize = 25;
@@ -39,7 +47,8 @@ pub struct VideoDecoder {
 }
 
 impl VideoDecoder {
-    pub fn new(width: usize, height: usize, tb_num: u32, tb_den: u32, dec: DecoderStuff, sc_dbg: bool) -> Self {
+    pub fn new(vparams: VideoParams, dec: DecoderStuff, sc_dbg: bool) -> Self {
+        let VideoParams { width, height, tb_num, tb_den } = vparams;
         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 };
@@ -267,10 +276,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)>, sc_dbg: bool) -> JoinHandle<()> {
+fn start_video_decoding(vparams: VideoParams, 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, sc_dbg);
+            let mut vdec = VideoDecoder::new(vparams, video_dec, sc_dbg);
             let mut skip_mode = FrameSkipMode::None;
             loop {
                 match vprecv.recv() {
@@ -366,14 +375,14 @@ pub struct VideoControl {
 }
 
 impl VideoControl {
-    pub fn new(video_dec: Option<DecoderStuff>, width: usize, height: usize, tb_num: u32, tb_den: u32, sc_dbg: bool) -> Self {
+    pub fn new(video_dec: Option<DecoderStuff>, vparams: VideoParams, 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, sc_dbg)
+                start_video_decoding(vparams, video_dec, vprecv, vfsend, sc_dbg)
             } else {
                 thread::Builder::new().name("vdecoder-dummy".to_string()).spawn(move ||{
                         loop {