| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 VP9LfSync *const lf_sync = &pbi->lf_row_sync; | 140 VP9LfSync *const lf_sync = &pbi->lf_row_sync; |
| 141 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); | 141 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 142 // Number of superblock rows and cols | 142 // Number of superblock rows and cols |
| 143 const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2; | 143 const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2; |
| 144 const int tile_cols = 1 << cm->log2_tile_cols; | 144 const int tile_cols = 1 << cm->log2_tile_cols; |
| 145 const int num_workers = MIN(pbi->max_threads & ~1, tile_cols); | 145 const int num_workers = MIN(pbi->max_threads & ~1, tile_cols); |
| 146 int i; | 146 int i; |
| 147 | 147 |
| 148 // Allocate memory used in thread synchronization. | 148 // Allocate memory used in thread synchronization. |
| 149 // This always needs to be done even if frame_filter_level is 0. | 149 // This always needs to be done even if frame_filter_level is 0. |
| 150 if (!cm->current_video_frame || cm->last_height != cm->height) { | 150 if (!lf_sync->sync_range || cm->last_height != cm->height) { |
| 151 if (cm->last_height != cm->height) { | 151 vp9_loop_filter_dealloc(lf_sync); |
| 152 const int aligned_last_height = | |
| 153 ALIGN_POWER_OF_TWO(cm->last_height, MI_SIZE_LOG2); | |
| 154 const int last_sb_rows = | |
| 155 mi_cols_aligned_to_sb(aligned_last_height >> MI_SIZE_LOG2) >> | |
| 156 MI_BLOCK_SIZE_LOG2; | |
| 157 | |
| 158 vp9_loop_filter_dealloc(lf_sync, last_sb_rows); | |
| 159 } | |
| 160 | |
| 161 vp9_loop_filter_alloc(cm, lf_sync, sb_rows, cm->width); | 152 vp9_loop_filter_alloc(cm, lf_sync, sb_rows, cm->width); |
| 162 } | 153 } |
| 163 | 154 |
| 164 if (!frame_filter_level) return; | 155 if (!frame_filter_level) return; |
| 165 | 156 |
| 166 vp9_loop_filter_frame_init(cm, frame_filter_level); | 157 vp9_loop_filter_frame_init(cm, frame_filter_level); |
| 167 | 158 |
| 168 // Initialize cur_sb_col to -1 for all SB rows. | 159 // Initialize cur_sb_col to -1 for all SB rows. |
| 169 vpx_memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows); | 160 vpx_memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows); |
| 170 | 161 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 return 2; | 211 return 2; |
| 221 else if (width <= 4096) | 212 else if (width <= 4096) |
| 222 return 4; | 213 return 4; |
| 223 else | 214 else |
| 224 return 8; | 215 return 8; |
| 225 } | 216 } |
| 226 | 217 |
| 227 // Allocate memory for lf row synchronization | 218 // Allocate memory for lf row synchronization |
| 228 void vp9_loop_filter_alloc(VP9_COMMON *cm, VP9LfSync *lf_sync, int rows, | 219 void vp9_loop_filter_alloc(VP9_COMMON *cm, VP9LfSync *lf_sync, int rows, |
| 229 int width) { | 220 int width) { |
| 221 lf_sync->rows = rows; |
| 230 #if CONFIG_MULTITHREAD | 222 #if CONFIG_MULTITHREAD |
| 231 int i; | 223 { |
| 224 int i; |
| 232 | 225 |
| 233 CHECK_MEM_ERROR(cm, lf_sync->mutex_, | 226 CHECK_MEM_ERROR(cm, lf_sync->mutex_, |
| 234 vpx_malloc(sizeof(*lf_sync->mutex_) * rows)); | 227 vpx_malloc(sizeof(*lf_sync->mutex_) * rows)); |
| 235 for (i = 0; i < rows; ++i) { | 228 for (i = 0; i < rows; ++i) { |
| 236 pthread_mutex_init(&lf_sync->mutex_[i], NULL); | 229 pthread_mutex_init(&lf_sync->mutex_[i], NULL); |
| 237 } | 230 } |
| 238 | 231 |
| 239 CHECK_MEM_ERROR(cm, lf_sync->cond_, | 232 CHECK_MEM_ERROR(cm, lf_sync->cond_, |
| 240 vpx_malloc(sizeof(*lf_sync->cond_) * rows)); | 233 vpx_malloc(sizeof(*lf_sync->cond_) * rows)); |
| 241 for (i = 0; i < rows; ++i) { | 234 for (i = 0; i < rows; ++i) { |
| 242 pthread_cond_init(&lf_sync->cond_[i], NULL); | 235 pthread_cond_init(&lf_sync->cond_[i], NULL); |
| 236 } |
| 243 } | 237 } |
| 244 #endif // CONFIG_MULTITHREAD | 238 #endif // CONFIG_MULTITHREAD |
| 245 | 239 |
| 246 CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col, | 240 CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col, |
| 247 vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows)); | 241 vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows)); |
| 248 | 242 |
| 249 // Set up nsync. | 243 // Set up nsync. |
| 250 lf_sync->sync_range = get_sync_range(width); | 244 lf_sync->sync_range = get_sync_range(width); |
| 251 } | 245 } |
| 252 | 246 |
| 253 // Deallocate lf synchronization related mutex and data | 247 // Deallocate lf synchronization related mutex and data |
| 254 void vp9_loop_filter_dealloc(VP9LfSync *lf_sync, int rows) { | 248 void vp9_loop_filter_dealloc(VP9LfSync *lf_sync) { |
| 255 #if !CONFIG_MULTITHREAD | |
| 256 (void)rows; | |
| 257 #endif // !CONFIG_MULTITHREAD | |
| 258 | |
| 259 if (lf_sync != NULL) { | 249 if (lf_sync != NULL) { |
| 260 #if CONFIG_MULTITHREAD | 250 #if CONFIG_MULTITHREAD |
| 261 int i; | 251 int i; |
| 262 | 252 |
| 263 if (lf_sync->mutex_ != NULL) { | 253 if (lf_sync->mutex_ != NULL) { |
| 264 for (i = 0; i < rows; ++i) { | 254 for (i = 0; i < lf_sync->rows; ++i) { |
| 265 pthread_mutex_destroy(&lf_sync->mutex_[i]); | 255 pthread_mutex_destroy(&lf_sync->mutex_[i]); |
| 266 } | 256 } |
| 267 vpx_free(lf_sync->mutex_); | 257 vpx_free(lf_sync->mutex_); |
| 268 } | 258 } |
| 269 if (lf_sync->cond_ != NULL) { | 259 if (lf_sync->cond_ != NULL) { |
| 270 for (i = 0; i < rows; ++i) { | 260 for (i = 0; i < lf_sync->rows; ++i) { |
| 271 pthread_cond_destroy(&lf_sync->cond_[i]); | 261 pthread_cond_destroy(&lf_sync->cond_[i]); |
| 272 } | 262 } |
| 273 vpx_free(lf_sync->cond_); | 263 vpx_free(lf_sync->cond_); |
| 274 } | 264 } |
| 275 #endif // CONFIG_MULTITHREAD | 265 #endif // CONFIG_MULTITHREAD |
| 276 vpx_free(lf_sync->cur_sb_col); | 266 vpx_free(lf_sync->cur_sb_col); |
| 277 // clear the structure as the source of this call may be a resize in which | 267 // clear the structure as the source of this call may be a resize in which |
| 278 // case this call will be followed by an _alloc() which may fail. | 268 // case this call will be followed by an _alloc() which may fail. |
| 279 vp9_zero(*lf_sync); | 269 vp9_zero(*lf_sync); |
| 280 } | 270 } |
| 281 } | 271 } |
| OLD | NEW |