media/libvpx/vp9/common/vp9_alloccommon.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11
michael@0 12 #include "./vpx_config.h"
michael@0 13 #include "vpx_mem/vpx_mem.h"
michael@0 14
michael@0 15 #include "vp9/common/vp9_blockd.h"
michael@0 16 #include "vp9/common/vp9_entropymode.h"
michael@0 17 #include "vp9/common/vp9_entropymv.h"
michael@0 18 #include "vp9/common/vp9_findnearmv.h"
michael@0 19 #include "vp9/common/vp9_onyxc_int.h"
michael@0 20 #include "vp9/common/vp9_systemdependent.h"
michael@0 21
michael@0 22 void vp9_update_mode_info_border(VP9_COMMON *cm, MODE_INFO *mi) {
michael@0 23 const int stride = cm->mode_info_stride;
michael@0 24 int i;
michael@0 25
michael@0 26 // Clear down top border row
michael@0 27 vpx_memset(mi, 0, sizeof(MODE_INFO) * stride);
michael@0 28
michael@0 29 // Clear left border column
michael@0 30 for (i = 1; i < cm->mi_rows + 1; i++)
michael@0 31 vpx_memset(&mi[i * stride], 0, sizeof(MODE_INFO));
michael@0 32 }
michael@0 33
michael@0 34 void vp9_free_frame_buffers(VP9_COMMON *cm) {
michael@0 35 int i;
michael@0 36
michael@0 37 for (i = 0; i < NUM_YV12_BUFFERS; i++)
michael@0 38 vp9_free_frame_buffer(&cm->yv12_fb[i]);
michael@0 39
michael@0 40 vp9_free_frame_buffer(&cm->post_proc_buffer);
michael@0 41
michael@0 42 vpx_free(cm->mip);
michael@0 43 vpx_free(cm->prev_mip);
michael@0 44 vpx_free(cm->last_frame_seg_map);
michael@0 45 vpx_free(cm->mi_grid_base);
michael@0 46 vpx_free(cm->prev_mi_grid_base);
michael@0 47
michael@0 48 cm->mip = NULL;
michael@0 49 cm->prev_mip = NULL;
michael@0 50 cm->last_frame_seg_map = NULL;
michael@0 51 cm->mi_grid_base = NULL;
michael@0 52 cm->prev_mi_grid_base = NULL;
michael@0 53 }
michael@0 54
michael@0 55 static void set_mb_mi(VP9_COMMON *cm, int aligned_width, int aligned_height) {
michael@0 56 cm->mi_cols = aligned_width >> MI_SIZE_LOG2;
michael@0 57 cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
michael@0 58 cm->mode_info_stride = cm->mi_cols + MI_BLOCK_SIZE;
michael@0 59
michael@0 60 cm->mb_cols = (cm->mi_cols + 1) >> 1;
michael@0 61 cm->mb_rows = (cm->mi_rows + 1) >> 1;
michael@0 62 cm->MBs = cm->mb_rows * cm->mb_cols;
michael@0 63 }
michael@0 64
michael@0 65 static void setup_mi(VP9_COMMON *cm) {
michael@0 66 cm->mi = cm->mip + cm->mode_info_stride + 1;
michael@0 67 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1;
michael@0 68 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1;
michael@0 69 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1;
michael@0 70
michael@0 71 vpx_memset(cm->mip, 0,
michael@0 72 cm->mode_info_stride * (cm->mi_rows + 1) * sizeof(MODE_INFO));
michael@0 73
michael@0 74 vpx_memset(cm->mi_grid_base, 0,
michael@0 75 cm->mode_info_stride * (cm->mi_rows + 1) *
michael@0 76 sizeof(*cm->mi_grid_base));
michael@0 77
michael@0 78 vp9_update_mode_info_border(cm, cm->mip);
michael@0 79 vp9_update_mode_info_border(cm, cm->prev_mip);
michael@0 80 }
michael@0 81
michael@0 82 int vp9_resize_frame_buffers(VP9_COMMON *cm, int width, int height) {
michael@0 83 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
michael@0 84 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
michael@0 85 const int ss_x = cm->subsampling_x;
michael@0 86 const int ss_y = cm->subsampling_y;
michael@0 87 int mi_size;
michael@0 88
michael@0 89 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
michael@0 90 VP9BORDERINPIXELS) < 0)
michael@0 91 goto fail;
michael@0 92
michael@0 93 set_mb_mi(cm, aligned_width, aligned_height);
michael@0 94
michael@0 95 // Allocation
michael@0 96 mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE);
michael@0 97
michael@0 98 vpx_free(cm->mip);
michael@0 99 cm->mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
michael@0 100 if (!cm->mip)
michael@0 101 goto fail;
michael@0 102
michael@0 103 vpx_free(cm->prev_mip);
michael@0 104 cm->prev_mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
michael@0 105 if (!cm->prev_mip)
michael@0 106 goto fail;
michael@0 107
michael@0 108 vpx_free(cm->mi_grid_base);
michael@0 109 cm->mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
michael@0 110 if (!cm->mi_grid_base)
michael@0 111 goto fail;
michael@0 112
michael@0 113 vpx_free(cm->prev_mi_grid_base);
michael@0 114 cm->prev_mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
michael@0 115 if (!cm->prev_mi_grid_base)
michael@0 116 goto fail;
michael@0 117
michael@0 118 setup_mi(cm);
michael@0 119
michael@0 120 // Create the segmentation map structure and set to 0.
michael@0 121 vpx_free(cm->last_frame_seg_map);
michael@0 122 cm->last_frame_seg_map = vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
michael@0 123 if (!cm->last_frame_seg_map)
michael@0 124 goto fail;
michael@0 125
michael@0 126 return 0;
michael@0 127
michael@0 128 fail:
michael@0 129 vp9_free_frame_buffers(cm);
michael@0 130 return 1;
michael@0 131 }
michael@0 132
michael@0 133 int vp9_alloc_frame_buffers(VP9_COMMON *cm, int width, int height) {
michael@0 134 int i;
michael@0 135
michael@0 136 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
michael@0 137 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
michael@0 138 const int ss_x = cm->subsampling_x;
michael@0 139 const int ss_y = cm->subsampling_y;
michael@0 140 int mi_size;
michael@0 141
michael@0 142 vp9_free_frame_buffers(cm);
michael@0 143
michael@0 144 for (i = 0; i < NUM_YV12_BUFFERS; i++) {
michael@0 145 cm->fb_idx_ref_cnt[i] = 0;
michael@0 146 if (vp9_alloc_frame_buffer(&cm->yv12_fb[i], width, height, ss_x, ss_y,
michael@0 147 VP9BORDERINPIXELS) < 0)
michael@0 148 goto fail;
michael@0 149 }
michael@0 150
michael@0 151 cm->new_fb_idx = NUM_YV12_BUFFERS - 1;
michael@0 152 cm->fb_idx_ref_cnt[cm->new_fb_idx] = 1;
michael@0 153
michael@0 154 for (i = 0; i < ALLOWED_REFS_PER_FRAME; i++)
michael@0 155 cm->active_ref_idx[i] = i;
michael@0 156
michael@0 157 for (i = 0; i < NUM_REF_FRAMES; i++) {
michael@0 158 cm->ref_frame_map[i] = i;
michael@0 159 cm->fb_idx_ref_cnt[i] = 1;
michael@0 160 }
michael@0 161
michael@0 162 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
michael@0 163 VP9BORDERINPIXELS) < 0)
michael@0 164 goto fail;
michael@0 165
michael@0 166 set_mb_mi(cm, aligned_width, aligned_height);
michael@0 167
michael@0 168 // Allocation
michael@0 169 mi_size = cm->mode_info_stride * (cm->mi_rows + MI_BLOCK_SIZE);
michael@0 170
michael@0 171 cm->mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
michael@0 172 if (!cm->mip)
michael@0 173 goto fail;
michael@0 174
michael@0 175 cm->prev_mip = vpx_calloc(mi_size, sizeof(MODE_INFO));
michael@0 176 if (!cm->prev_mip)
michael@0 177 goto fail;
michael@0 178
michael@0 179 cm->mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->mi_grid_base));
michael@0 180 if (!cm->mi_grid_base)
michael@0 181 goto fail;
michael@0 182
michael@0 183 cm->prev_mi_grid_base = vpx_calloc(mi_size, sizeof(*cm->prev_mi_grid_base));
michael@0 184 if (!cm->prev_mi_grid_base)
michael@0 185 goto fail;
michael@0 186
michael@0 187 setup_mi(cm);
michael@0 188
michael@0 189 // Create the segmentation map structure and set to 0.
michael@0 190 cm->last_frame_seg_map = vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
michael@0 191 if (!cm->last_frame_seg_map)
michael@0 192 goto fail;
michael@0 193
michael@0 194 return 0;
michael@0 195
michael@0 196 fail:
michael@0 197 vp9_free_frame_buffers(cm);
michael@0 198 return 1;
michael@0 199 }
michael@0 200
michael@0 201 void vp9_create_common(VP9_COMMON *cm) {
michael@0 202 vp9_machine_specific_config(cm);
michael@0 203
michael@0 204 cm->tx_mode = ONLY_4X4;
michael@0 205 cm->comp_pred_mode = HYBRID_PREDICTION;
michael@0 206 }
michael@0 207
michael@0 208 void vp9_remove_common(VP9_COMMON *cm) {
michael@0 209 vp9_free_frame_buffers(cm);
michael@0 210 }
michael@0 211
michael@0 212 void vp9_initialize_common() {
michael@0 213 vp9_init_neighbors();
michael@0 214 vp9_coef_tree_initialize();
michael@0 215 vp9_entropy_mode_init();
michael@0 216 vp9_entropy_mv_init();
michael@0 217 }
michael@0 218
michael@0 219 void vp9_update_frame_size(VP9_COMMON *cm) {
michael@0 220 const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, MI_SIZE_LOG2);
michael@0 221 const int aligned_height = ALIGN_POWER_OF_TWO(cm->height, MI_SIZE_LOG2);
michael@0 222
michael@0 223 set_mb_mi(cm, aligned_width, aligned_height);
michael@0 224 setup_mi(cm);
michael@0 225
michael@0 226 // Initialize the previous frame segment map to 0.
michael@0 227 if (cm->last_frame_seg_map)
michael@0 228 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols);
michael@0 229 }

mercurial