| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 VP9_COMMON *const cm, | 92 VP9_COMMON *const cm, |
| 93 struct macroblockd_plane planes[MAX_MB_PLANE], | 93 struct macroblockd_plane planes[MAX_MB_PLANE], |
| 94 int start, int stop, int y_only, | 94 int start, int stop, int y_only, |
| 95 VP9LfSync *const lf_sync, int num_lf_workers) { | 95 VP9LfSync *const lf_sync, int num_lf_workers) { |
| 96 const int num_planes = y_only ? 1 : MAX_MB_PLANE; | 96 const int num_planes = y_only ? 1 : MAX_MB_PLANE; |
| 97 int r, c; // SB row and col | 97 int r, c; // SB row and col |
| 98 const int sb_cols = mi_cols_aligned_to_sb(cm->mi_cols) >> MI_BLOCK_SIZE_LOG2; | 98 const int sb_cols = mi_cols_aligned_to_sb(cm->mi_cols) >> MI_BLOCK_SIZE_LOG2; |
| 99 | 99 |
| 100 for (r = start; r < stop; r += num_lf_workers) { | 100 for (r = start; r < stop; r += num_lf_workers) { |
| 101 const int mi_row = r << MI_BLOCK_SIZE_LOG2; | 101 const int mi_row = r << MI_BLOCK_SIZE_LOG2; |
| 102 MODE_INFO **const mi = cm->mi_grid_visible + mi_row * cm->mi_stride; | 102 MODE_INFO *const mi = cm->mi + mi_row * cm->mi_stride; |
| 103 | 103 |
| 104 for (c = 0; c < sb_cols; ++c) { | 104 for (c = 0; c < sb_cols; ++c) { |
| 105 const int mi_col = c << MI_BLOCK_SIZE_LOG2; | 105 const int mi_col = c << MI_BLOCK_SIZE_LOG2; |
| 106 LOOP_FILTER_MASK lfm; | 106 LOOP_FILTER_MASK lfm; |
| 107 int plane; | 107 int plane; |
| 108 | 108 |
| 109 sync_read(lf_sync, r, c); | 109 sync_read(lf_sync, r, c); |
| 110 | 110 |
| 111 vp9_setup_dst_planes(planes, frame_buffer, mi_row, mi_col); | 111 vp9_setup_dst_planes(planes, frame_buffer, mi_row, mi_col); |
| 112 vp9_setup_mask(cm, mi_row, mi_col, mi + mi_col, cm->mi_stride, &lfm); | 112 vp9_setup_mask(cm, mi_row, mi_col, mi + mi_col, cm->mi_stride, &lfm); |
| 113 | 113 |
| 114 for (plane = 0; plane < num_planes; ++plane) { | 114 for (plane = 0; plane < num_planes; ++plane) { |
| 115 vp9_filter_block_plane(cm, &planes[plane], mi_row, &lfm); | 115 vp9_filter_block_plane(cm, &planes[plane], mi_row, &lfm); |
| 116 } | 116 } |
| 117 | 117 |
| 118 sync_write(lf_sync, r, c, sb_cols); | 118 sync_write(lf_sync, r, c, sb_cols); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Row-based multi-threaded loopfilter hook | 123 // Row-based multi-threaded loopfilter hook |
| 124 static int loop_filter_row_worker(void *arg1, void *arg2) { | 124 static int loop_filter_row_worker(TileWorkerData *const tile_data, |
| 125 TileWorkerData *const tile_data = (TileWorkerData*)arg1; | 125 void *unused) { |
| 126 LFWorkerData *const lf_data = &tile_data->lfdata; | 126 LFWorkerData *const lf_data = &tile_data->lfdata; |
| 127 (void) arg2; | 127 (void)unused; |
| 128 loop_filter_rows_mt(lf_data->frame_buffer, lf_data->cm, lf_data->planes, | 128 loop_filter_rows_mt(lf_data->frame_buffer, lf_data->cm, lf_data->planes, |
| 129 lf_data->start, lf_data->stop, lf_data->y_only, | 129 lf_data->start, lf_data->stop, lf_data->y_only, |
| 130 lf_data->lf_sync, lf_data->num_lf_workers); | 130 lf_data->lf_sync, lf_data->num_lf_workers); |
| 131 return 1; | 131 return 1; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // VP9 decoder: Implement multi-threaded loopfilter that uses the tile | 134 // VP9 decoder: Implement multi-threaded loopfilter that uses the tile |
| 135 // threads. | 135 // threads. |
| 136 void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, | 136 void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, |
| 137 VP9Decoder *pbi, VP9_COMMON *cm, | 137 VP9Decoder *pbi, VP9_COMMON *cm, |
| 138 int frame_filter_level, | 138 int frame_filter_level, |
| 139 int y_only) { | 139 int y_only) { |
| 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 if (!frame_filter_level) return; |
| 149 // This always needs to be done even if frame_filter_level is 0. | 149 |
| 150 if (!lf_sync->sync_range || cm->last_height != cm->height) { | 150 if (!lf_sync->sync_range || cm->last_height != cm->height) { |
| 151 vp9_loop_filter_dealloc(lf_sync); | 151 vp9_loop_filter_dealloc(lf_sync); |
| 152 vp9_loop_filter_alloc(cm, lf_sync, sb_rows, cm->width); | 152 vp9_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width); |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (!frame_filter_level) return; | |
| 156 | |
| 157 vp9_loop_filter_frame_init(cm, frame_filter_level); | 155 vp9_loop_filter_frame_init(cm, frame_filter_level); |
| 158 | 156 |
| 159 // Initialize cur_sb_col to -1 for all SB rows. | 157 // Initialize cur_sb_col to -1 for all SB rows. |
| 160 vpx_memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows); | 158 vpx_memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows); |
| 161 | 159 |
| 162 // Set up loopfilter thread data. | 160 // Set up loopfilter thread data. |
| 163 // The decoder is using num_workers instead of pbi->num_tile_workers | 161 // The decoder is using num_workers instead of pbi->num_tile_workers |
| 164 // because it has been observed that using more threads on the | 162 // because it has been observed that using more threads on the |
| 165 // loopfilter, than there are tile columns in the frame will hurt | 163 // loopfilter, than there are tile columns in the frame will hurt |
| 166 // performance on Android. This is because the system will only | 164 // performance on Android. This is because the system will only |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return 1; | 207 return 1; |
| 210 else if (width <= 1280) | 208 else if (width <= 1280) |
| 211 return 2; | 209 return 2; |
| 212 else if (width <= 4096) | 210 else if (width <= 4096) |
| 213 return 4; | 211 return 4; |
| 214 else | 212 else |
| 215 return 8; | 213 return 8; |
| 216 } | 214 } |
| 217 | 215 |
| 218 // Allocate memory for lf row synchronization | 216 // Allocate memory for lf row synchronization |
| 219 void vp9_loop_filter_alloc(VP9_COMMON *cm, VP9LfSync *lf_sync, int rows, | 217 void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows, |
| 220 int width) { | 218 int width) { |
| 221 lf_sync->rows = rows; | 219 lf_sync->rows = rows; |
| 222 #if CONFIG_MULTITHREAD | 220 #if CONFIG_MULTITHREAD |
| 223 { | 221 { |
| 224 int i; | 222 int i; |
| 225 | 223 |
| 226 CHECK_MEM_ERROR(cm, lf_sync->mutex_, | 224 CHECK_MEM_ERROR(cm, lf_sync->mutex_, |
| 227 vpx_malloc(sizeof(*lf_sync->mutex_) * rows)); | 225 vpx_malloc(sizeof(*lf_sync->mutex_) * rows)); |
| 228 for (i = 0; i < rows; ++i) { | 226 for (i = 0; i < rows; ++i) { |
| 229 pthread_mutex_init(&lf_sync->mutex_[i], NULL); | 227 pthread_mutex_init(&lf_sync->mutex_[i], NULL); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 260 } |
| 263 vpx_free(lf_sync->cond_); | 261 vpx_free(lf_sync->cond_); |
| 264 } | 262 } |
| 265 #endif // CONFIG_MULTITHREAD | 263 #endif // CONFIG_MULTITHREAD |
| 266 vpx_free(lf_sync->cur_sb_col); | 264 vpx_free(lf_sync->cur_sb_col); |
| 267 // clear the structure as the source of this call may be a resize in which | 265 // clear the structure as the source of this call may be a resize in which |
| 268 // case this call will be followed by an _alloc() which may fail. | 266 // case this call will be followed by an _alloc() which may fail. |
| 269 vp9_zero(*lf_sync); | 267 vp9_zero(*lf_sync); |
| 270 } | 268 } |
| 271 } | 269 } |
| OLD | NEW |