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"
|
2013-10-02 23:13:33 +02:00
|
|
|
#include "vp9/common/vp9_idct.h"
|
2013-06-28 01:15:43 +02:00
|
|
|
#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-08-01 01:15:10 +02:00
|
|
|
#include "vp9/decoder/vp9_thread.h"
|
2013-07-25 23:13:44 +02:00
|
|
|
#include "vp9/decoder/vp9_treereader.h"
|
2013-05-22 00:31:32 +02:00
|
|
|
|
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-07-15 23:47:25 +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-19 20:37:13 +02:00
|
|
|
static TX_MODE read_tx_mode(vp9_reader *r) {
|
|
|
|
TX_MODE tx_mode = vp9_read_literal(r, 2);
|
|
|
|
if (tx_mode == ALLOW_32X32)
|
|
|
|
tx_mode += vp9_read_bit(r);
|
|
|
|
return tx_mode;
|
2013-07-08 20:54:36 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 23:47:25 +02:00
|
|
|
static void read_tx_probs(struct tx_probs *tx_probs, vp9_reader *r) {
|
2013-07-08 20:54:36 +02:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
|
2013-07-27 02:15:37 +02:00
|
|
|
for (j = 0; j < TX_SIZES - 3; ++j)
|
2013-10-03 19:55:36 +02:00
|
|
|
vp9_diff_update_prob(r, MODE_UPDATE_PROB, &tx_probs->p8x8[i][j]);
|
2013-07-08 20:54:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
|
2013-07-27 02:15:37 +02:00
|
|
|
for (j = 0; j < TX_SIZES - 2; ++j)
|
2013-10-03 19:55:36 +02:00
|
|
|
vp9_diff_update_prob(r, MODE_UPDATE_PROB, &tx_probs->p16x16[i][j]);
|
2013-07-08 20:54:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TX_SIZE_CONTEXTS; ++i)
|
2013-07-27 02:15:37 +02:00
|
|
|
for (j = 0; j < TX_SIZES - 1; ++j)
|
2013-10-03 19:55:36 +02:00
|
|
|
vp9_diff_update_prob(r, MODE_UPDATE_PROB, &tx_probs->p32x32[i][j]);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-08-28 23:49:09 +02:00
|
|
|
static void setup_plane_dequants(VP9_COMMON *cm, MACROBLOCKD *xd, int q_index) {
|
2012-07-14 00:21:29 +02:00
|
|
|
int i;
|
2013-08-28 23:49:09 +02:00
|
|
|
xd->plane[0].dequant = cm->y_dequant[q_index];
|
2013-09-11 19:45:44 +02:00
|
|
|
|
2013-04-24 23:48:17 +02:00
|
|
|
for (i = 1; i < MAX_MB_PLANE; i++)
|
2013-08-28 23:49:09 +02:00
|
|
|
xd->plane[i].dequant = cm->uv_dequant[q_index];
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 20:33:16 +02:00
|
|
|
static void decode_block(int plane, int block, BLOCK_SIZE plane_bsize,
|
2013-08-16 02:03:03 +02:00
|
|
|
TX_SIZE tx_size, void *arg) {
|
2013-04-27 02:52:35 +02:00
|
|
|
MACROBLOCKD* const xd = arg;
|
2013-08-15 20:44:57 +02:00
|
|
|
struct macroblockd_plane *const pd = &xd->plane[plane];
|
2013-08-10 01:40:05 +02:00
|
|
|
int16_t* const qcoeff = BLOCK_OFFSET(pd->qcoeff, block);
|
2013-06-15 00:11:18 +02:00
|
|
|
const int stride = pd->dst.stride;
|
2013-07-24 21:55:45 +02:00
|
|
|
const int eob = pd->eobs[block];
|
2013-10-02 20:48:08 +02:00
|
|
|
if (eob > 0) {
|
|
|
|
TX_TYPE tx_type;
|
|
|
|
const int raster_block = txfrm_block_to_raster_block(plane_bsize, tx_size,
|
|
|
|
block);
|
|
|
|
uint8_t* const dst = raster_block_offset_uint8(plane_bsize, raster_block,
|
|
|
|
pd->dst.buf, stride);
|
|
|
|
switch (tx_size) {
|
|
|
|
case TX_4X4:
|
|
|
|
tx_type = get_tx_type_4x4(pd->plane_type, xd, raster_block);
|
|
|
|
if (tx_type == DCT_DCT)
|
|
|
|
xd->itxm_add(qcoeff, dst, stride, eob);
|
|
|
|
else
|
2013-10-02 23:13:33 +02:00
|
|
|
vp9_iht_add(tx_type, qcoeff, dst, stride, eob);
|
2013-10-02 20:48:08 +02:00
|
|
|
break;
|
|
|
|
case TX_8X8:
|
|
|
|
tx_type = get_tx_type_8x8(pd->plane_type, xd);
|
2013-10-02 23:13:33 +02:00
|
|
|
vp9_iht_add_8x8(tx_type, qcoeff, dst, stride, eob);
|
2013-10-02 20:48:08 +02:00
|
|
|
break;
|
|
|
|
case TX_16X16:
|
|
|
|
tx_type = get_tx_type_16x16(pd->plane_type, xd);
|
2013-10-02 23:13:33 +02:00
|
|
|
vp9_iht_add_16x16(tx_type, qcoeff, dst, stride, eob);
|
2013-10-02 20:48:08 +02:00
|
|
|
break;
|
|
|
|
case TX_32X32:
|
|
|
|
tx_type = DCT_DCT;
|
|
|
|
vp9_idct_add_32x32(qcoeff, dst, stride, eob);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(!"Invalid transform size");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eob == 1) {
|
|
|
|
*((int32_t *)qcoeff) = 0;
|
|
|
|
} else {
|
|
|
|
if (tx_type == DCT_DCT && tx_size <= TX_16X16 && eob <= 10)
|
|
|
|
vpx_memset(qcoeff, 0, 4 * (4 << tx_size) * sizeof(qcoeff[0]));
|
2013-04-27 02:52:35 +02:00
|
|
|
else
|
2013-10-02 20:48:08 +02:00
|
|
|
vpx_memset(qcoeff, 0, (16 << (tx_size << 1)) * sizeof(qcoeff[0]));
|
2013-07-24 21:55:45 +02:00
|
|
|
}
|
2012-11-16 00:14:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-26 20:33:16 +02:00
|
|
|
static void decode_block_intra(int plane, int block, BLOCK_SIZE plane_bsize,
|
2013-08-16 02:03:03 +02:00
|
|
|
TX_SIZE tx_size, void *arg) {
|
2013-05-17 21:50:40 +02:00
|
|
|
MACROBLOCKD* const xd = arg;
|
2013-08-15 20:44:57 +02:00
|
|
|
struct macroblockd_plane *const pd = &xd->plane[plane];
|
2013-09-11 19:45:44 +02:00
|
|
|
MODE_INFO *const mi = xd->this_mi;
|
2013-08-19 22:20:21 +02:00
|
|
|
const int raster_block = txfrm_block_to_raster_block(plane_bsize, tx_size,
|
|
|
|
block);
|
|
|
|
uint8_t* const dst = raster_block_offset_uint8(plane_bsize, raster_block,
|
2013-06-15 00:11:18 +02:00
|
|
|
pd->dst.buf, pd->dst.stride);
|
2013-08-27 00:24:12 +02:00
|
|
|
const MB_PREDICTION_MODE mode = (plane == 0)
|
|
|
|
? ((mi->mbmi.sb_type < BLOCK_8X8) ? mi->bmi[raster_block].as_mode
|
|
|
|
: mi->mbmi.mode)
|
|
|
|
: mi->mbmi.uv_mode;
|
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-08-19 22:20:21 +02:00
|
|
|
extend_for_intra(xd, plane_bsize, plane, block, tx_size);
|
2013-06-06 15:07:09 +02:00
|
|
|
|
2013-08-27 00:24:12 +02:00
|
|
|
vp9_predict_intra_block(xd, raster_block >> tx_size,
|
|
|
|
b_width_log2(plane_bsize), tx_size, mode,
|
|
|
|
dst, pd->dst.stride, dst, pd->dst.stride);
|
2013-05-17 21:50:40 +02:00
|
|
|
|
2013-08-28 21:22:37 +02:00
|
|
|
if (!mi->mbmi.skip_coeff)
|
|
|
|
decode_block(plane, block, plane_bsize, tx_size, arg);
|
2013-05-17 21:50:40 +02:00
|
|
|
}
|
|
|
|
|
2013-08-26 20:33:16 +02:00
|
|
|
static int decode_tokens(VP9D_COMP *pbi, BLOCK_SIZE bsize, vp9_reader *r) {
|
2013-08-28 23:49:09 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-06-28 01:15:43 +02:00
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-09-11 19:45:44 +02:00
|
|
|
MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi;
|
2013-04-30 19:16:09 +02:00
|
|
|
|
2013-08-28 23:49:09 +02:00
|
|
|
if (mbmi->skip_coeff) {
|
|
|
|
reset_skip_context(xd, bsize);
|
2013-06-28 01:15:43 +02:00
|
|
|
return -1;
|
2013-04-30 19:16:09 +02:00
|
|
|
} else {
|
2013-08-28 23:49:09 +02:00
|
|
|
if (cm->seg.enabled)
|
|
|
|
setup_plane_dequants(cm, xd, vp9_get_qindex(&cm->seg, mbmi->segment_id,
|
|
|
|
cm->base_qindex));
|
2013-04-30 19:16:09 +02:00
|
|
|
|
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-08-26 20:33:16 +02:00
|
|
|
static void set_offsets(VP9D_COMP *pbi, BLOCK_SIZE 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-08-28 21:22:37 +02:00
|
|
|
const int bh = num_8x8_blocks_high_lookup[bsize];
|
|
|
|
const int bw = num_8x8_blocks_wide_lookup[bsize];
|
|
|
|
const int offset = mi_row * cm->mode_info_stride + mi_col;
|
2013-04-09 19:17:22 +02:00
|
|
|
|
2013-08-28 23:49:09 +02:00
|
|
|
xd->mode_info_stride = cm->mode_info_stride;
|
2013-09-11 19:45:44 +02:00
|
|
|
|
|
|
|
xd->mi_8x8 = cm->mi_grid_visible + offset;
|
|
|
|
xd->prev_mi_8x8 = cm->prev_mi_grid_visible + offset;
|
|
|
|
|
|
|
|
// we are using the mode info context stream here
|
|
|
|
xd->this_mi =
|
|
|
|
xd->mi_8x8[0] = xd->mic_stream_ptr;
|
|
|
|
xd->this_mi->mbmi.sb_type = bsize;
|
|
|
|
xd->mic_stream_ptr++;
|
|
|
|
|
2013-05-29 22:42:23 +02:00
|
|
|
// Special case: if prev_mi is NULL, the previous mode info context
|
|
|
|
// cannot be used.
|
2013-09-11 19:45:44 +02:00
|
|
|
xd->last_mi = cm->prev_mi ? xd->prev_mi_8x8[0] : NULL;
|
2013-07-03 20:15:58 +02:00
|
|
|
|
2013-08-12 20:24:24 +02:00
|
|
|
set_skip_context(cm, xd, mi_row, mi_col);
|
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-09-11 19:45:44 +02:00
|
|
|
MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi;
|
2013-08-23 00:19:05 +02:00
|
|
|
const int ref = mbmi->ref_frame[i] - LAST_FRAME;
|
2013-07-04 02:42:01 +02:00
|
|
|
const YV12_BUFFER_CONFIG *cfg = &cm->yv12_fb[cm->active_ref_idx[ref]];
|
2013-08-23 00:19:05 +02:00
|
|
|
const struct scale_factors *sf = &cm->active_ref_scale[ref];
|
|
|
|
if (!vp9_is_valid_scale(sf))
|
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
|
|
|
|
"Invalid scale factors");
|
|
|
|
|
|
|
|
xd->scale_factor[i] = *sf;
|
|
|
|
setup_pre_planes(xd, i, cfg, mi_row, mi_col, sf);
|
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-08-26 20:33:16 +02:00
|
|
|
vp9_reader *r, BLOCK_SIZE 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-08-02 20:45:21 +02:00
|
|
|
const int less8x8 = bsize < BLOCK_8X8;
|
2013-06-29 03:34:30 +02:00
|
|
|
MB_MODE_INFO *mbmi;
|
2013-10-02 00:41:30 +02:00
|
|
|
int eobtotal;
|
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)
|
2013-08-02 20:45:21 +02:00
|
|
|
bsize = BLOCK_8X8;
|
2013-06-29 03:34:30 +02:00
|
|
|
|
|
|
|
// Has to be called after set_offsets
|
2013-09-11 19:45:44 +02:00
|
|
|
mbmi = &xd->this_mi->mbmi;
|
2013-10-02 00:41:30 +02:00
|
|
|
eobtotal = decode_tokens(pbi, bsize, r);
|
2013-06-29 03:34:30 +02:00
|
|
|
|
2013-08-03 01:25:33 +02:00
|
|
|
if (!is_inter_block(mbmi)) {
|
2013-06-29 03:34:30 +02:00
|
|
|
// Intra reconstruction
|
|
|
|
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
|
2013-10-02 00:41:30 +02:00
|
|
|
const int decode_blocks = (eobtotal > 0);
|
|
|
|
|
|
|
|
if (!less8x8) {
|
|
|
|
assert(mbmi->sb_type == bsize);
|
|
|
|
if (eobtotal == 0)
|
|
|
|
mbmi->skip_coeff = 1; // skip loopfilter
|
|
|
|
}
|
2013-07-04 02:42:01 +02:00
|
|
|
|
|
|
|
set_ref(pbi, 0, mi_row, mi_col);
|
2013-08-28 21:22:37 +02:00
|
|
|
if (has_second_ref(mbmi))
|
2013-07-04 02:42:01 +02:00
|
|
|
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);
|
2013-10-02 00:41:30 +02:00
|
|
|
|
|
|
|
if (decode_blocks)
|
|
|
|
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-08-26 20:33:16 +02:00
|
|
|
vp9_reader* r, BLOCK_SIZE bsize) {
|
2013-08-23 05:03:08 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-04-05 19:47:26 +02:00
|
|
|
MACROBLOCKD *const xd = &pbi->mb;
|
2013-08-28 21:22:37 +02:00
|
|
|
const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2;
|
2013-04-16 09:18:02 +02:00
|
|
|
PARTITION_TYPE partition = PARTITION_NONE;
|
2013-08-26 20:33:16 +02:00
|
|
|
BLOCK_SIZE subsize;
|
2013-04-16 09:18:02 +02:00
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols)
|
2013-04-16 09:18:02 +02:00
|
|
|
return;
|
|
|
|
|
2013-08-02 20:45:21 +02:00
|
|
|
if (bsize < BLOCK_8X8) {
|
2013-05-11 02:06:37 +02:00
|
|
|
if (xd->ab_index != 0)
|
|
|
|
return;
|
2013-07-15 23:47:25 +02:00
|
|
|
} else {
|
2013-04-23 19:12:18 +02:00
|
|
|
int pl;
|
2013-08-23 05:03:08 +02:00
|
|
|
const int idx = check_bsize_coverage(hbs, cm->mi_rows, cm->mi_cols,
|
2013-08-23 00:45:56 +02:00
|
|
|
mi_row, mi_col);
|
2013-08-23 05:03:08 +02:00
|
|
|
set_partition_seg_context(cm, 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,
|
2013-08-23 05:03:08 +02:00
|
|
|
cm->fc.partition_prob[cm->frame_type][pl]);
|
2013-06-07 00:33:57 +02:00
|
|
|
else if (idx > 0 &&
|
2013-08-23 05:03:08 +02:00
|
|
|
!vp9_read(r, cm->fc.partition_prob[cm->frame_type][pl][idx]))
|
2013-06-07 00:33:57 +02:00
|
|
|
partition = (idx == 1) ? PARTITION_HORZ : PARTITION_VERT;
|
|
|
|
else
|
|
|
|
partition = PARTITION_SPLIT;
|
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
cm->counts.partition[pl][partition]++;
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
|
|
|
|
2013-05-01 18:43:59 +02:00
|
|
|
subsize = get_subsize(bsize, partition);
|
2013-08-28 21:22:37 +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-08-28 21:22:37 +02:00
|
|
|
*get_sb_index(xd, subsize) = 1;
|
2013-08-23 05:03:08 +02:00
|
|
|
if (mi_row + hbs < cm->mi_rows)
|
2013-08-28 21:22:37 +02:00
|
|
|
decode_modes_b(pbi, mi_row + hbs, 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-08-28 21:22:37 +02:00
|
|
|
*get_sb_index(xd, subsize) = 1;
|
2013-08-23 05:03:08 +02:00
|
|
|
if (mi_col + hbs < cm->mi_cols)
|
2013-08-28 21:22:37 +02:00
|
|
|
decode_modes_b(pbi, mi_row, mi_col + hbs, r, subsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
break;
|
2013-08-23 00:45:56 +02:00
|
|
|
case PARTITION_SPLIT: {
|
|
|
|
int n;
|
2013-04-16 09:18:02 +02:00
|
|
|
for (n = 0; n < 4; n++) {
|
2013-08-23 00:45:56 +02:00
|
|
|
const int j = n >> 1, i = n & 1;
|
2013-08-28 21:22:37 +02:00
|
|
|
*get_sb_index(xd, subsize) = n;
|
|
|
|
decode_modes_sb(pbi, mi_row + j * hbs, mi_col + i * hbs, r, subsize);
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
2013-08-23 00:45:56 +02:00
|
|
|
} break;
|
2013-04-16 09:18:02 +02:00
|
|
|
default:
|
2013-07-15 23:47:25 +02:00
|
|
|
assert(!"Invalid partition type");
|
2013-04-16 09:18:02 +02:00
|
|
|
}
|
2013-07-15 23:47:25 +02:00
|
|
|
|
2013-04-23 19:12:18 +02:00
|
|
|
// update partition context
|
2013-08-02 20:45:21 +02:00
|
|
|
if (bsize >= BLOCK_8X8 &&
|
|
|
|
(bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) {
|
2013-08-23 05:03:08 +02:00
|
|
|
set_partition_seg_context(cm, xd, mi_row, mi_col);
|
2013-05-12 00:19:56 +02:00
|
|
|
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-08-23 05:03:08 +02:00
|
|
|
VP9_COMMON *cm = &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))
|
2013-08-23 05:03:08 +02:00
|
|
|
vpx_internal_error(&cm->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))
|
2013-08-23 05:03:08 +02:00
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
|
2012-07-14 00:21:29 +02:00
|
|
|
"Failed to allocate bool decoder %d", 1);
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 23:47:25 +02:00
|
|
|
static void read_coef_probs_common(vp9_coeff_probs_model *coef_probs,
|
2013-05-31 18:18:59 +02:00
|
|
|
vp9_reader *r) {
|
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++)
|
2013-10-03 19:55:36 +02:00
|
|
|
vp9_diff_update_prob(r, VP9_COEF_UPDATE_PROB,
|
|
|
|
&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-19 20:37:13 +02:00
|
|
|
static void read_coef_probs(FRAME_CONTEXT *fc, TX_MODE tx_mode,
|
2013-07-08 20:54:36 +02:00
|
|
|
vp9_reader *r) {
|
2013-07-15 23:47:25 +02:00
|
|
|
read_coef_probs_common(fc->coef_probs[TX_4X4], r);
|
2012-10-24 21:59:22 +02:00
|
|
|
|
2013-07-19 20:37:13 +02:00
|
|
|
if (tx_mode > ONLY_4X4)
|
2013-07-15 23:47:25 +02:00
|
|
|
read_coef_probs_common(fc->coef_probs[TX_8X8], r);
|
2013-03-12 01:02:27 +01:00
|
|
|
|
2013-07-19 20:37:13 +02:00
|
|
|
if (tx_mode > ALLOW_8X8)
|
2013-07-15 23:47:25 +02:00
|
|
|
read_coef_probs_common(fc->coef_probs[TX_16X16], r);
|
2013-03-12 01:02:27 +01:00
|
|
|
|
2013-07-19 20:37:13 +02:00
|
|
|
if (tx_mode > ALLOW_16X16)
|
2013-07-15 23:47:25 +02:00
|
|
|
read_coef_probs_common(fc->coef_probs[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-07-23 13:09:04 +02:00
|
|
|
for (i = 0; i < 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
|
|
|
|
2013-07-23 13:09:04 +02:00
|
|
|
for (i = 0; i < MAX_SEGMENTS; i++) {
|
2013-04-24 00:50:56 +02:00
|
|
|
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-07-18 03:37:45 +02:00
|
|
|
static void setup_loopfilter(struct loopfilter *lf,
|
|
|
|
struct vp9_read_bit_buffer *rb) {
|
|
|
|
lf->filter_level = vp9_rb_read_literal(rb, 6);
|
|
|
|
lf->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.
|
2013-07-18 03:37:45 +02:00
|
|
|
lf->mode_ref_delta_update = 0;
|
2013-03-26 19:04:25 +01:00
|
|
|
|
2013-07-18 03:37:45 +02:00
|
|
|
lf->mode_ref_delta_enabled = vp9_rb_read_bit(rb);
|
|
|
|
if (lf->mode_ref_delta_enabled) {
|
|
|
|
lf->mode_ref_delta_update = vp9_rb_read_bit(rb);
|
|
|
|
if (lf->mode_ref_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))
|
2013-07-18 03:37:45 +02:00
|
|
|
lf->ref_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))
|
2013-07-18 03:37:45 +02:00
|
|
|
lf->mode_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-08-30 00:33:06 +02:00
|
|
|
*delta_q = vp9_rb_read_bit(rb) ? vp9_rb_read_signed_literal(rb, 4) : 0;
|
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
|
|
|
|
2013-10-02 23:13:33 +02:00
|
|
|
xd->itxm_add = xd->lossless ? vp9_idct_add_lossless
|
2013-06-25 20:52:44 +02:00
|
|
|
: 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) {
|
2013-08-05 21:26:15 +02:00
|
|
|
const INTERPOLATIONFILTERTYPE literal_to_type[] = { EIGHTTAP_SMOOTH,
|
|
|
|
EIGHTTAP,
|
2013-10-03 03:04:12 +02:00
|
|
|
EIGHTTAP_SHARP,
|
|
|
|
BILINEAR };
|
2013-06-06 05:56:37 +02:00
|
|
|
return vp9_rb_read_bit(rb) ? SWITCHABLE
|
2013-08-05 21:26:15 +02:00
|
|
|
: literal_to_type[vp9_rb_read_literal(rb, 2)];
|
2013-04-24 00:50:56 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 01:59:15 +02:00
|
|
|
static void read_frame_size(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-08-01 01:59:15 +02:00
|
|
|
static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
|
2013-06-08 03:09:29 +02:00
|
|
|
cm->display_width = cm->width;
|
|
|
|
cm->display_height = cm->height;
|
|
|
|
if (vp9_rb_read_bit(rb))
|
2013-08-01 01:59:15 +02:00
|
|
|
read_frame_size(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) {
|
|
|
|
int width, height;
|
2013-08-01 01:59:15 +02:00
|
|
|
read_frame_size(rb, &width, &height);
|
2013-06-07 22:41:44 +02:00
|
|
|
apply_frame_size(pbi, width, height);
|
2013-08-23 22:12:46 +02:00
|
|
|
setup_display_size(&pbi->common, rb);
|
2013-06-07 22:41:44 +02:00
|
|
|
}
|
|
|
|
|
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)
|
2013-08-01 01:59:15 +02:00
|
|
|
read_frame_size(rb, &width, &height);
|
2013-06-08 03:09:29 +02:00
|
|
|
|
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
|
|
|
apply_frame_size(pbi, width, height);
|
2013-08-23 22:12:46 +02:00
|
|
|
setup_display_size(cm, rb);
|
2013-06-08 03:09:29 +02:00
|
|
|
}
|
|
|
|
|
2013-04-25 23:25:40 +02:00
|
|
|
static void decode_tile(VP9D_COMP *pbi, vp9_reader *r) {
|
2013-08-01 01:15:10 +02:00
|
|
|
const int num_threads = pbi->oxcf.max_threads;
|
2013-08-23 05:03:08 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-04-26 20:57:17 +02:00
|
|
|
int mi_row, mi_col;
|
2013-08-23 05:03:08 +02:00
|
|
|
YV12_BUFFER_CONFIG *const fb = &cm->yv12_fb[cm->new_fb_idx];
|
2013-04-25 23:25:40 +02:00
|
|
|
|
2013-07-19 23:40:34 +02:00
|
|
|
if (pbi->do_loopfilter_inline) {
|
2013-08-01 01:15:10 +02:00
|
|
|
if (num_threads > 1) {
|
|
|
|
LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
|
2013-08-13 03:28:13 +02:00
|
|
|
lf_data->frame_buffer = fb;
|
2013-08-23 05:03:08 +02:00
|
|
|
lf_data->cm = cm;
|
2013-08-01 01:15:10 +02:00
|
|
|
lf_data->xd = pbi->mb;
|
2013-08-22 02:43:44 +02:00
|
|
|
lf_data->stop = 0;
|
2013-08-01 01:15:10 +02:00
|
|
|
lf_data->y_only = 0;
|
|
|
|
}
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_loop_filter_frame_init(cm, cm->lf.filter_level);
|
2013-07-19 23:40:34 +02:00
|
|
|
}
|
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
for (mi_row = cm->cur_tile_mi_row_start; mi_row < cm->cur_tile_mi_row_end;
|
2013-07-03 19:54:50 +02:00
|
|
|
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-08-23 05:03:08 +02:00
|
|
|
vp9_zero(cm->left_context);
|
|
|
|
vp9_zero(cm->left_seg_context);
|
|
|
|
for (mi_col = cm->cur_tile_mi_col_start; mi_col < cm->cur_tile_mi_col_end;
|
2013-08-28 21:22:37 +02:00
|
|
|
mi_col += MI_BLOCK_SIZE)
|
2013-08-02 20:45:21 +02:00
|
|
|
decode_modes_sb(pbi, mi_row, mi_col, r, BLOCK_64X64);
|
2013-07-19 23:40:34 +02:00
|
|
|
|
|
|
|
if (pbi->do_loopfilter_inline) {
|
|
|
|
// delay the loopfilter by 1 macroblock row.
|
|
|
|
const int lf_start = mi_row - MI_BLOCK_SIZE;
|
|
|
|
if (lf_start < 0) continue;
|
2013-08-01 01:15:10 +02:00
|
|
|
|
|
|
|
if (num_threads > 1) {
|
|
|
|
LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
|
|
|
|
|
2013-08-22 02:43:44 +02:00
|
|
|
// decoding has completed: finish up the loop filter in this thread.
|
2013-08-23 05:03:08 +02:00
|
|
|
if (mi_row + MI_BLOCK_SIZE >= cm->cur_tile_mi_row_end) continue;
|
2013-08-22 02:43:44 +02:00
|
|
|
|
2013-08-01 01:15:10 +02:00
|
|
|
vp9_worker_sync(&pbi->lf_worker);
|
|
|
|
lf_data->start = lf_start;
|
|
|
|
lf_data->stop = mi_row;
|
|
|
|
pbi->lf_worker.hook = vp9_loop_filter_worker;
|
|
|
|
vp9_worker_launch(&pbi->lf_worker);
|
|
|
|
} else {
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_loop_filter_rows(fb, cm, &pbi->mb, lf_start, mi_row, 0);
|
2013-08-01 01:15:10 +02:00
|
|
|
}
|
2013-07-19 23:40:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pbi->do_loopfilter_inline) {
|
2013-08-22 02:43:44 +02:00
|
|
|
int lf_start;
|
2013-08-01 01:15:10 +02:00
|
|
|
if (num_threads > 1) {
|
2013-08-22 02:43:44 +02:00
|
|
|
LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1;
|
|
|
|
|
2013-08-01 01:15:10 +02:00
|
|
|
vp9_worker_sync(&pbi->lf_worker);
|
2013-08-22 02:43:44 +02:00
|
|
|
lf_start = lf_data->stop;
|
|
|
|
} else {
|
|
|
|
lf_start = mi_row - MI_BLOCK_SIZE;
|
2013-08-01 01:15:10 +02:00
|
|
|
}
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_loop_filter_rows(fb, cm, &pbi->mb,
|
|
|
|
lf_start, cm->mi_rows, 0);
|
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) {
|
2013-07-16 23:47:15 +02:00
|
|
|
int min_log2_tile_cols, max_log2_tile_cols, max_ones;
|
|
|
|
vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
|
2013-03-28 00:23:12 +01:00
|
|
|
|
2013-07-16 23:47:15 +02:00
|
|
|
// columns
|
|
|
|
max_ones = max_log2_tile_cols - min_log2_tile_cols;
|
|
|
|
cm->log2_tile_cols = min_log2_tile_cols;
|
|
|
|
while (max_ones-- && vp9_rb_read_bit(rb))
|
|
|
|
cm->log2_tile_cols++;
|
2013-06-06 21:33:12 +02:00
|
|
|
|
2013-07-16 23:47:15 +02:00
|
|
|
// rows
|
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);
|
|
|
|
}
|
|
|
|
|
2013-07-19 21:27:56 +02:00
|
|
|
static const uint8_t *decode_tiles(VP9D_COMP *pbi, const uint8_t *data) {
|
|
|
|
vp9_reader residual_bc;
|
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-06-06 21:33:12 +02:00
|
|
|
|
2013-07-08 23:54:04 +02:00
|
|
|
const uint8_t *const data_end = pbi->source + pbi->source_sz;
|
2013-08-23 05:03:08 +02:00
|
|
|
const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols);
|
|
|
|
const int tile_cols = 1 << cm->log2_tile_cols;
|
|
|
|
const int tile_rows = 1 << cm->log2_tile_rows;
|
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-08-23 05:03:08 +02:00
|
|
|
vpx_memset(cm->above_context[0], 0,
|
2013-08-12 20:24:24 +02:00
|
|
|
sizeof(ENTROPY_CONTEXT) * MAX_MB_PLANE * (2 * aligned_mi_cols));
|
2013-04-23 19:12:18 +02:00
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
vpx_memset(cm->above_seg_context, 0,
|
2013-07-08 23:54:04 +02:00
|
|
|
sizeof(PARTITION_CONTEXT) * aligned_mi_cols);
|
2013-03-28 00:23:12 +01:00
|
|
|
|
|
|
|
if (pbi->oxcf.inv_tile_order) {
|
|
|
|
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
|
2013-07-19 21:27:56 +02:00
|
|
|
data_ptr2[0][0] = data;
|
2013-07-16 23:47:15 +02:00
|
|
|
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
|
2013-03-28 00:23:12 +01:00
|
|
|
if (tile_row) {
|
2013-07-16 23:47:15 +02:00
|
|
|
const int size = read_be32(data_ptr2[tile_row - 1][tile_cols - 1]);
|
|
|
|
data_ptr2[tile_row - 1][tile_cols - 1] += 4;
|
|
|
|
data_ptr2[tile_row][0] = data_ptr2[tile_row - 1][tile_cols - 1] + size;
|
2013-03-28 00:23:12 +01:00
|
|
|
}
|
|
|
|
|
2013-07-16 23:47:15 +02:00
|
|
|
for (tile_col = 1; tile_col < tile_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-16 23:47:15 +02:00
|
|
|
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_get_tile_row_offsets(cm, tile_row);
|
2013-07-16 23:47:15 +02:00
|
|
|
for (tile_col = tile_cols - 1; tile_col >= 0; tile_col--) {
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_get_tile_col_offsets(cm, 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],
|
2013-07-19 21:27:56 +02:00
|
|
|
&residual_bc);
|
|
|
|
decode_tile(pbi, &residual_bc);
|
2013-07-16 23:47:15 +02:00
|
|
|
if (tile_row == tile_rows - 1 && tile_col == tile_cols - 1)
|
2013-07-19 21:27:56 +02:00
|
|
|
bc_bak = residual_bc;
|
2013-03-28 00:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
2013-07-19 21:27:56 +02:00
|
|
|
residual_bc = bc_bak;
|
2013-03-28 00:23:12 +01:00
|
|
|
} else {
|
|
|
|
int has_more;
|
|
|
|
|
2013-07-16 23:47:15 +02:00
|
|
|
for (tile_row = 0; tile_row < tile_rows; tile_row++) {
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_get_tile_row_offsets(cm, tile_row);
|
2013-07-16 23:47:15 +02:00
|
|
|
for (tile_col = 0; tile_col < tile_cols; tile_col++) {
|
2013-06-11 19:06:31 +02:00
|
|
|
size_t size;
|
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_get_tile_col_offsets(cm, tile_col);
|
2013-03-28 00:23:12 +01:00
|
|
|
|
2013-07-16 23:47:15 +02:00
|
|
|
has_more = tile_col < tile_cols - 1 || tile_row < tile_rows - 1;
|
2013-03-28 00:23:12 +01:00
|
|
|
if (has_more) {
|
2013-07-19 21:27:56 +02:00
|
|
|
if (!read_is_valid(data, 4, data_end))
|
2013-08-23 05:03:08 +02:00
|
|
|
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
|
2013-06-11 19:06:31 +02:00
|
|
|
"Truncated packet or corrupt tile length");
|
|
|
|
|
2013-07-19 21:27:56 +02:00
|
|
|
size = read_be32(data);
|
|
|
|
data += 4;
|
2013-06-11 19:06:31 +02:00
|
|
|
} else {
|
2013-07-19 21:27:56 +02:00
|
|
|
size = data_end - data;
|
2013-03-28 00:23:12 +01:00
|
|
|
}
|
2013-06-11 19:06:31 +02:00
|
|
|
|
2013-07-19 21:27:56 +02:00
|
|
|
setup_token_decoder(pbi, data, size, &residual_bc);
|
|
|
|
decode_tile(pbi, &residual_bc);
|
|
|
|
data += size;
|
2013-03-28 00:23:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-19 21:27:56 +02:00
|
|
|
|
|
|
|
return vp9_reader_find_end(&residual_bc);
|
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;
|
2013-07-15 23:47:25 +02:00
|
|
|
for (i = 1; i < ALLOWED_REFS_PER_FRAME; ++i)
|
|
|
|
cm->allow_comp_inter_inter |=
|
2013-06-08 03:09:29 +02:00
|
|
|
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;
|
2013-08-09 23:41:51 +02:00
|
|
|
cm->lf.filter_level = 0;
|
2012-10-03 21:11:05 +02:00
|
|
|
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 {
|
2013-08-05 21:26:15 +02:00
|
|
|
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-08-14 20:20:33 +02:00
|
|
|
vp9_setup_past_independence(cm);
|
2013-06-09 19:10:33 +02:00
|
|
|
|
2013-08-09 23:41:51 +02:00
|
|
|
setup_loopfilter(&cm->lf, rb);
|
2013-06-03 19:50:57 +02:00
|
|
|
setup_quantization(pbi, rb);
|
2013-08-14 20:20:33 +02:00
|
|
|
setup_segmentation(&cm->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");
|
|
|
|
|
2013-07-19 20:37:13 +02:00
|
|
|
cm->tx_mode = xd->lossless ? ONLY_4X4 : read_tx_mode(&r);
|
|
|
|
if (cm->tx_mode == TX_MODE_SELECT)
|
2013-07-15 23:47:25 +02:00
|
|
|
read_tx_probs(&cm->fc.tx_probs, &r);
|
2013-07-19 20:37:13 +02:00
|
|
|
read_coef_probs(&cm->fc, cm->tx_mode, &r);
|
2013-07-08 20:54:36 +02:00
|
|
|
|
|
|
|
vp9_prepare_read_mode_info(pbi, &r);
|
|
|
|
|
|
|
|
return vp9_reader_has_error(&r);
|
|
|
|
}
|
|
|
|
|
2013-07-15 23:47:25 +02:00
|
|
|
void vp9_init_dequantizer(VP9_COMMON *cm) {
|
2013-06-25 20:52:44 +02:00
|
|
|
int q;
|
|
|
|
|
|
|
|
for (q = 0; q < QINDEX_RANGE; q++) {
|
2013-07-15 23:47:25 +02:00
|
|
|
cm->y_dequant[q][0] = vp9_dc_quant(q, cm->y_dc_delta_q);
|
|
|
|
cm->y_dequant[q][1] = vp9_ac_quant(q, 0);
|
2013-06-25 20:52:44 +02:00
|
|
|
|
2013-07-15 23:47:25 +02:00
|
|
|
cm->uv_dequant[q][0] = vp9_dc_quant(q, cm->uv_dc_delta_q);
|
|
|
|
cm->uv_dequant[q][1] = vp9_ac_quant(q, cm->uv_ac_delta_q);
|
2013-06-25 20:52:44 +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;
|
2013-08-23 05:03:08 +02:00
|
|
|
VP9_COMMON *const cm = &pbi->common;
|
2013-05-29 03:07:54 +02:00
|
|
|
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,
|
2013-08-23 05:03:08 +02:00
|
|
|
cm, error_handler };
|
2013-05-29 03:07:54 +02:00
|
|
|
const size_t first_partition_size = read_uncompressed_header(pbi, &rb);
|
2013-08-23 05:03:08 +02:00
|
|
|
const int keyframe = cm->frame_type == KEY_FRAME;
|
|
|
|
YV12_BUFFER_CONFIG *new_fb = &cm->yv12_fb[cm->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;
|
2013-07-19 23:40:34 +02:00
|
|
|
pbi->do_loopfilter_inline =
|
2013-08-23 05:03:08 +02:00
|
|
|
(cm->log2_tile_rows | cm->log2_tile_cols) == 0 && cm->lf.filter_level;
|
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-08-23 05:03:08 +02:00
|
|
|
vpx_internal_error(&cm->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-08-28 23:49:09 +02:00
|
|
|
setup_plane_dequants(cm, &pbi->mb, cm->base_qindex);
|
2013-05-16 03:20:51 +02:00
|
|
|
|
2013-09-11 19:45:44 +02:00
|
|
|
xd->mi_8x8 = cm->mi_grid_visible;
|
|
|
|
xd->mic_stream_ptr = cm->mi;
|
|
|
|
xd->mode_info_stride = cm->mode_info_stride;
|
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
cm->fc = cm->frame_contexts[cm->frame_context_idx];
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
vp9_zero(cm->counts);
|
2013-04-19 01:08:10 +02:00
|
|
|
|
2013-07-08 20:54:36 +02:00
|
|
|
new_fb->corrupted |= read_compressed_header(pbi, data, first_partition_size);
|
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
setup_block_dptrs(xd, cm->subsampling_x, cm->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-08-23 05:03:08 +02:00
|
|
|
set_prev_mi(cm);
|
2013-05-29 22:42:23 +02:00
|
|
|
|
2013-07-19 21:27:56 +02:00
|
|
|
*p_data_end = decode_tiles(pbi, data + first_partition_size);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
cm->last_width = cm->width;
|
|
|
|
cm->last_height = cm->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-08-23 05:03:08 +02:00
|
|
|
vpx_internal_error(&cm->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-08-23 05:03:08 +02:00
|
|
|
if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) {
|
|
|
|
vp9_adapt_coef_probs(cm);
|
2013-05-07 18:24:21 +02:00
|
|
|
|
2013-08-23 05:03:08 +02:00
|
|
|
if (!keyframe && !cm->intra_only) {
|
|
|
|
vp9_adapt_mode_probs(cm);
|
|
|
|
vp9_adapt_mv_probs(cm, 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-08-23 05:03:08 +02:00
|
|
|
if (cm->refresh_frame_context)
|
|
|
|
cm->frame_contexts[cm->frame_context_idx] = cm->fc;
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return 0;
|
2010-05-18 17:58:33 +02:00
|
|
|
}
|