| 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 find_mv_refs_sync sync, void *const data) { |
| 21 const int *ref_sign_bias = cm->ref_frame_sign_bias; | 22 const int *ref_sign_bias = cm->ref_frame_sign_bias; |
| 22 int i, refmv_count = 0; | 23 int i, refmv_count = 0; |
| 23 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; | 24 const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; |
| 24 int different_ref_found = 0; | 25 int different_ref_found = 0; |
| 25 int context_counter = 0; | 26 int context_counter = 0; |
| 26 const MV_REF *const prev_frame_mvs = cm->use_prev_frame_mvs ? | 27 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; | 28 cm->prev_frame->mvs + mi_row * cm->mi_cols + mi_col : NULL; |
| 28 | 29 |
| 29 // Blank the reference vector list | 30 // Blank the reference vector list |
| 30 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); | 31 vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 61 xd->mi_stride].src_mi->mbmi; | 62 xd->mi_stride].src_mi->mbmi; |
| 62 different_ref_found = 1; | 63 different_ref_found = 1; |
| 63 | 64 |
| 64 if (candidate->ref_frame[0] == ref_frame) | 65 if (candidate->ref_frame[0] == ref_frame) |
| 65 ADD_MV_REF_LIST(candidate->mv[0], refmv_count, mv_ref_list, Done); | 66 ADD_MV_REF_LIST(candidate->mv[0], refmv_count, mv_ref_list, Done); |
| 66 else if (candidate->ref_frame[1] == ref_frame) | 67 else if (candidate->ref_frame[1] == ref_frame) |
| 67 ADD_MV_REF_LIST(candidate->mv[1], refmv_count, mv_ref_list, Done); | 68 ADD_MV_REF_LIST(candidate->mv[1], refmv_count, mv_ref_list, Done); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 | 71 |
| 72 // Synchronize here for frame parallel decode if sync function is provided. |
| 73 if (sync != NULL) { |
| 74 sync(data, mi_row); |
| 75 } |
| 76 |
| 71 // Check the last frame's mode and mv info. | 77 // Check the last frame's mode and mv info. |
| 72 if (cm->use_prev_frame_mvs) { | 78 if (cm->use_prev_frame_mvs) { |
| 73 if (prev_frame_mvs->ref_frame[0] == ref_frame) { | 79 if (prev_frame_mvs->ref_frame[0] == ref_frame) { |
| 74 ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, Done); | 80 ADD_MV_REF_LIST(prev_frame_mvs->mv[0], refmv_count, mv_ref_list, Done); |
| 75 } else if (prev_frame_mvs->ref_frame[1] == ref_frame) { | 81 } else if (prev_frame_mvs->ref_frame[1] == ref_frame) { |
| 76 ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, Done); | 82 ADD_MV_REF_LIST(prev_frame_mvs->mv[1], refmv_count, mv_ref_list, Done); |
| 77 } | 83 } |
| 78 } | 84 } |
| 79 | 85 |
| 80 // Since we couldn't find 2 mvs from the same reference frame | 86 // Since we couldn't find 2 mvs from the same reference frame |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 132 |
| 127 // Clamp vectors | 133 // Clamp vectors |
| 128 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) | 134 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) |
| 129 clamp_mv_ref(&mv_ref_list[i].as_mv, xd); | 135 clamp_mv_ref(&mv_ref_list[i].as_mv, xd); |
| 130 } | 136 } |
| 131 | 137 |
| 132 void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd, | 138 void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd, |
| 133 const TileInfo *const tile, | 139 const TileInfo *const tile, |
| 134 MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, | 140 MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, |
| 135 int_mv *mv_ref_list, | 141 int_mv *mv_ref_list, |
| 136 int mi_row, int mi_col) { | 142 int mi_row, int mi_col, |
| 143 find_mv_refs_sync sync, void *const data) { |
| 137 find_mv_refs_idx(cm, xd, tile, mi, ref_frame, mv_ref_list, -1, | 144 find_mv_refs_idx(cm, xd, tile, mi, ref_frame, mv_ref_list, -1, |
| 138 mi_row, mi_col); | 145 mi_row, mi_col, sync, data); |
| 139 } | 146 } |
| 140 | 147 |
| 141 static void lower_mv_precision(MV *mv, int allow_hp) { | 148 static void lower_mv_precision(MV *mv, int allow_hp) { |
| 142 const int use_hp = allow_hp && vp9_use_mv_hp(mv); | 149 const int use_hp = allow_hp && vp9_use_mv_hp(mv); |
| 143 if (!use_hp) { | 150 if (!use_hp) { |
| 144 if (mv->row & 1) | 151 if (mv->row & 1) |
| 145 mv->row += (mv->row > 0 ? -1 : 1); | 152 mv->row += (mv->row > 0 ? -1 : 1); |
| 146 if (mv->col & 1) | 153 if (mv->col & 1) |
| 147 mv->col += (mv->col > 0 ? -1 : 1); | 154 mv->col += (mv->col > 0 ? -1 : 1); |
| 148 } | 155 } |
| 149 } | 156 } |
| 150 | 157 |
| 151 void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp, | 158 void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp, |
| 152 int_mv *mvlist, int_mv *nearest, int_mv *near) { | 159 int_mv *mvlist, int_mv *nearest_mv, |
| 160 int_mv *near_mv) { |
| 153 int i; | 161 int i; |
| 154 // Make sure all the candidates are properly clamped etc | 162 // Make sure all the candidates are properly clamped etc |
| 155 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) { | 163 for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) { |
| 156 lower_mv_precision(&mvlist[i].as_mv, allow_hp); | 164 lower_mv_precision(&mvlist[i].as_mv, allow_hp); |
| 157 clamp_mv2(&mvlist[i].as_mv, xd); | 165 clamp_mv2(&mvlist[i].as_mv, xd); |
| 158 } | 166 } |
| 159 *nearest = mvlist[0]; | 167 *nearest_mv = mvlist[0]; |
| 160 *near = mvlist[1]; | 168 *near_mv = mvlist[1]; |
| 161 } | 169 } |
| 162 | 170 |
| 163 void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, | 171 void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 164 const TileInfo *const tile, | 172 const TileInfo *const tile, |
| 165 int block, int ref, int mi_row, int mi_col, | 173 int block, int ref, int mi_row, int mi_col, |
| 166 int_mv *nearest, int_mv *near) { | 174 int_mv *nearest_mv, int_mv *near_mv) { |
| 167 int_mv mv_list[MAX_MV_REF_CANDIDATES]; | 175 int_mv mv_list[MAX_MV_REF_CANDIDATES]; |
| 168 MODE_INFO *const mi = xd->mi[0].src_mi; | 176 MODE_INFO *const mi = xd->mi[0].src_mi; |
| 169 b_mode_info *bmi = mi->bmi; | 177 b_mode_info *bmi = mi->bmi; |
| 170 int n; | 178 int n; |
| 171 | 179 |
| 172 assert(MAX_MV_REF_CANDIDATES == 2); | 180 assert(MAX_MV_REF_CANDIDATES == 2); |
| 173 | 181 |
| 174 find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block, | 182 find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block, |
| 175 mi_row, mi_col); | 183 mi_row, mi_col, NULL, NULL); |
| 176 | 184 |
| 177 near->as_int = 0; | 185 near_mv->as_int = 0; |
| 178 switch (block) { | 186 switch (block) { |
| 179 case 0: | 187 case 0: |
| 180 nearest->as_int = mv_list[0].as_int; | 188 nearest_mv->as_int = mv_list[0].as_int; |
| 181 near->as_int = mv_list[1].as_int; | 189 near_mv->as_int = mv_list[1].as_int; |
| 182 break; | 190 break; |
| 183 case 1: | 191 case 1: |
| 184 case 2: | 192 case 2: |
| 185 nearest->as_int = bmi[0].as_mv[ref].as_int; | 193 nearest_mv->as_int = bmi[0].as_mv[ref].as_int; |
| 186 for (n = 0; n < MAX_MV_REF_CANDIDATES; ++n) | 194 for (n = 0; n < MAX_MV_REF_CANDIDATES; ++n) |
| 187 if (nearest->as_int != mv_list[n].as_int) { | 195 if (nearest_mv->as_int != mv_list[n].as_int) { |
| 188 near->as_int = mv_list[n].as_int; | 196 near_mv->as_int = mv_list[n].as_int; |
| 189 break; | 197 break; |
| 190 } | 198 } |
| 191 break; | 199 break; |
| 192 case 3: { | 200 case 3: { |
| 193 int_mv candidates[2 + MAX_MV_REF_CANDIDATES]; | 201 int_mv candidates[2 + MAX_MV_REF_CANDIDATES]; |
| 194 candidates[0] = bmi[1].as_mv[ref]; | 202 candidates[0] = bmi[1].as_mv[ref]; |
| 195 candidates[1] = bmi[0].as_mv[ref]; | 203 candidates[1] = bmi[0].as_mv[ref]; |
| 196 candidates[2] = mv_list[0]; | 204 candidates[2] = mv_list[0]; |
| 197 candidates[3] = mv_list[1]; | 205 candidates[3] = mv_list[1]; |
| 198 | 206 |
| 199 nearest->as_int = bmi[2].as_mv[ref].as_int; | 207 nearest_mv->as_int = bmi[2].as_mv[ref].as_int; |
| 200 for (n = 0; n < 2 + MAX_MV_REF_CANDIDATES; ++n) | 208 for (n = 0; n < 2 + MAX_MV_REF_CANDIDATES; ++n) |
| 201 if (nearest->as_int != candidates[n].as_int) { | 209 if (nearest_mv->as_int != candidates[n].as_int) { |
| 202 near->as_int = candidates[n].as_int; | 210 near_mv->as_int = candidates[n].as_int; |
| 203 break; | 211 break; |
| 204 } | 212 } |
| 205 break; | 213 break; |
| 206 } | 214 } |
| 207 default: | 215 default: |
| 208 assert("Invalid block index."); | 216 assert("Invalid block index."); |
| 209 } | 217 } |
| 210 } | 218 } |
| OLD | NEW |