| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license | 5 * Use of this source code is governed by a BSD-style license |
| 6 * that can be found in the LICENSE file in the root of the source | 6 * that can be found in the LICENSE file in the root of the source |
| 7 * tree. An additional intellectual property rights grant can be found | 7 * tree. An additional intellectual property rights grant can be found |
| 8 * in the file PATENTS. All contributing project authors may | 8 * in the file PATENTS. All contributing project authors may |
| 9 * be found in the AUTHORS file in the root of the source tree. | 9 * be found in the AUTHORS file in the root of the source tree. |
| 10 */ | 10 */ |
| 11 | 11 |
| 12 #include "vp9/common/vp9_mvref_common.h" | 12 #include "vp9/common/vp9_mvref_common.h" |
| 13 | 13 |
| 14 // This function searches the neighbourhood of a given MB/SB | 14 // This function searches the neighbourhood of a given MB/SB |
| 15 // to try and find candidate reference vectors. | 15 // to try and find candidate reference vectors. |
| 16 static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, | 16 static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, |
| 17 const TileInfo *const tile, | 17 const TileInfo *const tile, |
| 18 MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, | 18 MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, |
| 19 int_mv *mv_ref_list, | 19 int_mv *mv_ref_list, |
| 20 int block, int mi_row, int mi_col) { | 20 int block, int mi_row, int mi_col) { |
| 21 const int *ref_sign_bias = cm->ref_frame_sign_bias; | 21 const int *ref_sign_bias = cm->ref_frame_sign_bias; |
| 22 int i, refmv_count = 0; | 22 int i, refmv_count = 0; |
| 23 const MODE_INFO *prev_mi = !cm->error_resilient_mode && cm->prev_mi | |
| 24 ? cm->prev_mi[mi_row * xd->mi_stride + mi_col].src_mi | |
| 25 : NULL; | |
| 26 const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->src_mi->mbmi : NULL; | |
| 27 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; | 23 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; |
| 28 int different_ref_found = 0; | 24 int different_ref_found = 0; |
| 29 int context_counter = 0; | 25 int context_counter = 0; |
| 26 const MV_REF *const prev_frame_mvs = cm->use_prev_frame_mvs ? |
| 27 cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col : NULL; |
| 30 | 28 |
| 31 // Blank the reference vector list | 29 // Blank the reference vector list |
| 32 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); | 30 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); |
| 33 | 31 |
| 34 // The nearest 2 blocks are treated differently | 32 // The nearest 2 blocks are treated differently |
| 35 // if the size < 8x8 we get the mv from the bmi substructure, | 33 // if the size < 8x8 we get the mv from the bmi substructure, |
| 36 // and we also need to keep a mode count. | 34 // and we also need to keep a mode count. |
| 37 for (i = 0; i < 2; ++i) { | 35 for (i = 0; i < 2; ++i) { |
| 38 const POSITION *const mv_ref = &mv_ref_search[i]; | 36 const POSITION *const mv_ref = &mv_ref_search[i]; |
| 39 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 37 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 40 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * | 38 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * |
| 41 xd->mi_stride].src_mi; | 39 xd->mi_stride].src_mi; |
| 42 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; | 40 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
| 43 // Keep counts for entropy encoding. | 41 // Keep counts for entropy encoding. |
| 44 context_counter += mode_2_counter[candidate->mode]; | 42 context_counter += mode_2_counter[candidate->mode]; |
| 45 different_ref_found = 1; | 43 different_ref_found = 1; |
| 46 | 44 |
| 47 if (candidate->ref_frame[0] == ref_frame) | 45 if (candidate->ref_frame[0] == ref_frame) |
| 48 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block)); | 46 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block), |
| 47 refmv_count, mv_ref_list, Done); |
| 49 else if (candidate->ref_frame[1] == ref_frame) | 48 else if (candidate->ref_frame[1] == ref_frame) |
| 50 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block)); | 49 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block), |
| 50 refmv_count, mv_ref_list, Done); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Check the rest of the neighbors in much the same way | 54 // Check the rest of the neighbors in much the same way |
| 55 // as before except we don't need to keep track of sub blocks or | 55 // as before except we don't need to keep track of sub blocks or |
| 56 // mode counts. | 56 // mode counts. |
| 57 for (; i < MVREF_NEIGHBOURS; ++i) { | 57 for (; i < MVREF_NEIGHBOURS; ++i) { |
| 58 const POSITION *const mv_ref = &mv_ref_search[i]; | 58 const POSITION *const mv_ref = &mv_ref_search[i]; |
| 59 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 59 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 60 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * | 60 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * |
| 61 xd->mi_stride].src_mi->mbmi; | 61 xd->mi_stride].src_mi->mbmi; |
| 62 different_ref_found = 1; | 62 different_ref_found = 1; |
| 63 | 63 |
| 64 if (candidate->ref_frame[0] == ref_frame) | 64 if (candidate->ref_frame[0] == ref_frame) |
| 65 ADD_MV_REF_LIST(candidate->mv[0]); | 65 ADD_MV_REF_LIST(candidate->mv[0], refmv_count, mv_ref_list, Done); |
| 66 else if (candidate->ref_frame[1] == ref_frame) | 66 else if (candidate->ref_frame[1] == ref_frame) |
| 67 ADD_MV_REF_LIST(candidate->mv[1]); | 67 ADD_MV_REF_LIST(candidate->mv[1], refmv_count, mv_ref_list, Done); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Check the last frame's mode and mv info. | 71 // Check the last frame's mode and mv info. |
| 72 if (prev_mbmi) { | 72 if (cm->use_prev_frame_mvs) { |
| 73 if (prev_mbmi->ref_frame[0] == ref_frame) | 73 if (prev_frame_mvs->ref_frame[0] == ref_frame) { |
| 74 ADD_MV_REF_LIST(prev_mbmi->mv[0]); | 74 ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, Done); |
| 75 else if (prev_mbmi->ref_frame[1] == ref_frame) | 75 } else if (prev_frame_mvs->ref_frame[1] == ref_frame) { |
| 76 ADD_MV_REF_LIST(prev_mbmi->mv[1]); | 76 ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, Done); |
| 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 // Since we couldn't find 2 mvs from the same reference frame | 80 // Since we couldn't find 2 mvs from the same reference frame |
| 80 // go back through the neighbors and find motion vectors from | 81 // go back through the neighbors and find motion vectors from |
| 81 // different reference frames. | 82 // different reference frames. |
| 82 if (different_ref_found) { | 83 if (different_ref_found) { |
| 83 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { | 84 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { |
| 84 const POSITION *mv_ref = &mv_ref_search[i]; | 85 const POSITION *mv_ref = &mv_ref_search[i]; |
| 85 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 86 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 86 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row | 87 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row |
| 87 * xd->mi_stride].src_mi->mbmi; | 88 * xd->mi_stride].src_mi->mbmi; |
| 88 | 89 |
| 89 // If the candidate is INTRA we don't want to consider its mv. | 90 // If the candidate is INTRA we don't want to consider its mv. |
| 90 IF_DIFF_REF_FRAME_ADD_MV(candidate); | 91 IF_DIFF_REF_FRAME_ADD_MV(candidate, ref_frame, ref_sign_bias, |
| 92 refmv_count, mv_ref_list, Done); |
| 91 } | 93 } |
| 92 } | 94 } |
| 93 } | 95 } |
| 94 | 96 |
| 95 // Since we still don't have a candidate we'll try the last frame. | 97 // Since we still don't have a candidate we'll try the last frame. |
| 96 if (prev_mbmi) | 98 if (cm->use_prev_frame_mvs) { |
| 97 IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); | 99 if (prev_frame_mvs->ref_frame[0] != ref_frame && |
| 100 prev_frame_mvs->ref_frame[0] > INTRA_FRAME) { |
| 101 int_mv mv = prev_frame_mvs->mv[0]; |
| 102 if (ref_sign_bias[prev_frame_mvs->ref_frame[0]] != |
| 103 ref_sign_bias[ref_frame]) { |
| 104 mv.as_mv.row *= -1; |
| 105 mv.as_mv.col *= -1; |
| 106 } |
| 107 ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done); |
| 108 } |
| 109 |
| 110 if (prev_frame_mvs->ref_frame[1] > INTRA_FRAME && |
| 111 prev_frame_mvs->ref_frame[1] != ref_frame && |
| 112 prev_frame_mvs->mv[1].as_int != prev_frame_mvs->mv[0].as_int) { |
| 113 int_mv mv = prev_frame_mvs->mv[1]; |
| 114 if (ref_sign_bias[prev_frame_mvs->ref_frame[1]] != |
| 115 ref_sign_bias[ref_frame]) { |
| 116 mv.as_mv.row *= -1; |
| 117 mv.as_mv.col *= -1; |
| 118 } |
| 119 ADD_MV_REF_LIST(mv, refmv_count, mv_ref_list, Done); |
| 120 } |
| 121 } |
| 98 | 122 |
| 99 Done: | 123 Done: |
| 100 | 124 |
| 101 mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; | 125 mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; |
| 102 | 126 |
| 103 // Clamp vectors | 127 // Clamp vectors |
| 104 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) | 128 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) |
| 105 clamp_mv_ref(&mv_ref_list[i].as_mv, xd); | 129 clamp_mv_ref(&mv_ref_list[i].as_mv, xd); |
| 106 } | 130 } |
| 107 | 131 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 if (nearest->as_int != candidates[n].as_int) { | 201 if (nearest->as_int != candidates[n].as_int) { |
| 178 near->as_int = candidates[n].as_int; | 202 near->as_int = candidates[n].as_int; |
| 179 break; | 203 break; |
| 180 } | 204 } |
| 181 break; | 205 break; |
| 182 } | 206 } |
| 183 default: | 207 default: |
| 184 assert("Invalid block index."); | 208 assert("Invalid block index."); |
| 185 } | 209 } |
| 186 } | 210 } |
| OLD | NEW |