// This function searches the neighbourhood of a given MB/SB // to try and find candidate reference vectors. static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int block, int mi_row, int mi_col) { const int *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0; const MODE_INFO *prev_mi = cm->prev_mi ? cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col] : NULL; const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->mbmi : NULL; const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; int different_ref_found = 0; int context_counter = 0; // Blank the reference vector list vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); // The nearest 2 blocks are treated differently // if the size < 8x8 we get the mv from the bmi substructure, // and we also need to keep a mode count. for (i = 0; i < 2; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]; const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; // Keep counts for entropy encoding. context_counter += mode_2_counter[candidate->mode]; different_ref_found = 1; if (candidate->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block)); else if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block)); } } // Check the rest of the neighbors in much the same way // as before except we don't need to keep track of sub blocks or // mode counts. for (; i < MVREF_NEIGHBOURS; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; different_ref_found = 1; if (candidate->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(candidate->mv[0]); else if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(candidate->mv[1]); } } // Check the last frame's mode and mv info. if (prev_mbmi) { if (prev_mbmi->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[0]); else if (prev_mbmi->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[1]); } // Since we couldn't find 2 mvs from the same reference frame // go back through the neighbors and find motion vectors from // different reference frames. if (different_ref_found) { for (i = 0; i < MVREF_NEIGHBOURS; ++i) { const POSITION *mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; // If the candidate is INTRA we don't want to consider its mv. IF_DIFF_REF_FRAME_ADD_MV(candidate); } } } // Since we still don't have a candidate we'll try the last frame. if (prev_mbmi) IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); Done: mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; // Clamp vectors for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) clamp_mv_ref(&mv_ref_list[i].as_mv, xd); }
// This function searches the neighbourhood of a given MB/SB // to try and find candidate reference vectors. static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int block, int mi_row, int mi_col, find_mv_refs_sync sync, void *const data) { const int *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0; const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; int different_ref_found = 0; int context_counter = 0; const MV_REF *const prev_frame_mvs = cm->use_prev_frame_mvs ? cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col : NULL; // Blank the reference vector list memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); // The nearest 2 blocks are treated differently // if the size < 8x8 we get the mv from the bmi substructure, // and we also need to keep a mode count. for (i = 0; i < 2; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]; const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; // Keep counts for entropy encoding. context_counter += mode_2_counter[candidate->mode]; different_ref_found = 1; if (candidate->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block), refmv_count, mv_ref_list, Done); else if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block), refmv_count, mv_ref_list, Done); } } // Check the rest of the neighbors in much the same way // as before except we don't need to keep track of sub blocks or // mode counts. for (; i < MVREF_NEIGHBOURS; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; different_ref_found = 1; if (candidate->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(candidate->mv[0], refmv_count, mv_ref_list, Done); else if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(candidate->mv[1], refmv_count, mv_ref_list, Done); } } // TODO(hkuang): Remove this sync after fixing pthread_cond_broadcast // on windows platform. The sync here is unncessary if use_perv_frame_mvs // is 0. But after removing it, there will be hang in the unit test on windows // due to several threads waiting for a thread's signal. #if defined(_WIN32) && !HAVE_PTHREAD_H if (cm->frame_parallel_decode && sync != NULL) { sync(data, mi_row); } #endif // Check the last frame's mode and mv info. if (cm->use_prev_frame_mvs) { // Synchronize here for frame parallel decode if sync function is provided. if (cm->frame_parallel_decode && sync != NULL) { sync(data, mi_row); } if (prev_frame_mvs->ref_frame[0] == ref_frame) { ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, Done); } else if (prev_frame_mvs->ref_frame[1] == ref_frame) { ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, Done); } } // Since we couldn't find 2 mvs from the same reference frame // go back through the neighbors and find motion vectors from // different reference frames. if (different_ref_found) { for (i = 0; i < MVREF_NEIGHBOURS; ++i) { const POSITION *mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; // If the candidate is INTRA we don't want to consider its mv. IF_DIFF_REF_FRAME_ADD_MV(candidate, ref_frame, ref_sign_bias, refmv_count, mv_ref_list, Done); } } } // Since we still don't have a candidate we'll try the last frame. if (cm->use_prev_frame_mvs) { if (prev_frame_mvs->ref_frame[0] != ref_frame && prev_frame_mvs->ref_frame[0] > INTRA_FRAME) { int_mv mv = prev_frame_mvs->mv[0]; if (ref_sign_bias[prev_frame_mvs->ref_frame[0]] != ref_sign_bias[ref_frame]) { mv.as_mv.row *= -1; mv.as_mv.col *= -1; } ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done); } if (prev_frame_mvs->ref_frame[1] > INTRA_FRAME && prev_frame_mvs->ref_frame[1] != ref_frame && prev_frame_mvs->mv[1].as_int != prev_frame_mvs->mv[0].as_int) { int_mv mv = prev_frame_mvs->mv[1]; if (ref_sign_bias[prev_frame_mvs->ref_frame[1]] != ref_sign_bias[ref_frame]) { mv.as_mv.row *= -1; mv.as_mv.col *= -1; } ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done); } } Done: mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; // Clamp vectors for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) clamp_mv_ref(&mv_ref_list[i].as_mv, xd); }
void vp9_find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, MODE_INFO *mi, const MODE_INFO *prev_mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int block_idx, int mi_row, int mi_col) { const int *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0; const MV *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->mbmi : NULL; int different_ref_found = 0; int context_counter = 0; vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); for (i = 0; i < 2; ++i) { const MV *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi = xd->mi_8x8[mv_ref->col + mv_ref->row * xd->mode_info_stride]; const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; context_counter += mode_2_counter[candidate->mode]; if (candidate->ref_frame[0] == ref_frame) { ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block_idx)); different_ref_found = candidate->ref_frame[1] != ref_frame; } else { if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block_idx)); different_ref_found = 1; } } } for (; i < MVREF_NEIGHBOURS; ++i) { const MV *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi_8x8[mv_ref->col + mv_ref->row * xd->mode_info_stride]->mbmi; if (candidate->ref_frame[0] == ref_frame) { ADD_MV_REF_LIST(candidate->mv[0]); different_ref_found = candidate->ref_frame[1] != ref_frame; } else { if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(candidate->mv[1]); different_ref_found = 1; } } } if (prev_mbmi) { if (prev_mbmi->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[0]); else if (prev_mbmi->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[1]); } if (different_ref_found) { for (i = 0; i < MVREF_NEIGHBOURS; ++i) { const MV *mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi_8x8[mv_ref->col + mv_ref->row * xd->mode_info_stride]->mbmi; if (is_inter_block(candidate)) IF_DIFF_REF_FRAME_ADD_MV(candidate); } } } if (prev_mbmi && is_inter_block(prev_mbmi)) IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); Done: mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) clamp_mv_ref(&mv_ref_list[i].as_mv, xd); }
static uint8_t add_ref_mv_candidate(const MACROBLOCKD *xd, const MODE_INFO *const candidate_mi, const MB_MODE_INFO *const candidate, const MV_REFERENCE_FRAME rf[2], uint8_t *refmv_count, CANDIDATE_MV *ref_mv_stack, const int use_hp, int len, int block, int col) { int index = 0, ref; int newmv_count = 0; if (rf[1] == NONE) { // single reference frame for (ref = 0; ref < 2; ++ref) { if (candidate->ref_frame[ref] == rf[0]) { int_mv this_refmv = get_sub_block_mv(candidate_mi, ref, col, block); lower_mv_precision(&this_refmv.as_mv, use_hp); clamp_mv_ref(&this_refmv.as_mv, xd->n8_w << 3, xd->n8_h << 3, xd); for (index = 0; index < *refmv_count; ++index) if (ref_mv_stack[index].this_mv.as_int == this_refmv.as_int) break; if (index < *refmv_count) ref_mv_stack[index].weight += 2 * len; // Add a new item to the list. if (index == *refmv_count) { ref_mv_stack[index].this_mv = this_refmv; ref_mv_stack[index].pred_mv = get_sub_block_pred_mv(candidate_mi, ref, col, block); ref_mv_stack[index].weight = 2 * len; ++(*refmv_count); if (candidate->mode == NEWMV) ++newmv_count; } if (candidate_mi->mbmi.sb_type < BLOCK_8X8 && block >= 0) { int alt_block = 3 - block; this_refmv = get_sub_block_mv(candidate_mi, ref, col, alt_block); lower_mv_precision(&this_refmv.as_mv, use_hp); clamp_mv_ref(&this_refmv.as_mv, xd->n8_w << 3, xd->n8_h << 3, xd); for (index = 0; index < *refmv_count; ++index) if (ref_mv_stack[index].this_mv.as_int == this_refmv.as_int) break; if (index < *refmv_count) ref_mv_stack[index].weight += len; // Add a new item to the list. if (index == *refmv_count) { ref_mv_stack[index].this_mv = this_refmv; ref_mv_stack[index].pred_mv = get_sub_block_pred_mv(candidate_mi, ref, col, alt_block); ref_mv_stack[index].weight = len; ++(*refmv_count); if (candidate->mode == NEWMV) ++newmv_count; } } } } } else { // compound reference frame if (candidate->ref_frame[0] == rf[0] && candidate->ref_frame[1] == rf[1]) { int_mv this_refmv[2] = { get_sub_block_mv(candidate_mi, 0, col, block), get_sub_block_mv(candidate_mi, 1, col, block) }; for (ref = 0; ref < 2; ++ref) { lower_mv_precision(&this_refmv[ref].as_mv, use_hp); clamp_mv_ref(&this_refmv[ref].as_mv, xd->n8_w << 3, xd->n8_h << 3, xd); } for (index = 0; index < *refmv_count; ++index) if ((ref_mv_stack[index].this_mv.as_int == this_refmv[0].as_int) && (ref_mv_stack[index].comp_mv.as_int == this_refmv[1].as_int)) break; if (index < *refmv_count) ref_mv_stack[index].weight += 2 * len; // Add a new item to the list. if (index == *refmv_count) { ref_mv_stack[index].this_mv = this_refmv[0]; ref_mv_stack[index].comp_mv = this_refmv[1]; ref_mv_stack[index].weight = 2 * len; ++(*refmv_count); if (candidate->mode == NEWMV) ++newmv_count; } if (candidate_mi->mbmi.sb_type < BLOCK_8X8 && block >= 0) { int alt_block = 3 - block; this_refmv[0] = get_sub_block_mv(candidate_mi, 0, col, alt_block); this_refmv[1] = get_sub_block_mv(candidate_mi, 1, col, alt_block); for (ref = 0; ref < 2; ++ref) { lower_mv_precision(&this_refmv[ref].as_mv, use_hp); clamp_mv_ref(&this_refmv[ref].as_mv, xd->n8_w << 3, xd->n8_h << 3, xd); } for (index = 0; index < *refmv_count; ++index) if (ref_mv_stack[index].this_mv.as_int == this_refmv[0].as_int && ref_mv_stack[index].comp_mv.as_int == this_refmv[1].as_int) break; if (index < *refmv_count) ref_mv_stack[index].weight += len; // Add a new item to the list. if (index == *refmv_count) { ref_mv_stack[index].this_mv = this_refmv[0]; ref_mv_stack[index].comp_mv = this_refmv[1]; ref_mv_stack[index].weight = len; ++(*refmv_count); if (candidate->mode == NEWMV) ++newmv_count; } } } } return newmv_count; }