| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 vpx_memset(mi, 0, sizeof(MODE_INFO) * stride); | 27 vpx_memset(mi, 0, sizeof(MODE_INFO) * stride); |
| 28 | 28 |
| 29 // Clear left border column | 29 // Clear left border column |
| 30 for (i = 1; i < cm->mi_rows + 1; i++) | 30 for (i = 1; i < cm->mi_rows + 1; i++) |
| 31 vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO)); | 31 vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void vp9_free_frame_buffers(VP9_COMMON *cm) { | 34 void vp9_free_frame_buffers(VP9_COMMON *cm) { |
| 35 int i; | 35 int i; |
| 36 | 36 |
| 37 for (i = 0; i < NUM_YV12_BUFFERS; i++) | 37 for (i = 0; i < cm->fb_count; i++) |
| 38 vp9_free_frame_buffer(&cm->yv12_fb[i]); | 38 vp9_free_frame_buffer(&cm->yv12_fb[i]); |
| 39 | 39 |
| 40 vp9_free_frame_buffer(&cm->post_proc_buffer); | 40 vp9_free_frame_buffer(&cm->post_proc_buffer); |
| 41 | 41 |
| 42 vpx_free(cm->mip); | 42 vpx_free(cm->mip); |
| 43 vpx_free(cm->prev_mip); | 43 vpx_free(cm->prev_mip); |
| 44 vpx_free(cm->last_frame_seg_map); | 44 vpx_free(cm->last_frame_seg_map); |
| 45 vpx_free(cm->mi_grid_base); | 45 vpx_free(cm->mi_grid_base); |
| 46 vpx_free(cm->prev_mi_grid_base); | 46 vpx_free(cm->prev_mi_grid_base); |
| 47 | 47 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 68 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1; | 68 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1; |
| 69 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1; | 69 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1; |
| 70 | 70 |
| 71 vpx_memset(cm->mip, 0, | 71 vpx_memset(cm->mip, 0, |
| 72 cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO)); | 72 cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO)); |
| 73 | 73 |
| 74 vpx_memset(cm->mi_grid_base, 0, | 74 vpx_memset(cm->mi_grid_base, 0, |
| 75 cm->mode_info_stride * (cm->mi_rows + 1) * | 75 cm->mode_info_stride * (cm->mi_rows + 1) * |
| 76 sizeof(*cm->mi_grid_base)); | 76 sizeof(*cm->mi_grid_base)); |
| 77 | 77 |
| 78 vp9_update_mode_info_border(cm, cm->mip); | |
| 79 vp9_update_mode_info_border(cm, cm->prev_mip); | 78 vp9_update_mode_info_border(cm, cm->prev_mip); |
| 80 } | 79 } |
| 81 | 80 |
| 81 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) { |
| 82 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); |
| 83 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); |
| 84 const int ss_x = cm->subsampling_x; |
| 85 const int ss_y = cm->subsampling_y; |
| 86 int mi_size; |
| 87 |
| 88 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, |
| 89 VP9BORDERINPIXELS, NULL, NULL, NULL) < 0) |
| 90 goto fail; |
| 91 |
| 92 set_mb_mi(cm, aligned_width, aligned_height); |
| 93 |
| 94 // Allocation |
| 95 mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE); |
| 96 |
| 97 vpx_free(cm->mip); |
| 98 cm->mip = vpx_calloc(mi_size, sizeof(MODE_INFO)); |
| 99 if (!cm->mip) |
| 100 goto fail; |
| 101 |
| 102 vpx_free(cm->prev_mip); |
| 103 cm->prev_mip = vpx_calloc(mi_size, sizeof(MODE_INFO)); |
| 104 if (!cm->prev_mip) |
| 105 goto fail; |
| 106 |
| 107 vpx_free(cm->mi_grid_base); |
| 108 cm->mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->mi_grid_base)); |
| 109 if (!cm->mi_grid_base) |
| 110 goto fail; |
| 111 |
| 112 vpx_free(cm->prev_mi_grid_base); |
| 113 cm->prev_mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base)); |
| 114 if (!cm->prev_mi_grid_base) |
| 115 goto fail; |
| 116 |
| 117 setup_mi(cm); |
| 118 |
| 119 // Create the segmentation map structure and set to 0. |
| 120 vpx_free(cm->last_frame_seg_map); |
| 121 cm->last_frame_seg_map = vpx_calloc(cm->mi_rows * cm->mi_cols, 1); |
| 122 if (!cm->last_frame_seg_map) |
| 123 goto fail; |
| 124 |
| 125 return 0; |
| 126 |
| 127 fail: |
| 128 vp9_free_frame_buffers(cm); |
| 129 return 1; |
| 130 } |
| 131 |
| 82 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { | 132 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) { |
| 83 int i; | 133 int i; |
| 84 | 134 |
| 85 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); | 135 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); |
| 86 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); | 136 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); |
| 87 const int ss_x = cm->subsampling_x; | 137 const int ss_x = cm->subsampling_x; |
| 88 const int ss_y = cm->subsampling_y; | 138 const int ss_y = cm->subsampling_y; |
| 89 int mi_size; | 139 int mi_size; |
| 90 | 140 |
| 141 if (cm->fb_count == 0) { |
| 142 cm->fb_count = FRAME_BUFFERS; |
| 143 CHECK_MEM_ERROR(cm, cm->yv12_fb, |
| 144 vpx_calloc(cm->fb_count, sizeof(*cm->yv12_fb))); |
| 145 CHECK_MEM_ERROR(cm, cm->fb_idx_ref_cnt, |
| 146 vpx_calloc(cm->fb_count, sizeof(*cm->fb_idx_ref_cnt))); |
| 147 if (cm->fb_lru) { |
| 148 CHECK_MEM_ERROR(cm, cm->fb_idx_ref_lru, |
| 149 vpx_calloc(cm->fb_count, sizeof(*cm->fb_idx_ref_lru))); |
| 150 } |
| 151 } |
| 152 |
| 91 vp9_free_frame_buffers(cm); | 153 vp9_free_frame_buffers(cm); |
| 92 | 154 |
| 93 for (i = 0; i < NUM_YV12_BUFFERS; i++) { | 155 for (i = 0; i < cm->fb_count; i++) { |
| 94 cm->fb_idx_ref_cnt[i] = 0; | 156 cm->fb_idx_ref_cnt[i] = 0; |
| 95 if (vp9_alloc_frame_buffer(&cm->yv12_fb[i], width, height, ss_x, ss_y, | 157 if (vp9_alloc_frame_buffer(&cm->yv12_fb[i], width, height, ss_x, ss_y, |
| 96 VP9BORDERINPIXELS) < 0) | 158 VP9BORDERINPIXELS) < 0) |
| 97 goto fail; | 159 goto fail; |
| 98 } | 160 } |
| 99 | 161 |
| 100 cm->new_fb_idx = NUM_YV12_BUFFERS - 1; | 162 cm->new_fb_idx = cm->fb_count - 1; |
| 101 cm->fb_idx_ref_cnt[cm->new_fb_idx] = 1; | 163 cm->fb_idx_ref_cnt[cm->new_fb_idx] = 1; |
| 102 | 164 |
| 103 for (i = 0; i < ALLOWED_REFS_PER_FRAME; i++) | 165 for (i = 0; i < REFS_PER_FRAME; i++) |
| 104 cm->active_ref_idx[i] = i; | 166 cm->active_ref_idx[i] = i; |
| 105 | 167 |
| 106 for (i = 0; i < NUM_REF_FRAMES; i++) { | 168 for (i = 0; i < REF_FRAMES; i++) { |
| 107 cm->ref_frame_map[i] = i; | 169 cm->ref_frame_map[i] = i; |
| 108 cm->fb_idx_ref_cnt[i] = 1; | 170 cm->fb_idx_ref_cnt[i] = 1; |
| 109 } | 171 } |
| 110 | 172 |
| 111 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, | 173 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, |
| 112 VP9BORDERINPIXELS) < 0) | 174 VP9BORDERINPIXELS) < 0) |
| 113 goto fail; | 175 goto fail; |
| 114 | 176 |
| 115 set_mb_mi(cm, aligned_width, aligned_height); | 177 set_mb_mi(cm, aligned_width, aligned_height); |
| 116 | 178 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 142 | 204 |
| 143 return 0; | 205 return 0; |
| 144 | 206 |
| 145 fail: | 207 fail: |
| 146 vp9_free_frame_buffers(cm); | 208 vp9_free_frame_buffers(cm); |
| 147 return 1; | 209 return 1; |
| 148 } | 210 } |
| 149 | 211 |
| 150 void vp9_create_common(VP9_COMMON *cm) { | 212 void vp9_create_common(VP9_COMMON *cm) { |
| 151 vp9_machine_specific_config(cm); | 213 vp9_machine_specific_config(cm); |
| 152 | |
| 153 cm->tx_mode = ONLY_4X4; | |
| 154 cm->comp_pred_mode = HYBRID_PREDICTION; | |
| 155 } | 214 } |
| 156 | 215 |
| 157 void vp9_remove_common(VP9_COMMON *cm) { | 216 void vp9_remove_common(VP9_COMMON *cm) { |
| 158 vp9_free_frame_buffers(cm); | 217 vp9_free_frame_buffers(cm); |
| 218 |
| 219 vpx_free(cm->yv12_fb); |
| 220 vpx_free(cm->fb_idx_ref_cnt); |
| 221 vpx_free(cm->fb_idx_ref_lru); |
| 222 |
| 223 cm->yv12_fb = NULL; |
| 224 cm->fb_idx_ref_cnt = NULL; |
| 225 cm->fb_idx_ref_lru = NULL; |
| 159 } | 226 } |
| 160 | 227 |
| 161 void vp9_initialize_common() { | 228 void vp9_initialize_common() { |
| 162 vp9_init_neighbors(); | 229 vp9_init_neighbors(); |
| 163 vp9_coef_tree_initialize(); | |
| 164 vp9_entropy_mode_init(); | |
| 165 vp9_entropy_mv_init(); | |
| 166 } | 230 } |
| 167 | 231 |
| 168 void vp9_update_frame_size(VP9_COMMON *cm) { | 232 void vp9_update_frame_size(VP9_COMMON *cm) { |
| 169 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2); | 233 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2); |
| 170 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2); | 234 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2); |
| 171 | 235 |
| 172 set_mb_mi(cm, aligned_width, aligned_height); | 236 set_mb_mi(cm, aligned_width, aligned_height); |
| 173 setup_mi(cm); | 237 setup_mi(cm); |
| 174 | 238 |
| 175 // Initialize the previous frame segment map to 0. | 239 // Initialize the previous frame segment map to 0. |
| 176 if (cm->last_frame_seg_map) | 240 if (cm->last_frame_seg_map) |
| 177 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); | 241 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); |
| 178 } | 242 } |
| OLD | NEW |