| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 t += cpi->num_workers) { | 47 t += cpi->num_workers) { |
| 48 int tile_row = t / tile_cols; | 48 int tile_row = t / tile_cols; |
| 49 int tile_col = t % tile_cols; | 49 int tile_col = t % tile_cols; |
| 50 | 50 |
| 51 vp9_encode_tile(cpi, thread_data->td, tile_row, tile_col); | 51 vp9_encode_tile(cpi, thread_data->td, tile_row, tile_col); |
| 52 } | 52 } |
| 53 | 53 |
| 54 return 0; | 54 return 0; |
| 55 } | 55 } |
| 56 | 56 |
| 57 static int get_max_tile_cols(VP9_COMP *cpi) { |
| 58 const int aligned_width = ALIGN_POWER_OF_TWO(cpi->oxcf.width, MI_SIZE_LOG2); |
| 59 int mi_cols = aligned_width >> MI_SIZE_LOG2; |
| 60 int min_log2_tile_cols, max_log2_tile_cols; |
| 61 int log2_tile_cols; |
| 62 |
| 63 vp9_get_tile_n_bits(mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); |
| 64 log2_tile_cols = clamp(cpi->oxcf.tile_columns, |
| 65 min_log2_tile_cols, max_log2_tile_cols); |
| 66 return (1 << log2_tile_cols); |
| 67 } |
| 68 |
| 57 void vp9_encode_tiles_mt(VP9_COMP *cpi) { | 69 void vp9_encode_tiles_mt(VP9_COMP *cpi) { |
| 58 VP9_COMMON *const cm = &cpi->common; | 70 VP9_COMMON *const cm = &cpi->common; |
| 59 const int tile_cols = 1 << cm->log2_tile_cols; | 71 const int tile_cols = 1 << cm->log2_tile_cols; |
| 60 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); | 72 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 61 const int num_workers = MIN(cpi->oxcf.max_threads, tile_cols); | 73 const int num_workers = MIN(cpi->oxcf.max_threads, tile_cols); |
| 62 int i; | 74 int i; |
| 63 | 75 |
| 64 vp9_init_tile_data(cpi); | 76 vp9_init_tile_data(cpi); |
| 65 | 77 |
| 66 // Only run once to create threads and allocate thread data. | 78 // Only run once to create threads and allocate thread data. |
| 67 if (cpi->num_workers == 0) { | 79 if (cpi->num_workers == 0) { |
| 80 int allocated_workers = num_workers; |
| 81 |
| 82 // While using SVC, we need to allocate threads according to the highest |
| 83 // resolution. |
| 84 if (cpi->use_svc) { |
| 85 int max_tile_cols = get_max_tile_cols(cpi); |
| 86 allocated_workers = MIN(cpi->oxcf.max_threads, max_tile_cols); |
| 87 } |
| 88 |
| 68 CHECK_MEM_ERROR(cm, cpi->workers, | 89 CHECK_MEM_ERROR(cm, cpi->workers, |
| 69 vpx_malloc(num_workers * sizeof(*cpi->workers))); | 90 vpx_malloc(allocated_workers * sizeof(*cpi->workers))); |
| 70 | 91 |
| 71 CHECK_MEM_ERROR(cm, cpi->tile_thr_data, | 92 CHECK_MEM_ERROR(cm, cpi->tile_thr_data, |
| 72 vpx_calloc(num_workers, sizeof(*cpi->tile_thr_data))); | 93 vpx_calloc(allocated_workers, |
| 94 sizeof(*cpi->tile_thr_data))); |
| 73 | 95 |
| 74 for (i = 0; i < num_workers; i++) { | 96 for (i = 0; i < allocated_workers; i++) { |
| 75 VP9Worker *const worker = &cpi->workers[i]; | 97 VP9Worker *const worker = &cpi->workers[i]; |
| 76 EncWorkerData *thread_data = &cpi->tile_thr_data[i]; | 98 EncWorkerData *thread_data = &cpi->tile_thr_data[i]; |
| 77 | 99 |
| 78 ++cpi->num_workers; | 100 ++cpi->num_workers; |
| 79 winterface->init(worker); | 101 winterface->init(worker); |
| 80 | 102 |
| 81 if (i < num_workers - 1) { | 103 if (i < allocated_workers - 1) { |
| 82 thread_data->cpi = cpi; | 104 thread_data->cpi = cpi; |
| 83 | 105 |
| 84 // Allocate thread data. | 106 // Allocate thread data. |
| 85 CHECK_MEM_ERROR(cm, thread_data->td, | 107 CHECK_MEM_ERROR(cm, thread_data->td, |
| 86 vpx_memalign(32, sizeof(*thread_data->td))); | 108 vpx_memalign(32, sizeof(*thread_data->td))); |
| 87 vp9_zero(*thread_data->td); | 109 vp9_zero(*thread_data->td); |
| 88 | 110 |
| 89 // Set up pc_tree. | 111 // Set up pc_tree. |
| 90 thread_data->td->leaf_tree = NULL; | 112 thread_data->td->leaf_tree = NULL; |
| 91 thread_data->td->pc_tree = NULL; | 113 thread_data->td->pc_tree = NULL; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 169 } |
| 148 | 170 |
| 149 // Encode a frame | 171 // Encode a frame |
| 150 for (i = 0; i < num_workers; i++) { | 172 for (i = 0; i < num_workers; i++) { |
| 151 VP9Worker *const worker = &cpi->workers[i]; | 173 VP9Worker *const worker = &cpi->workers[i]; |
| 152 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; | 174 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; |
| 153 | 175 |
| 154 // Set the starting tile for each thread. | 176 // Set the starting tile for each thread. |
| 155 thread_data->start = i; | 177 thread_data->start = i; |
| 156 | 178 |
| 157 if (i == num_workers - 1) | 179 if (i == cpi->num_workers - 1) |
| 158 winterface->execute(worker); | 180 winterface->execute(worker); |
| 159 else | 181 else |
| 160 winterface->launch(worker); | 182 winterface->launch(worker); |
| 161 } | 183 } |
| 162 | 184 |
| 163 // Encoding ends. | 185 // Encoding ends. |
| 164 for (i = 0; i < num_workers; i++) { | 186 for (i = 0; i < num_workers; i++) { |
| 165 VP9Worker *const worker = &cpi->workers[i]; | 187 VP9Worker *const worker = &cpi->workers[i]; |
| 166 winterface->sync(worker); | 188 winterface->sync(worker); |
| 167 } | 189 } |
| 168 | 190 |
| 169 for (i = 0; i < num_workers; i++) { | 191 for (i = 0; i < num_workers; i++) { |
| 170 VP9Worker *const worker = &cpi->workers[i]; | 192 VP9Worker *const worker = &cpi->workers[i]; |
| 171 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; | 193 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; |
| 172 | 194 |
| 173 // Accumulate counters. | 195 // Accumulate counters. |
| 174 if (i < num_workers - 1) { | 196 if (i < cpi->num_workers - 1) { |
| 175 vp9_accumulate_frame_counts(cm, thread_data->td->counts, 0); | 197 vp9_accumulate_frame_counts(cm, thread_data->td->counts, 0); |
| 176 accumulate_rd_opt(&cpi->td, thread_data->td); | 198 accumulate_rd_opt(&cpi->td, thread_data->td); |
| 177 } | 199 } |
| 178 } | 200 } |
| 179 } | 201 } |
| OLD | NEW |