X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=videoplayer%2Fsrc%2Fvideodec.rs;h=295cfc753ee64002f9288eacf7f54f256d6fbbba;hb=6efb6f30892427a02282e39cc4d21a23d5c8add5;hp=1d70112902d0f0a12f44f3666de94d3e8374f995;hpb=364f01a375903b90fc9b0af001a0808249aabac3;p=nihav-player.git diff --git a/videoplayer/src/videodec.rs b/videoplayer/src/videodec.rs index 1d70112..295cfc7 100644 --- a/videoplayer/src/videodec.rs +++ b/videoplayer/src/videodec.rs @@ -59,7 +59,7 @@ impl VideoDecoder { self.ifmt.get_format() != vinfo.get_format() { self.ifmt = vinfo; let sc_ifmt = ScaleInfo { width: self.ifmt.get_width(), height: self.ifmt.get_height(), fmt: self.ifmt.get_format() }; - let do_yuv = if let ColorModel::YUV(_) = self.ifmt.get_format().get_model() { true } else { false }; + 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"); } @@ -103,7 +103,7 @@ impl VideoDecoder { }, DecoderType::VideoMT(ref mut vdec, ref mut reord) => { let queue_id = reord.register_frame(); - match vdec.queue_pkt(&mut self.dec.dsupp, &pkt, queue_id) { + match vdec.queue_pkt(&mut self.dec.dsupp, pkt, queue_id) { Ok(true) => {}, Ok(false) => { while !vdec.can_take_input() || vdec.has_output() { @@ -113,11 +113,13 @@ impl VideoDecoder { }, (Err(err), id) => { reord.drop_frame(id); - println!("frame {} decoding error {:?}", id, err); + if err != DecoderError::MissingReference { + println!("frame {} decoding error {:?}", id, err); + } }, }; } - match vdec.queue_pkt(&mut self.dec.dsupp, &pkt, queue_id) { + match vdec.queue_pkt(&mut self.dec.dsupp, pkt, queue_id) { Ok(true) => {}, Ok(false) => { println!("still can't queue frame!"); @@ -135,6 +137,16 @@ impl VideoDecoder { return self.convert_buf(bt, ts); } }, + #[cfg(feature="hwaccel")] + DecoderType::VideoHW(ref mut vdec) => { + let _ = vdec.queue_pkt(pkt); + while let Some(frm) = vdec.get_frame() { + let bt = frm.get_buffer(); + if let NABufferType::None = bt { continue; } + let ts = frm.get_dts().unwrap_or_else(|| frm.get_pts().unwrap_or(0)); + return self.convert_buf(bt, ts); + } + }, _ => panic!("not a video decoder!"), }; None @@ -159,7 +171,9 @@ impl VideoDecoder { }, (Err(err), id) => { reord.drop_frame(id); - println!("frame {} decoding error {:?}", id, err); + if err != DecoderError::MissingReference { + println!("frame {} decoding error {:?}", id, err); + } }, }; } @@ -171,7 +185,9 @@ impl VideoDecoder { (Err(DecoderError::NoFrame), _) => {}, (Err(err), id) => { reord.drop_frame(id); - println!("frame {} decoding error {:?}", id, err); + if err != DecoderError::MissingReference { + println!("frame {} decoding error {:?}", id, err); + } }, }; } @@ -182,6 +198,15 @@ impl VideoDecoder { return self.convert_buf(bt, ts); } }, + #[cfg(feature="hwaccel")] + DecoderType::VideoHW(ref mut vdec) => { + while let Some(frm) = vdec.get_frame() { + let bt = frm.get_buffer(); + if let NABufferType::None = bt { continue; } + let ts = frm.get_dts().unwrap_or_else(|| frm.get_pts().unwrap_or(0)); + return self.convert_buf(bt, ts); + } + }, _ => {}, }; None @@ -204,6 +229,15 @@ impl VideoDecoder { return self.convert_buf(bt, ts); } }, + #[cfg(feature="hwaccel")] + DecoderType::VideoHW(ref mut dec) => { + while let Some(frm) = dec.get_last_frames() { + let bt = frm.get_buffer(); + if let NABufferType::None = bt { continue; } + let ts = frm.get_dts().unwrap_or_else(|| frm.get_pts().unwrap_or(0)); + return self.convert_buf(bt, ts); + } + }, _ => {}, }; None @@ -218,6 +252,10 @@ impl VideoDecoder { dec.flush(); reord.flush(); }, + #[cfg(feature="hwaccel")] + DecoderType::VideoHW(ref mut dec) => { + dec.flush(); + }, _ => {}, }; } @@ -268,6 +306,7 @@ fn start_video_decoding(width: usize, height: usize, tb_num: u32, tb_den: u32, v Ok(PktSendEvent::HurryUp) => { skip_mode = skip_mode.advance(); if let DecoderType::Video(ref mut dec, ref mut _reord) = vdec.dec.dec { + println!("setting hurry up mode to {}", skip_mode.to_string()); dec.set_options(&[NAOption{ name: FRAME_SKIP_OPTION, value: NAValue::String(skip_mode.to_string()), @@ -377,7 +416,7 @@ impl VideoControl { self.vqueue.len() >= size } pub fn try_send_video(&mut self, evt: PktSendEvent) -> bool { - if self.vqueue.len() > 0 { + if !self.vqueue.is_empty() { self.vqueue.push(evt); false } else { @@ -438,7 +477,7 @@ impl VideoControl { frm.rgb_tex.with_lock(None, |buffer: &mut [u8], pitch: usize| { let csize = sstride.min(pitch); for (dst, src) in buffer.chunks_mut(pitch).zip(src.chunks(sstride)) { - (&mut dst[..csize]).copy_from_slice(&src[..csize]); + dst[..csize].copy_from_slice(&src[..csize]); } true }).expect("surface should be locked");