Added more descriptive comments and did some smaller refactoring. Also changed to setting the mb_skip_coeff flag when a macroblock needs to be concealed.

Change-Id: I0bbf6de899f5b27f4a8ca0454da7e928e8b23919
This commit is contained in:
Stefan Holmer
2011-04-28 16:28:07 +02:00
parent 8d49ea12c2
commit 98ea0d71a4
5 changed files with 142 additions and 98 deletions

View File

@@ -182,18 +182,20 @@ void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, unsigned int mb_idx)
int eobtotal = 0;
int i, do_clamp = xd->mode_info_context->mbmi.need_to_clamp_mvs;
#ifndef EC_COPY_PREDICTOR
/* TODO(holmer): change when we have MB level error tracking
* The residuals may not match the predicted signal when a macroblock is
* corrupted due to previous losses. Should we try to add the residual
* anyway, or just throw it away? Should test this on a couple of files.
*/
if (pbi->ec_enabled && xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME
&& (xd->corrupted || mb_idx >= pbi->mvs_corrupt_from_mb))
if (pbi->ec_enabled)
{
xd->mode_info_context->mbmi.mb_skip_coeff = 1;
if ((xd->corrupted &&
xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME) ||
vp8dx_bool_error(xd->current_bc))
{
xd->mode_info_context->mbmi.mb_skip_coeff = 1;
}
}
#endif
if (xd->mode_info_context->mbmi.mb_skip_coeff)
{
@@ -239,20 +241,6 @@ void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, unsigned int mb_idx)
vp8_build_inter_predictors_mb(xd);
}
#ifndef EC_COPY_PREDICTOR
/* TODO(holmer): change when we have MB level error tracking
* The residuals may not match the predicted signal when a macroblock is
* corrupted due to previous losses. Should we try to add the residual
* anyway, or just throw it away? Should test this on a couple of files.
*/
if (pbi->ec_enabled && xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME
&& (xd->corrupted || mb_idx >= pbi->mvs_corrupt_from_mb))
{
vp8_conceal_corrupt_block(xd);
return;
}
#endif
/* dequantization and idct */
if (xd->mode_info_context->mbmi.mode != B_PRED && xd->mode_info_context->mbmi.mode != SPLITMV)
{
@@ -393,10 +381,10 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
* coefficients if it's the first block with missing coefficients,
* since the bool dec error detection is done after reconstruction.
*/
vp8_interpolate_mv(xd,
mb_row, mb_col,
pc->mb_rows, pc->mb_cols,
pc->mode_info_stride);
vp8_interpolate_motion(xd,
mb_row, mb_col,
pc->mb_rows, pc->mb_cols,
pc->mode_info_stride);
}
if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)

40
vp8/decoder/ec_types.h Normal file
View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2011 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VP8_DEC_EC_TYPES_H
#define VP8_DEC_EC_TYPES_H
#define MAX_OVERLAPS 16
typedef struct
{
int overlap;
B_MODE_INFO *bmi;
MV_REFERENCE_FRAME ref_frame;
} OVERLAP_NODE;
typedef struct
{
/* TODO(holmer): This array should be exchanged for a linked list */
OVERLAP_NODE overlaps[MAX_OVERLAPS];
} B_OVERLAP;
typedef struct
{
B_OVERLAP overlaps[16];
} MB_OVERLAP;
typedef struct
{
MV mv;
MV_REFERENCE_FRAME ref_frame;
} EC_BLOCK;
#endif /* VP8_DEC_EC_TYPES_H */

View File

@@ -42,7 +42,7 @@ static const int weights_q7[5][5] = {
{ 32, 31, 29, 26, 23 }
};
int vp8_need_to_clamp_mv(MV *mv,
static int vp8_need_to_clamp_mv(MV *mv,
int mb_to_left_edge,
int mb_to_right_edge,
int mb_to_top_edge,
@@ -111,15 +111,15 @@ int vp8_block_overlap(int b1_row, int b1_col, int b2_row, int b2_col)
void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
MV_REFERENCE_FRAME ref_frame,
int new_row, int new_col,
int first_ol_mb_row, int first_ol_mb_col,
int first_ol_blk_row, int first_ol_blk_col)
int mb_row, int mb_col,
int first_blk_row, int first_blk_col)
{
/* Find the blocks within this MB which are overlapped by bmi and
* calculate and assign overlap for each of those blocks. */
/* Block coordinates relative the upper-left block */
const int rel_ol_blk_row = first_ol_blk_row - first_ol_mb_row * 4;
const int rel_ol_blk_col = first_ol_blk_col - first_ol_mb_col * 4;
const int rel_ol_blk_row = first_blk_row - mb_row * 4;
const int rel_ol_blk_col = first_blk_col - mb_col * 4;
/* If the block partly overlaps any previous MB, these coordinates
* can be < 0. We don't want to access blocks in previous MBs.
*/
@@ -130,9 +130,10 @@ void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
/* Calculate and assign overlaps for all blocks in this MB
* which the motion compensated block overlaps
*/
/* Avoid calculating overlaps for blocks in later MBs */
int end_row = MIN(4 + mb_row * 4 - first_blk_row, 2);
int end_col = MIN(4 + mb_col * 4 - first_blk_col, 2);
int row, col;
int end_row = MIN(4 + first_ol_mb_row * 4 - first_ol_blk_row, 2);
int end_col = MIN(4 + first_ol_mb_col * 4 - first_ol_blk_col, 2);
/* Check if new_row and new_col are evenly divisible by 4 (Q3),
* and if so we shouldn't check neighboring blocks
@@ -142,10 +143,12 @@ void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
if (new_col >= 0 && (new_col & 0x1F) == 0)
end_col = 1;
/* Avoid calculating overlap for blocks in the previous MB */
if (new_row < (first_ol_mb_row*16)<<3)
/* Check if the overlapping block partly overlaps a previous MB
* and if so, we're overlapping fewer blocks in this MB.
*/
if (new_row < (mb_row*16)<<3)
end_row = 1;
if (new_col < (first_ol_mb_col*16)<<3)
if (new_col < (mb_col*16)<<3)
end_col = 1;
for (row = 0; row < end_row; ++row)
@@ -154,9 +157,9 @@ void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
{
/* input in Q3, result in Q6 */
const int overlap = vp8_block_overlap(new_row, new_col,
(((first_ol_blk_row + row) *
(((first_blk_row + row) *
4) << 3),
(((first_ol_blk_col + col) *
(((first_blk_col + col) *
4) << 3));
vp8_assign_overlap(b_ol_ul[row * 4 + col].overlaps,
bmi,
@@ -166,11 +169,11 @@ void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
}
}
void vp8_calculate_overlaps_submb(MB_OVERLAP *overlap_ul,
int mb_rows, int mb_cols,
B_MODE_INFO *bmi,
MV_REFERENCE_FRAME ref_frame,
int b_row, int b_col)
void vp8_calculate_overlaps(MB_OVERLAP *overlap_ul,
int mb_rows, int mb_cols,
B_MODE_INFO *bmi,
MV_REFERENCE_FRAME ref_frame,
int b_row, int b_col)
{
MB_OVERLAP *mb_overlap;
int row, col, rel_row, rel_col;
@@ -365,6 +368,7 @@ void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
const unsigned int num_mbs = mb_rows * mb_cols;
int mb_row, mb_col;
vpx_memset(overlaps, 0, sizeof(MB_OVERLAP) * mb_rows * mb_cols);
/* First calculate the overlaps for all blocks */
for (mb_row = 0; mb_row < mb_rows; ++mb_row)
{
for (mb_col = 0; mb_col < mb_cols; ++mb_col)
@@ -375,7 +379,7 @@ void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
{
for (sub_col = 0; sub_col < 4; ++sub_col)
{
vp8_calculate_overlaps_submb(
vp8_calculate_overlaps(
overlaps, mb_rows, mb_cols,
&(prev_mi->bmi[sub_row * 4 + sub_col]),
prev_mi->mbmi.ref_frame,
@@ -391,6 +395,9 @@ void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
mb_row = first_corrupt / mb_cols;
mb_col = first_corrupt - mb_row * mb_cols;
mi += mb_row*(mb_cols + 1) + mb_col;
/* Go through all macroblocks in the current image with missing MVs
* and calculate new MVs using the overlaps.
*/
for (; mb_row < mb_rows; ++mb_row)
{
int mb_to_top_edge = -((mb_row * 16)) << 3;
@@ -412,9 +419,8 @@ void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
mb_to_right_edge,
mb_to_top_edge,
mb_to_bottom_edge);
mi->mbmi.mode = SPLITMV;
mi->mbmi.uv_mode = DC_PRED;
mi->mbmi.mb_skip_coeff = 0;
++mi;
}
mb_col = 0;
@@ -422,7 +428,7 @@ void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
}
}
void assign_neighbor(EC_BLOCK *neighbor, MODE_INFO *mi, int block_idx)
static void assign_neighbor(EC_BLOCK *neighbor, MODE_INFO *mi, int block_idx)
{
assert(mi->mbmi.ref_frame < MAX_REF_FRAMES);
neighbor->ref_frame = mi->mbmi.ref_frame;
@@ -492,18 +498,18 @@ void vp8_find_neighboring_blocks(MODE_INFO *mi,
MV_REFERENCE_FRAME vp8_dominant_ref_frame(EC_BLOCK *neighbors)
{
/* default to referring to "skip" */
/* Default to referring to "skip" */
MV_REFERENCE_FRAME dom_ref_frame = LAST_FRAME;
int max_ref_frame_cnt = 0;
int ref_frame_cnt[MAX_REF_FRAMES] = {0};
int i;
/* count neighboring reference frames */
/* Count neighboring reference frames */
for (i = 0; i < NUM_NEIGHBORS; ++i)
{
if (neighbors[i].ref_frame < MAX_REF_FRAMES)
++ref_frame_cnt[neighbors[i].ref_frame];
}
/* find maximum */
/* Find maximum */
for (i = 0; i < MAX_REF_FRAMES; ++i)
{
if (ref_frame_cnt[i] > max_ref_frame_cnt)
@@ -572,7 +578,7 @@ void vp8_interpolate_mvs(MACROBLOCKD *mb,
}
}
void vp8_interpolate_mv(MACROBLOCKD *mb,
void vp8_interpolate_motion(MACROBLOCKD *mb,
int mb_row, int mb_col,
int mb_rows, int mb_cols,
int mi_stride)
@@ -599,22 +605,7 @@ void vp8_interpolate_mv(MACROBLOCKD *mb,
vp8_interpolate_mvs(mb, neighbors, dom_ref_frame);
mb->mode_info_context->mbmi.ref_frame = dom_ref_frame;
mb->mode_info_context->mbmi.mode = SPLITMV;
mb->mode_info_context->mbmi.uv_mode = DC_PRED;
mb->mode_info_context->mbmi.mb_skip_coeff = 0;
}
void vp8_conceal_corrupt_block(MACROBLOCKD *xd)
{
/* this macroblock has corrupt residual, use the motion compensated
image for concealment */
int i;
for (i = 0; i < 16; i++)
vpx_memcpy(xd->dst.y_buffer + i * xd->dst.y_stride,
xd->predictor + i * 16, 16);
for (i = 0; i < 8; i++)
vpx_memcpy(xd->dst.u_buffer + i * xd->dst.uv_stride,
xd->predictor + 256 + i * 8, 8);
for (i = 0; i < 8; i++)
vpx_memcpy(xd->dst.v_buffer + i * xd->dst.uv_stride,
xd->predictor + 320 + i * 8, 8);
}

View File

@@ -13,57 +13,100 @@
#define ERROR_CONCEALMENT_H
#include "onyxd_int.h"
#include "ec_types.h"
typedef struct ec_block
{
MV mv;
MV_REFERENCE_FRAME ref_frame;
} EC_BLOCK;
/* Allocate memory for the overlap lists */
int vp8_alloc_overlap_lists(VP8D_COMP *pbi);
/* Deallocate the overlap lists */
void vp8_de_alloc_overlap_lists(VP8D_COMP *pbi);
/* Inserts a new overlap area value to the list of overlaps of a block */
void vp8_assign_overlap(OVERLAP_NODE* overlaps,
B_MODE_INFO *bmi,
MV_REFERENCE_FRAME ref_frame,
int overlap);
/* Calculates the overlap area between two 4x4 squares, where the first
* square has its upper-left corner at (b1_row, b1_col) and the second
* square has its upper-left corner at (b2_row, b2_col). Doesn't
* properly handle squares which doesn't overlap.
*/
int vp8_block_overlap(int b1_row, int b1_col, int b2_row, int b2_col);
/* Finds the reference frame type which has the largest overlapping area. */
MV_REFERENCE_FRAME vp8_largest_overlap_type(const B_OVERLAP *block_overlaps);
/* Calculates the overlap area for all blocks in a macroblock at position
* (mb_row, mb_col) in macroblocks, which are being overlapped by a given
* overlapping block at position (new_row, new_col) (in pixels, Q3). The
* first block being overlapped in the macroblock has position (first_blk_row,
* first_blk_col) in blocks relative the upper-left corner of the image.
*/
void vp8_calculate_overlaps_mb(B_OVERLAP *b_overlaps, B_MODE_INFO *bmi,
MV_REFERENCE_FRAME ref_frame,
int new_row, int new_col,
int first_ol_mb_row, int first_ol_mb_col,
int first_ol_blk_row, int first_ol_blk_col);
MV_REFERENCE_FRAME vp8_largest_overlap_type(const B_OVERLAP *block_overlaps);
int mb_row, int mb_col,
int first_blk_row, int first_blk_col);
/* Estimates a motion vector given the overlapping blocks' motion vectors.
* Filters out all overlapping blocks which doesn't refer to the correct
* reference frame type.
*/
void vp8_estimate_mv(const OVERLAP_NODE *overlaps, B_MODE_INFO *bmi,
MV_REFERENCE_FRAME type);
/* Estimates all motion vectors for a macroblock given the lists of
* overlaps for each block. Decides whether or not the MVs must be clamped.
*/
void vp8_estimate_mb_mvs(const B_OVERLAP *block_overlaps,
MODE_INFO *mi,
int mb_to_left_edge,
int mb_to_right_edge,
int mb_to_top_edge,
int mb_to_bottom_edge);
/* Estimate all missing motion vectors.
*/
void vp8_estimate_missing_mvs(VP8D_COMP *pbi);
/* Estimate all missing motion vectors */
void vp8_estimate_missing_mvs_ex(MB_OVERLAP *overlaps,
MODE_INFO *mi, MODE_INFO *prev_mi,
int mb_rows, int mb_cols,
unsigned int first_corrupt);
/* Functions for spatial MV interpolation */
/* Finds the neighboring blocks of a macroblocks. In the general case
* 20 blocks are found. If a fewer number of blocks are found due to
* image boundaries, those positions in the EC_BLOCK array are left "empty".
* The neighbors are enumerated with the upper-left neighbor as the first
* element, the second element refers to the neighbor to right of the previous
* neighbor, and so on. The last element refers to the neighbor below the first
* neighbor.
*/
void vp8_find_neighboring_blocks(MODE_INFO *mi,
EC_BLOCK *neighbors,
int mb_row, int mb_col,
int mb_rows, int mb_cols,
int mi_stride);
/* Calculates which reference frame type is dominating among the neighbors */
MV_REFERENCE_FRAME vp8_dominant_ref_frame(EC_BLOCK *neighbors);
/* Interpolates all motion vectors for a macroblock from the neighboring blocks'
* motion vectors.
*/
void vp8_interpolate_mvs(MACROBLOCKD *mb,
EC_BLOCK *neighbors,
MV_REFERENCE_FRAME dom_ref_frame);
void vp8_interpolate_mv(MACROBLOCKD *mb,
int mb_row, int mb_col,
int mb_rows, int mb_cols,
int mi_stride);
/* Function for concealing errors in an MB by copying the predictor signal */
void vp8_conceal_corrupt_block(MACROBLOCKD *);
/* Interpolates all motion vectors for a macroblock mb at position
* (mb_row, mb_col). */
void vp8_interpolate_motion(MACROBLOCKD *mb,
int mb_row, int mb_col,
int mb_rows, int mb_cols,
int mi_stride);
#endif

View File

@@ -17,25 +17,7 @@
#include "onyxc_int.h"
#include "threading.h"
#include "dequantize.h"
#define MAX_OVERLAPS 16
typedef struct overlap_node
{
int overlap;
B_MODE_INFO *bmi;
MV_REFERENCE_FRAME ref_frame;
} OVERLAP_NODE;
typedef struct
{
OVERLAP_NODE overlaps[MAX_OVERLAPS];
} B_OVERLAP;
typedef struct
{
B_OVERLAP overlaps[16];
} MB_OVERLAP;
#include "ec_types.h"
typedef struct
{