From: Kostya Shishkov Date: Thu, 2 May 2019 12:18:15 +0000 (+0200) Subject: realmedia: use video buffer pool in RV3/4/6 X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=3c69ce1b2da6d6c9d1fa9962616f4e4e8d1d06df;p=nihav.git realmedia: use video buffer pool in RV3/4/6 --- diff --git a/nihav-realmedia/src/codecs/rv30.rs b/nihav-realmedia/src/codecs/rv30.rs index 95e6190..d729b43 100644 --- a/nihav-realmedia/src/codecs/rv30.rs +++ b/nihav-realmedia/src/codecs/rv30.rs @@ -117,7 +117,7 @@ impl RealVideo30Decoder { } impl NADecoder for RealVideo30Decoder { - fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { + fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, fmt)); @@ -138,16 +138,20 @@ impl NADecoder for RealVideo30Decoder { self.bd.width = vinfo.get_width(); self.bd.height = vinfo.get_height(); + + supp.pool_u8.set_dec_bufs(3); + supp.pool_u8.prealloc_video(NAVideoInfo::new(self.bd.width, self.bd.height, false, fmt), 4)?; + Ok(()) } else { println!("???"); Err(DecoderError::InvalidData) } } - fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { + fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); - let (bufinfo, ftype, pts) = self.dec.parse_frame(src.as_slice(), &mut self.bd)?; + let (bufinfo, ftype, pts) = self.dec.parse_frame(supp, src.as_slice(), &mut self.bd)?; let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); frm.set_keyframe(ftype == FrameType::I); diff --git a/nihav-realmedia/src/codecs/rv3040.rs b/nihav-realmedia/src/codecs/rv3040.rs index adde678..42de3e4 100644 --- a/nihav-realmedia/src/codecs/rv3040.rs +++ b/nihav-realmedia/src/codecs/rv3040.rs @@ -1,6 +1,6 @@ use nihav_core::formats::YUV420_FORMAT; use nihav_core::frame::{NABufferType, NAVideoInfo, NAVideoBuffer, NAVideoBufferRef, FrameType, alloc_video_buffer}; -use nihav_core::codecs::{MV, ZERO_MV, DecoderError, DecoderResult, IPBShuffler}; +use nihav_core::codecs::{NADecoderSupport, MV, ZERO_MV, DecoderError, DecoderResult, IPBShuffler}; use nihav_core::io::bitreader::{BitReader,BitReaderMode}; use nihav_core::io::intcode::*; use std::mem; @@ -1112,7 +1112,7 @@ impl RV34Decoder { } } - pub fn parse_frame(&mut self, src: &[u8], bd: &mut RV34BitstreamDecoder) -> DecoderResult<(NABufferType, FrameType, u64)> { + pub fn parse_frame(&mut self, supp: &mut NADecoderSupport, src: &[u8], bd: &mut RV34BitstreamDecoder) -> DecoderResult<(NABufferType, FrameType, u64)> { let mut slice_offs: Vec = Vec::new(); parse_slice_offsets(src, &mut slice_offs)?; let ini_off = slice_offs.len() * 8 + 1; @@ -1157,10 +1157,21 @@ impl RV34Decoder { //todo validate against ref frame let vinfo = NAVideoInfo::new(hdr0.width, hdr0.height, false, YUV420_FORMAT); - let bufret = alloc_video_buffer(vinfo, 4); - if let Err(_) = bufret { return Err(DecoderError::InvalidData); } - let bufinfo = bufret.unwrap(); - let mut buf = bufinfo.get_vbuf().unwrap(); + let ret = supp.pool_u8.get_free(); + if ret.is_none() { + return Err(DecoderError::AllocError); + } + let mut buf = ret.unwrap(); + if buf.get_info() != vinfo { + self.ipbs.clear(); + supp.pool_u8.reset(); + supp.pool_u8.prealloc_video(vinfo, 4)?; + let ret = supp.pool_u8.get_free(); + if ret.is_none() { + return Err(DecoderError::AllocError); + } + buf = ret.unwrap(); + } sstate.q = q; sstate.has_top = false; @@ -1269,11 +1280,11 @@ impl RV34Decoder { self.dsp.loop_filter(&mut buf, hdr0.ftype, &mbinfo, mb_w, mb_h - 1); } if !self.is_b { - self.ipbs.add_frame(buf); + self.ipbs.add_frame(buf.clone()); mem::swap(&mut self.mvi, &mut self.ref_mvi); mem::swap(&mut self.mbinfo, &mut mbinfo); } - Ok((bufinfo, hdr0.ftype, ts)) + Ok((NABufferType::Video(buf), hdr0.ftype, ts)) } } diff --git a/nihav-realmedia/src/codecs/rv40.rs b/nihav-realmedia/src/codecs/rv40.rs index 62fafba..272226d 100644 --- a/nihav-realmedia/src/codecs/rv40.rs +++ b/nihav-realmedia/src/codecs/rv40.rs @@ -314,7 +314,7 @@ impl RealVideo40Decoder { } impl NADecoder for RealVideo40Decoder { - fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { + fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = formats::YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, fmt)); @@ -331,16 +331,20 @@ for i in 0..src.len() { print!(" {:02X}", src[i]); } println!(""); self.bd.width = vinfo.get_width(); self.bd.height = vinfo.get_height(); + + supp.pool_u8.set_dec_bufs(3); + supp.pool_u8.prealloc_video(NAVideoInfo::new(self.bd.width, self.bd.height, false, fmt), 4)?; + Ok(()) } else { println!("???"); Err(DecoderError::InvalidData) } } - fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { + fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); - let (bufinfo, ftype, ts) = self.dec.parse_frame(src.as_slice(), &mut self.bd)?; + let (bufinfo, ftype, ts) = self.dec.parse_frame(supp, src.as_slice(), &mut self.bd)?; let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); frm.set_keyframe(ftype == FrameType::I); diff --git a/nihav-realmedia/src/codecs/rv60.rs b/nihav-realmedia/src/codecs/rv60.rs index 2ec99ed..8ab11f1 100644 --- a/nihav-realmedia/src/codecs/rv60.rs +++ b/nihav-realmedia/src/codecs/rv60.rs @@ -1391,8 +1391,8 @@ println!(" left {} bits", br.left()); } impl NADecoder for RealVideo60Decoder { - fn init(&mut self, _supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { - if let NACodecTypeInfo::Video(_vinfo) = info.get_properties() { + fn init(&mut self, supp: &mut NADecoderSupport, info: NACodecInfoRef) -> DecoderResult<()> { + if let NACodecTypeInfo::Video(vinfo) = info.get_properties() { let fmt = YUV420_FORMAT; let myinfo = NACodecTypeInfo::Video(NAVideoInfo::new(0, 0, false, fmt)); self.info = NACodecInfo::new_ref(info.get_name(), myinfo, info.get_extradata()).into_ref(); @@ -1412,13 +1412,17 @@ impl NADecoder for RealVideo60Decoder { //self.bd.width = vinfo.get_width(); //self.bd.height = vinfo.get_height(); //self.frmmgr.clear(); + + supp.pool_u8.set_dec_bufs(3); + supp.pool_u8.prealloc_video(NAVideoInfo::new(vinfo.get_width(), vinfo.get_height(), false, fmt), 6)?; + Ok(()) } else { println!("???"); Err(DecoderError::InvalidData) } } - fn decode(&mut self, _supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { + fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult { let src = pkt.get_buffer(); validate!(src.len() > 9); @@ -1429,10 +1433,21 @@ println!("???"); hdr.parse_slice_sizes(&mut br, &mut slices)?; let tmp_vinfo = NAVideoInfo::new(hdr.width, hdr.height, false, YUV420_FORMAT); - let res = alloc_video_buffer(tmp_vinfo, 6); - if !res.is_ok() { return Err(DecoderError::InvalidData); } - let bufinfo = res.unwrap(); - let mut buf = bufinfo.get_vbuf().unwrap(); + let ret = supp.pool_u8.get_free(); + if ret.is_none() { + return Err(DecoderError::AllocError); + } + let mut buf = ret.unwrap(); + if buf.get_info() != tmp_vinfo { + self.ipbs.clear(); + supp.pool_u8.reset(); + supp.pool_u8.prealloc_video(tmp_vinfo, 6)?; + let ret = supp.pool_u8.get_free(); + if ret.is_none() { + return Err(DecoderError::AllocError); + } + buf = ret.unwrap(); + } let cu_w = hdr.get_width_cu(); let cu_h = hdr.get_height_cu(); @@ -1451,10 +1466,10 @@ println!("???"); off += size; } if (hdr.ftype == FrameType::I) || (hdr.ftype == FrameType::P) { - self.ipbs.add_frame(buf); + self.ipbs.add_frame(buf.clone()); } - let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo); + let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), NABufferType::Video(buf)); frm.set_keyframe(hdr.ftype == FrameType::I); frm.set_pts(Some(hdr.ts as u64)); frm.set_frame_type(hdr.ftype);