]> git.nihav.org Git - nihav-player.git/blobdiff - videoplayer/src/main.rs
hwdec-vaapi: handle copying data into kodaed chroma planes
[nihav-player.git] / videoplayer / src / main.rs
index cd35eb5e8d2e6d8cb9aff0d314c2041e34abaf1e..94dea167822348a6f0a400bc9245f38d43d2e5f6 100644 (file)
@@ -27,6 +27,9 @@ use nihav_core::demuxers::*;
 use nihav_registry::register::*;
 use nihav_allstuff::*;
 
+#[cfg(feature="hwaccel")]
+use hwdec_vaapi::*;
+
 mod audiodec;
 use audiodec::*;
 mod videodec;
@@ -140,6 +143,8 @@ pub enum DecoderType {
     Audio(Box<dyn NADecoder + Send>),
     Video(Box<dyn NADecoder + Send>, Box<dyn FrameReorderer + Send>),
     VideoMT(Box<dyn NADecoderMT + Send>, MTFrameReorderer),
+    #[cfg(feature="hwaccel")]
+    VideoHW(Box<dyn HWDecoder + Send>),
 }
 
 pub struct DecoderStuff {
@@ -315,7 +320,7 @@ fn try_display(disp_queue: &mut DispQueue, canvas: &mut Canvas<Window>, osd: &mu
 
             disp_queue.move_start();
             if !disp_queue.is_empty() {
-                return Some((disp_queue.first_ts - ctime).saturating_sub(2));
+                return Some(disp_queue.first_ts.saturating_sub(ctime).saturating_sub(2));
             } else {
                 return None;
             }
@@ -342,6 +347,8 @@ struct Player {
 
     vthreads:       usize,
     use_mt:         bool,
+    #[cfg(feature="hwaccel")]
+    use_hwaccel:    bool,
 
     paused:         bool,
     mute:           bool,
@@ -380,6 +387,8 @@ impl Player {
 
             vthreads:       3,
             use_mt:         true,
+            #[cfg(feature="hwaccel")]
+            use_hwaccel:    true,
 
             paused:         false,
             mute:           false,
@@ -526,12 +535,13 @@ impl Player {
                         return Ok(true);
                     },
                     Keycode::Return | Keycode::KpEnter => return Ok(true),
-                    Keycode::Right      => { self.seek(10, true,  dmx, disp_queue)?; },
-                    Keycode::Left       => { self.seek(10, false, dmx, disp_queue)?; },
-                    Keycode::Up         => { self.seek(60, true,  dmx, disp_queue)?; },
-                    Keycode::Down       => { self.seek(60, false, dmx, disp_queue)?; },
-                    Keycode::PageUp     => { self.seek(600, true,  dmx, disp_queue)?; },
-                    Keycode::PageDown   => { self.seek(600, false, dmx, disp_queue)?; },
+                    Keycode::R          => { self.seek(0, true,  dmx, disp_queue)?; },
+                    Keycode::Right    | Keycode::Kp6 => { self.seek(10, true,  dmx, disp_queue)?; },
+                    Keycode::Left     | Keycode::Kp4 => { self.seek(10, false, dmx, disp_queue)?; },
+                    Keycode::Up       | Keycode::Kp8 => { self.seek(60, true,  dmx, disp_queue)?; },
+                    Keycode::Down     | Keycode::Kp2 => { self.seek(60, false, dmx, disp_queue)?; },
+                    Keycode::PageUp   | Keycode::Kp9 => { self.seek(600, true,  dmx, disp_queue)?; },
+                    Keycode::PageDown | Keycode::Kp3 => { self.seek(600, false, dmx, disp_queue)?; },
                     Keycode::Space => { self.toggle_pause(); },
                     Keycode::Plus | Keycode::KpPlus => {
                         self.volume = (self.volume + 10).min(MAX_VOLUME);
@@ -539,6 +549,12 @@ impl Player {
                             self.acontrol.set_volume(self.volume);
                         }
                     },
+                    Keycode::Equals if keymod.contains(Mod::RSHIFTMOD) || keymod.contains(Mod::LSHIFTMOD) => {
+                        self.volume = (self.volume + 10).min(MAX_VOLUME);
+                        if !self.mute {
+                            self.acontrol.set_volume(self.volume);
+                        }
+                    },
                     Keycode::Minus | Keycode::KpMinus => {
                         self.volume = self.volume.saturating_sub(10);
                         if !self.mute {
@@ -660,6 +676,28 @@ impl Player {
             let str_id = s.get_id();
             if info.is_video() {
                 if video_dec.is_none() && self.play_video {
+                    #[cfg(feature="hwaccel")]
+                    if info.get_name() == "h264" && self.use_hwaccel {
+                        let mut dec = new_h264_hwdec();
+                        let dsupp = Box::new(NADecoderSupport::new());
+                        let props = info.get_properties().get_video_info().unwrap();
+                        if props.get_width() != 0 {
+                            width  = props.get_width();
+                            height = props.get_height();
+                        }
+                        if dec.init(info.clone()).is_err() {
+                            println!("failed to initialise hwaccel video decoder");
+                        } else {
+                            video_dec = Some(DecoderStuff{ dsupp, dec: DecoderType::VideoHW(dec) });
+                            self.video_str = str_id;
+                            let (tbn, tbd) = s.get_timebase();
+                            tb_num = tbn;
+                            tb_den = tbd;
+                            self.has_video = true;
+                            println!(" using hardware-accelerated decoding");
+                            continue;
+                        }
+                    }
                     if let Some(decfunc) = decfunc_mt {
                         let mut dec = (decfunc)();
                         let mut dsupp = Box::new(NADecoderSupport::new());
@@ -971,6 +1009,14 @@ fn main() {
             "-nomt" => {
                 player.use_mt = false;
             },
+            #[cfg(feature="hwaccel")]
+            "-hwaccel" => {
+                player.use_hwaccel = true;
+            },
+            #[cfg(feature="hwaccel")]
+            "-nohwaccel" => {
+                player.use_hwaccel = false;
+            },
             "-threads" => {
                 if let Some(arg) = aiter.next() {
                     if let Ok(val) = arg.parse::<usize>() {