if no_up && no_left { return PredType4x4::DC128; }
let no_down = !has_left || (x != 0) || (y == 3);
-//println!(" orig {} @ {}", self.cache.data[self.cache.xpos + x + y * self.cache.stride], self.cache.xpos + x + y * self.cache.stride);
let mut im = RV34_INTRA_PRED4[self.cache.data[self.cache.xpos + x + y * self.cache.stride] as usize];
if no_up {
if no_up && no_left { return PredType4x4::DC128; }
let no_down = !has_left || (x != 0) || (y == 1);
-//println!(" orig {}", self.cache.data[self.cache.xpos + x + y * self.cache.stride]);
let mut im = RV34_INTRA_PRED4[self.cache.data[self.cache.xpos + x * 2 + y * 2 * self.cache.stride] as usize];
if no_up {
} else {
tr_mv = left_mv;
}
-//print!(" pred {} {} {}", left_mv, top_mv, tr_mv);
MV::pred(left_mv, top_mv, tr_mv)
}
pub fn pred_mb_mv(&self, mb_x: usize, mb_y: usize, fwd: bool, has_top: bool, has_left: bool, has_tr: bool, has_tl: bool) -> MV {
self.fill(mb_x, mb_y, false, ZERO_MV);
return;
}
-//println!(" mvpred {:?} - {}", mbtype, mbtype.is_16x16());
-//for i in 0..mbtype.get_num_mvs() { println!(" {}", mvs[i]);}
if mbtype.is_fwd() {
self.fill(mb_x, mb_y, false, ZERO_MV);
} else if mbtype.is_bwd() {
self.fill(mb_x, mb_y, true, ZERO_MV);
}
let idx = mb_x * 2 + mb_y * 2 * self.w;
-/* let pred_mv = if mbtype.is_16x16() && mbtype != MBType::MBSkip {
- self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true)
- } else {
- ZERO_MV
- };*/
match mbtype {
MBType::MBSkip => {
},
MBType::MBP16x16 |
MBType::MBP16x16Mix => {
-let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
-//println!(" + {}", mvs[0]);
+ let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
let new_mv = mvs[0] + pred_mv;
self.fill(mb_x, mb_y, true, new_mv);
},
MBType::MBP16x8 => {
-let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
-//println!(" + {}", mvs[0]);
+ let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
let new_mv = mvs[0] + pred_mv;
self.mv_f[idx + 0] = new_mv;
self.mv_f[idx + 1] = new_mv;
let idx2 = idx + self.w;
let pred_mv = self.pred_mv(idx2, true, true, sstate.has_left, false, sstate.has_left, true);
-//println!(" + {}", mvs[1]);
let new_mv = mvs[1] + pred_mv;
self.mv_f[idx2 + 0] = new_mv;
self.mv_f[idx2 + 1] = new_mv;
},
MBType::MBP8x16 => {
let pred_mv = self.pred_mv(idx, true, sstate.has_top, sstate.has_left, sstate.has_top, sstate.has_tl, false);
-//println!(" + {}", mvs[0]);
let new_mv = mvs[0] + pred_mv;
self.mv_f[idx] = new_mv;
self.mv_f[idx + self.w] = new_mv;
let pred_mv = self.pred_mv(idx + 1, true, sstate.has_top, true, sstate.has_tr, sstate.has_top, false);
-//println!(" + {}", mvs[1]);
let new_mv = mvs[1] + pred_mv;
self.mv_f[idx + 1] = new_mv;
self.mv_f[idx + self.w + 1] = new_mv;
has_tl = if x == 0 { sstate.has_left } else { true };
}
let pred_mv = self.pred_mv(idx8 + x, true, has_top, has_left, has_tr, has_tl, false);
-//println!(" + {}", mvs[x+y*2]);
let new_mv = mvs[x + y * 2] + pred_mv;
self.mv_f[idx8 + x] = new_mv;
}
self.fill(mb_x, mb_y, false, new_mv);
},
MBType::MBForward => {
-let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
-println!(" fwd = {} + {}", pred_mv, mvs[0]);
+ let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
let new_mv = mvs[0] + pred_mv;
self.fill(mb_x, mb_y, true, new_mv);
},
MBType::MBBackward => {
-let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
-println!(" bwd = {} + {}", pred_mv, mvs[0]);
+ let pred_mv = self.pred_mv(idx, mbtype.is_fwd(), sstate.has_top, sstate.has_left, sstate.has_tr, sstate.has_tl, true);
let new_mv = mvs[0] + pred_mv;
self.fill(mb_x, mb_y, false, new_mv);
},
} else {
shdr.end = ((shdr.width + 15) >> 4) * ((shdr.height + 15) >> 4);
}
-//println!(" slice {}: {} - {}x{} deblock {} {:X} q{} {}-{}", slice_no, shdr.ftype, shdr.width, shdr.height, shdr.deblock, shdr.pts, shdr.quant, shdr.start, shdr.end);
Ok(shdr)
}
if is_16 {
let im16 = imode.get_pred16_type(sstate.has_top, sstate.has_left);
-//println!(" pred16 {:?}", im16);
self.cdsp.ipred16x16[im16 as usize](framebuf, offset, stride);
}
} else {
[0; 4]
};
-//println!(" pred4 {},{} {:?} ({})", x, y, im, im as u8);
self.cdsp.ipred4x4[im as usize](framebuf, offset + x*4, stride, &topright);
}
if has_ac {
let framebuf: &mut [u8] = data.as_mut_slice();
if is_16 {
let im8 = imode.get_pred8_type(sstate.has_top, sstate.has_left);
-//println!(" pred8 {:?}", im8);
self.cdsp.ipred8x8[im8 as usize](framebuf, offset, stride);
}
for y in 0..2 {
} else {
[0; 4]
};
-//println!(" pred4chr {},{} {:?} ({})", x, y, im, im as u8);
self.cdsp.ipred4x4[im as usize](framebuf, offset + x*4, stride, &topright);
}
if has_ac {
}
//todo validate against ref frame
-//println!(" frame {:?} pts {} {}x{} trd = {} trb = {}", hdr0.ftype, hdr0.pts, hdr0.width, hdr0.height, sstate.trd, sstate.trb);
-
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); }
sstate.mb_x = mb_x;
if mb_pos == slice.end {
slice = decode_slice_header(&mut br, bd, slice_no, &slice_offs, self.width, self.height)?;
-//println!(" new slice! {}-{}", mb_pos, slice.end);
validate!(slice.fits(&hdr0));
q = slice.quant;
slice_no += 1;
}
}
let cbp;
-// println!(" mb {}.{} type {:?}", mb_x, mb_y, mbh.mbtype);
let is_16 = (mbh.mbtype == MBType::MBIntra16) || (mbh.mbtype == MBType::MBP16x16Mix);
if mbh.mbtype == MBType::MBSkip {
cbp = 0;
self.coderead.select_codes(true, q, slice.set_idx, true);
}
cbp = self.coderead.decode_cbp(&mut br)?;
-// println!(" CBP {:X} @ {}", cbp, br.tell());
}
sstate.cbp = cbp;
if is_intra || mbh.mbtype.is_intra() {
if hdr0.deblock {
self.dsp.loop_filter(&mut buf, hdr0.ftype, &mbinfo, mb_w, mb_h - 1);
}
-/*if self.is_b{
- let stride = buf.get_stride(0);
- let mut offset = buf.get_offset(0);
- let mut data = buf.get_data_mut();
- let framebuf: &mut [u8] = data.as_mut_slice();
-
- for _ in 0..mb_h {
- for x in 0..mb_w {
- for i in 0..16 { framebuf[offset + x * 16 + 15 + i*stride] = 255; }
- }
- for x in 0..mb_w*16 { framebuf[offset+stride*15+x] = 255;}
- offset += 16 * stride;
- }
-}*/
if !self.is_b {
self.ipbs.add_frame(buf);
mem::swap(&mut self.mvi, &mut self.ref_mvi);
h = old_h;
}
let start = br.read(get_slice_start_offset_bits(w, h))? as usize;
-//println!(" type {:?} q {} set {} pts {} {}x{} start {} @ {}", ftype, q, set_idx, pts, w, h, start, br.tell());
self.had_skip_run = false;
}
fn decode_intra_pred(&mut self, br: &mut BitReader, types: &mut [i8], mut pos: usize, tstride: usize, has_top: bool) -> DecoderResult<()> {
let start;
-//println!(" @ {}", br.tell());
if has_top {
start = 0;
} else {
types[pos + 1] = (code >> 1) & 2;
types[pos + 2] = (code >> 0) & 2;
types[pos + 3] = (code << 1) & 2;
-//println!(" first line {} {} {} {} @ {}", types[pos +0],types[pos+1],types[pos+2],types[pos+3],br.tell());
pos += tstride;
start = 1;
}
let tr = types[pos + x - tstride + 1];
let t = types[pos + x - tstride];
let l = types[pos + x - 1];
-//println!(" x = {} ctx {} {} {} @ {}", x, l, t, tr, br.tell());
let ctx = if x < 3 { ((tr & 0xF) as u16) + (((t as u16) & 0xF) << 4) + (((l as u16) & 0xF) << 8) } else { 0xFFF };
let res = RV40_AIC_PATTERNS.iter().position(|&x| x == ctx);
if let Some(idx) = res {
let code = br.read_cb(&self.aic_mode2_cb[idx])?;
types[pos + x + 0] = code / 9;
types[pos + x + 1] = code % 9;
-//println!(" -> {} {}", types[pos + x + 0], types[pos + x + 1]);
x += 2;
} else {
if (t != -1) && (l != -1) {
_ => { types[pos + x] = 0; },
};
}
-//println!(" -> {}", types[pos + x]);
x += 1;
}
}
fn decode(&mut self, pkt: &NAPacket) -> DecoderResult<NAFrameRef> {
let src = pkt.get_buffer();
-//println!(" decode frame size {}, {} slices", src.len(), src[0]+1);
-
let (bufinfo, ftype, ts) = self.dec.parse_frame(src.as_slice(), &mut self.bd)?;
let mut frm = NAFrame::new_from_pkt(pkt, self.info.clone(), bufinfo);