Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 2 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 3 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 4 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 5 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 6 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 7 | * was not distributed with this source code in the LICENSE file, you can |
| 8 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 9 | * Media Patent License 1.0 was not distributed with this source code in the |
| 10 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 13 | #include "./aom_config.h" |
| 14 | #include "aom_mem/aom_mem.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 15 | |
| 16 | #include "av1/common/alloccommon.h" |
| 17 | #include "av1/common/blockd.h" |
| 18 | #include "av1/common/entropymode.h" |
| 19 | #include "av1/common/entropymv.h" |
| 20 | #include "av1/common/onyxc_int.h" |
| 21 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 22 | int av1_get_MBs(int width, int height) { |
| 23 | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
| 24 | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
| 25 | const int mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 26 | const int mi_rows = aligned_height >> MI_SIZE_LOG2; |
| 27 | |
| 28 | #if CONFIG_CB4X4 |
| 29 | const int mb_cols = (mi_cols + 2) >> 2; |
| 30 | const int mb_rows = (mi_rows + 2) >> 2; |
| 31 | #else |
| 32 | const int mb_cols = (mi_cols + 1) >> 1; |
| 33 | const int mb_rows = (mi_rows + 1) >> 1; |
| 34 | #endif |
| 35 | return mb_rows * mb_cols; |
| 36 | } |
| 37 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 38 | void av1_set_mb_mi(AV1_COMMON *cm, int width, int height) { |
David Barker | ee0fd92 | 2017-09-07 15:18:35 +0100 | [diff] [blame] | 39 | // Ensure that the decoded width and height are both multiples of |
| 40 | // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if |
| 41 | // subsampling is used). |
| 42 | // This simplifies the implementation of various experiments, |
| 43 | // eg. cdef, which operates on units of 8x8 luma pixels. |
Jingning Han | 944b805 | 2017-03-31 08:57:30 -0700 | [diff] [blame] | 44 | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
| 45 | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | |
| 47 | cm->mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 48 | cm->mi_rows = aligned_height >> MI_SIZE_LOG2; |
| 49 | cm->mi_stride = calc_mi_size(cm->mi_cols); |
| 50 | |
Jingning Han | 91ad0e8 | 2016-12-07 17:59:32 -0800 | [diff] [blame] | 51 | #if CONFIG_CB4X4 |
| 52 | cm->mb_cols = (cm->mi_cols + 2) >> 2; |
| 53 | cm->mb_rows = (cm->mi_rows + 2) >> 2; |
| 54 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | cm->mb_cols = (cm->mi_cols + 1) >> 1; |
| 56 | cm->mb_rows = (cm->mi_rows + 1) >> 1; |
Jingning Han | 91ad0e8 | 2016-12-07 17:59:32 -0800 | [diff] [blame] | 57 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | cm->MBs = cm->mb_rows * cm->mb_cols; |
| 59 | } |
| 60 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 61 | static int alloc_seg_map(AV1_COMMON *cm, int seg_map_size) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 62 | int i; |
| 63 | |
| 64 | for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | cm->seg_map_array[i] = (uint8_t *)aom_calloc(seg_map_size, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 66 | if (cm->seg_map_array[i] == NULL) return 1; |
| 67 | } |
| 68 | cm->seg_map_alloc_size = seg_map_size; |
| 69 | |
| 70 | // Init the index. |
| 71 | cm->seg_map_idx = 0; |
| 72 | cm->prev_seg_map_idx = 1; |
| 73 | |
| 74 | cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; |
| 75 | if (!cm->frame_parallel_decode) |
| 76 | cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | static void free_seg_map(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 82 | int i; |
| 83 | |
| 84 | for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 85 | aom_free(cm->seg_map_array[i]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 86 | cm->seg_map_array[i] = NULL; |
| 87 | } |
| 88 | |
| 89 | cm->current_frame_seg_map = NULL; |
| 90 | |
| 91 | if (!cm->frame_parallel_decode) { |
| 92 | cm->last_frame_seg_map = NULL; |
| 93 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 94 | cm->seg_map_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Debargha Mukherjee | 5d108a3 | 2017-10-05 19:47:08 -0700 | [diff] [blame] | 97 | static void free_scratch_buffers(AV1_COMMON *cm) { |
| 98 | (void)cm; |
| 99 | #if CONFIG_NCOBMC && CONFIG_NCOBMC_ADAPT_WEIGHT |
| 100 | for (int i = 0; i < 4; ++i) { |
| 101 | if (cm->ncobmcaw_buf[i]) { |
| 102 | aom_free(cm->ncobmcaw_buf[i]); |
| 103 | cm->ncobmcaw_buf[i] = NULL; |
| 104 | } |
| 105 | } |
| 106 | #endif // CONFIG_NCOBMC && CONFIG_NCOBMC_ADAPT_WEIGHT |
| 107 | } |
| 108 | |
| 109 | static int alloc_scratch_buffers(AV1_COMMON *cm) { |
| 110 | (void)cm; |
| 111 | #if CONFIG_NCOBMC && CONFIG_NCOBMC_ADAPT_WEIGHT |
| 112 | // If not allocated already, allocate |
| 113 | if (!cm->ncobmcaw_buf[0] && !cm->ncobmcaw_buf[1] && !cm->ncobmcaw_buf[2] && |
| 114 | !cm->ncobmcaw_buf[3]) { |
| 115 | for (int i = 0; i < 4; ++i) { |
| 116 | CHECK_MEM_ERROR( |
| 117 | cm, cm->ncobmcaw_buf[i], |
| 118 | (uint8_t *)aom_memalign( |
| 119 | 16, (1 + CONFIG_HIGHBITDEPTH) * MAX_MB_PLANE * MAX_SB_SQUARE)); |
| 120 | } |
| 121 | } |
| 122 | #endif // CONFIG_NCOBMC && CONFIG_NCOBMC_ADAPT_WEIGHT |
| 123 | return 0; |
| 124 | } |
| 125 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 126 | void av1_free_ref_frame_buffers(BufferPool *pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 127 | int i; |
| 128 | |
| 129 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 130 | if (pool->frame_bufs[i].ref_count > 0 && |
| 131 | pool->frame_bufs[i].raw_frame_buffer.data != NULL) { |
| 132 | pool->release_fb_cb(pool->cb_priv, &pool->frame_bufs[i].raw_frame_buffer); |
| 133 | pool->frame_bufs[i].ref_count = 0; |
| 134 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 135 | aom_free(pool->frame_bufs[i].mvs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 136 | pool->frame_bufs[i].mvs = NULL; |
Jingning Han | ffbb0f9 | 2017-08-24 11:52:21 -0700 | [diff] [blame] | 137 | #if CONFIG_MFMV |
| 138 | aom_free(pool->frame_bufs[i].tpl_mvs); |
| 139 | pool->frame_bufs[i].tpl_mvs = NULL; |
| 140 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 141 | aom_free_frame_buffer(&pool->frame_bufs[i].buf); |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 142 | #if CONFIG_HASH_ME |
| 143 | av1_hash_table_destroy(&pool->frame_bufs[i].hash_table); |
| 144 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | #if CONFIG_LOOP_RESTORATION |
Debargha Mukherjee | 1008c1e | 2017-03-06 19:18:43 -0800 | [diff] [blame] | 149 | // Assumes cm->rst_info[p].restoration_tilesize is already initialized |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 150 | void av1_alloc_restoration_buffers(AV1_COMMON *cm) { |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 151 | int p; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 152 | #if CONFIG_FRAME_SUPERRES |
| 153 | int width = cm->superres_upscaled_width; |
| 154 | int height = cm->superres_upscaled_height; |
| 155 | #else |
| 156 | int width = cm->width; |
| 157 | int height = cm->height; |
| 158 | #endif // CONFIG_FRAME_SUPERRES |
| 159 | av1_alloc_restoration_struct(cm, &cm->rst_info[0], width, height); |
Debargha Mukherjee | d748914 | 2017-01-05 13:58:16 -0800 | [diff] [blame] | 160 | for (p = 1; p < MAX_MB_PLANE; ++p) |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 161 | av1_alloc_restoration_struct(cm, &cm->rst_info[p], |
| 162 | ROUND_POWER_OF_TWO(width, cm->subsampling_x), |
| 163 | ROUND_POWER_OF_TWO(height, cm->subsampling_y)); |
Alex Converse | 7f094f1 | 2017-02-23 17:29:40 -0800 | [diff] [blame] | 164 | aom_free(cm->rst_internal.tmpbuf); |
| 165 | CHECK_MEM_ERROR(cm, cm->rst_internal.tmpbuf, |
Yaowu Xu | bcf25cd | 2017-03-10 10:27:22 -0800 | [diff] [blame] | 166 | (int32_t *)aom_memalign(16, RESTORATION_TMPBUF_SIZE)); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 167 | |
| 168 | #if CONFIG_STRIPED_LOOP_RESTORATION |
| 169 | // Allocate internal storage for the loop restoration stripe boundary lines |
| 170 | for (p = 0; p < MAX_MB_PLANE; ++p) { |
| 171 | int w = p == 0 ? width : ROUND_POWER_OF_TWO(width, cm->subsampling_x); |
| 172 | int align_bits = 5; // align for efficiency |
| 173 | int stride = ALIGN_POWER_OF_TWO(w, align_bits); |
| 174 | int num_stripes = (height + 63) / 64; |
| 175 | // for each processing stripe: 2 lines above, 2 below |
| 176 | int buf_size = num_stripes * 2 * stride; |
| 177 | uint8_t *above_buf, *below_buf; |
| 178 | |
| 179 | aom_free(cm->rst_internal.stripe_boundary_above[p]); |
| 180 | aom_free(cm->rst_internal.stripe_boundary_below[p]); |
| 181 | |
| 182 | #if CONFIG_HIGHBITDEPTH |
| 183 | if (cm->use_highbitdepth) buf_size = buf_size * 2; |
| 184 | #endif |
| 185 | CHECK_MEM_ERROR(cm, above_buf, |
| 186 | (uint8_t *)aom_memalign(1 << align_bits, buf_size)); |
| 187 | CHECK_MEM_ERROR(cm, below_buf, |
| 188 | (uint8_t *)aom_memalign(1 << align_bits, buf_size)); |
| 189 | cm->rst_internal.stripe_boundary_above[p] = above_buf; |
| 190 | cm->rst_internal.stripe_boundary_below[p] = below_buf; |
| 191 | cm->rst_internal.stripe_boundary_stride[p] = stride; |
| 192 | } |
| 193 | #endif // CONFIG_STRIPED_LOOP_RESTORATION |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 196 | void av1_free_restoration_buffers(AV1_COMMON *cm) { |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 197 | int p; |
| 198 | for (p = 0; p < MAX_MB_PLANE; ++p) |
| 199 | av1_free_restoration_struct(&cm->rst_info[p]); |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 200 | aom_free(cm->rst_internal.tmpbuf); |
| 201 | cm->rst_internal.tmpbuf = NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 202 | } |
| 203 | #endif // CONFIG_LOOP_RESTORATION |
| 204 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 205 | void av1_free_context_buffers(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 206 | int i; |
| 207 | cm->free_mi(cm); |
| 208 | free_seg_map(cm); |
Debargha Mukherjee | 5d108a3 | 2017-10-05 19:47:08 -0700 | [diff] [blame] | 209 | free_scratch_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 210 | for (i = 0; i < MAX_MB_PLANE; i++) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 211 | aom_free(cm->above_context[i]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 212 | cm->above_context[i] = NULL; |
| 213 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 214 | aom_free(cm->above_seg_context); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 215 | cm->above_seg_context = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 216 | cm->above_context_alloc_cols = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 217 | #if CONFIG_VAR_TX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 218 | aom_free(cm->above_txfm_context); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | cm->above_txfm_context = NULL; |
Jingning Han | 6e4955d | 2017-05-30 22:54:48 -0700 | [diff] [blame] | 220 | |
| 221 | for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 222 | aom_free(cm->top_txfm_context[i]); |
| 223 | cm->top_txfm_context[i] = NULL; |
| 224 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 225 | #endif |
| 226 | } |
| 227 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 228 | int av1_alloc_context_buffers(AV1_COMMON *cm, int width, int height) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 229 | int new_mi_size; |
| 230 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 231 | av1_set_mb_mi(cm, width, height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 232 | new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
| 233 | if (cm->mi_alloc_size < new_mi_size) { |
| 234 | cm->free_mi(cm); |
| 235 | if (cm->alloc_mi(cm, new_mi_size)) goto fail; |
| 236 | } |
| 237 | |
| 238 | if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) { |
| 239 | // Create the segmentation map structure and set to 0. |
| 240 | free_seg_map(cm); |
| 241 | if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) goto fail; |
| 242 | } |
Debargha Mukherjee | 5d108a3 | 2017-10-05 19:47:08 -0700 | [diff] [blame] | 243 | if (alloc_scratch_buffers(cm)) goto fail; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 244 | |
| 245 | if (cm->above_context_alloc_cols < cm->mi_cols) { |
| 246 | // TODO(geza.lore): These are bigger than they need to be. |
| 247 | // cm->tile_width would be enough but it complicates indexing a |
| 248 | // little elsewhere. |
| 249 | const int aligned_mi_cols = |
| 250 | ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 251 | int i; |
| 252 | |
| 253 | for (i = 0; i < MAX_MB_PLANE; i++) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 254 | aom_free(cm->above_context[i]); |
| 255 | cm->above_context[i] = (ENTROPY_CONTEXT *)aom_calloc( |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 256 | aligned_mi_cols << (MI_SIZE_LOG2 - tx_size_wide_log2[0]), |
| 257 | sizeof(*cm->above_context[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | if (!cm->above_context[i]) goto fail; |
| 259 | } |
| 260 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 261 | aom_free(cm->above_seg_context); |
| 262 | cm->above_seg_context = (PARTITION_CONTEXT *)aom_calloc( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | aligned_mi_cols, sizeof(*cm->above_seg_context)); |
| 264 | if (!cm->above_seg_context) goto fail; |
| 265 | |
| 266 | #if CONFIG_VAR_TX |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 267 | aom_free(cm->above_txfm_context); |
| 268 | cm->above_txfm_context = (TXFM_CONTEXT *)aom_calloc( |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 269 | aligned_mi_cols << TX_UNIT_WIDE_LOG2, sizeof(*cm->above_txfm_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 270 | if (!cm->above_txfm_context) goto fail; |
Jingning Han | 6e4955d | 2017-05-30 22:54:48 -0700 | [diff] [blame] | 271 | |
| 272 | for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 273 | aom_free(cm->top_txfm_context[i]); |
| 274 | cm->top_txfm_context[i] = |
| 275 | (TXFM_CONTEXT *)aom_calloc(aligned_mi_cols << TX_UNIT_WIDE_LOG2, |
| 276 | sizeof(*cm->top_txfm_context[0])); |
| 277 | if (!cm->top_txfm_context[i]) goto fail; |
| 278 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | #endif |
| 280 | |
| 281 | cm->above_context_alloc_cols = aligned_mi_cols; |
| 282 | } |
| 283 | |
| 284 | return 0; |
| 285 | |
| 286 | fail: |
| 287 | // clear the mi_* values to force a realloc on resync |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 288 | av1_set_mb_mi(cm, 0, 0); |
| 289 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | return 1; |
| 291 | } |
| 292 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 293 | void av1_remove_common(AV1_COMMON *cm) { |
| 294 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 295 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 296 | aom_free(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 297 | cm->fc = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 298 | aom_free(cm->frame_contexts); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 299 | cm->frame_contexts = NULL; |
| 300 | } |
| 301 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 302 | void av1_init_context_buffers(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 303 | cm->setup_mi(cm); |
| 304 | if (cm->last_frame_seg_map && !cm->frame_parallel_decode) |
| 305 | memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); |
| 306 | } |
| 307 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 308 | void av1_swap_current_and_last_seg_map(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | // Swap indices. |
| 310 | const int tmp = cm->seg_map_idx; |
| 311 | cm->seg_map_idx = cm->prev_seg_map_idx; |
| 312 | cm->prev_seg_map_idx = tmp; |
| 313 | |
| 314 | cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; |
| 315 | cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; |
| 316 | } |