| 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 | 23 const MODE_INFO *prev_mi = !cm->error_resilient_mode && cm->prev_mi |
| 24 ? cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col] | 24 ? cm->prev_mi[mi_row * xd->mi_stride + mi_col].src_mi |
| 25 : NULL; | 25 : NULL; |
| 26 const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->mbmi : NULL; | 26 const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->src_mi->mbmi : NULL; |
| 27 | 27 |
| 28 | 28 |
| 29 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; | 29 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; |
| 30 | 30 |
| 31 int different_ref_found = 0; | 31 int different_ref_found = 0; |
| 32 int context_counter = 0; | 32 int context_counter = 0; |
| 33 | 33 |
| 34 // Blank the reference vector list | 34 // Blank the reference vector list |
| 35 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); | 35 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); |
| 36 | 36 |
| 37 // The nearest 2 blocks are treated differently | 37 // The nearest 2 blocks are treated differently |
| 38 // if the size < 8x8 we get the mv from the bmi substructure, | 38 // if the size < 8x8 we get the mv from the bmi substructure, |
| 39 // and we also need to keep a mode count. | 39 // and we also need to keep a mode count. |
| 40 for (i = 0; i < 2; ++i) { | 40 for (i = 0; i < 2; ++i) { |
| 41 const POSITION *const mv_ref = &mv_ref_search[i]; | 41 const POSITION *const mv_ref = &mv_ref_search[i]; |
| 42 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 42 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 43 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * | 43 const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * |
| 44 xd->mi_stride]; | 44 xd->mi_stride].src_mi; |
| 45 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; | 45 const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; |
| 46 // Keep counts for entropy encoding. | 46 // Keep counts for entropy encoding. |
| 47 context_counter += mode_2_counter[candidate->mode]; | 47 context_counter += mode_2_counter[candidate->mode]; |
| 48 different_ref_found = 1; | 48 different_ref_found = 1; |
| 49 | 49 |
| 50 if (candidate->ref_frame[0] == ref_frame) | 50 if (candidate->ref_frame[0] == ref_frame) |
| 51 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block)); | 51 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block)); |
| 52 else if (candidate->ref_frame[1] == ref_frame) | 52 else if (candidate->ref_frame[1] == ref_frame) |
| 53 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block)); | 53 ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block)); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Check the rest of the neighbors in much the same way | 57 // Check the rest of the neighbors in much the same way |
| 58 // as before except we don't need to keep track of sub blocks or | 58 // as before except we don't need to keep track of sub blocks or |
| 59 // mode counts. | 59 // mode counts. |
| 60 for (; i < MVREF_NEIGHBOURS; ++i) { | 60 for (; i < MVREF_NEIGHBOURS; ++i) { |
| 61 const POSITION *const mv_ref = &mv_ref_search[i]; | 61 const POSITION *const mv_ref = &mv_ref_search[i]; |
| 62 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 62 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 63 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * | 63 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * |
| 64 xd->mi_stride]->mbmi; | 64 xd->mi_stride].src_mi->mbmi; |
| 65 different_ref_found = 1; | 65 different_ref_found = 1; |
| 66 | 66 |
| 67 if (candidate->ref_frame[0] == ref_frame) | 67 if (candidate->ref_frame[0] == ref_frame) |
| 68 ADD_MV_REF_LIST(candidate->mv[0]); | 68 ADD_MV_REF_LIST(candidate->mv[0]); |
| 69 else if (candidate->ref_frame[1] == ref_frame) | 69 else if (candidate->ref_frame[1] == ref_frame) |
| 70 ADD_MV_REF_LIST(candidate->mv[1]); | 70 ADD_MV_REF_LIST(candidate->mv[1]); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Check the last frame's mode and mv info. | 74 // Check the last frame's mode and mv info. |
| 75 if (prev_mbmi) { | 75 if (prev_mbmi) { |
| 76 if (prev_mbmi->ref_frame[0] == ref_frame) | 76 if (prev_mbmi->ref_frame[0] == ref_frame) |
| 77 ADD_MV_REF_LIST(prev_mbmi->mv[0]); | 77 ADD_MV_REF_LIST(prev_mbmi->mv[0]); |
| 78 else if (prev_mbmi->ref_frame[1] == ref_frame) | 78 else if (prev_mbmi->ref_frame[1] == ref_frame) |
| 79 ADD_MV_REF_LIST(prev_mbmi->mv[1]); | 79 ADD_MV_REF_LIST(prev_mbmi->mv[1]); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Since we couldn't find 2 mvs from the same reference frame | 82 // Since we couldn't find 2 mvs from the same reference frame |
| 83 // go back through the neighbors and find motion vectors from | 83 // go back through the neighbors and find motion vectors from |
| 84 // different reference frames. | 84 // different reference frames. |
| 85 if (different_ref_found) { | 85 if (different_ref_found) { |
| 86 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { | 86 for (i = 0; i < MVREF_NEIGHBOURS; ++i) { |
| 87 const POSITION *mv_ref = &mv_ref_search[i]; | 87 const POSITION *mv_ref = &mv_ref_search[i]; |
| 88 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { | 88 if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { |
| 89 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row | 89 const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row |
| 90 * xd->mi_stride]->mbmi; | 90 * xd->mi_stride].src_mi->mbmi; |
| 91 | 91 |
| 92 // If the candidate is INTRA we don't want to consider its mv. | 92 // If the candidate is INTRA we don't want to consider its mv. |
| 93 IF_DIFF_REF_FRAME_ADD_MV(candidate); | 93 IF_DIFF_REF_FRAME_ADD_MV(candidate); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Since we still don't have a candidate we'll try the last frame. | 98 // Since we still don't have a candidate we'll try the last frame. |
| 99 if (prev_mbmi) | 99 if (prev_mbmi) |
| 100 IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); | 100 IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 *nearest = mvlist[0]; | 139 *nearest = mvlist[0]; |
| 140 *near = mvlist[1]; | 140 *near = mvlist[1]; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, | 143 void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 144 const TileInfo *const tile, | 144 const TileInfo *const tile, |
| 145 int block, int ref, int mi_row, int mi_col, | 145 int block, int ref, int mi_row, int mi_col, |
| 146 int_mv *nearest, int_mv *near) { | 146 int_mv *nearest, int_mv *near) { |
| 147 int_mv mv_list[MAX_MV_REF_CANDIDATES]; | 147 int_mv mv_list[MAX_MV_REF_CANDIDATES]; |
| 148 MODE_INFO *const mi = xd->mi[0]; | 148 MODE_INFO *const mi = xd->mi[0].src_mi; |
| 149 b_mode_info *bmi = mi->bmi; | 149 b_mode_info *bmi = mi->bmi; |
| 150 int n; | 150 int n; |
| 151 | 151 |
| 152 assert(MAX_MV_REF_CANDIDATES == 2); | 152 assert(MAX_MV_REF_CANDIDATES == 2); |
| 153 | 153 |
| 154 find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block, | 154 find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block, |
| 155 mi_row, mi_col); | 155 mi_row, mi_col); |
| 156 | 156 |
| 157 near->as_int = 0; | 157 near->as_int = 0; |
| 158 switch (block) { | 158 switch (block) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 181 if (nearest->as_int != candidates[n].as_int) { | 181 if (nearest->as_int != candidates[n].as_int) { |
| 182 near->as_int = candidates[n].as_int; | 182 near->as_int = candidates[n].as_int; |
| 183 break; | 183 break; |
| 184 } | 184 } |
| 185 break; | 185 break; |
| 186 } | 186 } |
| 187 default: | 187 default: |
| 188 assert("Invalid block index."); | 188 assert("Invalid block index."); |
| 189 } | 189 } |
| 190 } | 190 } |
| OLD | NEW |