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"
|
|
|
|
|
|
|
|
#include "vp9/common/vp9_extend.h"
|
|
|
|
#include "vp9/common/vp9_modecont.h"
|
2013-01-06 03:20:25 +01:00
|
|
|
#include "vp9/common/vp9_common.h"
|
2012-11-27 22:59:17 +01:00
|
|
|
#include "vp9/common/vp9_reconintra.h"
|
|
|
|
#include "vp9/common/vp9_reconinter.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_alloccommon.h"
|
|
|
|
#include "vp9/common/vp9_entropymode.h"
|
|
|
|
#include "vp9/common/vp9_quant_common.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"
|
|
|
|
#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-04-24 00:50:56 +02:00
|
|
|
static void setup_txfm_mode(VP9_COMMON *pc, int lossless, vp9_reader *r) {
|
|
|
|
if (lossless) {
|
|
|
|
pc->txfm_mode = ONLY_4X4;
|
|
|
|
} else {
|
|
|
|
pc->txfm_mode = vp9_read_literal(r, 2);
|
|
|
|
if (pc->txfm_mode == ALLOW_32X32)
|
|
|
|
pc->txfm_mode += vp9_read_bit(r);
|
|
|
|
if (pc->txfm_mode == TX_MODE_SELECT) {
|
2013-06-06 20:14:04 +02:00
|
|
|
int i, j;
|
2013-06-08 09:09:44 +02:00
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
|
2013-06-06 20:14:04 +02:00
|
|
|
for (j = 0; j < TX_SIZE_MAX_SB - 3; ++j) {
|
2013-06-10 21:00:43 +02:00
|
|
|
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
|
2013-06-06 20:14:04 +02:00
|
|
|
pc->fc.tx_probs_8x8p[i][j] =
|
|
|
|
vp9_read_prob_diff_update(r, pc->fc.tx_probs_8x8p[i][j]);
|
|
|
|
}
|
|
|
|
}
|
2013-06-08 09:09:44 +02:00
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
|
2013-06-06 20:14:04 +02:00
|
|
|
for (j = 0; j < TX_SIZE_MAX_SB - 2; ++j) {
|
2013-06-10 21:00:43 +02:00
|
|
|
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
|
2013-06-06 20:14:04 +02:00
|
|
|
pc->fc.tx_probs_16x16p[i][j] =
|
|
|
|
vp9_read_prob_diff_update(r, pc->fc.tx_probs_16x16p[i][j]);
|
|
|
|
}
|
|
|
|
}
|
2013-06-08 09:09:44 +02:00
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i) {
|
2013-06-06 20:14:04 +02:00
|
|
|
for (j = 0; j < TX_SIZE_MAX_SB - 1; ++j) {
|
2013-06-10 21:00:43 +02:00
|
|
|
if (vp9_read(r, VP9_MODE_UPDATE_PROB))
|
2013-06-06 20:14:04 +02:00
|
|
|
pc->fc.tx_probs_32x32p[i][j] =
|
|
|
|
vp9_read_prob_diff_update(r, pc->fc.tx_probs_32x32p[i][j]);
|
|
|
|
}
|
2013-06-06 20:14:04 +02:00
|
|
|
}
|
2013-04-24 00:50:56 +02:00
|
|
|
}
|
|
|
|
}
|
2013-04-03 21:18:15 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 21:14:27 +02:00
|
|
|
static int get_unsigned_bits(unsigned int num_values) {
|
|
|
|
int cat = 0;
|
|
|
|
if (num_values <= 1)
|
|
|
|
return 0;
|
|
|
|
num_values--;
|
|
|
|
while (num_values > 0) {
|
|
|
|
cat++;
|
|
|
|
num_values >>= 1;
|
|
|
|
}
|
|
|
|
return cat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int inv_recenter_nonneg(int v, int m) {
|
2013-04-25 23:25:40 +02:00
|
|
|
if (v > 2 * m)
|
2013-04-17 21:14:27 +02:00
|
|
|
return v;
|
2013-04-25 23:25:40 +02:00
|
|
|
|
|
|
|
return v % 2 ? m - (v + 1) / 2 : m + v / 2;
|
2013-04-17 21:14:27 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 01:08:10 +02:00
|
|
|
static int decode_uniform(vp9_reader *r, int n) {
|
2013-04-17 21:14:27 +02:00
|
|
|
int v;
|
|
|
|
const int l = get_unsigned_bits(n);
|
|
|
|
const int m = (1 << l) - n;
|
|
|
|
if (!l)
|
|
|
|
return 0;
|
|
|
|
|
2013-04-19 01:08:10 +02:00
|
|
|
v = vp9_read_literal(r, l - 1);
|
|
|
|
return v < m ? v : (v << 1) - m + vp9_read_bit(r);
|
2013-04-17 21:14:27 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 01:08:10 +02:00
|
|
|
static int decode_term_subexp(vp9_reader *r, int k, int num_syms) {
|
2013-04-17 21:14:27 +02:00
|
|
|
int i = 0, mk = 0, word;
|
|
|
|
while (1) {
|
|
|
|
const int b = i ? k + i - 1 : k;
|
|
|
|
const int a = 1 << b;
|
|
|
|
if (num_syms <= mk + 3 * a) {
|
2013-04-19 01:08:10 +02:00
|
|
|
word = decode_uniform(r, num_syms - mk) + mk;
|
2013-04-17 21:14:27 +02:00
|
|
|
break;
|
|
|
|
} else {
|
2013-04-19 01:08:10 +02:00
|
|
|
if (vp9_read_bit(r)) {
|
2013-04-17 21:14:27 +02:00
|
|
|
i++;
|
|
|
|
mk += a;
|
|
|
|
} else {
|
2013-04-19 01:08:10 +02:00
|
|
|
word = vp9_read_literal(r, b) + mk;
|
2013-04-17 21:14:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return word;
|
|
|
|
}
|
|
|
|
|
2013-06-06 21:33:12 +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));
|
2013-04-17 21:14:27 +02:00
|
|
|
return data > max ? max : data;
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static int merge_index(int v, int n, int modulus) {
|
|
|
|
int max1 = (n - 1 - modulus / 2) / modulus + 1;
|
2013-04-25 23:25:40 +02:00
|
|
|
if (v < max1) {
|
|
|
|
v = v * modulus + modulus / 2;
|
|
|
|
} else {
|
2012-07-14 00:21:29 +02:00
|
|
|
int w;
|
|
|
|
v -= max1;
|
|
|
|
w = v;
|
|
|
|
v += (v + modulus - modulus / 2) / modulus;
|
|
|
|
while (v % modulus == modulus / 2 ||
|
|
|
|
w != v - (v + modulus - modulus / 2) / modulus) v++;
|
|
|
|
}
|
|
|
|
return v;
|
2012-05-03 11:22:26 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
static int inv_remap_prob(int v, int m) {
|
2013-06-11 18:31:33 +02:00
|
|
|
const int n = 255;
|
2013-03-14 20:31:54 +01:00
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
v = merge_index(v, n - 1, MODULUS_PARAM);
|
2013-06-11 18:31:33 +02:00
|
|
|
m--;
|
2012-07-14 00:21:29 +02:00
|
|
|
if ((m << 1) <= n) {
|
2013-06-11 18:31:33 +02:00
|
|
|
return 1 + inv_recenter_nonneg(v + 1, m);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
2013-06-11 18:31:33 +02:00
|
|
|
return n - inv_recenter_nonneg(v + 1, n - 1 - m);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2012-04-12 18:24:03 +02:00
|
|
|
}
|
2012-05-03 11:22:26 +02:00
|
|
|
|
2013-06-05 00:25:16 +02:00
|
|
|
vp9_prob vp9_read_prob_diff_update(vp9_reader *r, int oldp) {
|
2013-04-19 01:08:10 +02:00
|
|
|
int delp = decode_term_subexp(r, SUBEXP_PARAM, 255);
|
2012-10-31 22:40:53 +01:00
|
|
|
return (vp9_prob)inv_remap_prob(delp, oldp);
|
2012-05-03 11:22:26 +02:00
|
|
|
}
|
2012-04-12 18:24:03 +02:00
|
|
|
|
2013-04-26 21:30:20 +02:00
|
|
|
void vp9_init_dequantizer(VP9_COMMON *pc) {
|
2013-05-01 22:25:10 +02:00
|
|
|
int q;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-02-23 02:27:34 +01:00
|
|
|
for (q = 0; q < QINDEX_RANGE; q++) {
|
2013-04-24 00:50:56 +02:00
|
|
|
// DC value
|
2013-04-26 21:30:20 +02:00
|
|
|
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);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-04-24 00:50:56 +02:00
|
|
|
// AC values
|
2013-05-01 22:25:10 +02:00
|
|
|
pc->y_dequant[q][1] = vp9_ac_quant(q, 0);
|
|
|
|
pc->uv_dequant[q][1] = vp9_ac_quant(q, pc->uv_ac_delta_q);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
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:
|
|
|
|
tx_type = plane == 0 ? get_tx_type_8x8(xd, raster_block) : 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:
|
|
|
|
tx_type = plane == 0 ? get_tx_type_16x16(xd, raster_block) : 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-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;
|
|
|
|
const int mode = plane == 0 ? xd->mode_info_context->mbmi.mode
|
|
|
|
: xd->mode_info_context->mbmi.uv_mode;
|
2013-05-17 21:50:40 +02:00
|
|
|
|
2013-06-06 15:07:09 +02:00
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
if (plane == 0 && xd->mode_info_context->mbmi.sb_type < BLOCK_SIZE_SB8X8) {
|
2013-05-30 20:27:40 +02:00
|
|
|
assert(bsize == BLOCK_SIZE_SB8X8);
|
2013-05-17 21:50:40 +02:00
|
|
|
b_mode = xd->mode_info_context->bmi[raster_block].as_mode.first;
|
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,
|
|
|
|
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
|
|
|
|
if (xd->mode_info_context->mbmi.mb_skip_coeff)
|
|
|
|
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-04-30 19:16:09 +02:00
|
|
|
static void decode_atom(VP9D_COMP *pbi, MACROBLOCKD *xd,
|
|
|
|
int mi_row, int mi_col,
|
|
|
|
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
|
|
|
|
MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
|
|
|
|
|
2013-06-06 22:44:34 +02:00
|
|
|
assert(mbmi->ref_frame[0] != INTRA_FRAME);
|
2013-05-22 20:27:38 +02:00
|
|
|
|
2013-06-09 19:10:33 +02:00
|
|
|
if ((pbi->common.frame_type != KEY_FRAME) && (!pbi->common.intra_only))
|
2013-04-30 19:16:09 +02:00
|
|
|
vp9_setup_interp_filters(xd, mbmi->interp_filter, &pbi->common);
|
|
|
|
|
|
|
|
// prediction
|
2013-05-22 20:27:38 +02:00
|
|
|
vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
|
2013-04-30 19:16:09 +02:00
|
|
|
|
|
|
|
if (mbmi->mb_skip_coeff) {
|
|
|
|
vp9_reset_sb_tokens_context(xd, bsize);
|
|
|
|
} else {
|
|
|
|
if (xd->segmentation_enabled)
|
|
|
|
mb_init_dequantizer(&pbi->common, xd);
|
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
if (!vp9_reader_has_error(r))
|
|
|
|
vp9_decode_tokens(pbi, r, bsize);
|
2013-06-14 01:37:52 +02:00
|
|
|
|
|
|
|
foreach_transformed_block(xd, bsize, decode_block, xd);
|
2013-04-30 19:16:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-17 21:50:40 +02:00
|
|
|
static void decode_sb_intra(VP9D_COMP *pbi, MACROBLOCKD *xd,
|
|
|
|
int mi_row, int mi_col,
|
|
|
|
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
|
|
|
|
MB_MODE_INFO *const mbmi = &xd->mode_info_context->mbmi;
|
|
|
|
if (mbmi->mb_skip_coeff) {
|
|
|
|
vp9_reset_sb_tokens_context(xd, bsize);
|
|
|
|
} else {
|
|
|
|
if (xd->segmentation_enabled)
|
|
|
|
mb_init_dequantizer(&pbi->common, xd);
|
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
if (!vp9_reader_has_error(r))
|
|
|
|
vp9_decode_tokens(pbi, r, bsize);
|
2013-05-17 21:50:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach_transformed_block(xd, bsize, decode_block_intra, xd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
static void decode_sb(VP9D_COMP *pbi, MACROBLOCKD *xd, int mi_row, int mi_col,
|
2013-04-19 01:08:10 +02:00
|
|
|
vp9_reader *r, BLOCK_SIZE_TYPE bsize) {
|
2013-04-26 20:57:17 +02:00
|
|
|
const int bwl = mi_width_log2(bsize), bhl = mi_height_log2(bsize);
|
2013-04-10 21:30:20 +02:00
|
|
|
const int bw = 1 << bwl, bh = 1 << bhl;
|
2013-02-27 19:00:24 +01:00
|
|
|
int n, eobtotal;
|
2012-11-08 20:03:00 +01:00
|
|
|
VP9_COMMON *const pc = &pbi->common;
|
2013-04-25 23:25:40 +02:00
|
|
|
MODE_INFO *const mi = xd->mode_info_context;
|
|
|
|
MB_MODE_INFO *const mbmi = &mi->mbmi;
|
32x32 transform for superblocks.
This adds Debargha's DCT/DWT hybrid and a regular 32x32 DCT, and adds
code all over the place to wrap that in the bitstream/encoder/decoder/RD.
Some implementation notes (these probably need careful review):
- token range is extended by 1 bit, since the value range out of this
transform is [-16384,16383].
- the coefficients coming out of the FDCT are manually scaled back by
1 bit, or else they won't fit in int16_t (they are 17 bits). Because
of this, the RD error scoring does not right-shift the MSE score by
two (unlike for 4x4/8x8/16x16).
- to compensate for this loss in precision, the quantizer is halved
also. This is currently a little hacky.
- FDCT and IDCT is double-only right now. Needs a fixed-point impl.
- There are no default probabilities for the 32x32 transform yet; I'm
simply using the 16x16 luma ones. A future commit will add newly
generated probabilities for all transforms.
- No ADST version. I don't think we'll add one for this level; if an
ADST is desired, transform-size selection can scale back to 16x16
or lower, and use an ADST at that level.
Additional notes specific to Debargha's DWT/DCT hybrid:
- coefficient scale is different for the top/left 16x16 (DCT-over-DWT)
block than for the rest (DWT pixel differences) of the block. Therefore,
RD error scoring isn't easily scalable between coefficient and pixel
domain. Thus, unfortunately, we need to compute the RD distortion in
the pixel domain until we figure out how to scale these appropriately.
Change-Id: I00386f20f35d7fabb19aba94c8162f8aee64ef2b
2012-12-07 23:45:05 +01:00
|
|
|
const int mis = pc->mode_info_stride;
|
2012-11-08 20:03:00 +01:00
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
assert(mbmi->sb_type == bsize);
|
2013-06-06 22:44:34 +02:00
|
|
|
assert(mbmi->ref_frame[0] != INTRA_FRAME);
|
2013-01-06 03:20:25 +01:00
|
|
|
|
|
|
|
if (pbi->common.frame_type != KEY_FRAME)
|
2013-04-25 23:25:40 +02:00
|
|
|
vp9_setup_interp_filters(xd, mbmi->interp_filter, pc);
|
2013-01-06 03:20:25 +01:00
|
|
|
|
2013-04-10 21:30:20 +02:00
|
|
|
// generate prediction
|
2013-05-22 20:27:38 +02:00
|
|
|
vp9_build_inter_predictors_sb(xd, mi_row, mi_col, bsize);
|
2013-01-06 03:20:25 +01:00
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
if (mbmi->mb_skip_coeff) {
|
2013-04-13 01:57:23 +02:00
|
|
|
vp9_reset_sb_tokens_context(xd, bsize);
|
2013-03-04 23:12:17 +01:00
|
|
|
} else {
|
2013-04-13 01:57:23 +02:00
|
|
|
// re-initialize macroblock dequantizer before detokenization
|
|
|
|
if (xd->segmentation_enabled)
|
2013-04-25 23:25:40 +02:00
|
|
|
mb_init_dequantizer(pc, xd);
|
2013-04-13 01:57:23 +02:00
|
|
|
|
|
|
|
// dequantization and idct
|
2013-06-15 00:11:18 +02:00
|
|
|
eobtotal = vp9_decode_tokens(pbi, r, bsize);
|
2013-04-13 01:57:23 +02:00
|
|
|
if (eobtotal == 0) { // skip loopfilter
|
|
|
|
for (n = 0; n < bw * bh; n++) {
|
|
|
|
const int x_idx = n & (bw - 1), y_idx = n >> bwl;
|
|
|
|
|
2013-04-26 20:57:17 +02:00
|
|
|
if (mi_col + x_idx < pc->mi_cols && mi_row + y_idx < pc->mi_rows)
|
2013-04-13 01:57:23 +02:00
|
|
|
mi[y_idx * mis + x_idx].mbmi.mb_skip_coeff = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-27 02:52:35 +02:00
|
|
|
foreach_transformed_block(xd, bsize, decode_block, xd);
|
2012-11-08 20:03:00 +01:00
|
|
|
}
|
32x32 transform for superblocks.
This adds Debargha's DCT/DWT hybrid and a regular 32x32 DCT, and adds
code all over the place to wrap that in the bitstream/encoder/decoder/RD.
Some implementation notes (these probably need careful review):
- token range is extended by 1 bit, since the value range out of this
transform is [-16384,16383].
- the coefficients coming out of the FDCT are manually scaled back by
1 bit, or else they won't fit in int16_t (they are 17 bits). Because
of this, the RD error scoring does not right-shift the MSE score by
two (unlike for 4x4/8x8/16x16).
- to compensate for this loss in precision, the quantizer is halved
also. This is currently a little hacky.
- FDCT and IDCT is double-only right now. Needs a fixed-point impl.
- There are no default probabilities for the 32x32 transform yet; I'm
simply using the 16x16 luma ones. A future commit will add newly
generated probabilities for all transforms.
- No ADST version. I don't think we'll add one for this level; if an
ADST is desired, transform-size selection can scale back to 16x16
or lower, and use an ADST at that level.
Additional notes specific to Debargha's DWT/DCT hybrid:
- coefficient scale is different for the top/left 16x16 (DCT-over-DWT)
block than for the rest (DWT pixel differences) of the block. Therefore,
RD error scoring isn't easily scalable between coefficient and pixel
domain. Thus, unfortunately, we need to compute the RD distortion in
the pixel domain until we figure out how to scale these appropriately.
Change-Id: I00386f20f35d7fabb19aba94c8162f8aee64ef2b
2012-12-07 23:45:05 +01:00
|
|
|
}
|
2012-11-08 20:03:00 +01: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-05-08 00:36:30 +02:00
|
|
|
xd->above_seg_context = cm->above_seg_context + mi_col;
|
|
|
|
xd->left_seg_context = cm->left_seg_context + (mi_row & MI_MASK);
|
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-04-26 20:57:17 +02:00
|
|
|
static void set_refs(VP9D_COMP *pbi, 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-01-06 03:20:25 +01:00
|
|
|
|
2013-06-06 22:44:34 +02:00
|
|
|
if (mbmi->ref_frame[0] > INTRA_FRAME) {
|
2013-03-14 20:31:54 +01:00
|
|
|
// Select the appropriate reference frame for this MB
|
2013-06-06 22:44:34 +02:00
|
|
|
const int fb_idx = cm->active_ref_idx[mbmi->ref_frame[0] - 1];
|
2013-03-30 00:31:46 +01:00
|
|
|
const YV12_BUFFER_CONFIG *cfg = &cm->yv12_fb[fb_idx];
|
2013-06-06 22:44:34 +02:00
|
|
|
xd->scale_factor[0] = cm->active_ref_scale[mbmi->ref_frame[0] - 1];
|
|
|
|
xd->scale_factor_uv[0] = cm->active_ref_scale[mbmi->ref_frame[0] - 1];
|
2013-04-26 20:57:17 +02:00
|
|
|
setup_pre_planes(xd, cfg, NULL, mi_row, mi_col,
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->scale_factor, xd->scale_factor_uv);
|
2013-03-30 00:31:46 +01:00
|
|
|
xd->corrupted |= cfg->corrupted;
|
2012-08-20 23:43:34 +02:00
|
|
|
|
2013-06-06 22:44:34 +02:00
|
|
|
if (mbmi->ref_frame[1] > INTRA_FRAME) {
|
2013-03-14 20:31:54 +01:00
|
|
|
// Select the appropriate reference frame for this MB
|
2013-06-06 22:44:34 +02:00
|
|
|
const int second_fb_idx = cm->active_ref_idx[mbmi->ref_frame[1] - 1];
|
2013-03-30 00:31:46 +01:00
|
|
|
const YV12_BUFFER_CONFIG *second_cfg = &cm->yv12_fb[second_fb_idx];
|
2013-06-06 22:44:34 +02:00
|
|
|
xd->scale_factor[1] = cm->active_ref_scale[mbmi->ref_frame[1] - 1];
|
|
|
|
xd->scale_factor_uv[1] = cm->active_ref_scale[mbmi->ref_frame[1] - 1];
|
2013-04-26 20:57:17 +02:00
|
|
|
setup_pre_planes(xd, NULL, second_cfg, mi_row, mi_col,
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->scale_factor, xd->scale_factor_uv);
|
2013-03-30 00:31:46 +01:00
|
|
|
xd->corrupted |= second_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) {
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
|
|
|
|
2013-05-16 07:28:36 +02:00
|
|
|
if (bsize < BLOCK_SIZE_SB8X8)
|
|
|
|
if (xd->ab_index > 0)
|
|
|
|
return;
|
2013-04-26 20:57:17 +02:00
|
|
|
set_offsets(pbi, bsize, mi_row, mi_col);
|
|
|
|
vp9_decode_mb_mode_mv(pbi, xd, mi_row, mi_col, r);
|
|
|
|
set_refs(pbi, mi_row, mi_col);
|
2013-04-16 09:18:02 +02:00
|
|
|
|
2013-06-06 22:44:34 +02:00
|
|
|
if (xd->mode_info_context->mbmi.ref_frame[0] == INTRA_FRAME)
|
2013-05-22 06:28:42 +02:00
|
|
|
decode_sb_intra(pbi, xd, mi_row, mi_col, r, (bsize < BLOCK_SIZE_SB8X8) ?
|
|
|
|
BLOCK_SIZE_SB8X8 : bsize);
|
2013-05-17 21:50:40 +02:00
|
|
|
else if (bsize < BLOCK_SIZE_SB8X8)
|
2013-05-11 02:06:37 +02:00
|
|
|
decode_atom(pbi, xd, mi_row, mi_col, r, BLOCK_SIZE_SB8X8);
|
2013-04-30 21:08:32 +02:00
|
|
|
else
|
2013-05-01 18:43:59 +02:00
|
|
|
decode_sb(pbi, xd, mi_row, mi_col, r, bsize);
|
2013-04-16 09:18:02 +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-06-07 00:33:57 +02:00
|
|
|
int idx = check_bsize_coverage(pc, xd, mi_row, mi_col, bsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
// read the partition information
|
2013-05-08 00:36:30 +02:00
|
|
|
xd->left_seg_context = pc->left_seg_context + (mi_row & MI_MASK);
|
|
|
|
xd->above_seg_context = pc->above_seg_context + 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-03-13 19:03:17 +01:00
|
|
|
|
2013-04-19 01:08:10 +02:00
|
|
|
if (vp9_read_bit(r)) {
|
2013-06-15 00:11:18 +02:00
|
|
|
int i, j, k, l, m;
|
2013-03-26 23:23:30 +01:00
|
|
|
for (i = 0; i < BLOCK_TYPES; i++) {
|
2013-02-19 22:36:38 +01:00
|
|
|
for (j = 0; j < REF_TYPES; j++) {
|
|
|
|
for (k = 0; k < COEF_BANDS; k++) {
|
|
|
|
for (l = 0; l < PREV_COEF_CONTEXTS; l++) {
|
|
|
|
if (l >= 3 && k == 0)
|
|
|
|
continue;
|
2013-03-26 23:23:30 +01:00
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
for (m = 0; m < UNCONSTRAINED_NODES; m++) {
|
2013-02-19 22:36:38 +01:00
|
|
|
vp9_prob *const p = coef_probs[i][j][k][l] + m;
|
|
|
|
|
2013-06-15 00:11:18 +02:00
|
|
|
if (vp9_read(r, VP9_COEF_UPDATE_PROB))
|
2013-06-05 00:25:16 +02:00
|
|
|
*p = vp9_read_prob_diff_update(r, *p);
|
2012-09-10 07:42:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-20 00:35:36 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-10 07:42:35 +02:00
|
|
|
}
|
2012-10-20 00:35:36 +02:00
|
|
|
}
|
2012-09-10 07:42:35 +02:00
|
|
|
|
2013-04-19 01:08:10 +02:00
|
|
|
static void read_coef_probs(VP9D_COMP *pbi, vp9_reader *r) {
|
2013-06-06 21:33:12 +02:00
|
|
|
const TXFM_MODE txfm_mode = pbi->common.txfm_mode;
|
2013-04-19 01:08:10 +02:00
|
|
|
FRAME_CONTEXT *const fc = &pbi->common.fc;
|
2012-08-03 02:03:14 +02:00
|
|
|
|
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-06-06 21:33:12 +02:00
|
|
|
static void setup_segmentation(VP9D_COMP *pbi, struct vp9_read_bit_buffer *rb) {
|
2013-03-26 19:04:25 +01:00
|
|
|
int i, j;
|
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
|
|
|
|
2013-04-19 19:44:03 +02:00
|
|
|
xd->update_mb_segmentation_map = 0;
|
|
|
|
xd->update_mb_segmentation_data = 0;
|
|
|
|
|
2013-06-06 21:33:12 +02:00
|
|
|
xd->segmentation_enabled = vp9_rb_read_bit(rb);
|
2013-04-24 00:50:56 +02:00
|
|
|
if (!xd->segmentation_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Segmentation map update
|
2013-06-06 21:33:12 +02:00
|
|
|
xd->update_mb_segmentation_map = vp9_rb_read_bit(rb);
|
2013-04-24 00:50:56 +02:00
|
|
|
if (xd->update_mb_segmentation_map) {
|
2013-04-24 14:04:45 +02:00
|
|
|
for (i = 0; i < MB_SEG_TREE_PROBS; i++)
|
2013-06-06 21:33:12 +02:00
|
|
|
xd->mb_segment_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-06-06 21:33:12 +02:00
|
|
|
cm->temporal_update = vp9_rb_read_bit(rb);
|
|
|
|
if (cm->temporal_update) {
|
2013-04-24 00:50:56 +02:00
|
|
|
for (i = 0; i < PREDICTION_PROBS; i++)
|
2013-06-06 21:33:12 +02:00
|
|
|
cm->segment_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-06-06 21:33:12 +02:00
|
|
|
cm->segment_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-06-06 21:33:12 +02:00
|
|
|
xd->update_mb_segmentation_data = vp9_rb_read_bit(rb);
|
2013-04-24 00:50:56 +02:00
|
|
|
if (xd->update_mb_segmentation_data) {
|
2013-06-06 21:33:12 +02:00
|
|
|
xd->mb_segment_abs_delta = vp9_rb_read_bit(rb);
|
2013-04-24 00:50:56 +02:00
|
|
|
|
|
|
|
vp9_clearall_segfeatures(xd);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
vp9_enable_segfeature(xd, 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-04-24 00:50:56 +02:00
|
|
|
vp9_set_segdata(xd, 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-03-26 19:04:25 +01:00
|
|
|
for (i = 0; i < MAX_REF_LF_DELTAS; i++) {
|
2013-06-03 19:50:57 +02:00
|
|
|
if (vp9_rb_read_bit(rb)) {
|
|
|
|
const int value = vp9_rb_read_literal(rb, 6);
|
|
|
|
xd->ref_lf_deltas[i] = vp9_rb_read_bit(rb) ? -value : value;
|
2013-03-26 19:04:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_MODE_LF_DELTAS; i++) {
|
2013-06-03 19:50:57 +02:00
|
|
|
if (vp9_rb_read_bit(rb)) {
|
|
|
|
const int value = vp9_rb_read_literal(rb, 6);
|
|
|
|
xd->mode_lf_deltas[i] = vp9_rb_read_bit(rb) ? -value : value;
|
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;
|
|
|
|
if (vp9_rb_read_bit(rb)) {
|
|
|
|
const int value = vp9_rb_read_literal(rb, 4);
|
|
|
|
*delta_q = vp9_rb_read_bit(rb) ? -value : value;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
if (xd->lossless) {
|
|
|
|
xd->itxm_add = vp9_idct_add_lossless_c;
|
|
|
|
} else {
|
|
|
|
xd->itxm_add = 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-06-06 20:14:04 +02:00
|
|
|
vp9_copy(fc->pre_tx_probs_8x8p, fc->tx_probs_8x8p);
|
|
|
|
vp9_copy(fc->pre_tx_probs_16x16p, fc->tx_probs_16x16p);
|
|
|
|
vp9_copy(fc->pre_tx_probs_32x32p, fc->tx_probs_32x32p);
|
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-06-06 20:14:04 +02:00
|
|
|
vp9_zero(fc->tx_count_8x8p);
|
|
|
|
vp9_zero(fc->tx_count_16x16p);
|
|
|
|
vp9_zero(fc->tx_count_32x32p);
|
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-04-26 20:57:17 +02:00
|
|
|
for (mi_row = pc->cur_tile_mi_row_start;
|
2013-05-08 23:24:43 +02:00
|
|
|
mi_row < pc->cur_tile_mi_row_end; mi_row += 64 / MI_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-04-26 20:57:17 +02:00
|
|
|
for (mi_col = pc->cur_tile_mi_col_start;
|
2013-05-08 23:24:43 +02:00
|
|
|
mi_col < pc->cur_tile_mi_col_end; mi_col += 64 / MI_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-06-11 19:06:31 +02:00
|
|
|
const uint8_t* const data_end = pbi->source + pbi->source_sz;
|
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-05-08 00:36:30 +02:00
|
|
|
vpx_memset(pc->above_context[0], 0, sizeof(ENTROPY_CONTEXT) * 2 *
|
|
|
|
MAX_MB_PLANE * mi_cols_aligned_to_sb(pc));
|
2013-04-23 19:12:18 +02:00
|
|
|
|
|
|
|
vpx_memset(pc->above_seg_context, 0, sizeof(PARTITION_CONTEXT) *
|
2013-05-08 00:36:30 +02:00
|
|
|
mi_cols_aligned_to_sb(pc));
|
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) {
|
|
|
|
const int ref = vp9_rb_read_literal(rb, NUM_REF_FRAMES_LG2);
|
|
|
|
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-06-06 05:56:37 +02:00
|
|
|
cm->frame_context_idx = vp9_rb_read_literal(rb, NUM_FRAME_CONTEXTS_LG2);
|
|
|
|
|
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-06-06 21:33:12 +02:00
|
|
|
setup_segmentation(pbi, rb);
|
|
|
|
|
|
|
|
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-05-29 03:07:54 +02:00
|
|
|
int vp9_decode_frame(VP9D_COMP *pbi, const uint8_t **p_data_end) {
|
|
|
|
int i;
|
|
|
|
vp9_reader header_bc, residual_bc;
|
|
|
|
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-04-19 19:37:24 +02:00
|
|
|
if (vp9_reader_init(&header_bc, data, first_partition_size))
|
2012-07-14 00:21:29 +02:00
|
|
|
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
|
|
|
|
"Failed to allocate bool decoder 0");
|
2010-05-18 17:58:33 +02: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-06-06 20:14:04 +02:00
|
|
|
setup_txfm_mode(pc, xd->lossless, &header_bc);
|
|
|
|
|
2013-04-19 01:08:10 +02:00
|
|
|
read_coef_probs(pbi, &header_bc);
|
2012-02-29 02:11:12 +01:00
|
|
|
|
2013-03-27 22:04:35 +01:00
|
|
|
// Initialize xd pointers. Any reference should do for xd->pre, so use 0.
|
2013-04-20 04:16:14 +02:00
|
|
|
setup_pre_planes(xd, &pc->yv12_fb[pc->active_ref_idx[0]], NULL,
|
|
|
|
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
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Create the segmentation map structure and set to 0
|
|
|
|
if (!pc->last_frame_seg_map)
|
|
|
|
CHECK_MEM_ERROR(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-05-07 00:52:06 +02:00
|
|
|
vp9_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);
|
|
|
|
|
2012-10-30 22:51:31 +01:00
|
|
|
vp9_decode_mode_mvs_init(pbi, &header_bc);
|
2010-05-18 17:58:33 +02:00
|
|
|
|
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-04-24 00:50:56 +02:00
|
|
|
new_fb->corrupted = vp9_reader_has_error(&header_bc) | 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-05-09 19:47:58 +02:00
|
|
|
vp9_adapt_nmv_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
|
|
|
}
|