2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-09 17:29:20 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-09 17:29:20 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
#include <assert.h>
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
#include "./vp9_rtcd.h"
|
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
#include "vpx_scale/vpx_scale.h"
|
|
|
|
|
2013-06-28 01:15:43 +02:00
|
|
|
#include "vp9/common/vp9_alloccommon.h"
|
2013-01-06 03:20:25 +01:00
|
|
|
#include "vp9/common/vp9_common.h"
|
2012-11-29 00:15:51 +01:00
|
|
|
#include "vp9/common/vp9_entropy.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_entropymode.h"
|
2013-06-28 01:15:43 +02:00
|
|
|
#include "vp9/common/vp9_extend.h"
|
|
|
|
#include "vp9/common/vp9_pred_common.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_quant_common.h"
|
2013-06-28 01:15:43 +02:00
|
|
|
#include "vp9/common/vp9_reconintra.h"
|
|
|
|
#include "vp9/common/vp9_reconinter.h"
|
2013-05-29 03:07:54 +02:00
|
|
|
#include "vp9/common/vp9_seg_common.h"
|
|
|
|
#include "vp9/common/vp9_tile_common.h"
|
2013-05-22 00:31:32 +02:00
|
|
|
|
|
|
|
#include "vp9/decoder/vp9_dboolhuff.h"
|
2013-05-29 03:07:54 +02:00
|
|
|
#include "vp9/decoder/vp9_decodframe.h"
|
|
|
|
#include "vp9/decoder/vp9_detokenize.h"
|
|
|
|
#include "vp9/decoder/vp9_decodemv.h"
|
2013-06-25 20:52:44 +02:00
|
|
|
#include "vp9/decoder/vp9_dsubexp.h"
|
2013-05-29 03:07:54 +02:00
|
|
|
#include "vp9/decoder/vp9_onyxd_int.h"
|
|
|
|
#include "vp9/decoder/vp9_read_bit_buffer.h"
|
2013-05-22 00:31:32 +02:00
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2013-02-20 19:16:24 +01:00
|
|
|
// #define DEC_DEBUG
|
2012-11-16 00:14:38 +01:00
|
|
|
#ifdef DEC_DEBUG
|
|
|
|
int dec_debug = 0;
|
|
|
|
#endif
|
|
|
|
|
2013-06-11 01:13:08 +02:00
|
|
|
static int read_be32(const uint8_t *p) {
|
|
|
|
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
|
2013-03-14 20:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// len == 0 is not allowed
|
2013-04-05 19:47:26 +02:00
|
|
|
static int read_is_valid(const uint8_t *start, size_t len,
|
|
|
|
const uint8_t *end) {
|
2013-03-14 20:31:54 +01:00
|
|
|
return start + len > start && start + len <= end;
|
|
|
|
}
|
|
|
|
|
2013-06-25 20:52:44 +02:00
|
|
|
static int decode_unsigned_max(struct vp9_read_bit_buffer *rb, int max) {
|
|
|
|
const int data = vp9_rb_read_literal(rb, get_unsigned_bits(max));
|
|
|
|
return data > max ? max : data;
|
|
|
|
}
|
|
|
|
|
2013-07-08 20:54:36 +02:00
|
|
|
static TXFM_MODE read_tx_mode(vp9_reader *r) {
|
|
|
|
TXFM_MODE txfm_mode = vp9_read_literal(r, 2);
|
|
|
|
if (txfm_mode == ALLOW_32X32)
|
|
|
|
txfm_mode += vp9_read_bit(r);
|
|
|
|
return txfm_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void read_tx_probs(FRAME_CONTEXT *fc, vp9_reader *r) {
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
|
|
|
|
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j)
|
|
|
|
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
|
2013-07-11 02:36:06 +02:00
|
|
|
vp9_diff_update_prob(r, &fc->tx_probs.p8x8[i][j]);
|
2013-07-08 20:54:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
|
|
|
|
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j)
|
|
|
|
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
|
2013-07-11 02:36:06 +02:00
|
|
|
vp9_diff_update_prob(r, &fc->tx_probs.p16x16[i][j]);
|
2013-07-08 20:54:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
|
|
|
|
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j)
|
|
|
|
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
|
2013-07-11 02:36:06 +02:00
|
|
|
vp9_diff_update_prob(r, &fc->tx_probs.p32x32[i][j]);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
static void mb_init_dequantizer(VP9_COMMON *pc, MACROBLOCKD *xd) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2013-04-25 23:25:40 +02:00
|
|
|
const int segment_id = xd->mode_info_context->mbmi.segment_id;
|
2013-04-30 22:39:50 +02:00
|
|
|
xd->q_index = vp9_get_qindex(xd, segment_id, pc->base_qindex);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
xd->plane[0].dequant = pc->y_dequant[xd->q_index];
|
2013-04-24 23:48:17 +02:00
|
|
|
for (i = 1; i < MAX_MB_PLANE; i++)
|
2013-04-25 23:25:40 +02:00
|
|
|
xd->plane[i].dequant = pc->uv_dequant[xd->q_index];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-27 02:52:35 +02:00
|
|
|
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
|
|
|
|
int ss_txfrm_size, void *arg) {
|
|
|
|
MACROBLOCKD* const xd = arg;
|
2013-06-15 00:11:18 +02:00
|
|
|
struct macroblockd_plane *pd = &xd->plane[plane];
|
|
|
|
int16_t* const qcoeff = BLOCK_OFFSET(pd->qcoeff, block, 16);
|
|
|
|
const int stride = pd->dst.stride;
|
2013-04-27 02:52:35 +02:00
|
|
|
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
|
|
|
|
block, ss_txfrm_size);
|
|
|
|
uint8_t* const dst = raster_block_offset_uint8(xd, bsize, plane,
|
|
|
|
raster_block,
|
2013-06-15 00:11:18 +02:00
|
|
|
pd->dst.buf, stride);
|
2013-03-30 00:31:46 +01:00
|
|
|
|
2013-04-27 02:52:35 +02:00
|
|
|
TX_TYPE tx_type;
|
2013-04-10 21:30:20 +02:00
|
|
|
|
2013-04-27 02:52:35 +02:00
|
|
|
switch (ss_txfrm_size / 2) {
|
|
|
|
case TX_4X4:
|
|
|
|
tx_type = plane == 0 ? get_tx_type_4x4(xd, raster_block) : DCT_DCT;
|
|
|
|
if (tx_type == DCT_DCT)
|
2013-06-15 00:11:18 +02:00
|
|
|
xd->itxm_add(qcoeff, dst, stride, pd->eobs[block]);
|
2013-04-27 02:52:35 +02:00
|
|
|
else
|
2013-06-15 00:11:18 +02:00
|
|
|
vp9_iht_add_c(tx_type, qcoeff, dst, stride, pd->eobs[block]);
|
2013-04-27 02:52:35 +02:00
|
|
|
break;
|
|
|
|
case TX_8X8:
|
2013-06-25 02:56:06 +02:00
|
|
|
tx_type = plane == 0 ? get_tx_type_8x8(xd) : DCT_DCT;
|
2013-06-15 00:11:18 +02:00
|
|
|
vp9_iht_add_8x8_c(tx_type, qcoeff, dst, stride, pd->eobs[block]);
|
2013-04-27 02:52:35 +02:00
|
|
|
break;
|
|
|
|
case TX_16X16:
|
2013-06-25 02:56:06 +02:00
|
|
|
tx_type = plane == 0 ? get_tx_type_16x16(xd) : DCT_DCT;
|
2013-06-15 00:11:18 +02:00
|
|
|
vp9_iht_add_16x16_c(tx_type, qcoeff, dst, stride, pd->eobs[block]);
|
2013-04-27 02:52:35 +02:00
|
|
|
break;
|
|
|
|
case TX_32X32:
|
2013-06-15 00:11:18 +02:00
|
|
|
vp9_idct_add_32x32(qcoeff, dst, stride, pd->eobs[block]);
|
2013-04-27 02:52:35 +02:00
|
|
|
break;
|
2012-11-16 00:14:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-17 21:50:40 +02:00
|
|
|
static void decode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
|
|
|
|
int ss_txfrm_size, void *arg) {
|
|
|
|
MACROBLOCKD* const xd = arg;
|
2013-06-15 00:11:18 +02:00
|
|
|
struct macroblockd_plane *pd = &xd->plane[plane];
|
2013-06-28 01:15:43 +02:00
|
|
|
MODE_INFO *const mi = xd->mode_info_context;
|
2013-06-15 00:11:18 +02:00
|
|
|
|
2013-05-17 21:50:40 +02:00
|
|
|
const int raster_block = txfrm_block_to_raster_block(xd, bsize, plane,
|
|
|
|
block, ss_txfrm_size);
|
|
|
|
uint8_t* const dst = raster_block_offset_uint8(xd, bsize, plane,
|
|
|
|
raster_block,
|
2013-06-15 00:11:18 +02:00
|
|
|
pd->dst.buf, pd->dst.stride);
|
2013-05-17 21:50:40 +02:00
|
|
|
const TX_SIZE tx_size = (TX_SIZE)(ss_txfrm_size / 2);
|
2013-06-15 00:11:18 +02:00
|
|
|
int b_mode;
|
2013-05-17 21:50:40 +02:00
|
|
|
int plane_b_size;
|
2013-06-15 00:11:18 +02:00
|
|
|
const int tx_ib = raster_block >> tx_size;
|
2013-06-28 01:15:43 +02:00
|
|
|
const int mode = plane == 0 ? mi->mbmi.mode
|
|
|
|
: mi->mbmi.uv_mode;
|
2013-05-17 21:50:40 +02:00
|
|
|
|
2013-06-28 01:15:43 +02:00
|
|
|
if (plane == 0 && mi->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
|
2013-05-30 20:27:40 +02:00
|
|
|
assert(bsize == BLOCK_SIZE_SB8X8);
|
2013-07-03 01:51:57 +02:00
|
|
|
b_mode = mi->bmi[raster_block].as_mode;
|
2013-05-30 20:27:40 +02:00
|
|
|
} else {
|
2013-05-17 21:50:40 +02:00
|
|
|
b_mode = mode;
|
2013-05-30 20:27:40 +02:00
|
|
|
}
|
2013-05-17 21:50:40 +02:00
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0)
|
2013-06-06 15:07:09 +02:00
|
|
|
extend_for_intra(xd, plane, block, bsize, ss_txfrm_size);
|
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
plane_b_size = b_width_log2(bsize) - pd->subsampling_x;
|
|
|
|
vp9_predict_intra_block(xd, tx_ib, plane_b_size, tx_size, b_mode,
|
2013-06-26 04:41:56 +02:00
|
|
|
dst, pd->dst.stride,
|
2013-06-15 00:11:18 +02:00
|
|
|
dst, pd->dst.stride);
|
2013-05-17 21:50:40 +02:00
|
|
|
|
2013-06-14 01:37:52 +02:00
|
|
|
// Early exit if there are no coefficients
|
2013-06-28 01:15:43 +02:00
|
|
|
if (mi->mbmi.mb_skip_coeff)
|
2013-06-14 01:37:52 +02:00
|
|
|
return;
|
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
decode_block(plane, block, bsize, ss_txfrm_size, arg);
|
2013-05-17 21:50:40 +02:00
|
|
|
}
|
|
|
|
|
2013-06-28 01:15:43 +02:00
|
|
|
static int decode_tokens(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize, vp9_reader *r) {
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-04-30 19:16:09 +02:00
|
|
|
|
2013-06-28 01:15:43 +02:00
|
|
|
if (xd->mode_info_context->mbmi.mb_skip_coeff) {
|
2013-04-30 19:16:09 +02:00
|
|
|
vp9_reset_sb_tokens_context(xd, bsize);
|
2013-06-28 01:15:43 +02:00
|
|
|
return -1;
|
2013-04-30 19:16:09 +02:00
|
|
|
} else {
|
2013-07-10 21:29:43 +02:00
|
|
|
if (xd->seg.enabled)
|
2013-04-30 19:16:09 +02:00
|
|
|
mb_init_dequantizer(&pbi->common, xd);
|
|
|
|
|
2013-06-28 01:15:43 +02:00
|
|
|
// TODO(dkovalev) if (!vp9_reader_has_error(r))
|
|
|
|
return vp9_decode_tokens(pbi, r, bsize);
|
2013-04-30 19:16:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 03:04:57 +02:00
|
|
|
static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize,
|
2013-04-26 20:57:17 +02:00
|
|
|
int mi_row, int mi_col) {
|
2013-01-06 03:20:25 +01:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-06-15 00:11:18 +02:00
|
|
|
const int bh = 1 << mi_height_log2(bsize);
|
|
|
|
const int bw = 1 << mi_width_log2(bsize);
|
2013-04-26 20:57:17 +02:00
|
|
|
const int mi_idx = mi_row * cm->mode_info_stride + mi_col;
|
2013-05-07 19:09:57 +02:00
|
|
|
int i;
|
2013-04-09 19:17:22 +02:00
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
xd->mode_info_context = cm->mi + mi_idx;
|
2013-04-11 03:04:57 +02:00
|
|
|
xd->mode_info_context->mbmi.sb_type = bsize;
|
2013-05-29 22:42:23 +02:00
|
|
|
// Special case: if prev_mi is NULL, the previous mode info context
|
|
|
|
// cannot be used.
|
2013-06-15 00:11:18 +02:00
|
|
|
xd->prev_mode_info_context = cm->prev_mi ? cm->prev_mi + mi_idx : NULL;
|
2013-04-26 20:57:17 +02:00
|
|
|
|
2013-04-29 19:37:25 +02:00
|
|
|
for (i = 0; i < MAX_MB_PLANE; i++) {
|
2013-06-15 00:11:18 +02:00
|
|
|
struct macroblockd_plane *pd = &xd->plane[i];
|
|
|
|
pd->above_context = cm->above_context[i] +
|
|
|
|
(mi_col * 2 >> pd->subsampling_x);
|
|
|
|
pd->left_context = cm->left_context[i] +
|
|
|
|
(((mi_row * 2) & 15) >> pd->subsampling_y);
|
2013-04-29 19:37:25 +02:00
|
|
|
}
|
2013-07-03 20:15:58 +02:00
|
|
|
|
|
|
|
set_partition_seg_context(cm, xd, mi_row, mi_col);
|
2013-01-06 03:20:25 +01:00
|
|
|
|
2013-04-09 19:17:22 +02:00
|
|
|
// Distance of Mb to the various image edges. These are specified to 8th pel
|
|
|
|
// as they are always compared to values that are in 1/8th pel units
|
2013-04-26 20:57:17 +02:00
|
|
|
set_mi_row_col(cm, xd, mi_row, bh, mi_col, bw);
|
2013-01-06 03:20:25 +01:00
|
|
|
|
2013-05-07 19:09:57 +02:00
|
|
|
setup_dst_planes(xd, &cm->yv12_fb[cm->new_fb_idx], mi_row, mi_col);
|
2013-01-06 03:20:25 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-07-04 02:42:01 +02:00
|
|
|
static void set_ref(VP9D_COMP *pbi, int i, int mi_row, int mi_col) {
|
2013-01-06 03:20:25 +01:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-03-14 20:31:54 +01:00
|
|
|
MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
|
2013-07-04 02:42:01 +02:00
|
|
|
const int ref = mbmi->ref_frame[i] - 1;
|
2013-01-06 03:20:25 +01:00
|
|
|
|
2013-07-04 02:42:01 +02:00
|
|
|
const YV12_BUFFER_CONFIG *cfg = &cm->yv12_fb[cm->active_ref_idx[ref]];
|
|
|
|
xd->scale_factor[i] = cm->active_ref_scale[ref];
|
|
|
|
xd->scale_factor_uv[i] = cm->active_ref_scale[ref];
|
|
|
|
setup_pre_planes(xd, i, cfg, mi_row, mi_col,
|
|
|
|
&xd->scale_factor[i], &xd->scale_factor_uv[i]);
|
2013-06-20 02:34:49 +02:00
|
|
|
xd->corrupted |= cfg->corrupted;
|
2013-01-06 03:20:25 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
static void decode_modes_b(VP9D_COMP *pbi, int mi_row, int mi_col,
|
2013-04-16 09:18:02 +02:00
|
|
|
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
|
2013-06-29 03:34:30 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-04-16 09:18:02 +02:00
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-06-29 03:34:30 +02:00
|
|
|
const int less8x8 = bsize < BLOCK_SIZE_SB8X8;
|
|
|
|
MB_MODE_INFO *mbmi;
|
2013-04-16 09:18:02 +02:00
|
|
|
|
2013-06-29 03:34:30 +02:00
|
|
|
if (less8x8)
|
2013-05-16 07:28:36 +02:00
|
|
|
if (xd->ab_index > 0)
|
|
|
|
return;
|
2013-06-28 01:15:43 +02:00
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
set_offsets(pbi, bsize, mi_row, mi_col);
|
2013-06-29 00:32:01 +02:00
|
|
|
vp9_read_mode_info(pbi, mi_row, mi_col, r);
|
2013-04-16 09:18:02 +02:00
|
|
|
|
2013-06-29 03:34:30 +02:00
|
|
|
if (less8x8)
|
|
|
|
bsize = BLOCK_SIZE_SB8X8;
|
|
|
|
|
|
|
|
// Has to be called after set_offsets
|
|
|
|
mbmi = &xd->mode_info_context->mbmi;
|
|
|
|
|
|
|
|
if (mbmi->ref_frame[0] == INTRA_FRAME) {
|
|
|
|
// Intra reconstruction
|
|
|
|
decode_tokens(pbi, bsize, r);
|
|
|
|
foreach_transformed_block(xd, bsize, decode_block_intra, xd);
|
2013-06-20 02:34:49 +02:00
|
|
|
} else {
|
2013-06-29 03:34:30 +02:00
|
|
|
// Inter reconstruction
|
|
|
|
int eobtotal;
|
2013-07-04 02:42:01 +02:00
|
|
|
|
|
|
|
set_ref(pbi, 0, mi_row, mi_col);
|
|
|
|
if (mbmi->ref_frame[1] > INTRA_FRAME)
|
|
|
|
set_ref(pbi, 1, mi_row, mi_col);
|
|
|
|
|
2013-06-29 03:34:30 +02:00
|
|
|
vp9_setup_interp_filters(xd, mbmi->interp_filter, cm);
|
|
|
|
vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
|
|
|
|
eobtotal = decode_tokens(pbi, bsize, r);
|
|
|
|
if (less8x8) {
|
|
|
|
if (eobtotal >= 0)
|
|
|
|
foreach_transformed_block(xd, bsize, decode_block, xd);
|
|
|
|
} else {
|
|
|
|
assert(mbmi->sb_type == bsize);
|
|
|
|
if (eobtotal == 0)
|
2013-07-10 04:55:07 +02:00
|
|
|
vp9_set_pred_flag_mbskip(xd, bsize, 1); // skip loopfilter
|
2013-06-29 03:34:30 +02:00
|
|
|
else if (eobtotal > 0)
|
|
|
|
foreach_transformed_block(xd, bsize, decode_block, xd);
|
|
|
|
}
|
2013-06-20 02:34:49 +02:00
|
|
|
}
|
2013-04-19 19:37:24 +02:00
|
|
|
xd->corrupted |= vp9_reader_has_error(r);
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
static void decode_modes_sb(VP9D_COMP *pbi, int mi_row, int mi_col,
|
2013-04-16 09:18:02 +02:00
|
|
|
vp9_reader* r, BLOCK_SIZE_TYPE bsize) {
|
2013-04-05 19:47:26 +02:00
|
|
|
VP9_COMMON *const pc = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-06-15 00:11:18 +02:00
|
|
|
int bs = (1 << mi_width_log2(bsize)) / 2, n;
|
2013-04-16 09:18:02 +02:00
|
|
|
PARTITION_TYPE partition = PARTITION_NONE;
|
|
|
|
BLOCK_SIZE_TYPE subsize;
|
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
if (mi_row >= pc->mi_rows || mi_col >= pc->mi_cols)
|
2013-04-16 09:18:02 +02:00
|
|
|
return;
|
|
|
|
|
2013-05-11 02:06:37 +02:00
|
|
|
if (bsize < BLOCK_SIZE_SB8X8)
|
|
|
|
if (xd->ab_index != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (bsize >= BLOCK_SIZE_SB8X8) {
|
2013-04-23 19:12:18 +02:00
|
|
|
int pl;
|
2013-07-03 20:15:58 +02:00
|
|
|
const int idx = check_bsize_coverage(pc, xd, mi_row, mi_col, bsize);
|
|
|
|
set_partition_seg_context(pc, xd, mi_row, mi_col);
|
2013-04-23 19:12:18 +02:00
|
|
|
pl = partition_plane_context(xd, bsize);
|
2013-06-07 00:33:57 +02:00
|
|
|
|
|
|
|
if (idx == 0)
|
|
|
|
partition = treed_read(r, vp9_partition_tree,
|
|
|
|
pc->fc.partition_prob[pc->frame_type][pl]);
|
|
|
|
else if (idx > 0 &&
|
|
|
|
!vp9_read(r, pc->fc.partition_prob[pc->frame_type][pl][idx]))
|
|
|
|
partition = (idx == 1) ? PARTITION_HORZ : PARTITION_VERT;
|
|
|
|
else
|
|
|
|
partition = PARTITION_SPLIT;
|
|
|
|
|
2013-04-23 19:12:18 +02:00
|
|
|
pc->fc.partition_counts[pl][partition]++;
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-05-01 18:43:59 +02:00
|
|
|
subsize = get_subsize(bsize, partition);
|
2013-05-16 07:28:36 +02:00
|
|
|
*(get_sb_index(xd, subsize)) = 0;
|
2013-05-11 02:06:37 +02:00
|
|
|
|
2013-04-16 09:18:02 +02:00
|
|
|
switch (partition) {
|
|
|
|
case PARTITION_NONE:
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_b(pbi, mi_row, mi_col, r, subsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
break;
|
|
|
|
case PARTITION_HORZ:
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_b(pbi, mi_row, mi_col, r, subsize);
|
2013-05-16 07:28:36 +02:00
|
|
|
*(get_sb_index(xd, subsize)) = 1;
|
2013-05-07 20:56:26 +02:00
|
|
|
if (mi_row + bs < pc->mi_rows)
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_b(pbi, mi_row + bs, mi_col, r, subsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
break;
|
|
|
|
case PARTITION_VERT:
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_b(pbi, mi_row, mi_col, r, subsize);
|
2013-05-16 07:28:36 +02:00
|
|
|
*(get_sb_index(xd, subsize)) = 1;
|
2013-05-07 20:56:26 +02:00
|
|
|
if (mi_col + bs < pc->mi_cols)
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_b(pbi, mi_row, mi_col + bs, r, subsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
break;
|
|
|
|
case PARTITION_SPLIT:
|
|
|
|
for (n = 0; n < 4; n++) {
|
|
|
|
int j = n >> 1, i = n & 0x01;
|
2013-05-11 22:24:03 +02:00
|
|
|
*(get_sb_index(xd, subsize)) = n;
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_sb(pbi, mi_row + j * bs, mi_col + i * bs, r, subsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2013-04-23 19:12:18 +02:00
|
|
|
// update partition context
|
2013-05-11 02:06:37 +02:00
|
|
|
if (bsize >= BLOCK_SIZE_SB8X8 &&
|
|
|
|
(bsize == BLOCK_SIZE_SB8X8 || partition != PARTITION_SPLIT)) {
|
2013-05-12 00:19:56 +02:00
|
|
|
set_partition_seg_context(pc, xd, mi_row, mi_col);
|
|
|
|
update_partition_context(xd, subsize, bsize);
|
|
|
|
}
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
|
|
|
|
2012-10-31 01:53:32 +01:00
|
|
|
static void setup_token_decoder(VP9D_COMP *pbi,
|
2013-06-11 19:06:31 +02:00
|
|
|
const uint8_t *data, size_t read_size,
|
2013-04-05 19:47:26 +02:00
|
|
|
vp9_reader *r) {
|
2013-03-12 01:02:27 +01:00
|
|
|
VP9_COMMON *pc = &pbi->common;
|
2013-04-05 19:47:26 +02:00
|
|
|
const uint8_t *data_end = pbi->source + pbi->source_sz;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-03-12 01:02:27 +01:00
|
|
|
// Validate the calculated partition length. If the buffer
|
|
|
|
// described by the partition can't be fully read, then restrict
|
|
|
|
// it to the portion that can be (for EC mode) or throw an error.
|
2013-06-11 19:06:31 +02:00
|
|
|
if (!read_is_valid(data, read_size, data_end))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
|
2013-06-11 19:06:31 +02:00
|
|
|
"Truncated packet or corrupt tile length");
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-06-11 19:06:31 +02:00
|
|
|
if (vp9_reader_init(r, data, read_size))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate bool decoder %d", 1);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-05-31 18:18:59 +02:00
|
|
|
static void read_coef_probs_common(FRAME_CONTEXT *fc, TX_SIZE tx_size,
|
|
|
|
vp9_reader *r) {
|
|
|
|
vp9_coeff_probs_model *coef_probs = fc->coef_probs[tx_size];
|
2013-07-08 20:54:36 +02:00
|
|
|
int i, j, k, l, m;
|
|
|
|
|
|
|
|
if (vp9_read_bit(r))
|
|
|
|
for (i = 0; i < BLOCK_TYPES; i++)
|
|
|
|
for (j = 0; j < REF_TYPES; j++)
|
|
|
|
for (k = 0; k < COEF_BANDS; k++)
|
|
|
|
for (l = 0; l < PREV_COEF_CONTEXTS; l++)
|
|
|
|
if (k > 0 || l < 3)
|
|
|
|
for (m = 0; m < UNCONSTRAINED_NODES; m++)
|
|
|
|
if (vp9_read(r, VP9_COEF_UPDATE_PROB))
|
|
|
|
vp9_diff_update_prob(r, &coef_probs[i][j][k][l][m]);
|
2012-10-20 00:35:36 +02:00
|
|
|
}
|
2012-09-10 07:42:35 +02:00
|
|
|
|
2013-07-08 20:54:36 +02:00
|
|
|
static void read_coef_probs(FRAME_CONTEXT *fc, TXFM_MODE txfm_mode,
|
|
|
|
vp9_reader *r) {
|
2013-05-31 18:18:59 +02:00
|
|
|
read_coef_probs_common(fc, TX_4X4, r);
|
2012-10-24 21:59:22 +02:00
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
if (txfm_mode > ONLY_4X4)
|
2013-05-31 18:18:59 +02:00
|
|
|
read_coef_probs_common(fc, TX_8X8, r);
|
2013-03-12 01:02:27 +01:00
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
if (txfm_mode > ALLOW_8X8)
|
2013-05-31 18:18:59 +02:00
|
|
|
read_coef_probs_common(fc, TX_16X16, r);
|
2013-03-12 01:02:27 +01:00
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
if (txfm_mode > ALLOW_16X16)
|
2013-05-31 18:18:59 +02:00
|
|
|
read_coef_probs_common(fc, TX_32X32, r);
|
2012-04-12 18:24:03 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 21:29:43 +02:00
|
|
|
static void setup_segmentation(struct segmentation *seg,
|
|
|
|
struct vp9_read_bit_buffer *rb) {
|
2013-03-26 19:04:25 +01:00
|
|
|
int i, j;
|
|
|
|
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->update_map = 0;
|
|
|
|
seg->update_data = 0;
|
2013-04-19 19:44:03 +02:00
|
|
|
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->enabled = vp9_rb_read_bit(rb);
|
|
|
|
if (!seg->enabled)
|
2013-04-24 00:50:56 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Segmentation map update
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->update_map = vp9_rb_read_bit(rb);
|
|
|
|
if (seg->update_map) {
|
2013-04-24 14:04:45 +02:00
|
|
|
for (i = 0; i < MB_SEG_TREE_PROBS; i++)
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->tree_probs[i] = vp9_rb_read_bit(rb) ? vp9_rb_read_literal(rb, 8)
|
|
|
|
: MAX_PROB;
|
2013-04-24 00:50:56 +02:00
|
|
|
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->temporal_update = vp9_rb_read_bit(rb);
|
|
|
|
if (seg->temporal_update) {
|
2013-04-24 00:50:56 +02:00
|
|
|
for (i = 0; i < PREDICTION_PROBS; i++)
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->pred_probs[i] = vp9_rb_read_bit(rb) ? vp9_rb_read_literal(rb, 8)
|
|
|
|
: MAX_PROB;
|
2013-04-24 00:50:56 +02:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < PREDICTION_PROBS; i++)
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->pred_probs[i] = MAX_PROB;
|
2013-03-26 19:04:25 +01:00
|
|
|
}
|
2013-04-24 00:50:56 +02:00
|
|
|
}
|
2013-03-26 19:04:25 +01:00
|
|
|
|
2013-04-24 00:50:56 +02:00
|
|
|
// Segmentation data update
|
2013-07-10 21:29:43 +02:00
|
|
|
seg->update_data = vp9_rb_read_bit(rb);
|
|
|
|
if (seg->update_data) {
|
|
|
|
seg->abs_delta = vp9_rb_read_bit(rb);
|
2013-04-24 00:50:56 +02:00
|
|
|
|
2013-07-10 21:29:43 +02:00
|
|
|
vp9_clearall_segfeatures(seg);
|
2013-04-24 00:50:56 +02:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_MB_SEGMENTS; i++) {
|
|
|
|
for (j = 0; j < SEG_LVL_MAX; j++) {
|
|
|
|
int data = 0;
|
2013-06-06 21:33:12 +02:00
|
|
|
const int feature_enabled = vp9_rb_read_bit(rb);
|
2013-04-24 00:50:56 +02:00
|
|
|
if (feature_enabled) {
|
2013-07-10 21:29:43 +02:00
|
|
|
vp9_enable_segfeature(seg, i, j);
|
2013-06-06 21:33:12 +02:00
|
|
|
data = decode_unsigned_max(rb, vp9_seg_feature_data_max(j));
|
2013-04-24 00:50:56 +02:00
|
|
|
if (vp9_is_segfeature_signed(j))
|
2013-06-06 21:33:12 +02:00
|
|
|
data = vp9_rb_read_bit(rb) ? -data : data;
|
2013-03-26 19:04:25 +01:00
|
|
|
}
|
2013-07-10 21:29:43 +02:00
|
|
|
vp9_set_segdata(seg, i, j, data);
|
2013-03-26 19:04:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
static void setup_loopfilter(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
|
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
|
|
|
|
|
|
|
cm->filter_level = vp9_rb_read_literal(rb, 6);
|
|
|
|
cm->sharpness_level = vp9_rb_read_literal(rb, 3);
|
2013-03-26 19:04:25 +01:00
|
|
|
|
|
|
|
// Read in loop filter deltas applied at the MB level based on mode or ref
|
|
|
|
// frame.
|
|
|
|
xd->mode_ref_lf_delta_update = 0;
|
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
xd->mode_ref_lf_delta_enabled = vp9_rb_read_bit(rb);
|
2013-03-26 19:04:25 +01:00
|
|
|
if (xd->mode_ref_lf_delta_enabled) {
|
2013-06-03 19:50:57 +02:00
|
|
|
xd->mode_ref_lf_delta_update = vp9_rb_read_bit(rb);
|
2013-03-26 19:04:25 +01:00
|
|
|
if (xd->mode_ref_lf_delta_update) {
|
2013-04-03 21:18:15 +02:00
|
|
|
int i;
|
|
|
|
|
2013-07-01 11:09:36 +02:00
|
|
|
for (i = 0; i < MAX_REF_LF_DELTAS; i++)
|
|
|
|
if (vp9_rb_read_bit(rb))
|
|
|
|
xd->ref_lf_deltas[i] = vp9_rb_read_signed_literal(rb, 6);
|
2013-03-26 19:04:25 +01:00
|
|
|
|
2013-07-01 11:09:36 +02:00
|
|
|
for (i = 0; i < MAX_MODE_LF_DELTAS; i++)
|
|
|
|
if (vp9_rb_read_bit(rb))
|
|
|
|
xd->mode_lf_deltas[i] = vp9_rb_read_signed_literal(rb, 6);
|
2013-03-26 19:04:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
static int read_delta_q(struct vp9_read_bit_buffer *rb, int *delta_q) {
|
|
|
|
const int old = *delta_q;
|
2013-07-01 11:09:36 +02:00
|
|
|
if (vp9_rb_read_bit(rb))
|
|
|
|
*delta_q = vp9_rb_read_signed_literal(rb, 4);
|
2013-06-03 19:50:57 +02:00
|
|
|
return old != *delta_q;
|
|
|
|
}
|
2013-04-10 03:24:08 +02:00
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
static void setup_quantization(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
|
2013-06-06 21:33:12 +02:00
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-06-03 19:50:57 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
int update = 0;
|
2013-06-06 21:33:12 +02:00
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS);
|
|
|
|
update |= read_delta_q(rb, &cm->y_dc_delta_q);
|
|
|
|
update |= read_delta_q(rb, &cm->uv_dc_delta_q);
|
|
|
|
update |= read_delta_q(rb, &cm->uv_ac_delta_q);
|
|
|
|
if (update)
|
|
|
|
vp9_init_dequantizer(cm);
|
2013-06-06 21:33:12 +02:00
|
|
|
|
|
|
|
xd->lossless = cm->base_qindex == 0 &&
|
|
|
|
cm->y_dc_delta_q == 0 &&
|
|
|
|
cm->uv_dc_delta_q == 0 &&
|
|
|
|
cm->uv_ac_delta_q == 0;
|
2013-06-25 20:52:44 +02:00
|
|
|
|
|
|
|
xd->itxm_add = xd->lossless ? vp9_idct_add_lossless_c
|
|
|
|
: vp9_idct_add;
|
2013-04-10 03:24:08 +02:00
|
|
|
}
|
|
|
|
|
2013-06-06 05:56:37 +02:00
|
|
|
static INTERPOLATIONFILTERTYPE read_interp_filter_type(
|
|
|
|
struct vp9_read_bit_buffer *rb) {
|
|
|
|
return vp9_rb_read_bit(rb) ? SWITCHABLE
|
|
|
|
: vp9_rb_read_literal(rb, 2);
|
2013-04-24 00:50:56 +02:00
|
|
|
}
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
static void read_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb,
|
2013-05-29 03:07:54 +02:00
|
|
|
int *width, int *height) {
|
2013-06-08 03:09:29 +02:00
|
|
|
const int w = vp9_rb_read_literal(rb, 16) + 1;
|
|
|
|
const int h = vp9_rb_read_literal(rb, 16) + 1;
|
2013-05-29 03:07:54 +02:00
|
|
|
*width = w;
|
|
|
|
*height = h;
|
2013-04-03 21:21:47 +02:00
|
|
|
}
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
static void setup_display_size(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
|
2013-06-07 22:41:44 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-06-08 03:09:29 +02:00
|
|
|
cm->display_width = cm->width;
|
|
|
|
cm->display_height = cm->height;
|
|
|
|
if (vp9_rb_read_bit(rb))
|
|
|
|
read_frame_size(cm, rb, &cm->display_width, &cm->display_height);
|
2013-06-07 22:41:44 +02:00
|
|
|
}
|
2013-03-27 22:04:35 +01:00
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
static void apply_frame_size(VP9D_COMP *pbi, int width, int height) {
|
|
|
|
VP9_COMMON *cm = &pbi->common;
|
2013-03-27 22:04:35 +01:00
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
if (cm->width != width || cm->height != height) {
|
2013-03-27 22:04:35 +01:00
|
|
|
if (!pbi->initial_width || !pbi->initial_height) {
|
2013-06-07 22:41:44 +02:00
|
|
|
if (vp9_alloc_frame_buffers(cm, width, height))
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
2013-03-27 22:04:35 +01:00
|
|
|
"Failed to allocate frame buffers");
|
2013-06-06 05:56:37 +02:00
|
|
|
pbi->initial_width = width;
|
|
|
|
pbi->initial_height = height;
|
2013-04-03 21:21:47 +02:00
|
|
|
} else {
|
|
|
|
if (width > pbi->initial_width)
|
2013-06-07 22:41:44 +02:00
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
|
2013-04-03 21:21:47 +02:00
|
|
|
"Frame width too large");
|
2013-03-27 22:04:35 +01:00
|
|
|
|
2013-04-03 21:21:47 +02:00
|
|
|
if (height > pbi->initial_height)
|
2013-06-07 22:41:44 +02:00
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
|
2013-04-03 21:21:47 +02:00
|
|
|
"Frame height too large");
|
2013-03-27 22:04:35 +01:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
cm->width = width;
|
|
|
|
cm->height = height;
|
2013-03-27 22:04:35 +01:00
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
vp9_update_frame_size(cm);
|
2013-03-27 22:04:35 +01:00
|
|
|
}
|
2013-06-06 05:56:37 +02:00
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
vp9_realloc_frame_buffer(&cm->yv12_fb[cm->new_fb_idx], cm->width, cm->height,
|
|
|
|
cm->subsampling_x, cm->subsampling_y,
|
2013-06-06 05:56:37 +02:00
|
|
|
VP9BORDERINPIXELS);
|
2013-03-27 22:04:35 +01:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
static void setup_frame_size(VP9D_COMP *pbi,
|
|
|
|
struct vp9_read_bit_buffer *rb) {
|
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
int width, height;
|
|
|
|
read_frame_size(cm, rb, &width, &height);
|
|
|
|
setup_display_size(pbi, rb);
|
|
|
|
apply_frame_size(pbi, width, height);
|
|
|
|
}
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
static void setup_frame_size_with_refs(VP9D_COMP *pbi,
|
|
|
|
struct vp9_read_bit_buffer *rb) {
|
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
|
|
|
|
int width, height;
|
|
|
|
int found = 0, i;
|
|
|
|
for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) {
|
|
|
|
if (vp9_rb_read_bit(rb)) {
|
|
|
|
YV12_BUFFER_CONFIG *cfg = &cm->yv12_fb[cm->active_ref_idx[i]];
|
|
|
|
width = cfg->y_crop_width;
|
|
|
|
height = cfg->y_crop_height;
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
read_frame_size(cm, rb, &width, &height);
|
|
|
|
|
2013-06-11 23:24:53 +02:00
|
|
|
if (!width || !height)
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
|
|
|
|
"Referenced frame with invalid size");
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
setup_display_size(pbi, rb);
|
|
|
|
apply_frame_size(pbi, width, height);
|
|
|
|
}
|
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
static void update_frame_context(FRAME_CONTEXT *fc) {
|
2013-05-31 18:18:59 +02:00
|
|
|
vp9_copy(fc->pre_coef_probs, fc->coef_probs);
|
2013-05-30 18:58:53 +02:00
|
|
|
vp9_copy(fc->pre_y_mode_prob, fc->y_mode_prob);
|
2013-03-27 22:04:35 +01:00
|
|
|
vp9_copy(fc->pre_uv_mode_prob, fc->uv_mode_prob);
|
2013-06-03 19:39:40 +02:00
|
|
|
vp9_copy(fc->pre_partition_prob, fc->partition_prob[1]);
|
2013-06-06 22:44:34 +02:00
|
|
|
vp9_copy(fc->pre_intra_inter_prob, fc->intra_inter_prob);
|
|
|
|
vp9_copy(fc->pre_comp_inter_prob, fc->comp_inter_prob);
|
|
|
|
vp9_copy(fc->pre_single_ref_prob, fc->single_ref_prob);
|
|
|
|
vp9_copy(fc->pre_comp_ref_prob, fc->comp_ref_prob);
|
2013-03-27 22:04:35 +01:00
|
|
|
fc->pre_nmvc = fc->nmvc;
|
2013-06-06 05:56:37 +02:00
|
|
|
vp9_copy(fc->pre_switchable_interp_prob, fc->switchable_interp_prob);
|
|
|
|
vp9_copy(fc->pre_inter_mode_probs, fc->inter_mode_probs);
|
2013-07-11 02:36:06 +02:00
|
|
|
fc->pre_tx_probs = fc->tx_probs;
|
2013-06-07 22:24:14 +02:00
|
|
|
vp9_copy(fc->pre_mbskip_probs, fc->mbskip_probs);
|
2013-03-27 22:04:35 +01:00
|
|
|
|
2013-05-31 18:18:59 +02:00
|
|
|
vp9_zero(fc->coef_counts);
|
2013-03-27 22:04:35 +01:00
|
|
|
vp9_zero(fc->eob_branch_counts);
|
2013-05-30 18:58:53 +02:00
|
|
|
vp9_zero(fc->y_mode_counts);
|
2013-03-27 22:04:35 +01:00
|
|
|
vp9_zero(fc->uv_mode_counts);
|
|
|
|
vp9_zero(fc->NMVcount);
|
2013-06-05 00:25:16 +02:00
|
|
|
vp9_zero(fc->inter_mode_counts);
|
2013-04-16 09:18:02 +02:00
|
|
|
vp9_zero(fc->partition_counts);
|
2013-06-05 00:25:16 +02:00
|
|
|
vp9_zero(fc->switchable_interp_count);
|
2013-06-06 22:44:34 +02:00
|
|
|
vp9_zero(fc->intra_inter_count);
|
|
|
|
vp9_zero(fc->comp_inter_count);
|
|
|
|
vp9_zero(fc->single_ref_count);
|
|
|
|
vp9_zero(fc->comp_ref_count);
|
2013-07-11 02:36:06 +02:00
|
|
|
vp9_zero(fc->tx_counts);
|
2013-06-07 22:24:14 +02:00
|
|
|
vp9_zero(fc->mbskip_count);
|
2013-03-27 22:04:35 +01:00
|
|
|
}
|
2013-03-26 19:04:25 +01:00
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
static void decode_tile(VP9D_COMP *pbi, vp9_reader *r) {
|
|
|
|
VP9_COMMON *const pc = &pbi->common;
|
2013-04-26 20:57:17 +02:00
|
|
|
int mi_row, mi_col;
|
2013-04-25 23:25:40 +02:00
|
|
|
|
2013-07-03 19:54:50 +02:00
|
|
|
for (mi_row = pc->cur_tile_mi_row_start; mi_row < pc->cur_tile_mi_row_end;
|
|
|
|
mi_row += MI_BLOCK_SIZE) {
|
2013-04-25 23:25:40 +02:00
|
|
|
// For a SB there are 2 left contexts, each pertaining to a MB row within
|
2013-04-29 19:37:25 +02:00
|
|
|
vpx_memset(&pc->left_context, 0, sizeof(pc->left_context));
|
2013-04-25 23:25:40 +02:00
|
|
|
vpx_memset(pc->left_seg_context, 0, sizeof(pc->left_seg_context));
|
2013-07-03 19:54:50 +02:00
|
|
|
for (mi_col = pc->cur_tile_mi_col_start; mi_col < pc->cur_tile_mi_col_end;
|
|
|
|
mi_col += MI_BLOCK_SIZE)
|
2013-04-26 20:57:17 +02:00
|
|
|
decode_modes_sb(pbi, mi_row, mi_col, r, BLOCK_SIZE_SB64X64);
|
2013-04-25 23:25:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
|
|
|
|
int delta_log2_tiles;
|
2013-03-28 00:23:12 +01:00
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
vp9_get_tile_n_bits(cm, &cm->log2_tile_columns, &delta_log2_tiles);
|
2013-03-28 00:23:12 +01:00
|
|
|
while (delta_log2_tiles--) {
|
2013-06-06 21:33:12 +02:00
|
|
|
if (vp9_rb_read_bit(rb)) {
|
|
|
|
cm->log2_tile_columns++;
|
2013-03-28 00:23:12 +01:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-06-06 21:33:12 +02:00
|
|
|
|
|
|
|
cm->log2_tile_rows = vp9_rb_read_bit(rb);
|
|
|
|
if (cm->log2_tile_rows)
|
|
|
|
cm->log2_tile_rows += vp9_rb_read_bit(rb);
|
|
|
|
|
|
|
|
cm->tile_columns = 1 << cm->log2_tile_columns;
|
|
|
|
cm->tile_rows = 1 << cm->log2_tile_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void decode_tiles(VP9D_COMP *pbi,
|
|
|
|
const uint8_t *data, size_t first_partition_size,
|
|
|
|
vp9_reader *residual_bc) {
|
|
|
|
VP9_COMMON *const pc = &pbi->common;
|
|
|
|
|
|
|
|
const uint8_t *data_ptr = data + first_partition_size;
|
2013-07-08 23:54:04 +02:00
|
|
|
const uint8_t *const data_end = pbi->source + pbi->source_sz;
|
|
|
|
const int aligned_mi_cols = mi_cols_aligned_to_sb(pc->mi_cols);
|
2013-06-06 21:33:12 +02:00
|
|
|
int tile_row, tile_col;
|
2013-03-28 00:23:12 +01:00
|
|
|
|
2013-04-29 19:37:25 +02:00
|
|
|
// Note: this memset assumes above_context[0], [1] and [2]
|
|
|
|
// are allocated as part of the same buffer.
|
2013-07-08 23:54:04 +02:00
|
|
|
vpx_memset(pc->above_context[0], 0,
|
|
|
|
sizeof(ENTROPY_CONTEXT) * 2 * MAX_MB_PLANE * aligned_mi_cols);
|
2013-04-23 19:12:18 +02:00
|
|
|
|
2013-07-08 23:54:04 +02:00
|
|
|
vpx_memset(pc->above_seg_context, 0,
|
|
|
|
sizeof(PARTITION_CONTEXT) * aligned_mi_cols);
|
2013-03-28 00:23:12 +01:00
|
|
|
|
|
|
|
if (pbi->oxcf.inv_tile_order) {
|
|
|
|
const int n_cols = pc->tile_columns;
|
|
|
|
const uint8_t *data_ptr2[4][1 << 6];
|
2013-04-26 20:40:43 +02:00
|
|
|
vp9_reader bc_bak = {0};
|
2013-03-28 00:23:12 +01:00
|
|
|
|
|
|
|
// pre-initialize the offsets, we're going to read in inverse order
|
|
|
|
data_ptr2[0][0] = data_ptr;
|
|
|
|
for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
|
|
|
|
if (tile_row) {
|
2013-06-11 01:13:08 +02:00
|
|
|
const int size = read_be32(data_ptr2[tile_row - 1][n_cols - 1]);
|
2013-03-28 00:23:12 +01:00
|
|
|
data_ptr2[tile_row - 1][n_cols - 1] += 4;
|
|
|
|
data_ptr2[tile_row][0] = data_ptr2[tile_row - 1][n_cols - 1] + size;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tile_col = 1; tile_col < n_cols; tile_col++) {
|
2013-06-11 01:13:08 +02:00
|
|
|
const int size = read_be32(data_ptr2[tile_row][tile_col - 1]);
|
2013-03-28 00:23:12 +01:00
|
|
|
data_ptr2[tile_row][tile_col - 1] += 4;
|
|
|
|
data_ptr2[tile_row][tile_col] =
|
|
|
|
data_ptr2[tile_row][tile_col - 1] + size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
|
|
|
|
vp9_get_tile_row_offsets(pc, tile_row);
|
|
|
|
for (tile_col = n_cols - 1; tile_col >= 0; tile_col--) {
|
|
|
|
vp9_get_tile_col_offsets(pc, tile_col);
|
2013-06-11 19:06:31 +02:00
|
|
|
setup_token_decoder(pbi, data_ptr2[tile_row][tile_col],
|
|
|
|
data_end - data_ptr2[tile_row][tile_col],
|
|
|
|
residual_bc);
|
2013-04-17 22:42:51 +02:00
|
|
|
decode_tile(pbi, residual_bc);
|
2013-03-28 00:23:12 +01:00
|
|
|
if (tile_row == pc->tile_rows - 1 && tile_col == n_cols - 1)
|
|
|
|
bc_bak = *residual_bc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*residual_bc = bc_bak;
|
|
|
|
} else {
|
|
|
|
int has_more;
|
|
|
|
|
|
|
|
for (tile_row = 0; tile_row < pc->tile_rows; tile_row++) {
|
|
|
|
vp9_get_tile_row_offsets(pc, tile_row);
|
|
|
|
for (tile_col = 0; tile_col < pc->tile_columns; tile_col++) {
|
2013-06-11 19:06:31 +02:00
|
|
|
size_t size;
|
|
|
|
|
2013-03-28 00:23:12 +01:00
|
|
|
vp9_get_tile_col_offsets(pc, tile_col);
|
|
|
|
|
|
|
|
has_more = tile_col < pc->tile_columns - 1 ||
|
|
|
|
tile_row < pc->tile_rows - 1;
|
|
|
|
if (has_more) {
|
2013-06-11 19:06:31 +02:00
|
|
|
if (!read_is_valid(data_ptr, 4, data_end))
|
|
|
|
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
|
|
|
|
"Truncated packet or corrupt tile length");
|
|
|
|
|
|
|
|
size = read_be32(data_ptr);
|
|
|
|
data_ptr += 4;
|
|
|
|
} else {
|
|
|
|
size = data_end - data_ptr;
|
2013-03-28 00:23:12 +01:00
|
|
|
}
|
2013-06-11 19:06:31 +02:00
|
|
|
|
|
|
|
setup_token_decoder(pbi, data_ptr, size, residual_bc);
|
|
|
|
decode_tile(pbi, residual_bc);
|
|
|
|
data_ptr += size;
|
2013-03-28 00:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
static void check_sync_code(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
|
|
|
|
if (vp9_rb_read_literal(rb, 8) != SYNC_CODE_0 ||
|
|
|
|
vp9_rb_read_literal(rb, 8) != SYNC_CODE_1 ||
|
|
|
|
vp9_rb_read_literal(rb, 8) != SYNC_CODE_2) {
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
|
|
|
|
"Invalid frame sync code");
|
|
|
|
}
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-06-14 00:17:23 +02:00
|
|
|
static void error_handler(void *data, size_t bit_offset) {
|
2013-05-29 03:07:54 +02:00
|
|
|
VP9_COMMON *const cm = (VP9_COMMON *)data;
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet");
|
|
|
|
}
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
static void setup_inter_inter(VP9_COMMON *cm) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cm->allow_comp_inter_inter = 0;
|
|
|
|
for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) {
|
|
|
|
cm->allow_comp_inter_inter |= i > 0 &&
|
|
|
|
cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cm->allow_comp_inter_inter) {
|
|
|
|
// which one is always-on in comp inter-inter?
|
|
|
|
if (cm->ref_frame_sign_bias[LAST_FRAME] ==
|
|
|
|
cm->ref_frame_sign_bias[GOLDEN_FRAME]) {
|
|
|
|
cm->comp_fixed_ref = ALTREF_FRAME;
|
|
|
|
cm->comp_var_ref[0] = LAST_FRAME;
|
|
|
|
cm->comp_var_ref[1] = GOLDEN_FRAME;
|
|
|
|
} else if (cm->ref_frame_sign_bias[LAST_FRAME] ==
|
|
|
|
cm->ref_frame_sign_bias[ALTREF_FRAME]) {
|
|
|
|
cm->comp_fixed_ref = GOLDEN_FRAME;
|
|
|
|
cm->comp_var_ref[0] = LAST_FRAME;
|
|
|
|
cm->comp_var_ref[1] = ALTREF_FRAME;
|
|
|
|
} else {
|
|
|
|
cm->comp_fixed_ref = LAST_FRAME;
|
|
|
|
cm->comp_var_ref[0] = GOLDEN_FRAME;
|
|
|
|
cm->comp_var_ref[1] = ALTREF_FRAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 08:53:56 +02:00
|
|
|
#define RESERVED \
|
|
|
|
if (vp9_rb_read_bit(rb)) \
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, \
|
|
|
|
"Reserved bit must be unset")
|
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
static size_t read_uncompressed_header(VP9D_COMP *pbi,
|
|
|
|
struct vp9_read_bit_buffer *rb) {
|
2013-05-29 03:07:54 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-06-06 05:56:37 +02:00
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-06-07 22:41:44 +02:00
|
|
|
int i;
|
2013-05-29 03:07:54 +02:00
|
|
|
|
|
|
|
cm->last_frame_type = cm->frame_type;
|
2013-06-07 22:41:44 +02:00
|
|
|
|
2013-06-07 08:53:56 +02:00
|
|
|
if (vp9_rb_read_literal(rb, 2) != 0x2)
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
|
|
|
|
"Invalid frame marker");
|
|
|
|
|
|
|
|
cm->version = vp9_rb_read_bit(rb);
|
|
|
|
RESERVED;
|
|
|
|
|
2012-10-03 21:11:05 +02:00
|
|
|
if (vp9_rb_read_bit(rb)) {
|
|
|
|
// show an existing frame directly
|
|
|
|
int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)];
|
|
|
|
ref_cnt_fb(cm->fb_idx_ref_cnt, &cm->new_fb_idx, frame_to_show);
|
|
|
|
pbi->refresh_frame_flags = 0;
|
|
|
|
cm->filter_level = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-07 22:41:44 +02:00
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb);
|
|
|
|
cm->show_frame = vp9_rb_read_bit(rb);
|
2013-06-07 22:41:44 +02:00
|
|
|
cm->error_resilient_mode = vp9_rb_read_bit(rb);
|
2013-05-29 03:07:54 +02:00
|
|
|
|
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
2013-06-07 23:45:49 +02:00
|
|
|
int csp;
|
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
check_sync_code(cm, rb);
|
2013-06-07 22:41:44 +02:00
|
|
|
|
2013-06-07 23:45:49 +02:00
|
|
|
csp = vp9_rb_read_literal(rb, 3); // colorspace
|
|
|
|
if (csp != 7) { // != sRGB
|
|
|
|
vp9_rb_read_bit(rb); // [16,235] (including xvycc) vs [0,255] range
|
|
|
|
if (cm->version == 1) {
|
|
|
|
cm->subsampling_x = vp9_rb_read_bit(rb);
|
|
|
|
cm->subsampling_y = vp9_rb_read_bit(rb);
|
|
|
|
vp9_rb_read_bit(rb); // has extra plane
|
|
|
|
} else {
|
|
|
|
cm->subsampling_y = cm->subsampling_x = 1;
|
|
|
|
}
|
2013-06-07 08:53:56 +02:00
|
|
|
} else {
|
2013-06-07 23:45:49 +02:00
|
|
|
if (cm->version == 1) {
|
|
|
|
cm->subsampling_y = cm->subsampling_x = 0;
|
|
|
|
vp9_rb_read_bit(rb); // has extra plane
|
|
|
|
} else {
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
|
|
|
|
"RGB not supported in profile 0");
|
|
|
|
}
|
2013-06-07 08:53:56 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-06-06 05:56:37 +02:00
|
|
|
pbi->refresh_frame_flags = (1 << NUM_REF_FRAMES) - 1;
|
|
|
|
|
|
|
|
for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i)
|
|
|
|
cm->active_ref_idx[i] = cm->new_fb_idx;
|
2013-06-07 22:41:44 +02:00
|
|
|
|
|
|
|
setup_frame_size(pbi, rb);
|
2013-06-06 05:56:37 +02:00
|
|
|
} else {
|
2013-06-08 00:55:15 +02:00
|
|
|
cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb);
|
|
|
|
|
2013-06-09 19:10:33 +02:00
|
|
|
cm->reset_frame_context = cm->error_resilient_mode ?
|
|
|
|
0 : vp9_rb_read_literal(rb, 2);
|
2013-06-06 05:56:37 +02:00
|
|
|
|
2013-06-08 00:55:15 +02:00
|
|
|
if (cm->intra_only) {
|
2013-06-08 03:09:29 +02:00
|
|
|
check_sync_code(cm, rb);
|
2013-06-09 19:10:33 +02:00
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
pbi->refresh_frame_flags = vp9_rb_read_literal(rb, NUM_REF_FRAMES);
|
|
|
|
setup_frame_size(pbi, rb);
|
2013-06-08 00:55:15 +02:00
|
|
|
} else {
|
|
|
|
pbi->refresh_frame_flags = vp9_rb_read_literal(rb, NUM_REF_FRAMES);
|
2013-06-07 22:41:44 +02:00
|
|
|
|
2013-06-08 00:55:15 +02:00
|
|
|
for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i) {
|
2013-07-12 20:37:43 +02:00
|
|
|
const int ref = vp9_rb_read_literal(rb, NUM_REF_FRAMES_LOG2);
|
2013-06-08 00:55:15 +02:00
|
|
|
cm->active_ref_idx[i] = cm->ref_frame_map[ref];
|
|
|
|
cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb);
|
|
|
|
}
|
2013-06-07 22:41:44 +02:00
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
setup_frame_size_with_refs(pbi, rb);
|
2013-06-06 05:56:37 +02:00
|
|
|
|
2013-06-08 00:55:15 +02:00
|
|
|
xd->allow_high_precision_mv = vp9_rb_read_bit(rb);
|
|
|
|
cm->mcomp_filter_type = read_interp_filter_type(rb);
|
2013-06-08 03:09:29 +02:00
|
|
|
|
|
|
|
for (i = 0; i < ALLOWED_REFS_PER_FRAME; ++i)
|
|
|
|
vp9_setup_scale_factors(cm, i);
|
|
|
|
|
|
|
|
setup_inter_inter(cm);
|
2013-06-08 00:55:15 +02:00
|
|
|
}
|
2013-06-06 05:56:37 +02:00
|
|
|
}
|
|
|
|
|
2013-06-07 22:41:44 +02:00
|
|
|
if (!cm->error_resilient_mode) {
|
|
|
|
cm->refresh_frame_context = vp9_rb_read_bit(rb);
|
|
|
|
cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb);
|
|
|
|
} else {
|
|
|
|
cm->refresh_frame_context = 0;
|
|
|
|
cm->frame_parallel_decoding_mode = 1;
|
|
|
|
}
|
|
|
|
|
2013-07-12 20:37:43 +02:00
|
|
|
cm->frame_context_idx = vp9_rb_read_literal(rb, NUM_FRAME_CONTEXTS_LOG2);
|
2013-06-06 05:56:37 +02:00
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
if (cm->frame_type == KEY_FRAME || cm->error_resilient_mode || cm->intra_only)
|
2013-06-09 19:10:33 +02:00
|
|
|
vp9_setup_past_independence(cm, xd);
|
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
setup_loopfilter(pbi, rb);
|
|
|
|
setup_quantization(pbi, rb);
|
2013-07-10 21:29:43 +02:00
|
|
|
setup_segmentation(&pbi->mb.seg, rb);
|
2013-06-06 21:33:12 +02:00
|
|
|
|
|
|
|
setup_tile_info(cm, rb);
|
2013-06-03 19:50:57 +02:00
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
return vp9_rb_read_literal(rb, 16);
|
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-07-08 20:54:36 +02:00
|
|
|
static int read_compressed_header(VP9D_COMP *pbi, const uint8_t *data,
|
|
|
|
size_t partition_size) {
|
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
|
|
|
vp9_reader r;
|
|
|
|
|
|
|
|
if (vp9_reader_init(&r, data, partition_size))
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate bool decoder 0");
|
|
|
|
|
|
|
|
cm->txfm_mode = xd->lossless ? ONLY_4X4 : read_tx_mode(&r);
|
|
|
|
if (cm->txfm_mode == TX_MODE_SELECT)
|
|
|
|
read_tx_probs(&cm->fc, &r);
|
|
|
|
read_coef_probs(&cm->fc, cm->txfm_mode, &r);
|
|
|
|
|
|
|
|
vp9_prepare_read_mode_info(pbi, &r);
|
|
|
|
|
|
|
|
return vp9_reader_has_error(&r);
|
|
|
|
}
|
|
|
|
|
2013-06-25 20:52:44 +02:00
|
|
|
void vp9_init_dequantizer(VP9_COMMON *pc) {
|
|
|
|
int q;
|
|
|
|
|
|
|
|
for (q = 0; q < QINDEX_RANGE; q++) {
|
|
|
|
// DC value
|
|
|
|
pc->y_dequant[q][0] = vp9_dc_quant(q, pc->y_dc_delta_q);
|
|
|
|
pc->uv_dequant[q][0] = vp9_dc_quant(q, pc->uv_dc_delta_q);
|
|
|
|
|
|
|
|
// AC values
|
|
|
|
pc->y_dequant[q][1] = vp9_ac_quant(q, 0);
|
|
|
|
pc->uv_dequant[q][1] = vp9_ac_quant(q, pc->uv_ac_delta_q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
|
|
|
|
int i;
|
2013-07-08 20:54:36 +02:00
|
|
|
vp9_reader residual_bc;
|
2013-05-29 03:07:54 +02:00
|
|
|
VP9_COMMON *const pc = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-06-06 05:56:37 +02:00
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
const uint8_t *data = pbi->source;
|
|
|
|
const uint8_t *data_end = pbi->source + pbi->source_sz;
|
2011-07-20 23:21:24 +02:00
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
struct vp9_read_bit_buffer rb = { data, data_end, 0,
|
|
|
|
pc, error_handler };
|
|
|
|
const size_t first_partition_size = read_uncompressed_header(pbi, &rb);
|
|
|
|
const int keyframe = pc->frame_type == KEY_FRAME;
|
2013-06-06 05:56:37 +02:00
|
|
|
YV12_BUFFER_CONFIG *new_fb = &pc->yv12_fb[pc->new_fb_idx];
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
|
2012-10-03 21:11:05 +02:00
|
|
|
if (!first_partition_size) {
|
|
|
|
// showing a frame directly
|
|
|
|
*p_data_end = data + 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-05-29 03:07:54 +02:00
|
|
|
data += vp9_rb_bytes_read(&rb);
|
|
|
|
xd->corrupted = 0;
|
|
|
|
new_fb->corrupted = 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-06-08 03:09:29 +02:00
|
|
|
if (!pbi->decoded_key_frame && !keyframe)
|
2012-07-14 00:21:29 +02:00
|
|
|
return -1;
|
2011-05-02 15:30:51 +02:00
|
|
|
|
2013-05-29 03:07:54 +02:00
|
|
|
if (!read_is_valid(data, first_partition_size, data_end))
|
2013-06-06 05:56:37 +02:00
|
|
|
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
|
2013-06-11 19:06:31 +02:00
|
|
|
"Truncated packet or corrupt header length");
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-06-06 05:56:37 +02:00
|
|
|
xd->mode_info_context = pc->mi;
|
|
|
|
xd->prev_mode_info_context = pc->prev_mi;
|
|
|
|
xd->frame_type = pc->frame_type;
|
|
|
|
xd->mode_info_stride = pc->mode_info_stride;
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
|
2013-06-03 19:50:57 +02:00
|
|
|
mb_init_dequantizer(pc, &pbi->mb); // MB level dequantizer setup
|
2013-05-16 03:20:51 +02:00
|
|
|
|
2013-06-06 05:56:37 +02:00
|
|
|
if (!keyframe)
|
2012-10-31 00:25:53 +01:00
|
|
|
vp9_setup_interp_filters(xd, pc->mcomp_filter_type, pc);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-25 02:20:53 +02:00
|
|
|
pc->fc = pc->frame_contexts[pc->frame_context_idx];
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
update_frame_context(&pc->fc);
|
2013-04-19 01:08:10 +02:00
|
|
|
|
2013-03-27 22:04:35 +01:00
|
|
|
// Initialize xd pointers. Any reference should do for xd->pre, so use 0.
|
2013-07-04 02:42:01 +02:00
|
|
|
setup_pre_planes(xd, 0, &pc->yv12_fb[pc->active_ref_idx[0]], 0, 0,
|
|
|
|
NULL, NULL);
|
2013-04-24 00:50:56 +02:00
|
|
|
setup_dst_planes(xd, new_fb, 0, 0);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-07-08 20:54:36 +02:00
|
|
|
new_fb->corrupted |= read_compressed_header(pbi, data, first_partition_size);
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Create the segmentation map structure and set to 0
|
|
|
|
if (!pc->last_frame_seg_map)
|
2013-06-28 19:36:20 +02:00
|
|
|
CHECK_MEM_ERROR(pc, pc->last_frame_seg_map,
|
2013-04-26 20:57:17 +02:00
|
|
|
vpx_calloc((pc->mi_rows * pc->mi_cols), 1));
|
2010-09-24 00:25:33 +02:00
|
|
|
|
2013-07-02 02:28:08 +02:00
|
|
|
setup_block_dptrs(xd, pc->subsampling_x, pc->subsampling_y);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-04 03:40:17 +02:00
|
|
|
// clear out the coeff buffer
|
2013-05-06 23:00:58 +02:00
|
|
|
for (i = 0; i < MAX_MB_PLANE; ++i)
|
|
|
|
vp9_zero(xd->plane[i].qcoeff);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-05-29 22:42:23 +02:00
|
|
|
set_prev_mi(pc);
|
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
decode_tiles(pbi, data, first_partition_size, &residual_bc);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-03-21 00:41:30 +01:00
|
|
|
pc->last_width = pc->width;
|
|
|
|
pc->last_height = pc->height;
|
2013-02-20 21:34:31 +01:00
|
|
|
|
2013-07-08 20:54:36 +02:00
|
|
|
new_fb->corrupted |= xd->corrupted;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
if (!pbi->decoded_key_frame) {
|
2013-05-29 03:07:54 +02:00
|
|
|
if (keyframe && !new_fb->corrupted)
|
2012-07-14 00:21:29 +02:00
|
|
|
pbi->decoded_key_frame = 1;
|
|
|
|
else
|
2013-04-24 00:50:56 +02:00
|
|
|
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
|
2012-07-14 00:21:29 +02:00
|
|
|
"A stream must start with a complete key frame");
|
|
|
|
}
|
2010-12-16 16:46:31 +01:00
|
|
|
|
2013-04-22 23:39:21 +02:00
|
|
|
// Adaptation
|
2013-03-14 20:31:54 +01:00
|
|
|
if (!pc->error_resilient_mode && !pc->frame_parallel_decoding_mode) {
|
2013-01-15 15:43:35 +01:00
|
|
|
vp9_adapt_coef_probs(pc);
|
2013-05-07 18:24:21 +02:00
|
|
|
|
2013-06-09 19:10:33 +02:00
|
|
|
if ((!keyframe) && (!pc->intra_only)) {
|
2013-01-15 15:43:35 +01:00
|
|
|
vp9_adapt_mode_probs(pc);
|
2013-04-24 00:50:56 +02:00
|
|
|
vp9_adapt_mode_context(pc);
|
2013-06-19 03:28:10 +02:00
|
|
|
vp9_adapt_mv_probs(pc, xd->allow_high_precision_mv);
|
2013-01-15 15:43:35 +01:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-26 23:39:58 +02:00
|
|
|
if (pc->refresh_frame_context)
|
2013-04-25 02:20:53 +02:00
|
|
|
pc->frame_contexts[pc->frame_context_idx] = pc->fc;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2013-04-15 23:54:19 +02:00
|
|
|
*p_data_end = vp9_reader_find_end(&residual_bc);
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|