From ae7d3ef39f4a3b851fc0f9b72790913899a94094 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalev Date: Mon, 12 May 2014 16:19:19 -0700 Subject: [PATCH] Moving loopfilter call to vp9_decode_frame(). Inline loopfilter has been already handled in vp9_decode_frame(). Collecting all similar code in one place now. Change-Id: I358a0280fc7c2b27cca520bc1e8c16c4eb6491dd --- vp9/common/vp9_loopfilter.c | 5 +++-- vp9/common/vp9_loopfilter.h | 3 ++- vp9/decoder/vp9_decodeframe.c | 33 +++++++++++++++++++++++---------- vp9/decoder/vp9_decoder.c | 10 ---------- vp9/decoder/vp9_decoder.h | 1 - vp9/decoder/vp9_dthread.c | 6 +++--- vp9/decoder/vp9_dthread.h | 3 ++- vp9/encoder/vp9_encoder.c | 2 +- vp9/encoder/vp9_picklpf.c | 3 ++- 9 files changed, 36 insertions(+), 30 deletions(-) diff --git a/vp9/common/vp9_loopfilter.c b/vp9/common/vp9_loopfilter.c index 3ac5a0577..5b43e233b 100644 --- a/vp9/common/vp9_loopfilter.c +++ b/vp9/common/vp9_loopfilter.c @@ -1224,7 +1224,8 @@ void vp9_loop_filter_rows(const YV12_BUFFER_CONFIG *frame_buffer, } } -void vp9_loop_filter_frame(VP9_COMMON *cm, MACROBLOCKD *xd, +void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame, + VP9_COMMON *cm, MACROBLOCKD *xd, int frame_filter_level, int y_only, int partial_frame) { int start_mi_row, end_mi_row, mi_rows_to_filter; @@ -1238,7 +1239,7 @@ void vp9_loop_filter_frame(VP9_COMMON *cm, MACROBLOCKD *xd, } end_mi_row = start_mi_row + mi_rows_to_filter; vp9_loop_filter_frame_init(cm, frame_filter_level); - vp9_loop_filter_rows(cm->frame_to_show, cm, xd, + vp9_loop_filter_rows(frame, cm, xd, start_mi_row, end_mi_row, y_only); } diff --git a/vp9/common/vp9_loopfilter.h b/vp9/common/vp9_loopfilter.h index 97ae9d22d..83463c544 100644 --- a/vp9/common/vp9_loopfilter.h +++ b/vp9/common/vp9_loopfilter.h @@ -104,7 +104,8 @@ void vp9_loop_filter_init(struct VP9Common *cm); // calls this function directly. void vp9_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl); -void vp9_loop_filter_frame(struct VP9Common *cm, +void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame, + struct VP9Common *cm, struct macroblockd *mbd, int filter_level, int y_only, int partial_frame); diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c index 9dd0c4415..adfa07cbc 100644 --- a/vp9/decoder/vp9_decodeframe.c +++ b/vp9/decoder/vp9_decodeframe.c @@ -676,13 +676,13 @@ static void setup_frame_size_with_refs(VP9_COMMON *cm, } static void decode_tile(VP9Decoder *pbi, const TileInfo *const tile, - vp9_reader *r) { + int do_loopfilter_inline, vp9_reader *r) { const int num_threads = pbi->max_threads; VP9_COMMON *const cm = &pbi->common; int mi_row, mi_col; MACROBLOCKD *xd = &pbi->mb; - if (pbi->do_loopfilter_inline) { + if (do_loopfilter_inline) { LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; lf_data->frame_buffer = get_frame_new_buffer(cm); lf_data->cm = cm; @@ -702,7 +702,7 @@ static void decode_tile(VP9Decoder *pbi, const TileInfo *const tile, decode_partition(cm, xd, tile, mi_row, mi_col, r, BLOCK_64X64); } - if (pbi->do_loopfilter_inline) { + if (do_loopfilter_inline) { const int lf_start = mi_row - MI_BLOCK_SIZE; LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; @@ -723,7 +723,7 @@ static void decode_tile(VP9Decoder *pbi, const TileInfo *const tile, } } - if (pbi->do_loopfilter_inline) { + if (do_loopfilter_inline) { LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; vp9_worker_sync(&pbi->lf_worker); @@ -790,7 +790,8 @@ typedef struct TileBuffer { static const uint8_t *decode_tiles(VP9Decoder *pbi, const uint8_t *data, - const uint8_t *data_end) { + const uint8_t *data_end, + int do_loopfilter_inline) { VP9_COMMON *const cm = &pbi->common; const int aligned_cols = mi_cols_aligned_to_sb(cm->mi_cols); const int tile_cols = 1 << cm->log2_tile_cols; @@ -837,7 +838,7 @@ static const uint8_t *decode_tiles(VP9Decoder *pbi, vp9_tile_init(&tile, cm, tile_row, col); setup_token_decoder(buf->data, data_end, buf->size, &cm->error, &r, pbi->decrypt_cb, pbi->decrypt_state); - decode_tile(pbi, &tile, &r); + decode_tile(pbi, &tile, do_loopfilter_inline, &r); if (last_tile) end = vp9_reader_find_end(&r); @@ -1305,6 +1306,8 @@ int vp9_decode_frame(VP9Decoder *pbi, const int tile_rows = 1 << cm->log2_tile_rows; const int tile_cols = 1 << cm->log2_tile_cols; YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm); + const int do_loopfilter_inline = tile_rows == 1 && tile_cols == 1 && + cm->lf.filter_level; xd->cur_buf = new_fb; if (!first_partition_size) { @@ -1321,9 +1324,7 @@ int vp9_decode_frame(VP9Decoder *pbi, vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet or corrupt header length"); - pbi->do_loopfilter_inline = - (cm->log2_tile_rows | cm->log2_tile_cols) == 0 && cm->lf.filter_level; - if (pbi->do_loopfilter_inline && pbi->lf_worker.data1 == NULL) { + if (do_loopfilter_inline && pbi->lf_worker.data1 == NULL) { CHECK_MEM_ERROR(cm, pbi->lf_worker.data1, vpx_memalign(32, sizeof(LFWorkerData))); pbi->lf_worker.hook = (VP9WorkerHook)vp9_loop_filter_worker; @@ -1356,7 +1357,8 @@ int vp9_decode_frame(VP9Decoder *pbi, cm->frame_parallel_decoding_mode) { *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); } else { - *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); + *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end, + do_loopfilter_inline); } new_fb->corrupted |= xd->corrupted; @@ -1385,5 +1387,16 @@ int vp9_decode_frame(VP9Decoder *pbi, if (cm->refresh_frame_context) cm->frame_contexts[cm->frame_context_idx] = cm->fc; + // Loopfilter + if (!do_loopfilter_inline) { + // If multiple threads are used to decode tiles, then we use those threads + // to do parallel loopfiltering. + if (pbi->num_tile_workers) { + vp9_loop_filter_frame_mt(new_fb, pbi, cm, cm->lf.filter_level, 0, 0); + } else { + vp9_loop_filter_frame(new_fb, cm, &pbi->mb, cm->lf.filter_level, 0, 0); + } + } + return 0; } diff --git a/vp9/decoder/vp9_decoder.c b/vp9/decoder/vp9_decoder.c index 8f72aa48f..6f310c765 100644 --- a/vp9/decoder/vp9_decoder.c +++ b/vp9/decoder/vp9_decoder.c @@ -279,16 +279,6 @@ int vp9_receive_compressed_data(VP9Decoder *pbi, swap_frame_buffers(pbi); - if (!pbi->do_loopfilter_inline) { - // If multiple threads are used to decode tiles, then we use those threads - // to do parallel loopfiltering. - if (pbi->num_tile_workers) { - vp9_loop_filter_frame_mt(pbi, cm, cm->lf.filter_level, 0, 0); - } else { - vp9_loop_filter_frame(cm, &pbi->mb, cm->lf.filter_level, 0, 0); - } - } - vp9_clear_system_state(); cm->last_width = cm->width; diff --git a/vp9/decoder/vp9_decoder.h b/vp9/decoder/vp9_decoder.h index 66b0f15f9..d6110c47e 100644 --- a/vp9/decoder/vp9_decoder.h +++ b/vp9/decoder/vp9_decoder.h @@ -39,7 +39,6 @@ typedef struct VP9Decoder { int decoded_key_frame; - int do_loopfilter_inline; // apply loopfilter to available rows immediately VP9Worker lf_worker; VP9Worker *tile_workers; diff --git a/vp9/decoder/vp9_dthread.c b/vp9/decoder/vp9_dthread.c index 019b0ffe8..5fe5ed79a 100644 --- a/vp9/decoder/vp9_dthread.c +++ b/vp9/decoder/vp9_dthread.c @@ -132,8 +132,8 @@ static int loop_filter_row_worker(void *arg1, void *arg2) { // VP9 decoder: Implement multi-threaded loopfilter that uses the tile // threads. -void vp9_loop_filter_frame_mt(VP9Decoder *pbi, - VP9_COMMON *cm, +void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, + VP9Decoder *pbi, VP9_COMMON *cm, int frame_filter_level, int y_only, int partial_frame) { VP9LfSync *const lf_sync = &pbi->lf_row_sync; @@ -184,7 +184,7 @@ void vp9_loop_filter_frame_mt(VP9Decoder *pbi, worker->hook = (VP9WorkerHook)loop_filter_row_worker; // Loopfilter data - lf_data->frame_buffer = get_frame_new_buffer(cm); + lf_data->frame_buffer = frame; lf_data->cm = cm; lf_data->xd = pbi->mb; lf_data->start = i; diff --git a/vp9/decoder/vp9_dthread.h b/vp9/decoder/vp9_dthread.h index 8738ceebd..c3b7a293b 100644 --- a/vp9/decoder/vp9_dthread.h +++ b/vp9/decoder/vp9_dthread.h @@ -48,7 +48,8 @@ void vp9_loop_filter_alloc(struct VP9Common *cm, VP9LfSync *lf_sync, void vp9_loop_filter_dealloc(VP9LfSync *lf_sync, int rows); // Multi-threaded loopfilter that uses the tile threads. -void vp9_loop_filter_frame_mt(struct VP9Decoder *pbi, +void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, + struct VP9Decoder *pbi, struct VP9Common *cm, int frame_filter_level, int y_only, int partial_frame); diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index cc2c552a7..678c31eb0 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -1617,7 +1617,7 @@ static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { } if (lf->filter_level > 0) { - vp9_loop_filter_frame(cm, xd, lf->filter_level, 0, 0); + vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); } vp9_extend_frame_inner_borders(cm->frame_to_show); diff --git a/vp9/encoder/vp9_picklpf.c b/vp9/encoder/vp9_picklpf.c index a4b280c53..53284656e 100644 --- a/vp9/encoder/vp9_picklpf.c +++ b/vp9/encoder/vp9_picklpf.c @@ -38,7 +38,8 @@ static int try_filter_frame(const YV12_BUFFER_CONFIG *sd, VP9_COMP *const cpi, VP9_COMMON *const cm = &cpi->common; int filt_err; - vp9_loop_filter_frame(cm, &cpi->mb.e_mbd, filt_level, 1, partial_frame); + vp9_loop_filter_frame(cm->frame_to_show, cm, &cpi->mb.e_mbd, filt_level, 1, + partial_frame); filt_err = vp9_get_y_sse(sd, cm->frame_to_show); // Re-instate the unfiltered frame -- 2.40.0