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 | |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 28 | const int mb_cols = (mi_cols + 2) >> 2; |
| 29 | const int mb_rows = (mi_rows + 2) >> 2; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 30 | return mb_rows * mb_cols; |
| 31 | } |
| 32 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 33 | void av1_set_mb_mi(AV1_COMMON *cm, int width, int height) { |
David Barker | ee0fd92 | 2017-09-07 15:18:35 +0100 | [diff] [blame] | 34 | // Ensure that the decoded width and height are both multiples of |
| 35 | // 8 luma pixels (note: this may only be a multiple of 4 chroma pixels if |
| 36 | // subsampling is used). |
| 37 | // This simplifies the implementation of various experiments, |
| 38 | // eg. cdef, which operates on units of 8x8 luma pixels. |
Jingning Han | 944b805 | 2017-03-31 08:57:30 -0700 | [diff] [blame] | 39 | const int aligned_width = ALIGN_POWER_OF_TWO(width, 3); |
| 40 | const int aligned_height = ALIGN_POWER_OF_TWO(height, 3); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 41 | |
| 42 | cm->mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 43 | cm->mi_rows = aligned_height >> MI_SIZE_LOG2; |
| 44 | cm->mi_stride = calc_mi_size(cm->mi_cols); |
| 45 | |
Jingning Han | 91ad0e8 | 2016-12-07 17:59:32 -0800 | [diff] [blame] | 46 | cm->mb_cols = (cm->mi_cols + 2) >> 2; |
| 47 | cm->mb_rows = (cm->mi_rows + 2) >> 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 48 | cm->MBs = cm->mb_rows * cm->mb_cols; |
| 49 | } |
| 50 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 51 | #if !CONFIG_SEGMENT_PRED_LAST |
Rostislav Pehlivanov | f624dd5 | 2017-10-24 16:46:09 +0100 | [diff] [blame] | 52 | static int alloc_seg_map(AV1_COMMON *cm, int rows, int cols) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | int i; |
Rostislav Pehlivanov | f624dd5 | 2017-10-24 16:46:09 +0100 | [diff] [blame] | 54 | int seg_map_size = rows * cols; |
| 55 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 56 | for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 57 | 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] | 58 | if (cm->seg_map_array[i] == NULL) return 1; |
| 59 | } |
| 60 | cm->seg_map_alloc_size = seg_map_size; |
| 61 | |
| 62 | // Init the index. |
| 63 | cm->seg_map_idx = 0; |
| 64 | cm->prev_seg_map_idx = 1; |
| 65 | |
| 66 | cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; |
| 67 | if (!cm->frame_parallel_decode) |
| 68 | cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | static void free_seg_map(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | int i; |
| 75 | |
| 76 | for (i = 0; i < NUM_PING_PONG_BUFFERS; ++i) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 77 | aom_free(cm->seg_map_array[i]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | cm->seg_map_array[i] = NULL; |
| 79 | } |
| 80 | |
| 81 | cm->current_frame_seg_map = NULL; |
| 82 | |
| 83 | if (!cm->frame_parallel_decode) { |
| 84 | cm->last_frame_seg_map = NULL; |
| 85 | } |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 86 | cm->seg_map_alloc_size = 0; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | } |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 88 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 90 | void av1_free_ref_frame_buffers(BufferPool *pool) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 91 | int i; |
| 92 | |
| 93 | for (i = 0; i < FRAME_BUFFERS; ++i) { |
| 94 | if (pool->frame_bufs[i].ref_count > 0 && |
| 95 | pool->frame_bufs[i].raw_frame_buffer.data != NULL) { |
| 96 | pool->release_fb_cb(pool->cb_priv, &pool->frame_bufs[i].raw_frame_buffer); |
| 97 | pool->frame_bufs[i].ref_count = 0; |
| 98 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 99 | aom_free(pool->frame_bufs[i].mvs); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 100 | pool->frame_bufs[i].mvs = NULL; |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 101 | #if CONFIG_SEGMENT_PRED_LAST |
| 102 | aom_free(pool->frame_bufs[i].seg_map); |
| 103 | pool->frame_bufs[i].seg_map = NULL; |
| 104 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 105 | aom_free_frame_buffer(&pool->frame_bufs[i].buf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | #if CONFIG_LOOP_RESTORATION |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 110 | // Assumes cm->rst_info[p].restoration_unit_size is already initialized |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 111 | void av1_alloc_restoration_buffers(AV1_COMMON *cm) { |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 112 | for (int p = 0; p < MAX_MB_PLANE; ++p) |
| 113 | av1_alloc_restoration_struct(cm, &cm->rst_info[p], p > 0); |
| 114 | aom_free(cm->rst_tmpbuf); |
| 115 | CHECK_MEM_ERROR(cm, cm->rst_tmpbuf, |
| 116 | (int32_t *)aom_memalign(16, RESTORATION_TMPBUF_SIZE)); |
| 117 | |
| 118 | #if CONFIG_STRIPED_LOOP_RESTORATION |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 119 | // For striped loop restoration, we divide each row of tiles into "stripes", |
| 120 | // of height 64 luma pixels but with an offset by RESTORATION_TILE_OFFSET |
| 121 | // luma pixels to match the output from CDEF. We will need to store 2 * |
| 122 | // RESTORATION_CTX_VERT lines of data for each stripe, and also need to be |
| 123 | // able to quickly answer the question "Where is the <n>'th stripe for tile |
| 124 | // row <m>?" To make that efficient, we generate the rst_last_stripe array. |
| 125 | int num_stripes = 0; |
| 126 | for (int i = 0; i < cm->tile_rows; ++i) { |
| 127 | #if CONFIG_MAX_TILE |
Dominic Symes | 917d6c0 | 2017-10-11 18:00:52 +0200 | [diff] [blame] | 128 | TileInfo tile_info; |
| 129 | av1_tile_set_row(&tile_info, cm, i); |
| 130 | const int mi_h = tile_info.mi_row_end - tile_info.mi_row_start; |
Fergus Simpson | 9cd57cf | 2017-06-12 17:02:03 -0700 | [diff] [blame] | 131 | #else |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 132 | const int mi_h = ((i + 1) < cm->tile_rows) |
| 133 | ? cm->tile_height |
| 134 | : (cm->mi_rows - i * cm->tile_height); |
| 135 | #endif |
| 136 | const int ext_h = RESTORATION_TILE_OFFSET + (mi_h << MI_SIZE_LOG2); |
| 137 | const int tile_stripes = (ext_h + 63) / 64; |
| 138 | num_stripes += tile_stripes; |
| 139 | cm->rst_end_stripe[i] = num_stripes; |
| 140 | } |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 141 | |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 142 | // Now we need to allocate enough space to store the line buffers for the |
| 143 | // stripes |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 144 | #if CONFIG_HORZONLY_FRAME_SUPERRES |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 145 | const int frame_w = cm->superres_upscaled_width; |
| 146 | #else |
| 147 | const int frame_w = cm->width; |
Urvang Joshi | 94ad370 | 2017-12-06 11:38:08 -0800 | [diff] [blame] | 148 | #endif // CONFIG_HORZONLY_FRAME_SUPERRES |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 149 | #if CONFIG_HIGHBITDEPTH |
| 150 | const int use_highbd = cm->use_highbitdepth ? 1 : 0; |
| 151 | #else |
| 152 | const int use_highbd = 0; |
| 153 | #endif |
Rupert Swarbrick | bcb65fe | 2017-10-25 17:15:28 +0100 | [diff] [blame] | 154 | for (int p = 0; p < MAX_MB_PLANE; ++p) { |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 155 | const int is_uv = p > 0; |
| 156 | const int ss_x = is_uv && cm->subsampling_x; |
Rupert Swarbrick | efa76d7 | 2017-11-06 17:13:46 +0000 | [diff] [blame] | 157 | const int plane_w = ((frame_w + ss_x) >> ss_x) + 2 * RESTORATION_EXTRA_HORZ; |
Yaowu Xu | a967ebb | 2017-12-14 14:25:05 -0800 | [diff] [blame] | 158 | const int stride = ALIGN_POWER_OF_TWO(plane_w, 5); |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 159 | const int buf_size = num_stripes * stride * RESTORATION_CTX_VERT |
| 160 | << use_highbd; |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 161 | RestorationStripeBoundaries *boundaries = &cm->rst_info[p].boundaries; |
| 162 | aom_free(boundaries->stripe_boundary_above); |
| 163 | aom_free(boundaries->stripe_boundary_below); |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 164 | |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 165 | CHECK_MEM_ERROR(cm, boundaries->stripe_boundary_above, |
Yaowu Xu | a967ebb | 2017-12-14 14:25:05 -0800 | [diff] [blame] | 166 | (uint8_t *)aom_memalign(32, buf_size)); |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 167 | CHECK_MEM_ERROR(cm, boundaries->stripe_boundary_below, |
Yaowu Xu | a967ebb | 2017-12-14 14:25:05 -0800 | [diff] [blame] | 168 | (uint8_t *)aom_memalign(32, buf_size)); |
Rupert Swarbrick | dee00eb | 2017-11-02 17:24:37 +0000 | [diff] [blame] | 169 | |
Rupert Swarbrick | dd6f09a | 2017-10-19 16:10:23 +0100 | [diff] [blame] | 170 | boundaries->stripe_boundary_stride = stride; |
Ola Hugosson | 1e7f2d0 | 2017-09-22 21:36:26 +0200 | [diff] [blame] | 171 | } |
| 172 | #endif // CONFIG_STRIPED_LOOP_RESTORATION |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 175 | void av1_free_restoration_buffers(AV1_COMMON *cm) { |
Debargha Mukherjee | a43a2d9 | 2017-01-03 15:14:57 -0800 | [diff] [blame] | 176 | int p; |
| 177 | for (p = 0; p < MAX_MB_PLANE; ++p) |
| 178 | av1_free_restoration_struct(&cm->rst_info[p]); |
Rupert Swarbrick | f88bc04 | 2017-10-18 10:45:51 +0100 | [diff] [blame] | 179 | aom_free(cm->rst_tmpbuf); |
| 180 | cm->rst_tmpbuf = NULL; |
Ola Hugosson | 5467190 | 2017-10-24 09:09:36 +0200 | [diff] [blame] | 181 | #if CONFIG_STRIPED_LOOP_RESTORATION |
| 182 | for (p = 0; p < MAX_MB_PLANE; ++p) { |
| 183 | RestorationStripeBoundaries *boundaries = &cm->rst_info[p].boundaries; |
| 184 | aom_free(boundaries->stripe_boundary_above); |
| 185 | aom_free(boundaries->stripe_boundary_below); |
| 186 | boundaries->stripe_boundary_above = NULL; |
| 187 | boundaries->stripe_boundary_below = NULL; |
| 188 | } |
| 189 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 190 | } |
| 191 | #endif // CONFIG_LOOP_RESTORATION |
| 192 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 193 | void av1_free_context_buffers(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 194 | int i; |
| 195 | cm->free_mi(cm); |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 196 | #if !CONFIG_SEGMENT_PRED_LAST |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 197 | free_seg_map(cm); |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 198 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 199 | for (i = 0; i < MAX_MB_PLANE; i++) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 200 | aom_free(cm->above_context[i]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | cm->above_context[i] = NULL; |
| 202 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 203 | aom_free(cm->above_seg_context); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 204 | cm->above_seg_context = NULL; |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 205 | cm->above_context_alloc_cols = 0; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 206 | aom_free(cm->above_txfm_context); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 207 | cm->above_txfm_context = NULL; |
Jingning Han | 6e4955d | 2017-05-30 22:54:48 -0700 | [diff] [blame] | 208 | |
| 209 | for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 210 | aom_free(cm->top_txfm_context[i]); |
| 211 | cm->top_txfm_context[i] = NULL; |
| 212 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 215 | int av1_alloc_context_buffers(AV1_COMMON *cm, int width, int height) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 216 | int new_mi_size; |
| 217 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 218 | av1_set_mb_mi(cm, width, height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows); |
| 220 | if (cm->mi_alloc_size < new_mi_size) { |
| 221 | cm->free_mi(cm); |
| 222 | if (cm->alloc_mi(cm, new_mi_size)) goto fail; |
| 223 | } |
| 224 | |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 225 | #if !CONFIG_SEGMENT_PRED_LAST |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 226 | if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) { |
| 227 | // Create the segmentation map structure and set to 0. |
| 228 | free_seg_map(cm); |
Rostislav Pehlivanov | f624dd5 | 2017-10-24 16:46:09 +0100 | [diff] [blame] | 229 | if (alloc_seg_map(cm, cm->mi_rows, cm->mi_cols)) goto fail; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 230 | } |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 231 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 232 | |
| 233 | if (cm->above_context_alloc_cols < cm->mi_cols) { |
| 234 | // TODO(geza.lore): These are bigger than they need to be. |
| 235 | // cm->tile_width would be enough but it complicates indexing a |
| 236 | // little elsewhere. |
| 237 | const int aligned_mi_cols = |
| 238 | ALIGN_POWER_OF_TWO(cm->mi_cols, MAX_MIB_SIZE_LOG2); |
| 239 | int i; |
| 240 | |
| 241 | for (i = 0; i < MAX_MB_PLANE; i++) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 242 | aom_free(cm->above_context[i]); |
| 243 | cm->above_context[i] = (ENTROPY_CONTEXT *)aom_calloc( |
Timothy B. Terriberry | 5e81643 | 2017-05-05 13:58:32 -0700 | [diff] [blame] | 244 | aligned_mi_cols << (MI_SIZE_LOG2 - tx_size_wide_log2[0]), |
| 245 | sizeof(*cm->above_context[0])); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | if (!cm->above_context[i]) goto fail; |
| 247 | } |
| 248 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 249 | aom_free(cm->above_seg_context); |
| 250 | cm->above_seg_context = (PARTITION_CONTEXT *)aom_calloc( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 251 | aligned_mi_cols, sizeof(*cm->above_seg_context)); |
| 252 | if (!cm->above_seg_context) goto fail; |
| 253 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 254 | aom_free(cm->above_txfm_context); |
| 255 | cm->above_txfm_context = (TXFM_CONTEXT *)aom_calloc( |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 256 | aligned_mi_cols << TX_UNIT_WIDE_LOG2, sizeof(*cm->above_txfm_context)); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 257 | if (!cm->above_txfm_context) goto fail; |
Jingning Han | 6e4955d | 2017-05-30 22:54:48 -0700 | [diff] [blame] | 258 | |
| 259 | for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 260 | aom_free(cm->top_txfm_context[i]); |
| 261 | cm->top_txfm_context[i] = |
| 262 | (TXFM_CONTEXT *)aom_calloc(aligned_mi_cols << TX_UNIT_WIDE_LOG2, |
| 263 | sizeof(*cm->top_txfm_context[0])); |
| 264 | if (!cm->top_txfm_context[i]) goto fail; |
| 265 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 266 | |
| 267 | cm->above_context_alloc_cols = aligned_mi_cols; |
| 268 | } |
| 269 | |
| 270 | return 0; |
| 271 | |
| 272 | fail: |
| 273 | // clear the mi_* values to force a realloc on resync |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 274 | av1_set_mb_mi(cm, 0, 0); |
| 275 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 276 | return 1; |
| 277 | } |
| 278 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 279 | void av1_remove_common(AV1_COMMON *cm) { |
| 280 | av1_free_context_buffers(cm); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 282 | aom_free(cm->fc); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 283 | cm->fc = NULL; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 284 | aom_free(cm->frame_contexts); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | cm->frame_contexts = NULL; |
| 286 | } |
| 287 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 288 | void av1_init_context_buffers(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | cm->setup_mi(cm); |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 290 | #if !CONFIG_SEGMENT_PRED_LAST |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | if (cm->last_frame_seg_map && !cm->frame_parallel_decode) |
| 292 | memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 293 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | } |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 295 | #if !CONFIG_SEGMENT_PRED_LAST |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 296 | void av1_swap_current_and_last_seg_map(AV1_COMMON *cm) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 297 | // Swap indices. |
| 298 | const int tmp = cm->seg_map_idx; |
| 299 | cm->seg_map_idx = cm->prev_seg_map_idx; |
| 300 | cm->prev_seg_map_idx = tmp; |
| 301 | |
| 302 | cm->current_frame_seg_map = cm->seg_map_array[cm->seg_map_idx]; |
| 303 | cm->last_frame_seg_map = cm->seg_map_array[cm->prev_seg_map_idx]; |
| 304 | } |
Soo-Chul Han | 934af35 | 2017-10-15 15:21:51 -0400 | [diff] [blame] | 305 | #endif |