Commit f857a850 authored by Yunqing Wang's avatar Yunqing Wang

Restructure multi-threaded decoder

On each MB, loopfiltering is done right after MB decoding. This
combines two loops in multi-threaded code into one, which reduces
number of synchronizations to half.

The above-row/left-col data are saved in temp buffers for
next-row/next MB decoding.

Tests on 4-core gLucid machine showed 10% decoder performance
gain with threads=4 (tulip clip). Testing on other platforms
isn't done yet.

Change-Id: Id18ea7c1e84965dabea65d4c01ca5bc056ddeac9
parent 9100073e
This diff is collapsed.
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef __INC_RECONINTRA_MT_H
#define __INC_RECONINTRA_MT_H
// reconintra functions used in multi-threaded decoder
#if CONFIG_MULTITHREAD
extern void vp8mt_build_intra_predictors_mby(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col);
extern void vp8mt_build_intra_predictors_mby_s(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col);
extern void vp8mt_build_intra_predictors_mbuv(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col);
extern void vp8mt_build_intra_predictors_mbuv_s(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col);
extern void vp8mt_predict_intra4x4(VP8D_COMP *pbi, MACROBLOCKD *x, int b_mode, unsigned char *predictor, int mb_row, int mb_col, int num);
extern void vp8mt_intra_prediction_down_copy(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col);
#endif
#endif
......@@ -15,12 +15,12 @@
#ifndef _DECODER_THREADING_H
#define _DECODER_THREADING_H
extern void vp8_mtdecode_mb_rows(VP8D_COMP *pbi,
MACROBLOCKD *xd);
extern void vp8_mt_loop_filter_frame(VP8D_COMP *pbi);
extern void vp8_stop_lfthread(VP8D_COMP *pbi);
extern void vp8_start_lfthread(VP8D_COMP *pbi);
#if CONFIG_MULTITHREAD
extern void vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd);
extern void vp8_decoder_remove_threads(VP8D_COMP *pbi);
extern void vp8_decoder_create_threads(VP8D_COMP *pbi);
extern int vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows);
extern void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows);
#endif
#endif
......@@ -21,7 +21,8 @@
#include "alloccommon.h"
#include "entropymode.h"
#include "quant_common.h"
#include "vpx_scale/vpxscale.h"
#include "vpx_scale/yv12extend.h"
#include "setupintrarecon.h"
#include "decodemv.h"
......@@ -64,7 +65,7 @@ void vp8cx_init_de_quantizer(VP8D_COMP *pbi)
}
}
static void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd)
void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd)
{
int i;
int QIndex;
......@@ -158,7 +159,7 @@ static void clamp_uvmv_to_umv_border(MV *mv, const MACROBLOCKD *xd)
mv->row = (2*mv->row > xd->mb_to_bottom_edge + (18 << 3)) ? (xd->mb_to_bottom_edge + (16 << 3)) >> 1 : mv->row;
}
static void clamp_mvs(MACROBLOCKD *xd)
void clamp_mvs(MACROBLOCKD *xd)
{
if (xd->mode_info_context->mbmi.mode == SPLITMV)
{
......@@ -294,6 +295,7 @@ void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd)
xd->dst.uv_stride, xd->eobs+16);
}
static int get_delta_q(vp8_reader *bc, int prev, int *q_update)
{
int ret_val = 0;
......@@ -398,7 +400,6 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
xd->above_context++;
pbi->current_mb_col_main = mb_col;
}
// adjust to the next row of mbs
......@@ -408,8 +409,6 @@ void vp8_decode_mb_row(VP8D_COMP *pbi,
);
++xd->mode_info_context; /* skip prediction column */
pbi->last_mb_row_decoded = mb_row;
}
......@@ -601,6 +600,8 @@ int vp8_decode_frame(VP8D_COMP *pbi)
if (Width != pc->Width || Height != pc->Height)
{
int prev_mb_rows = pc->mb_rows;
if (pc->Width <= 0)
{
pc->Width = Width;
......@@ -618,6 +619,11 @@ int vp8_decode_frame(VP8D_COMP *pbi)
if (vp8_alloc_frame_buffers(pc, pc->Width, pc->Height))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate frame buffers");
#if CONFIG_MULTITHREAD
if (pbi->b_multithreaded_rd)
vp8mt_alloc_temp_buffers(pbi, pc->Width, prev_mb_rows);
#endif
}
}
......@@ -822,7 +828,8 @@ int vp8_decode_frame(VP8D_COMP *pbi)
vpx_memcpy(&xd->dst, &pc->yv12_fb[pc->new_fb_idx], sizeof(YV12_BUFFER_CONFIG));
// set up frame new frame for intra coded blocks
vp8_setup_intra_recon(&pc->yv12_fb[pc->new_fb_idx]);
if (!(pbi->b_multithreaded_rd) || pc->multi_token_partition == ONE_PARTITION || !(pc->filter_level))
vp8_setup_intra_recon(&pc->yv12_fb[pc->new_fb_idx]);
vp8_setup_block_dptrs(xd);
......@@ -841,13 +848,18 @@ int vp8_decode_frame(VP8D_COMP *pbi)
vpx_memcpy(&xd->block[0].bmi, &xd->mode_info_context->bmi[0], sizeof(B_MODE_INFO));
if (pbi->b_multithreaded_lf && pc->filter_level != 0)
vp8_start_lfthread(pbi);
if (pbi->b_multithreaded_rd && pc->multi_token_partition != ONE_PARTITION)
{
vp8_mtdecode_mb_rows(pbi, xd);
vp8mt_decode_mb_rows(pbi, xd);
if(pbi->common.filter_level)
{
//vp8_mt_loop_filter_frame(pbi); //cm, &pbi->mb, cm->filter_level);
pc->last_frame_type = pc->frame_type;
pc->last_filter_type = pc->filter_type;
pc->last_sharpness_level = pc->sharpness_level;
}
vp8_yv12_extend_frame_borders_ptr(&pc->yv12_fb[pc->new_fb_idx]); //cm->frame_to_show);
}
else
{
......@@ -869,8 +881,6 @@ int vp8_decode_frame(VP8D_COMP *pbi)
vp8_decode_mb_row(pbi, pc, mb_row, xd);
}
pbi->last_mb_row_decoded = mb_row;
}
......
......@@ -142,6 +142,10 @@ void vp8dx_remove_decompressor(VP8D_PTR ptr)
if (!pbi)
return;
#if CONFIG_MULTITHREAD
if (pbi->b_multithreaded_rd)
vp8mt_de_alloc_temp_buffers(pbi, pbi->common.mb_rows);
#endif
vp8_decoder_remove_threads(pbi);
vp8_remove_common(&pbi->common);
vpx_free(pbi);
......@@ -355,67 +359,41 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
return retcode;
}
if (pbi->b_multithreaded_lf && pbi->common.filter_level != 0)
vp8_stop_lfthread(pbi);
if (swap_frame_buffers (cm))
if (pbi->b_multithreaded_rd && cm->multi_token_partition != ONE_PARTITION)
{
pbi->common.error.error_code = VPX_CODEC_ERROR;
pbi->common.error.setjmp = 0;
return -1;
}
/*
if (!pbi->b_multithreaded_lf)
if (swap_frame_buffers (cm))
{
pbi->common.error.error_code = VPX_CODEC_ERROR;
pbi->common.error.setjmp = 0;
return -1;
}
} else
{
struct vpx_usec_timer lpftimer;
vpx_usec_timer_start(&lpftimer);
// Apply the loop filter if appropriate.
if (cm->filter_level > 0)
vp8_loop_filter_frame(cm, &pbi->mb, cm->filter_level);
vpx_usec_timer_mark(&lpftimer);
pbi->time_loop_filtering += vpx_usec_timer_elapsed(&lpftimer);
}else{
struct vpx_usec_timer lpftimer;
vpx_usec_timer_start(&lpftimer);
// Apply the loop filter if appropriate.
if (cm->filter_level > 0)
vp8_mt_loop_filter_frame(cm, &pbi->mb, cm->filter_level);
vpx_usec_timer_mark(&lpftimer);
pbi->time_loop_filtering += vpx_usec_timer_elapsed(&lpftimer);
}
if (cm->filter_level > 0) {
cm->last_frame_type = cm->frame_type;
cm->last_filter_type = cm->filter_type;
cm->last_sharpness_level = cm->sharpness_level;
}
*/
if (swap_frame_buffers (cm))
{
pbi->common.error.error_code = VPX_CODEC_ERROR;
pbi->common.error.setjmp = 0;
return -1;
}
if(pbi->common.filter_level)
{
struct vpx_usec_timer lpftimer;
vpx_usec_timer_start(&lpftimer);
// Apply the loop filter if appropriate.
if(pbi->common.filter_level)
{
struct vpx_usec_timer lpftimer;
vpx_usec_timer_start(&lpftimer);
// Apply the loop filter if appropriate.
if (pbi->b_multithreaded_lf && cm->multi_token_partition != ONE_PARTITION)
vp8_mt_loop_filter_frame(pbi); //cm, &pbi->mb, cm->filter_level);
else
vp8_loop_filter_frame(cm, &pbi->mb, cm->filter_level);
vpx_usec_timer_mark(&lpftimer);
pbi->time_loop_filtering += vpx_usec_timer_elapsed(&lpftimer);
vpx_usec_timer_mark(&lpftimer);
pbi->time_loop_filtering += vpx_usec_timer_elapsed(&lpftimer);
cm->last_frame_type = cm->frame_type;
cm->last_filter_type = cm->filter_type;
cm->last_sharpness_level = cm->sharpness_level;
cm->last_frame_type = cm->frame_type;
cm->last_filter_type = cm->filter_type;
cm->last_sharpness_level = cm->sharpness_level;
}
vp8_yv12_extend_frame_borders_ptr(cm->frame_to_show);
}
vp8_yv12_extend_frame_borders_ptr(cm->frame_to_show);
#if 0
// DEBUG code
//vp8_recon_write_yuv_frame("recon.yuv", cm->frame_to_show);
......
......@@ -88,30 +88,32 @@ typedef struct VP8Decompressor
unsigned int time_loop_filtering;
volatile int b_multithreaded_rd;
volatile int b_multithreaded_lf;
int max_threads;
int last_mb_row_decoded;
int current_mb_col_main;
int decoding_thread_count;
int allocated_decoding_thread_count;
int *current_mb_col; //Each row remembers its already decoded column.
int mt_baseline_filter_level[MAX_MB_SEGMENTS];
// variable for threading
DECLARE_ALIGNED(16, MACROBLOCKD, lpfmb);
#if CONFIG_MULTITHREAD
//pthread_t h_thread_lpf; // thread for postprocessing
sem_t h_event_end_lpf; // Event for post_proc completed
sem_t *h_event_start_lpf;
#endif
int mt_baseline_filter_level[MAX_MB_SEGMENTS];
int *mt_current_mb_col; // Each row remembers its already decoded column.
unsigned char **mt_yabove_row; // mb_rows x width
unsigned char **mt_uabove_row;
unsigned char **mt_vabove_row;
unsigned char **mt_yleft_col; // mb_rows x 16
unsigned char **mt_uleft_col; // mb_rows x 8
unsigned char **mt_vleft_col; // mb_rows x 8
MB_ROW_DEC *mb_row_di;
DECODETHREAD_DATA *de_thread_data;
#if CONFIG_MULTITHREAD
DECODETHREAD_DATA *de_thread_data;
pthread_t *h_decoding_thread;
sem_t *h_event_start_decoding;
sem_t h_event_end_decoding;
sem_t h_event_end_decoding;
// end of threading data
#endif
vp8_reader *mbc;
INT64 last_time_stamp;
int ready_for_new_data;
......
This diff is collapsed.
......@@ -81,6 +81,8 @@ VP8_COMMON_SRCS-yes += common/recon.c
VP8_COMMON_SRCS-yes += common/reconinter.c
VP8_COMMON_SRCS-yes += common/reconintra.c
VP8_COMMON_SRCS-yes += common/reconintra4x4.c
VP8_COMMON_SRCS-yes += common/reconintra_mt.h
VP8_COMMON_SRCS-yes += common/reconintra_mt.c
VP8_COMMON_SRCS-yes += common/setupintrarecon.c
VP8_COMMON_SRCS-yes += common/swapyv12buffer.c
VP8_COMMON_SRCS-yes += common/textblit.c
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment