/* * Copyright (c) 2016, Alliance for Open Media. All rights reserved. * * This source code is subject to the terms of the BSD 2 Clause License and * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License * was not distributed with this source code in the LICENSE file, you can * obtain it at www.aomedia.org/license/software. If the Alliance for Open * Media Patent License 1.0 was not distributed with this source code in the * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
// Set up nsync by width. staticinlineint get_sync_range(int width) { // nsync numbers are picked by testing. For example, for 4k // video, using 4 gives best performance. if (width < 640) return 1; elseif (width <= 1280) return 2; elseif (width <= 4096) return 4; else return 8;
}
#if !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER staticinlineint get_lr_sync_range(int width) { #if 0 // nsync numbers are picked by testing. For example, for 4k // video, using 4 gives best performance. if (width < 640) return 1; elseif (width <= 1280) return 2; elseif (width <= 4096) return 4; else return 8; #else
(void)width; return 1; #endif
} #endif// !CONFIG_REALTIME_ONLY || CONFIG_AV1_DECODER
// Allocate memory for lf row synchronization void av1_loop_filter_alloc(AV1LfSync *lf_sync, AV1_COMMON *cm, int rows, int width, int num_workers) {
lf_sync->rows = rows; #if CONFIG_MULTITHREAD
{ int i, j;
for (j = 0; j < MAX_MB_PLANE; j++) {
CHECK_MEM_ERROR(cm, lf_sync->mutex_[j],
aom_malloc(sizeof(*(lf_sync->mutex_[j])) * rows)); if (lf_sync->mutex_[j]) { for (i = 0; i < rows; ++i) {
pthread_mutex_init(&lf_sync->mutex_[j][i], NULL);
}
}
CHECK_MEM_ERROR(cm, lf_sync->cond_[j],
aom_malloc(sizeof(*(lf_sync->cond_[j])) * rows)); if (lf_sync->cond_[j]) { for (i = 0; i < rows; ++i) {
pthread_cond_init(&lf_sync->cond_[j][i], NULL);
}
}
}
for (int j = 0; j < MAX_MB_PLANE; j++) {
CHECK_MEM_ERROR(cm, lf_sync->cur_sb_col[j],
aom_malloc(sizeof(*(lf_sync->cur_sb_col[j])) * rows));
}
CHECK_MEM_ERROR(
cm, lf_sync->job_queue,
aom_malloc(sizeof(*(lf_sync->job_queue)) * rows * MAX_MB_PLANE * 2)); // Set up nsync.
lf_sync->sync_range = get_sync_range(width);
}
// Deallocate lf synchronization related mutex and data void av1_loop_filter_dealloc(AV1LfSync *lf_sync) { if (lf_sync != NULL) { int j; #if CONFIG_MULTITHREAD int i; for (j = 0; j < MAX_MB_PLANE; j++) { if (lf_sync->mutex_[j] != NULL) { for (i = 0; i < lf_sync->rows; ++i) {
pthread_mutex_destroy(&lf_sync->mutex_[j][i]);
}
aom_free(lf_sync->mutex_[j]);
} if (lf_sync->cond_[j] != NULL) { for (i = 0; i < lf_sync->rows; ++i) {
pthread_cond_destroy(&lf_sync->cond_[j][i]);
}
aom_free(lf_sync->cond_[j]);
}
} if (lf_sync->job_mutex != NULL) {
pthread_mutex_destroy(lf_sync->job_mutex);
aom_free(lf_sync->job_mutex);
} #endif// CONFIG_MULTITHREAD
aom_free(lf_sync->lfdata); for (j = 0; j < MAX_MB_PLANE; j++) {
aom_free(lf_sync->cur_sb_col[j]);
}
aom_free(lf_sync->job_queue); // clear the structure as the source of this call may be a resize in which // case this call will be followed by an _alloc() which may fail.
av1_zero(*lf_sync);
}
}
void av1_alloc_cdef_sync(AV1_COMMON *const cm, AV1CdefSync *cdef_sync, int num_workers) { if (num_workers < 1) return; #if CONFIG_MULTITHREAD if (cdef_sync->mutex_ == NULL) {
CHECK_MEM_ERROR(cm, cdef_sync->mutex_,
aom_malloc(sizeof(*(cdef_sync->mutex_)))); if (cdef_sync->mutex_) pthread_mutex_init(cdef_sync->mutex_, NULL);
} #else
(void)cm;
(void)cdef_sync; #endif// CONFIG_MULTITHREAD
}
staticinlinevoid sync_write(AV1LfSync *const lf_sync, int r, int c, constint sb_cols, int plane) { #if CONFIG_MULTITHREAD constint nsync = lf_sync->sync_range; int cur; // Only signal when there are enough filtered SB for next row to run. int sig = 1;
if (c < sb_cols - 1) {
cur = c; if (c % nsync) sig = 0;
} else {
cur = sb_cols + nsync;
}
if (sig) {
pthread_mutex_lock(&lf_sync->mutex_[plane][r]);
// When a thread encounters an error, cur_sb_col[plane][r] is set to maximum // column number. In this case, the AOMMAX operation here ensures that // cur_sb_col[plane][r] is not overwritten with a smaller value thus // preventing the infinite waiting of threads in the relevant sync_read() // function.
lf_sync->cur_sb_col[plane][r] = AOMMAX(lf_sync->cur_sb_col[plane][r], cur);
// One job of row loopfiltering. void av1_thread_loop_filter_rows( const YV12_BUFFER_CONFIG *const frame_buffer, AV1_COMMON *const cm, struct macroblockd_plane *planes, MACROBLOCKD *xd, int mi_row, int plane, int dir, int lpf_opt_level, AV1LfSync *const lf_sync, struct aom_internal_error_info *error_info,
AV1_DEBLOCKING_PARAMETERS *params_buf, TX_SIZE *tx_buf, int num_mis_in_lpf_unit_height_log2) { // TODO(aomedia:3276): Pass error_info to the low-level functions as required // in future to handle error propagation.
(void)error_info; constint sb_cols =
CEIL_POWER_OF_TWO(cm->mi_params.mi_cols, MAX_MIB_SIZE_LOG2); constint r = mi_row >> num_mis_in_lpf_unit_height_log2; int mi_col, c;
if (lf_sync != NULL) { // Wait for vertical edge filtering of the top-right block to be // completed
sync_read(lf_sync, r, c, plane);
// Wait for vertical edge filtering of the right block to be completed
sync_read(lf_sync, r + 1, c, plane);
}
#if CONFIG_MULTITHREAD if (lf_sync && lf_sync->num_workers > 1) {
pthread_mutex_lock(lf_sync->job_mutex); constbool lf_mt_exit = lf_sync->lf_mt_exit;
pthread_mutex_unlock(lf_sync->job_mutex); // Exit in case any worker has encountered an error. if (lf_mt_exit) return;
} #endif
// In case of loopfilter row-multithreading, the worker on an SB row waits for // the vertical edge filtering of the right and top-right SBs. Hence, in case // a thread (main/worker) encounters an error, update that vertical // loopfiltering of every SB row in the frame is complete in order to avoid // dependent workers waiting indefinitely. for (sb_row = 0; sb_row < sb_rows; ++sb_row) for (plane = 0; plane < MAX_MB_PLANE; ++plane)
sync_write(lf_sync, sb_row, sb_cols - 1, sb_cols, plane);
}
staticinlinevoid sync_lf_workers(AVxWorker *const workers,
AV1_COMMON *const cm, int num_workers) { const AVxWorkerInterface *const winterface = aom_get_worker_interface(); int had_error = workers[0].had_error; struct aom_internal_error_info error_info;
// Read the error_info of main thread. if (had_error) {
AVxWorker *const worker = &workers[0];
error_info = ((LFWorkerData *)worker->data2)->error_info;
}
// Wait till all rows are finished. for (int i = num_workers - 1; i > 0; --i) {
AVxWorker *const worker = &workers[i]; if (!winterface->sync(worker)) {
had_error = 1;
error_info = ((LFWorkerData *)worker->data2)->error_info;
}
} if (had_error) aom_internal_error_copy(cm->error, &error_info);
}
// The jmp_buf is valid only for the duration of the function that calls // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 // before it returns. if (setjmp(error_info->jmp)) {
error_info->setjmp = 0; #if CONFIG_MULTITHREAD
pthread_mutex_lock(job_mutex_);
lf_sync->lf_mt_exit = true;
pthread_mutex_unlock(job_mutex_); #endif
av1_set_vert_loop_filter_done(lf_data->cm, lf_sync, MAX_MIB_SIZE_LOG2); return 0;
}
error_info->setjmp = 1;
// Loopfilter data
loop_filter_data_reset(lf_data, frame, cm, xd);
// Start loopfiltering
worker->had_error = 0; if (i == 0) {
winterface->execute(worker);
} else {
winterface->launch(worker);
}
}
sync_lf_workers(workers, cm, num_workers);
}
staticvoid loop_filter_rows(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
MACROBLOCKD *xd, int start, int stop, constint planes_to_lf[MAX_MB_PLANE], int lpf_opt_level) { // Filter top rows of all planes first, in case the output can be partially // reconstructed row by row. int mi_row, plane, dir;
for (dir = 0; dir < 2; ++dir) {
av1_thread_loop_filter_rows(frame, cm, xd->plane, xd, mi_row, plane,
dir, lpf_opt_level, /*lf_sync=*/NULL,
xd->error_info, params_buf, tx_buf,
MAX_MIB_SIZE_LOG2);
}
}
}
}
void av1_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, AV1_COMMON *cm,
MACROBLOCKD *xd, int plane_start, int plane_end, int partial_frame, AVxWorker *workers, int num_workers, AV1LfSync *lf_sync, int lpf_opt_level) { int start_mi_row, end_mi_row, mi_rows_to_filter; int planes_to_lf[MAX_MB_PLANE];
if (!check_planes_to_loop_filter(&cm->lf, planes_to_lf, plane_start,
plane_end)) return;
staticinlinevoid lr_sync_write(void *const lr_sync, int r, int c, constint sb_cols, int plane) { #if CONFIG_MULTITHREAD
AV1LrSync *const loop_res_sync = (AV1LrSync *)lr_sync; constint nsync = loop_res_sync->sync_range; int cur; // Only signal when there are enough filtered SB for next row to run. int sig = 1;
if (c < sb_cols - 1) {
cur = c; if (c % nsync) sig = 0;
} else {
cur = sb_cols + nsync;
}
if (sig) {
pthread_mutex_lock(&loop_res_sync->mutex_[plane][r]);
// When a thread encounters an error, cur_sb_col[plane][r] is set to maximum // column number. In this case, the AOMMAX operation here ensures that // cur_sb_col[plane][r] is not overwritten with a smaller value thus // preventing the infinite waiting of threads in the relevant sync_read() // function.
loop_res_sync->cur_sb_col[plane][r] =
AOMMAX(loop_res_sync->cur_sb_col[plane][r], cur);
// Allocate memory for loop restoration row synchronization void av1_loop_restoration_alloc(AV1LrSync *lr_sync, AV1_COMMON *cm, int num_workers, int num_rows_lr, int num_planes, int width) {
lr_sync->rows = num_rows_lr;
lr_sync->num_planes = num_planes; #if CONFIG_MULTITHREAD
{ int i, j;
for (j = 0; j < num_planes; j++) {
CHECK_MEM_ERROR(cm, lr_sync->mutex_[j],
aom_malloc(sizeof(*(lr_sync->mutex_[j])) * num_rows_lr)); if (lr_sync->mutex_[j]) { for (i = 0; i < num_rows_lr; ++i) {
pthread_mutex_init(&lr_sync->mutex_[j][i], NULL);
}
}
CHECK_MEM_ERROR(cm, lr_sync->cond_[j],
aom_malloc(sizeof(*(lr_sync->cond_[j])) * num_rows_lr)); if (lr_sync->cond_[j]) { for (i = 0; i < num_rows_lr; ++i) {
pthread_cond_init(&lr_sync->cond_[j][i], NULL);
}
}
}
// clear the structure as the source of this call may be a resize in which // case this call will be followed by an _alloc() which may fail.
av1_zero(*lr_sync);
}
}
// The jmp_buf is valid only for the duration of the function that calls // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 // before it returns. if (setjmp(error_info->jmp)) {
error_info->setjmp = 0; #if CONFIG_MULTITHREAD
pthread_mutex_lock(job_mutex_);
lr_sync->lr_mt_exit = true;
pthread_mutex_unlock(job_mutex_); #endif // In case of loop restoration multithreading, the worker on an even lr // block row waits for the completion of the filtering of the top-right and // bottom-right blocks. Hence, in case a thread (main/worker) encounters an // error, update that filtering of every row in the frame is complete in // order to avoid the dependent workers from waiting indefinitely.
set_loop_restoration_done(lr_sync, lr_ctxt->ctxt); return 0;
}
error_info->setjmp = 1;
typedefvoid (*copy_fun)(const YV12_BUFFER_CONFIG *src_ybc,
YV12_BUFFER_CONFIG *dst_ybc, int hstart, int hend, int vstart, int vend); staticconst copy_fun copy_funs[MAX_MB_PLANE] = {
aom_yv12_partial_coloc_copy_y, aom_yv12_partial_coloc_copy_u,
aom_yv12_partial_coloc_copy_v
};
staticinlinevoid sync_lr_workers(AVxWorker *const workers,
AV1_COMMON *const cm, int num_workers) { const AVxWorkerInterface *const winterface = aom_get_worker_interface(); int had_error = workers[0].had_error; struct aom_internal_error_info error_info;
// Read the error_info of main thread. if (had_error) {
AVxWorker *const worker = &workers[0];
error_info = ((LRWorkerData *)worker->data2)->error_info;
}
// Wait till all rows are finished. for (int i = num_workers - 1; i > 0; --i) {
AVxWorker *const worker = &workers[i]; if (!winterface->sync(worker)) {
had_error = 1;
error_info = ((LRWorkerData *)worker->data2)->error_info;
}
} if (had_error) aom_internal_error_copy(cm->error, &error_info);
}
staticvoid foreach_rest_unit_in_planes_mt(AV1LrStruct *lr_ctxt,
AVxWorker *workers, int num_workers,
AV1LrSync *lr_sync, AV1_COMMON *cm, int do_extend_border) {
FilterFrameCtxt *ctxt = lr_ctxt->ctxt;
constint num_planes = av1_num_planes(cm);
const AVxWorkerInterface *const winterface = aom_get_worker_interface(); int num_rows_lr = 0;
for (int plane = 0; plane < num_planes; plane++) { if (cm->rst_info[plane].frame_restoration_type == RESTORE_NONE) continue;
// Initialize cur_sb_col to -1 for all SB rows. for (i = 0; i < num_planes; i++) {
memset(lr_sync->cur_sb_col[i], -1, sizeof(*(lr_sync->cur_sb_col[i])) * num_rows_lr);
}
enqueue_lr_jobs(lr_sync, lr_ctxt, cm);
// Set up looprestoration thread data. for (i = num_workers - 1; i >= 0; --i) {
AVxWorker *const worker = &workers[i];
lr_sync->lrworkerdata[i].lr_ctxt = (void *)lr_ctxt;
lr_sync->lrworkerdata[i].do_extend_border = do_extend_border;
worker->hook = loop_restoration_row_worker;
worker->data1 = lr_sync;
worker->data2 = &lr_sync->lrworkerdata[i];
// Start loop restoration
worker->had_error = 0; if (i == 0) {
winterface->execute(worker);
} else {
winterface->launch(worker);
}
}
sync_lr_workers(workers, cm, num_workers);
}
void av1_loop_restoration_filter_frame_mt(YV12_BUFFER_CONFIG *frame,
AV1_COMMON *cm, int optimized_lr,
AVxWorker *workers, int num_workers,
AV1LrSync *lr_sync, void *lr_ctxt, int do_extend_border) {
assert(!cm->features.all_lossless);
staticinlinevoid launch_cdef_workers(AVxWorker *const workers, int num_workers) { const AVxWorkerInterface *const winterface = aom_get_worker_interface(); for (int i = num_workers - 1; i >= 0; i--) {
AVxWorker *const worker = &workers[i];
worker->had_error = 0; if (i == 0)
winterface->execute(worker); else
winterface->launch(worker);
}
}
staticinlinevoid sync_cdef_workers(AVxWorker *const workers,
AV1_COMMON *const cm, int num_workers) { const AVxWorkerInterface *const winterface = aom_get_worker_interface(); int had_error = workers[0].had_error; struct aom_internal_error_info error_info;
// Read the error_info of main thread. if (had_error) {
AVxWorker *const worker = &workers[0];
error_info = ((AV1CdefWorkerData *)worker->data2)->error_info;
}
// Wait till all rows are finished. for (int i = num_workers - 1; i > 0; --i) {
AVxWorker *const worker = &workers[i]; if (!winterface->sync(worker)) {
had_error = 1;
error_info = ((AV1CdefWorkerData *)worker->data2)->error_info;
}
} if (had_error) aom_internal_error_copy(cm->error, &error_info);
}
// Updates the row index of the next job to be processed. // Also updates end_of_frame flag when the processing of all rows is complete. staticvoid update_cdef_row_next_job_info(AV1CdefSync *const cdef_sync, constint nvfb) {
cdef_sync->fbr++; if (cdef_sync->fbr == nvfb) {
cdef_sync->end_of_frame = 1;
}
}
// Checks if a job is available. If job is available, // populates next job information and returns 1, else returns 0. staticinlineint get_cdef_row_next_job(AV1CdefSync *const cdef_sync, volatileint *cur_fbr, constint nvfb) { #if CONFIG_MULTITHREAD
pthread_mutex_lock(cdef_sync->mutex_); #endif// CONFIG_MULTITHREAD int do_next_row = 0; // Populates information needed for current job and update the row // index of the next row to be processed. if (!cdef_sync->cdef_mt_exit && cdef_sync->end_of_frame == 0) {
do_next_row = 1;
*cur_fbr = cdef_sync->fbr;
update_cdef_row_next_job_info(cdef_sync, nvfb);
} #if CONFIG_MULTITHREAD
pthread_mutex_unlock(cdef_sync->mutex_); #endif// CONFIG_MULTITHREAD return do_next_row;
}
staticvoid set_cdef_init_fb_row_done(AV1CdefSync *const cdef_sync, int nvfb) { for (int fbr = 0; fbr < nvfb; fbr++) cdef_row_mt_sync_write(cdef_sync, fbr);
}
// The jmp_buf is valid only for the duration of the function that calls // setjmp(). Therefore, this function must reset the 'setjmp' field to 0 // before it returns. if (setjmp(error_info->jmp)) {
error_info->setjmp = 0; #if CONFIG_MULTITHREAD
pthread_mutex_lock(job_mutex_);
cdef_sync->cdef_mt_exit = true;
pthread_mutex_unlock(job_mutex_); #endif // In case of cdef row-multithreading, the worker on a filter block row // (fbr) waits for the line buffers (top and bottom) copy of the above row. // Hence, in case a thread (main/worker) encounters an error before copying // of the line buffers, update that line buffer copy is complete in order to // avoid dependent workers waiting indefinitely.
set_cdef_init_fb_row_done(cdef_sync, nvfb); return 0;
}
error_info->setjmp = 1;
// Assigns CDEF hook function and thread data to each worker. staticvoid prepare_cdef_frame_workers(
AV1_COMMON *const cm, MACROBLOCKD *xd, AV1CdefWorkerData *const cdef_worker,
AVxWorkerHook hook, AVxWorker *const workers, AV1CdefSync *const cdef_sync, int num_workers, cdef_init_fb_row_t cdef_init_fb_row_fn, int do_extend_border) { constint num_planes = av1_num_planes(cm);
// for the current filter block, it's top left corner mi structure (mi_tl) // is first accessed to check whether the top and left boundaries are // frame boundaries. Then bottom-left and top-right mi structures are // accessed to check whether the bottom and right boundaries // (respectively) are frame boundaries. // // Note that we can't just check the bottom-right mi structure - eg. if // we're at the right-hand edge of the frame but not the bottom, then // the bottom-right mi is NULL but the bottom-left is not.
fb_info->frame_boundary[TOP] = (MI_SIZE_64X64 * fbr == 0) ? 1 : 0; if (fbr != nvfb - 1)
fb_info->frame_boundary[BOTTOM] =
(MI_SIZE_64X64 * (fbr + 1) == cm->mi_params.mi_rows) ? 1 : 0; else
fb_info->frame_boundary[BOTTOM] = 1;
int av1_get_intrabc_extra_top_right_sb_delay(const AV1_COMMON *cm) { // No additional top-right delay when intraBC tool is not enabled. if (!av1_allow_intrabc(cm)) return 0; // Due to the hardware constraints on processing the intraBC tool with row // multithreading, a top-right delay of 3 superblocks of size 128x128 or 5 // superblocks of size 64x64 is mandated. However, a minimum top-right delay // of 1 superblock is assured with 'sync_range'. Hence return only the // additional superblock delay when the intraBC tool is enabled. return cm->seq_params->sb_size == BLOCK_128X128 ? 2 : 4;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.55 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.