}
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));
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<NAFrameRef> {
+ fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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);
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;
}
}
- 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<usize> = Vec::new();
parse_slice_offsets(src, &mut slice_offs)?;
let ini_off = slice_offs.len() * 8 + 1;
//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;
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))
}
}
}
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));
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<NAFrameRef> {
+ fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
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);
}
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();
//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<NAFrameRef> {
+ fn decode(&mut self, supp: &mut NADecoderSupport, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
validate!(src.len() > 9);
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();
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);