| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 const int num_workers = MIN(cpi->oxcf.max_threads, tile_cols); | 160 const int num_workers = MIN(cpi->oxcf.max_threads, tile_cols); |
| 161 int i; | 161 int i; |
| 162 | 162 |
| 163 vp9_init_tile_data(cpi); | 163 vp9_init_tile_data(cpi); |
| 164 | 164 |
| 165 // Only run once to create threads and allocate thread data. | 165 // Only run once to create threads and allocate thread data. |
| 166 if (cpi->num_workers == 0) { | 166 if (cpi->num_workers == 0) { |
| 167 CHECK_MEM_ERROR(cm, cpi->workers, | 167 CHECK_MEM_ERROR(cm, cpi->workers, |
| 168 vpx_malloc(num_workers * sizeof(*cpi->workers))); | 168 vpx_malloc(num_workers * sizeof(*cpi->workers))); |
| 169 | 169 |
| 170 CHECK_MEM_ERROR(cm, cpi->tile_thr_data, |
| 171 vpx_calloc(num_workers, sizeof(*cpi->tile_thr_data))); |
| 172 |
| 170 for (i = 0; i < num_workers; i++) { | 173 for (i = 0; i < num_workers; i++) { |
| 171 VP9Worker *const worker = &cpi->workers[i]; | 174 VP9Worker *const worker = &cpi->workers[i]; |
| 172 EncWorkerData *thread_data; | 175 EncWorkerData *thread_data = &cpi->tile_thr_data[i]; |
| 173 | 176 |
| 174 ++cpi->num_workers; | 177 ++cpi->num_workers; |
| 175 | |
| 176 winterface->init(worker); | 178 winterface->init(worker); |
| 177 CHECK_MEM_ERROR(cm, worker->data1, | |
| 178 (EncWorkerData*)vpx_calloc(1, sizeof(EncWorkerData))); | |
| 179 thread_data = (EncWorkerData*)worker->data1; | |
| 180 | 179 |
| 181 if (i < num_workers - 1) { | 180 if (i < num_workers - 1) { |
| 182 thread_data->cpi = cpi; | 181 thread_data->cpi = cpi; |
| 183 | 182 |
| 184 // Allocate thread data. | 183 // Allocate thread data. |
| 185 CHECK_MEM_ERROR(cm, thread_data->td, | 184 CHECK_MEM_ERROR(cm, thread_data->td, |
| 186 vpx_calloc(1, sizeof(*thread_data->td))); | 185 vpx_memalign(32, sizeof(*thread_data->td))); |
| 186 vp9_zero(*thread_data->td); |
| 187 |
| 187 // Set up pc_tree. | 188 // Set up pc_tree. |
| 188 thread_data->td->leaf_tree = NULL; | 189 thread_data->td->leaf_tree = NULL; |
| 189 thread_data->td->pc_tree = NULL; | 190 thread_data->td->pc_tree = NULL; |
| 190 vp9_setup_pc_tree(cm, thread_data->td); | 191 vp9_setup_pc_tree(cm, thread_data->td); |
| 191 | 192 |
| 192 // Allocate frame counters in thread data. | 193 // Allocate frame counters in thread data. |
| 193 CHECK_MEM_ERROR(cm, thread_data->td->counts, | 194 CHECK_MEM_ERROR(cm, thread_data->td->counts, |
| 194 vpx_calloc(1, sizeof(*thread_data->td->counts))); | 195 vpx_calloc(1, sizeof(*thread_data->td->counts))); |
| 195 | 196 |
| 196 // Create threads | 197 // Create threads |
| 197 if (!winterface->reset(worker)) | 198 if (!winterface->reset(worker)) |
| 198 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, | 199 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, |
| 199 "Tile encoder thread creation failed"); | 200 "Tile encoder thread creation failed"); |
| 200 } else { | 201 } else { |
| 201 // Main thread acts as a worker and uses the thread data in cpi. | 202 // Main thread acts as a worker and uses the thread data in cpi. |
| 202 thread_data->cpi = cpi; | 203 thread_data->cpi = cpi; |
| 203 thread_data->td = &cpi->td; | 204 thread_data->td = &cpi->td; |
| 204 } | 205 } |
| 205 | 206 |
| 206 // data2 is unused. | |
| 207 worker->data2 = NULL; | |
| 208 | |
| 209 winterface->sync(worker); | 207 winterface->sync(worker); |
| 210 worker->hook = (VP9WorkerHook)enc_worker_hook; | |
| 211 } | 208 } |
| 212 } | 209 } |
| 213 | 210 |
| 214 for (i = 0; i < num_workers; i++) { | 211 for (i = 0; i < num_workers; i++) { |
| 215 VP9Worker *const worker = &cpi->workers[i]; | 212 VP9Worker *const worker = &cpi->workers[i]; |
| 216 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; | 213 EncWorkerData *thread_data; |
| 214 |
| 215 worker->hook = (VP9WorkerHook)enc_worker_hook; |
| 216 worker->data1 = &cpi->tile_thr_data[i]; |
| 217 worker->data2 = NULL; |
| 218 thread_data = (EncWorkerData*)worker->data1; |
| 217 | 219 |
| 218 // Before encoding a frame, copy the thread data from cpi. | 220 // Before encoding a frame, copy the thread data from cpi. |
| 219 thread_data->td->mb = cpi->td.mb; | 221 thread_data->td->mb = cpi->td.mb; |
| 220 thread_data->td->rd_counts = cpi->td.rd_counts; | 222 thread_data->td->rd_counts = cpi->td.rd_counts; |
| 221 vpx_memcpy(thread_data->td->counts, &cpi->common.counts, | 223 vpx_memcpy(thread_data->td->counts, &cpi->common.counts, |
| 222 sizeof(cpi->common.counts)); | 224 sizeof(cpi->common.counts)); |
| 223 | 225 |
| 224 // Handle use_nonrd_pick_mode case. | 226 // Handle use_nonrd_pick_mode case. |
| 225 if (cpi->sf.use_nonrd_pick_mode) { | 227 if (cpi->sf.use_nonrd_pick_mode) { |
| 226 MACROBLOCK *const x = &thread_data->td->mb; | 228 MACROBLOCK *const x = &thread_data->td->mb; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 VP9Worker *const worker = &cpi->workers[i]; | 265 VP9Worker *const worker = &cpi->workers[i]; |
| 264 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; | 266 EncWorkerData *const thread_data = (EncWorkerData*)worker->data1; |
| 265 | 267 |
| 266 // Accumulate counters. | 268 // Accumulate counters. |
| 267 if (i < num_workers - 1) { | 269 if (i < num_workers - 1) { |
| 268 accumulate_frame_counts(&cpi->common, thread_data->td); | 270 accumulate_frame_counts(&cpi->common, thread_data->td); |
| 269 accumulate_rd_opt(&cpi->td, thread_data->td); | 271 accumulate_rd_opt(&cpi->td, thread_data->td); |
| 270 } | 272 } |
| 271 } | 273 } |
| 272 } | 274 } |
| OLD | NEW |