--- /dev/null
+/*
+ * 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.
+ */
+
+
+#include "vpx_ports/config.h"
+#include "recon.h"
+#include "reconintra.h"
+#include "vpx_mem/vpx_mem.h"
+#include "onyxd_int.h"
+
+// For skip_recon_mb(), add vp8_build_intra_predictors_mby_s(MACROBLOCKD *x) and
+// vp8_build_intra_predictors_mbuv_s(MACROBLOCKD *x).
+
+void vp8mt_build_intra_predictors_mby(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col)
+{
+#if CONFIG_MULTITHREAD
+ unsigned char *yabove_row; // = x->dst.y_buffer - x->dst.y_stride;
+ unsigned char *yleft_col;
+ unsigned char yleft_buf[16];
+ unsigned char ytop_left; // = yabove_row[-1];
+ unsigned char *ypred_ptr = x->predictor;
+ int r, c, i;
+
+ if (pbi->common.filter_level)
+ {
+ yabove_row = pbi->mt_yabove_row[mb_row] + mb_col*16 +32;
+ yleft_col = pbi->mt_yleft_col[mb_row];
+ } else
+ {
+ yabove_row = x->dst.y_buffer - x->dst.y_stride;
+
+ for (i = 0; i < 16; i++)
+ yleft_buf[i] = x->dst.y_buffer [i* x->dst.y_stride -1];
+ yleft_col = yleft_buf;
+ }
+
+ ytop_left = yabove_row[-1];
+
+ // for Y
+ switch (x->mode_info_context->mbmi.mode)
+ {
+ case DC_PRED:
+ {
+ int expected_dc;
+ int i;
+ int shift;
+ int average = 0;
+
+
+ if (x->up_available || x->left_available)
+ {
+ if (x->up_available)
+ {
+ for (i = 0; i < 16; i++)
+ {
+ average += yabove_row[i];
+ }
+ }
+
+ if (x->left_available)
+ {
+
+ for (i = 0; i < 16; i++)
+ {
+ average += yleft_col[i];
+ }
+
+ }
+
+
+
+ shift = 3 + x->up_available + x->left_available;
+ expected_dc = (average + (1 << (shift - 1))) >> shift;
+ }
+ else
+ {
+ expected_dc = 128;
+ }
+
+ vpx_memset(ypred_ptr, expected_dc, 256);
+ }
+ break;
+ case V_PRED:
+ {
+
+ for (r = 0; r < 16; r++)
+ {
+
+ ((int *)ypred_ptr)[0] = ((int *)yabove_row)[0];
+ ((int *)ypred_ptr)[1] = ((int *)yabove_row)[1];
+ ((int *)ypred_ptr)[2] = ((int *)yabove_row)[2];
+ ((int *)ypred_ptr)[3] = ((int *)yabove_row)[3];
+ ypred_ptr += 16;
+ }
+ }
+ break;
+ case H_PRED:
+ {
+
+ for (r = 0; r < 16; r++)
+ {
+
+ vpx_memset(ypred_ptr, yleft_col[r], 16);
+ ypred_ptr += 16;
+ }
+
+ }
+ break;
+ case TM_PRED:
+ {
+
+ for (r = 0; r < 16; r++)
+ {
+ for (c = 0; c < 16; c++)
+ {
+ int pred = yleft_col[r] + yabove_row[ c] - ytop_left;
+
+ if (pred < 0)
+ pred = 0;
+
+ if (pred > 255)
+ pred = 255;
+
+ ypred_ptr[c] = pred;
+ }
+
+ ypred_ptr += 16;
+ }
+
+ }
+ break;
+ case B_PRED:
+ case NEARESTMV:
+ case NEARMV:
+ case ZEROMV:
+ case NEWMV:
+ case SPLITMV:
+ case MB_MODE_COUNT:
+ break;
+ }
+#else
+ (void) pbi;
+ (void) x;
+ (void) mb_row;
+ (void) mb_col;
+#endif
+}
+
+void vp8mt_build_intra_predictors_mby_s(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col)
+{
+#if CONFIG_MULTITHREAD
+ unsigned char *yabove_row; // = x->dst.y_buffer - x->dst.y_stride;
+ unsigned char *yleft_col;
+ unsigned char yleft_buf[16];
+ unsigned char ytop_left; // = yabove_row[-1];
+ unsigned char *ypred_ptr = x->predictor;
+ int r, c, i;
+
+ int y_stride = x->dst.y_stride;
+ ypred_ptr = x->dst.y_buffer; //x->predictor;
+
+ if (pbi->common.filter_level)
+ {
+ yabove_row = pbi->mt_yabove_row[mb_row] + mb_col*16 +32;
+ yleft_col = pbi->mt_yleft_col[mb_row];
+ } else
+ {
+ yabove_row = x->dst.y_buffer - x->dst.y_stride;
+
+ for (i = 0; i < 16; i++)
+ yleft_buf[i] = x->dst.y_buffer [i* x->dst.y_stride -1];
+ yleft_col = yleft_buf;
+ }
+
+ ytop_left = yabove_row[-1];
+
+ // for Y
+ switch (x->mode_info_context->mbmi.mode)
+ {
+ case DC_PRED:
+ {
+ int expected_dc;
+ int i;
+ int shift;
+ int average = 0;
+
+
+ if (x->up_available || x->left_available)
+ {
+ if (x->up_available)
+ {
+ for (i = 0; i < 16; i++)
+ {
+ average += yabove_row[i];
+ }
+ }
+
+ if (x->left_available)
+ {
+
+ for (i = 0; i < 16; i++)
+ {
+ average += yleft_col[i];
+ }
+
+ }
+
+
+
+ shift = 3 + x->up_available + x->left_available;
+ expected_dc = (average + (1 << (shift - 1))) >> shift;
+ }
+ else
+ {
+ expected_dc = 128;
+ }
+
+ //vpx_memset(ypred_ptr, expected_dc, 256);
+ for (r = 0; r < 16; r++)
+ {
+ vpx_memset(ypred_ptr, expected_dc, 16);
+ ypred_ptr += y_stride; //16;
+ }
+ }
+ break;
+ case V_PRED:
+ {
+
+ for (r = 0; r < 16; r++)
+ {
+
+ ((int *)ypred_ptr)[0] = ((int *)yabove_row)[0];
+ ((int *)ypred_ptr)[1] = ((int *)yabove_row)[1];
+ ((int *)ypred_ptr)[2] = ((int *)yabove_row)[2];
+ ((int *)ypred_ptr)[3] = ((int *)yabove_row)[3];
+ ypred_ptr += y_stride; //16;
+ }
+ }
+ break;
+ case H_PRED:
+ {
+
+ for (r = 0; r < 16; r++)
+ {
+
+ vpx_memset(ypred_ptr, yleft_col[r], 16);
+ ypred_ptr += y_stride; //16;
+ }
+
+ }
+ break;
+ case TM_PRED:
+ {
+
+ for (r = 0; r < 16; r++)
+ {
+ for (c = 0; c < 16; c++)
+ {
+ int pred = yleft_col[r] + yabove_row[ c] - ytop_left;
+
+ if (pred < 0)
+ pred = 0;
+
+ if (pred > 255)
+ pred = 255;
+
+ ypred_ptr[c] = pred;
+ }
+
+ ypred_ptr += y_stride; //16;
+ }
+
+ }
+ break;
+ case B_PRED:
+ case NEARESTMV:
+ case NEARMV:
+ case ZEROMV:
+ case NEWMV:
+ case SPLITMV:
+ case MB_MODE_COUNT:
+ break;
+ }
+#else
+ (void) pbi;
+ (void) x;
+ (void) mb_row;
+ (void) mb_col;
+#endif
+}
+
+void vp8mt_build_intra_predictors_mbuv(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col)
+{
+#if CONFIG_MULTITHREAD
+ unsigned char *uabove_row; // = x->dst.u_buffer - x->dst.uv_stride;
+ unsigned char *uleft_col; //[16];
+ unsigned char uleft_buf[8];
+ unsigned char utop_left; // = uabove_row[-1];
+ unsigned char *vabove_row; // = x->dst.v_buffer - x->dst.uv_stride;
+ unsigned char *vleft_col; //[20];
+ unsigned char vleft_buf[8];
+ unsigned char vtop_left; // = vabove_row[-1];
+ unsigned char *upred_ptr = &x->predictor[256];
+ unsigned char *vpred_ptr = &x->predictor[320];
+ int i, j;
+
+ if (pbi->common.filter_level)
+ {
+ uabove_row = pbi->mt_uabove_row[mb_row] + mb_col*8 +16;
+ vabove_row = pbi->mt_vabove_row[mb_row] + mb_col*8 +16;
+ uleft_col = pbi->mt_uleft_col[mb_row];
+ vleft_col = pbi->mt_vleft_col[mb_row];
+ } else
+ {
+ uabove_row = x->dst.u_buffer - x->dst.uv_stride;
+ vabove_row = x->dst.v_buffer - x->dst.uv_stride;
+
+ for (i = 0; i < 8; i++)
+ {
+ uleft_buf[i] = x->dst.u_buffer [i* x->dst.uv_stride -1];
+ vleft_buf[i] = x->dst.v_buffer [i* x->dst.uv_stride -1];
+ }
+ uleft_col = uleft_buf;
+ vleft_col = vleft_buf;
+ }
+ utop_left = uabove_row[-1];
+ vtop_left = vabove_row[-1];
+
+ switch (x->mode_info_context->mbmi.uv_mode)
+ {
+ case DC_PRED:
+ {
+ int expected_udc;
+ int expected_vdc;
+ int i;
+ int shift;
+ int Uaverage = 0;
+ int Vaverage = 0;
+
+ if (x->up_available)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ Uaverage += uabove_row[i];
+ Vaverage += vabove_row[i];
+ }
+ }
+
+ if (x->left_available)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ Uaverage += uleft_col[i];
+ Vaverage += vleft_col[i];
+ }
+ }
+
+ if (!x->up_available && !x->left_available)
+ {
+ expected_udc = 128;
+ expected_vdc = 128;
+ }
+ else
+ {
+ shift = 2 + x->up_available + x->left_available;
+ expected_udc = (Uaverage + (1 << (shift - 1))) >> shift;
+ expected_vdc = (Vaverage + (1 << (shift - 1))) >> shift;
+ }
+
+
+ vpx_memset(upred_ptr, expected_udc, 64);
+ vpx_memset(vpred_ptr, expected_vdc, 64);
+
+
+ }
+ break;
+ case V_PRED:
+ {
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ vpx_memcpy(upred_ptr, uabove_row, 8);
+ vpx_memcpy(vpred_ptr, vabove_row, 8);
+ upred_ptr += 8;
+ vpred_ptr += 8;
+ }
+
+ }
+ break;
+ case H_PRED:
+ {
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ vpx_memset(upred_ptr, uleft_col[i], 8);
+ vpx_memset(vpred_ptr, vleft_col[i], 8);
+ upred_ptr += 8;
+ vpred_ptr += 8;
+ }
+ }
+
+ break;
+ case TM_PRED:
+ {
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+ int predu = uleft_col[i] + uabove_row[j] - utop_left;
+ int predv = vleft_col[i] + vabove_row[j] - vtop_left;
+
+ if (predu < 0)
+ predu = 0;
+
+ if (predu > 255)
+ predu = 255;
+
+ if (predv < 0)
+ predv = 0;
+
+ if (predv > 255)
+ predv = 255;
+
+ upred_ptr[j] = predu;
+ vpred_ptr[j] = predv;
+ }
+
+ upred_ptr += 8;
+ vpred_ptr += 8;
+ }
+
+ }
+ break;
+ case B_PRED:
+ case NEARESTMV:
+ case NEARMV:
+ case ZEROMV:
+ case NEWMV:
+ case SPLITMV:
+ case MB_MODE_COUNT:
+ break;
+ }
+#else
+ (void) pbi;
+ (void) x;
+ (void) mb_row;
+ (void) mb_col;
+#endif
+}
+
+void vp8mt_build_intra_predictors_mbuv_s(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col)
+{
+#if CONFIG_MULTITHREAD
+ unsigned char *uabove_row; // = x->dst.u_buffer - x->dst.uv_stride;
+ unsigned char *uleft_col; //[16];
+ unsigned char uleft_buf[8];
+ unsigned char utop_left; // = uabove_row[-1];
+ unsigned char *vabove_row; // = x->dst.v_buffer - x->dst.uv_stride;
+ unsigned char *vleft_col; //[20];
+ unsigned char vleft_buf[8];
+ unsigned char vtop_left; // = vabove_row[-1];
+ unsigned char *upred_ptr = x->dst.u_buffer; //&x->predictor[256];
+ unsigned char *vpred_ptr = x->dst.v_buffer; //&x->predictor[320];
+ int uv_stride = x->dst.uv_stride;
+ int i, j;
+
+ if (pbi->common.filter_level)
+ {
+ uabove_row = pbi->mt_uabove_row[mb_row] + mb_col*8 +16;
+ vabove_row = pbi->mt_vabove_row[mb_row] + mb_col*8 +16;
+ uleft_col = pbi->mt_uleft_col[mb_row];
+ vleft_col = pbi->mt_vleft_col[mb_row];
+ } else
+ {
+ uabove_row = x->dst.u_buffer - x->dst.uv_stride;
+ vabove_row = x->dst.v_buffer - x->dst.uv_stride;
+
+ for (i = 0; i < 8; i++)
+ {
+ uleft_buf[i] = x->dst.u_buffer [i* x->dst.uv_stride -1];
+ vleft_buf[i] = x->dst.v_buffer [i* x->dst.uv_stride -1];
+ }
+ uleft_col = uleft_buf;
+ vleft_col = vleft_buf;
+ }
+ utop_left = uabove_row[-1];
+ vtop_left = vabove_row[-1];
+
+ switch (x->mode_info_context->mbmi.uv_mode)
+ {
+ case DC_PRED:
+ {
+ int expected_udc;
+ int expected_vdc;
+ int i;
+ int shift;
+ int Uaverage = 0;
+ int Vaverage = 0;
+
+ if (x->up_available)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ Uaverage += uabove_row[i];
+ Vaverage += vabove_row[i];
+ }
+ }
+
+ if (x->left_available)
+ {
+ for (i = 0; i < 8; i++)
+ {
+ Uaverage += uleft_col[i];
+ Vaverage += vleft_col[i];
+ }
+ }
+
+ if (!x->up_available && !x->left_available)
+ {
+ expected_udc = 128;
+ expected_vdc = 128;
+ }
+ else
+ {
+ shift = 2 + x->up_available + x->left_available;
+ expected_udc = (Uaverage + (1 << (shift - 1))) >> shift;
+ expected_vdc = (Vaverage + (1 << (shift - 1))) >> shift;
+ }
+
+
+ //vpx_memset(upred_ptr,expected_udc,64);
+ //vpx_memset(vpred_ptr,expected_vdc,64);
+ for (i = 0; i < 8; i++)
+ {
+ vpx_memset(upred_ptr, expected_udc, 8);
+ vpx_memset(vpred_ptr, expected_vdc, 8);
+ upred_ptr += uv_stride; //8;
+ vpred_ptr += uv_stride; //8;
+ }
+ }
+ break;
+ case V_PRED:
+ {
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ vpx_memcpy(upred_ptr, uabove_row, 8);
+ vpx_memcpy(vpred_ptr, vabove_row, 8);
+ upred_ptr += uv_stride; //8;
+ vpred_ptr += uv_stride; //8;
+ }
+
+ }
+ break;
+ case H_PRED:
+ {
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ vpx_memset(upred_ptr, uleft_col[i], 8);
+ vpx_memset(vpred_ptr, vleft_col[i], 8);
+ upred_ptr += uv_stride; //8;
+ vpred_ptr += uv_stride; //8;
+ }
+ }
+
+ break;
+ case TM_PRED:
+ {
+ int i;
+
+ for (i = 0; i < 8; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+ int predu = uleft_col[i] + uabove_row[j] - utop_left;
+ int predv = vleft_col[i] + vabove_row[j] - vtop_left;
+
+ if (predu < 0)
+ predu = 0;
+
+ if (predu > 255)
+ predu = 255;
+
+ if (predv < 0)
+ predv = 0;
+
+ if (predv > 255)
+ predv = 255;
+
+ upred_ptr[j] = predu;
+ vpred_ptr[j] = predv;
+ }
+
+ upred_ptr += uv_stride; //8;
+ vpred_ptr += uv_stride; //8;
+ }
+
+ }
+ break;
+ case B_PRED:
+ case NEARESTMV:
+ case NEARMV:
+ case ZEROMV:
+ case NEWMV:
+ case SPLITMV:
+ case MB_MODE_COUNT:
+ break;
+ }
+#else
+ (void) pbi;
+ (void) x;
+ (void) mb_row;
+ (void) mb_col;
+#endif
+}
+
+
+void vp8mt_predict_intra4x4(VP8D_COMP *pbi,
+ MACROBLOCKD *xd,
+ int b_mode,
+ unsigned char *predictor,
+ int mb_row,
+ int mb_col,
+ int num)
+{
+#if CONFIG_MULTITHREAD
+ int i, r, c;
+
+ unsigned char *Above; // = *(x->base_dst) + x->dst - x->dst_stride;
+ unsigned char Left[4];
+ unsigned char top_left; // = Above[-1];
+
+ BLOCKD *x = &xd->block[num];
+
+ //Caution: For some b_mode, it needs 8 pixels (4 above + 4 above-right).
+ if (num < 4 && pbi->common.filter_level)
+ Above = pbi->mt_yabove_row[mb_row] + mb_col*16 + num*4 + 32;
+ else
+ Above = *(x->base_dst) + x->dst - x->dst_stride;
+
+ if (num%4==0 && pbi->common.filter_level)
+ {
+ for (i=0; i<4; i++)
+ Left[i] = pbi->mt_yleft_col[mb_row][num + i];
+ }else
+ {
+ Left[0] = (*(x->base_dst))[x->dst - 1];
+ Left[1] = (*(x->base_dst))[x->dst - 1 + x->dst_stride];
+ Left[2] = (*(x->base_dst))[x->dst - 1 + 2 * x->dst_stride];
+ Left[3] = (*(x->base_dst))[x->dst - 1 + 3 * x->dst_stride];
+ }
+
+ if ((num==4 || num==8 || num==12) && pbi->common.filter_level)
+ top_left = pbi->mt_yleft_col[mb_row][num-1];
+ else
+ top_left = Above[-1];
+
+ switch (b_mode)
+ {
+ case B_DC_PRED:
+ {
+ int expected_dc = 0;
+
+ for (i = 0; i < 4; i++)
+ {
+ expected_dc += Above[i];
+ expected_dc += Left[i];
+ }
+
+ expected_dc = (expected_dc + 4) >> 3;
+
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 4; c++)
+ {
+ predictor[c] = expected_dc;
+ }
+
+ predictor += 16;
+ }
+ }
+ break;
+ case B_TM_PRED:
+ {
+ // prediction similar to true_motion prediction
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 4; c++)
+ {
+ int pred = Above[c] - top_left + Left[r];
+
+ if (pred < 0)
+ pred = 0;
+
+ if (pred > 255)
+ pred = 255;
+
+ predictor[c] = pred;
+ }
+
+ predictor += 16;
+ }
+ }
+ break;
+
+ case B_VE_PRED:
+ {
+
+ unsigned int ap[4];
+ ap[0] = (top_left + 2 * Above[0] + Above[1] + 2) >> 2;
+ ap[1] = (Above[0] + 2 * Above[1] + Above[2] + 2) >> 2;
+ ap[2] = (Above[1] + 2 * Above[2] + Above[3] + 2) >> 2;
+ ap[3] = (Above[2] + 2 * Above[3] + Above[4] + 2) >> 2;
+
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 4; c++)
+ {
+
+ predictor[c] = ap[c];
+ }
+
+ predictor += 16;
+ }
+
+ }
+ break;
+
+
+ case B_HE_PRED:
+ {
+
+ unsigned int lp[4];
+ lp[0] = (top_left + 2 * Left[0] + Left[1] + 2) >> 2;
+ lp[1] = (Left[0] + 2 * Left[1] + Left[2] + 2) >> 2;
+ lp[2] = (Left[1] + 2 * Left[2] + Left[3] + 2) >> 2;
+ lp[3] = (Left[2] + 2 * Left[3] + Left[3] + 2) >> 2;
+
+ for (r = 0; r < 4; r++)
+ {
+ for (c = 0; c < 4; c++)
+ {
+ predictor[c] = lp[r];
+ }
+
+ predictor += 16;
+ }
+ }
+ break;
+ case B_LD_PRED:
+ {
+ unsigned char *ptr = Above;
+ predictor[0 * 16 + 0] = (ptr[0] + ptr[1] * 2 + ptr[2] + 2) >> 2;
+ predictor[0 * 16 + 1] =
+ predictor[1 * 16 + 0] = (ptr[1] + ptr[2] * 2 + ptr[3] + 2) >> 2;
+ predictor[0 * 16 + 2] =
+ predictor[1 * 16 + 1] =
+ predictor[2 * 16 + 0] = (ptr[2] + ptr[3] * 2 + ptr[4] + 2) >> 2;
+ predictor[0 * 16 + 3] =
+ predictor[1 * 16 + 2] =
+ predictor[2 * 16 + 1] =
+ predictor[3 * 16 + 0] = (ptr[3] + ptr[4] * 2 + ptr[5] + 2) >> 2;
+ predictor[1 * 16 + 3] =
+ predictor[2 * 16 + 2] =
+ predictor[3 * 16 + 1] = (ptr[4] + ptr[5] * 2 + ptr[6] + 2) >> 2;
+ predictor[2 * 16 + 3] =
+ predictor[3 * 16 + 2] = (ptr[5] + ptr[6] * 2 + ptr[7] + 2) >> 2;
+ predictor[3 * 16 + 3] = (ptr[6] + ptr[7] * 2 + ptr[7] + 2) >> 2;
+
+ }
+ break;
+ case B_RD_PRED:
+ {
+
+ unsigned char pp[9];
+
+ pp[0] = Left[3];
+ pp[1] = Left[2];
+ pp[2] = Left[1];
+ pp[3] = Left[0];
+ pp[4] = top_left;
+ pp[5] = Above[0];
+ pp[6] = Above[1];
+ pp[7] = Above[2];
+ pp[8] = Above[3];
+
+ predictor[3 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
+ predictor[3 * 16 + 1] =
+ predictor[2 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
+ predictor[3 * 16 + 2] =
+ predictor[2 * 16 + 1] =
+ predictor[1 * 16 + 0] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
+ predictor[3 * 16 + 3] =
+ predictor[2 * 16 + 2] =
+ predictor[1 * 16 + 1] =
+ predictor[0 * 16 + 0] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
+ predictor[2 * 16 + 3] =
+ predictor[1 * 16 + 2] =
+ predictor[0 * 16 + 1] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
+ predictor[1 * 16 + 3] =
+ predictor[0 * 16 + 2] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
+ predictor[0 * 16 + 3] = (pp[6] + pp[7] * 2 + pp[8] + 2) >> 2;
+
+ }
+ break;
+ case B_VR_PRED:
+ {
+
+ unsigned char pp[9];
+
+ pp[0] = Left[3];
+ pp[1] = Left[2];
+ pp[2] = Left[1];
+ pp[3] = Left[0];
+ pp[4] = top_left;
+ pp[5] = Above[0];
+ pp[6] = Above[1];
+ pp[7] = Above[2];
+ pp[8] = Above[3];
+
+
+ predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
+ predictor[2 * 16 + 0] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
+ predictor[3 * 16 + 1] =
+ predictor[1 * 16 + 0] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
+ predictor[2 * 16 + 1] =
+ predictor[0 * 16 + 0] = (pp[4] + pp[5] + 1) >> 1;
+ predictor[3 * 16 + 2] =
+ predictor[1 * 16 + 1] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
+ predictor[2 * 16 + 2] =
+ predictor[0 * 16 + 1] = (pp[5] + pp[6] + 1) >> 1;
+ predictor[3 * 16 + 3] =
+ predictor[1 * 16 + 2] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
+ predictor[2 * 16 + 3] =
+ predictor[0 * 16 + 2] = (pp[6] + pp[7] + 1) >> 1;
+ predictor[1 * 16 + 3] = (pp[6] + pp[7] * 2 + pp[8] + 2) >> 2;
+ predictor[0 * 16 + 3] = (pp[7] + pp[8] + 1) >> 1;
+
+ }
+ break;
+ case B_VL_PRED:
+ {
+
+ unsigned char *pp = Above;
+
+ predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1;
+ predictor[1 * 16 + 0] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
+ predictor[2 * 16 + 0] =
+ predictor[0 * 16 + 1] = (pp[1] + pp[2] + 1) >> 1;
+ predictor[1 * 16 + 1] =
+ predictor[3 * 16 + 0] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
+ predictor[2 * 16 + 1] =
+ predictor[0 * 16 + 2] = (pp[2] + pp[3] + 1) >> 1;
+ predictor[3 * 16 + 1] =
+ predictor[1 * 16 + 2] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
+ predictor[0 * 16 + 3] =
+ predictor[2 * 16 + 2] = (pp[3] + pp[4] + 1) >> 1;
+ predictor[1 * 16 + 3] =
+ predictor[3 * 16 + 2] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
+ predictor[2 * 16 + 3] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
+ predictor[3 * 16 + 3] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
+ }
+ break;
+
+ case B_HD_PRED:
+ {
+ unsigned char pp[9];
+ pp[0] = Left[3];
+ pp[1] = Left[2];
+ pp[2] = Left[1];
+ pp[3] = Left[0];
+ pp[4] = top_left;
+ pp[5] = Above[0];
+ pp[6] = Above[1];
+ pp[7] = Above[2];
+ pp[8] = Above[3];
+
+
+ predictor[3 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1;
+ predictor[3 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
+ predictor[2 * 16 + 0] =
+ predictor[3 * 16 + 2] = (pp[1] + pp[2] + 1) >> 1;
+ predictor[2 * 16 + 1] =
+ predictor[3 * 16 + 3] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
+ predictor[2 * 16 + 2] =
+ predictor[1 * 16 + 0] = (pp[2] + pp[3] + 1) >> 1;
+ predictor[2 * 16 + 3] =
+ predictor[1 * 16 + 1] = (pp[2] + pp[3] * 2 + pp[4] + 2) >> 2;
+ predictor[1 * 16 + 2] =
+ predictor[0 * 16 + 0] = (pp[3] + pp[4] + 1) >> 1;
+ predictor[1 * 16 + 3] =
+ predictor[0 * 16 + 1] = (pp[3] + pp[4] * 2 + pp[5] + 2) >> 2;
+ predictor[0 * 16 + 2] = (pp[4] + pp[5] * 2 + pp[6] + 2) >> 2;
+ predictor[0 * 16 + 3] = (pp[5] + pp[6] * 2 + pp[7] + 2) >> 2;
+ }
+ break;
+
+
+ case B_HU_PRED:
+ {
+ unsigned char *pp = Left;
+ predictor[0 * 16 + 0] = (pp[0] + pp[1] + 1) >> 1;
+ predictor[0 * 16 + 1] = (pp[0] + pp[1] * 2 + pp[2] + 2) >> 2;
+ predictor[0 * 16 + 2] =
+ predictor[1 * 16 + 0] = (pp[1] + pp[2] + 1) >> 1;
+ predictor[0 * 16 + 3] =
+ predictor[1 * 16 + 1] = (pp[1] + pp[2] * 2 + pp[3] + 2) >> 2;
+ predictor[1 * 16 + 2] =
+ predictor[2 * 16 + 0] = (pp[2] + pp[3] + 1) >> 1;
+ predictor[1 * 16 + 3] =
+ predictor[2 * 16 + 1] = (pp[2] + pp[3] * 2 + pp[3] + 2) >> 2;
+ predictor[2 * 16 + 2] =
+ predictor[2 * 16 + 3] =
+ predictor[3 * 16 + 0] =
+ predictor[3 * 16 + 1] =
+ predictor[3 * 16 + 2] =
+ predictor[3 * 16 + 3] = pp[3];
+ }
+ break;
+
+
+ }
+#else
+ (void) pbi;
+ (void) xd;
+ (void) b_mode;
+ (void) predictor;
+ (void) mb_row;
+ (void) mb_col;
+ (void) num;
+#endif
+}
+
+// copy 4 bytes from the above right down so that the 4x4 prediction modes using pixels above and
+// to the right prediction have filled in pixels to use.
+void vp8mt_intra_prediction_down_copy(VP8D_COMP *pbi, MACROBLOCKD *x, int mb_row, int mb_col)
+{
+#if CONFIG_MULTITHREAD
+ unsigned char *above_right; // = *(x->block[0].base_dst) + x->block[0].dst - x->block[0].dst_stride + 16;
+ unsigned int *src_ptr;
+ unsigned int *dst_ptr0;
+ unsigned int *dst_ptr1;
+ unsigned int *dst_ptr2;
+
+ if (pbi->common.filter_level)
+ above_right = pbi->mt_yabove_row[mb_row] + mb_col*16 + 32 +16;
+ else
+ above_right = *(x->block[0].base_dst) + x->block[0].dst - x->block[0].dst_stride + 16;
+
+ src_ptr = (unsigned int *)above_right;
+ //dst_ptr0 = (unsigned int *)(above_right + 4 * x->block[0].dst_stride);
+ //dst_ptr1 = (unsigned int *)(above_right + 8 * x->block[0].dst_stride);
+ //dst_ptr2 = (unsigned int *)(above_right + 12 * x->block[0].dst_stride);
+ dst_ptr0 = (unsigned int *)(*(x->block[0].base_dst) + x->block[0].dst + 16 + 3 * x->block[0].dst_stride);
+ dst_ptr1 = (unsigned int *)(*(x->block[0].base_dst) + x->block[0].dst + 16 + 7 * x->block[0].dst_stride);
+ dst_ptr2 = (unsigned int *)(*(x->block[0].base_dst) + x->block[0].dst + 16 + 11 * x->block[0].dst_stride);
+ *dst_ptr0 = *src_ptr;
+ *dst_ptr1 = *src_ptr;
+ *dst_ptr2 = *src_ptr;
+#else
+ (void) pbi;
+ (void) x;
+ (void) mb_row;
+ (void) mb_col;
+#endif
+}
#include "loopfilter.h"
#include "extend.h"
#include "vpx_ports/vpx_timer.h"
+#include "detokenize.h"
+#include "reconinter.h"
+#include "reconintra_mt.h"
-#define MAX_ROWS 256
-
-extern void vp8_decode_mb_row(VP8D_COMP *pbi,
- VP8_COMMON *pc,
- int mb_row,
- MACROBLOCKD *xd);
-
+extern void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
+extern void clamp_mvs(MACROBLOCKD *xd);
extern void vp8_build_uvmvs(MACROBLOCKD *x, int fullpixel);
-extern void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd);
-void vp8_thread_loop_filter(VP8D_COMP *pbi, MB_ROW_DEC *mbrd, int ithread);
+#if CONFIG_RUNTIME_CPU_DETECT
+#define RTCD_VTABLE(x) (&(pbi)->common.rtcd.x)
+#else
+#define RTCD_VTABLE(x) NULL
+#endif
void vp8_setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
{
mbd->mb_segement_abs_delta = xd->mb_segement_abs_delta;
vpx_memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
+ //signed char ref_lf_deltas[MAX_REF_LF_DELTAS];
+ vpx_memcpy(mbd->ref_lf_deltas, xd->ref_lf_deltas, sizeof(xd->ref_lf_deltas));
+ //signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];
+ vpx_memcpy(mbd->mode_lf_deltas, xd->mode_lf_deltas, sizeof(xd->mode_lf_deltas));
+ //unsigned char mode_ref_lf_delta_enabled;
+ //unsigned char mode_ref_lf_delta_update;
+ mbd->mode_ref_lf_delta_enabled = xd->mode_ref_lf_delta_enabled;
+ mbd->mode_ref_lf_delta_update = xd->mode_ref_lf_delta_update;
+
mbd->current_bc = &pbi->bc2;
for (j = 0; j < 25; j++)
}
for (i=0; i< pc->mb_rows; i++)
- pbi->current_mb_col[i]=-1;
+ pbi->mt_current_mb_col[i]=-1;
#else
(void) pbi;
(void) xd;
#endif
}
-void vp8_setup_loop_filter_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
+
+void vp8mt_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col)
{
#if CONFIG_MULTITHREAD
- VP8_COMMON *const pc = & pbi->common;
- int i, j;
+ int eobtotal = 0;
+ int i, do_clamp = xd->mode_info_context->mbmi.need_to_clamp_mvs;
+ VP8_COMMON *pc = &pbi->common;
- for (i = 0; i < count; i++)
+ if (xd->mode_info_context->mbmi.mb_skip_coeff)
{
- MACROBLOCKD *mbd = &mbrd[i].mbd;
-//#if CONFIG_RUNTIME_CPU_DETECT
-// mbd->rtcd = xd->rtcd;
-//#endif
+ vp8_reset_mb_tokens_context(xd);
+ }
+ else
+ {
+ eobtotal = vp8_decode_mb_tokens(pbi, xd);
+ }
- //mbd->subpixel_predict = xd->subpixel_predict;
- //mbd->subpixel_predict8x4 = xd->subpixel_predict8x4;
- //mbd->subpixel_predict8x8 = xd->subpixel_predict8x8;
- //mbd->subpixel_predict16x16 = xd->subpixel_predict16x16;
+ // Perform temporary clamping of the MV to be used for prediction
+ if (do_clamp)
+ {
+ clamp_mvs(xd);
+ }
- mbd->mode_info_context = pc->mi + pc->mode_info_stride * (i + 1);
- mbd->mode_info_stride = pc->mode_info_stride;
+ xd->mode_info_context->mbmi.dc_diff = 1;
- //mbd->frame_type = pc->frame_type;
- //mbd->frames_since_golden = pc->frames_since_golden;
- //mbd->frames_till_alt_ref_frame = pc->frames_till_alt_ref_frame;
+ if (xd->mode_info_context->mbmi.mode != B_PRED && xd->mode_info_context->mbmi.mode != SPLITMV && eobtotal == 0)
+ {
+ xd->mode_info_context->mbmi.dc_diff = 0;
- //mbd->pre = pc->yv12_fb[pc->lst_fb_idx];
- //mbd->dst = pc->yv12_fb[pc->new_fb_idx];
+ //mt_skip_recon_mb(pbi, xd, mb_row, mb_col);
+ if (xd->frame_type == KEY_FRAME || xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
+ {
+ vp8mt_build_intra_predictors_mbuv_s(pbi, xd, mb_row, mb_col);
+ vp8mt_build_intra_predictors_mby_s(pbi, xd, mb_row, mb_col);
+ }
+ else
+ {
+ vp8_build_inter_predictors_mb_s(xd);
+ }
+ return;
+ }
- //vp8_setup_block_dptrs(mbd);
- //vp8_build_block_doffsets(mbd);
- mbd->segmentation_enabled = xd->segmentation_enabled; //
- mbd->mb_segement_abs_delta = xd->mb_segement_abs_delta; //
- vpx_memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data)); //
+ if (xd->segmentation_enabled)
+ mb_init_dequantizer(pbi, xd);
- //signed char ref_lf_deltas[MAX_REF_LF_DELTAS];
- vpx_memcpy(mbd->ref_lf_deltas, xd->ref_lf_deltas, sizeof(xd->ref_lf_deltas));
- //signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];
- vpx_memcpy(mbd->mode_lf_deltas, xd->mode_lf_deltas, sizeof(xd->mode_lf_deltas));
- //unsigned char mode_ref_lf_delta_enabled;
- //unsigned char mode_ref_lf_delta_update;
- mbd->mode_ref_lf_delta_enabled = xd->mode_ref_lf_delta_enabled;
- mbd->mode_ref_lf_delta_update = xd->mode_ref_lf_delta_update;
+ // do prediction
+ if (xd->frame_type == KEY_FRAME || xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
+ {
+ vp8mt_build_intra_predictors_mbuv(pbi, xd, mb_row, mb_col);
+
+ if (xd->mode_info_context->mbmi.mode != B_PRED)
+ {
+ vp8mt_build_intra_predictors_mby(pbi, xd, mb_row, mb_col);
+ } else {
+ vp8mt_intra_prediction_down_copy(pbi, xd, mb_row, mb_col);
+ }
+ }
+ else
+ {
+ vp8_build_inter_predictors_mb(xd);
+ }
- //mbd->mbmi.mode = DC_PRED;
- //mbd->mbmi.uv_mode = DC_PRED;
- //mbd->current_bc = &pbi->bc2;
+ // dequantization and idct
+ if (xd->mode_info_context->mbmi.mode != B_PRED && xd->mode_info_context->mbmi.mode != SPLITMV)
+ {
+ BLOCKD *b = &xd->block[24];
+ DEQUANT_INVOKE(&pbi->dequant, block)(b);
- //for (j = 0; j < 25; j++)
- //{
- // mbd->block[j].dequant = xd->block[j].dequant;
- //}
+ // do 2nd order transform on the dc block
+ if (xd->eobs[24] > 1)
+ {
+ IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh16)(&b->dqcoeff[0], b->diff);
+ ((int *)b->qcoeff)[0] = 0;
+ ((int *)b->qcoeff)[1] = 0;
+ ((int *)b->qcoeff)[2] = 0;
+ ((int *)b->qcoeff)[3] = 0;
+ ((int *)b->qcoeff)[4] = 0;
+ ((int *)b->qcoeff)[5] = 0;
+ ((int *)b->qcoeff)[6] = 0;
+ ((int *)b->qcoeff)[7] = 0;
+ }
+ else
+ {
+ IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh1)(&b->dqcoeff[0], b->diff);
+ ((int *)b->qcoeff)[0] = 0;
+ }
+
+ DEQUANT_INVOKE (&pbi->dequant, dc_idct_add_y_block)
+ (xd->qcoeff, &xd->block[0].dequant[0][0],
+ xd->predictor, xd->dst.y_buffer,
+ xd->dst.y_stride, xd->eobs, xd->block[24].diff);
}
+ else if ((xd->frame_type == KEY_FRAME || xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME) && xd->mode_info_context->mbmi.mode == B_PRED)
+ {
+ for (i = 0; i < 16; i++)
+ {
+ BLOCKD *b = &xd->block[i];
+ vp8mt_predict_intra4x4(pbi, xd, b->bmi.mode, b->predictor, mb_row, mb_col, i);
- for (i=0; i< pc->mb_rows; i++)
- pbi->current_mb_col[i]=-1;
+ if (xd->eobs[i] > 1)
+ {
+ DEQUANT_INVOKE(&pbi->dequant, idct_add)
+ (b->qcoeff, &b->dequant[0][0], b->predictor,
+ *(b->base_dst) + b->dst, 16, b->dst_stride);
+ }
+ else
+ {
+ IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)
+ (b->qcoeff[0] * b->dequant[0][0], b->predictor,
+ *(b->base_dst) + b->dst, 16, b->dst_stride);
+ ((int *)b->qcoeff)[0] = 0;
+ }
+ }
+ }
+ else
+ {
+ DEQUANT_INVOKE (&pbi->dequant, idct_add_y_block)
+ (xd->qcoeff, &xd->block[0].dequant[0][0],
+ xd->predictor, xd->dst.y_buffer,
+ xd->dst.y_stride, xd->eobs);
+ }
+
+ DEQUANT_INVOKE (&pbi->dequant, idct_add_uv_block)
+ (xd->qcoeff+16*16, &xd->block[16].dequant[0][0],
+ xd->predictor+16*16, xd->dst.u_buffer, xd->dst.v_buffer,
+ xd->dst.uv_stride, xd->eobs+16);
#else
(void) pbi;
(void) xd;
- (void) mbrd;
- (void) count;
+ (void) mb_row;
+ (void) mb_col;
#endif
}
+
THREAD_FUNCTION vp8_thread_decoding_proc(void *p_data)
{
#if CONFIG_MULTITHREAD
while (1)
{
- int current_filter_level = 0;
-
if (pbi->b_multithreaded_rd == 0)
break;
int recon_y_stride = pc->yv12_fb[ref_fb_idx].y_stride;
int recon_uv_stride = pc->yv12_fb[ref_fb_idx].uv_stride;
+ int filter_level;
+ loop_filter_info *lfi = pc->lf_info;
+ int alt_flt_enabled = xd->segmentation_enabled;
+ int Segment;
+
pbi->mb_row_di[ithread].mb_row = mb_row;
pbi->mb_row_di[ithread].mbd.current_bc = &pbi->mbc[mb_row%num_part];
- last_row_current_mb_col = &pbi->current_mb_col[mb_row -1];
+ last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];
recon_yoffset = mb_row * recon_y_stride * 16;
recon_uvoffset = mb_row * recon_uv_stride * 8;
}
}
+ if(pbi->common.filter_level)
+ {
+ //update loopfilter info
+ Segment = (alt_flt_enabled) ? xd->mode_info_context->mbmi.segment_id : 0;
+ filter_level = pbi->mt_baseline_filter_level[Segment];
+ // Distance of Mb to the various image edges.
+ // These specified to 8th pel as they are always compared to values that are in 1/8th pel units
+ // Apply any context driven MB level adjustment
+ vp8_adjust_mb_lf_value(xd, &filter_level);
+ }
+
// Distance of Mb to the various image edges.
// These specified to 8th pel as they are always compared to values that are in 1/8th pel units
xd->mb_to_left_edge = -((mb_col * 16) << 3);
xd->pre.v_buffer = pc->yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;
vp8_build_uvmvs(xd, pc->full_pixel);
+ vp8mt_decode_macroblock(pbi, xd, mb_row, mb_col);
- vp8_decode_macroblock(pbi, xd);
+ if (pbi->common.filter_level)
+ {
+ if( mb_row != pc->mb_rows-1 )
+ {
+ //Save decoded MB last row data for next-row decoding
+ vpx_memcpy((pbi->mt_yabove_row[mb_row + 1] + 32 + mb_col*16), (xd->dst.y_buffer + 15 * recon_y_stride), 16);
+ vpx_memcpy((pbi->mt_uabove_row[mb_row + 1] + 16 + mb_col*8), (xd->dst.u_buffer + 7 * recon_uv_stride), 8);
+ vpx_memcpy((pbi->mt_vabove_row[mb_row + 1] + 16 + mb_col*8), (xd->dst.v_buffer + 7 * recon_uv_stride), 8);
+ }
+
+ //save left_col for next MB decoding
+ if(mb_col != pc->mb_cols-1)
+ {
+ MODE_INFO *next = xd->mode_info_context +1;
+
+ if (xd->frame_type == KEY_FRAME || next->mbmi.ref_frame == INTRA_FRAME)
+ {
+ for (i = 0; i < 16; i++)
+ pbi->mt_yleft_col[mb_row][i] = xd->dst.y_buffer [i* recon_y_stride + 15];
+ for (i = 0; i < 8; i++)
+ {
+ pbi->mt_uleft_col[mb_row][i] = xd->dst.u_buffer [i* recon_uv_stride + 7];
+ pbi->mt_vleft_col[mb_row][i] = xd->dst.v_buffer [i* recon_uv_stride + 7];
+ }
+ }
+ }
+
+ // loopfilter on this macroblock.
+ if (filter_level)
+ {
+ if (mb_col > 0)
+ pc->lf_mbv(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+
+ if (xd->mode_info_context->mbmi.dc_diff > 0)
+ pc->lf_bv(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+
+ // don't apply across umv border
+ if (mb_row > 0)
+ pc->lf_mbh(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+
+ if (xd->mode_info_context->mbmi.dc_diff > 0)
+ pc->lf_bh(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+ }
+ }
recon_yoffset += 16;
recon_uvoffset += 8;
xd->above_context++;
//pbi->mb_row_di[ithread].current_mb_col = mb_col;
- pbi->current_mb_col[mb_row] = mb_col;
+ pbi->mt_current_mb_col[mb_row] = mb_col;
}
// adjust to the next row of mbs
- vp8_extend_mb_row(
- &pc->yv12_fb[dst_fb_idx],
- xd->dst.y_buffer + 16, xd->dst.u_buffer + 8, xd->dst.v_buffer + 8
- );
+ if (pbi->common.filter_level)
+ {
+ if(mb_row != pc->mb_rows-1)
+ {
+ int lasty = pc->yv12_fb[ref_fb_idx].y_width + VP8BORDERINPIXELS;
+ int lastuv = (pc->yv12_fb[ref_fb_idx].y_width>>1) + (VP8BORDERINPIXELS>>1);
+
+ for (i = 0; i < 4; i++)
+ {
+ pbi->mt_yabove_row[mb_row +1][lasty + i] = pbi->mt_yabove_row[mb_row +1][lasty -1];
+ pbi->mt_uabove_row[mb_row +1][lastuv + i] = pbi->mt_uabove_row[mb_row +1][lastuv -1];
+ pbi->mt_vabove_row[mb_row +1][lastuv + i] = pbi->mt_vabove_row[mb_row +1][lastuv -1];
+ }
+ }
+ } else
+ vp8_extend_mb_row(&pc->yv12_fb[dst_fb_idx], xd->dst.y_buffer + 16, xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
++xd->mode_info_context; /* skip prediction column */
// since we have multithread
xd->mode_info_context += xd->mode_info_stride * pbi->decoding_thread_count;
-
- pbi->last_mb_row_decoded = mb_row;
-
}
}
}
-
- // If |pbi->common.filter_level| is 0 the value can change in-between
- // the sem_post and the check to call vp8_thread_loop_filter.
- current_filter_level = pbi->common.filter_level;
-
// add this to each frame
if ((mbrd->mb_row == pbi->common.mb_rows-1) || ((mbrd->mb_row == pbi->common.mb_rows-2) && (pbi->common.mb_rows % (pbi->decoding_thread_count+1))==1))
{
//SetEvent(pbi->h_event_end_decoding);
sem_post(&pbi->h_event_end_decoding);
}
-
- if ((pbi->b_multithreaded_lf) && (current_filter_level))
- vp8_thread_loop_filter(pbi, mbrd, ithread);
-
}
#else
(void) p_data;
}
-void vp8_thread_loop_filter(VP8D_COMP *pbi, MB_ROW_DEC *mbrd, int ithread)
+void vp8_decoder_create_threads(VP8D_COMP *pbi)
{
#if CONFIG_MULTITHREAD
+ int core_count = 0;
+ int ithread;
+ int i;
- if (sem_wait(&pbi->h_event_start_lpf[ithread]) == 0)
- {
- // if (pbi->b_multithreaded_lf == 0) // we're shutting down ????
- // break;
- // else
- {
- VP8_COMMON *cm = &pbi->common;
- MACROBLOCKD *mbd = &mbrd->mbd;
- int default_filt_lvl = pbi->common.filter_level;
-
- YV12_BUFFER_CONFIG *post = cm->frame_to_show;
- loop_filter_info *lfi = cm->lf_info;
- //int frame_type = cm->frame_type;
-
- int mb_row;
- int mb_col;
-
- int filter_level;
- int alt_flt_enabled = mbd->segmentation_enabled;
-
- int i;
- unsigned char *y_ptr, *u_ptr, *v_ptr;
+ pbi->b_multithreaded_rd = 0;
+ pbi->allocated_decoding_thread_count = 0;
+ core_count = (pbi->max_threads > 16) ? 16 : pbi->max_threads;
- volatile int *last_row_current_mb_col;
+ if (core_count > 1)
+ {
+ pbi->b_multithreaded_rd = 1;
+ pbi->decoding_thread_count = core_count -1;
- // Set up the buffer pointers
- y_ptr = post->y_buffer + post->y_stride * 16 * (ithread +1);
- u_ptr = post->u_buffer + post->uv_stride * 8 * (ithread +1);
- v_ptr = post->v_buffer + post->uv_stride * 8 * (ithread +1);
+ CHECK_MEM_ERROR(pbi->h_decoding_thread, vpx_malloc(sizeof(pthread_t) * pbi->decoding_thread_count));
+ CHECK_MEM_ERROR(pbi->h_event_start_decoding, vpx_malloc(sizeof(sem_t) * pbi->decoding_thread_count));
+ CHECK_MEM_ERROR(pbi->mb_row_di, vpx_memalign(32, sizeof(MB_ROW_DEC) * pbi->decoding_thread_count));
+ vpx_memset(pbi->mb_row_di, 0, sizeof(MB_ROW_DEC) * pbi->decoding_thread_count);
+ CHECK_MEM_ERROR(pbi->de_thread_data, vpx_malloc(sizeof(DECODETHREAD_DATA) * pbi->decoding_thread_count));
- // vp8_filter each macro block
- for (mb_row = ithread+1; mb_row < cm->mb_rows; mb_row+= (pbi->decoding_thread_count + 1))
- {
- last_row_current_mb_col = &pbi->current_mb_col[mb_row -1];
+ for (ithread = 0; ithread < pbi->decoding_thread_count; ithread++)
+ {
+ sem_init(&pbi->h_event_start_decoding[ithread], 0, 0);
- for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
- {
- int Segment = (alt_flt_enabled) ? mbd->mode_info_context->mbmi.segment_id : 0;
+ pbi->de_thread_data[ithread].ithread = ithread;
+ pbi->de_thread_data[ithread].ptr1 = (void *)pbi;
+ pbi->de_thread_data[ithread].ptr2 = (void *) &pbi->mb_row_di[ithread];
- if ((mb_col & 7) == 0)
- {
- while (mb_col > (*last_row_current_mb_col-8) && *last_row_current_mb_col != cm->mb_cols - 1)
- {
- x86_pause_hint();
- thread_sleep(0);
- }
- }
+ pthread_create(&pbi->h_decoding_thread[ithread], 0, vp8_thread_decoding_proc, (&pbi->de_thread_data[ithread]));
+ }
- filter_level = pbi->mt_baseline_filter_level[Segment];
+ sem_init(&pbi->h_event_end_decoding, 0, 0);
- // Apply any context driven MB level adjustment
- vp8_adjust_mb_lf_value(mbd, &filter_level);
+ pbi->allocated_decoding_thread_count = pbi->decoding_thread_count;
+ }
- if (filter_level)
- {
- if (mb_col > 0)
- cm->lf_mbv(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
+#else
+ (void) pbi;
+#endif
+}
- if (mbd->mode_info_context->mbmi.dc_diff > 0)
- cm->lf_bv(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
- // don't apply across umv border
- if (mb_row > 0)
- cm->lf_mbh(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
+void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows)
+{
+#if CONFIG_MULTITHREAD
+ VP8_COMMON *const pc = & pbi->common;
+ int i;
- if (mbd->mode_info_context->mbmi.dc_diff > 0)
- cm->lf_bh(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
- }
+ if (pbi->b_multithreaded_rd)
+ {
+ if (pbi->mt_current_mb_col)
+ {
+ vpx_free(pbi->mt_current_mb_col);
+ pbi->mt_current_mb_col = NULL ;
+ }
- y_ptr += 16;
- u_ptr += 8;
- v_ptr += 8;
+ // Free above_row buffers.
+ if (pbi->mt_yabove_row)
+ {
+ for (i=0; i< mb_rows; i++)
+ {
+ if (pbi->mt_yabove_row[i])
+ {
+ vpx_free(pbi->mt_yabove_row[i]);
+ pbi->mt_yabove_row[i] = NULL ;
+ }
+ }
+ vpx_free(pbi->mt_yabove_row);
+ pbi->mt_yabove_row = NULL ;
+ }
- mbd->mode_info_context++; // step to next MB
- pbi->current_mb_col[mb_row] = mb_col;
- }
+ if (pbi->mt_uabove_row)
+ {
+ for (i=0; i< mb_rows; i++)
+ {
+ if (pbi->mt_uabove_row[i])
+ {
+ vpx_free(pbi->mt_uabove_row[i]);
+ pbi->mt_uabove_row[i] = NULL ;
+ }
+ }
+ vpx_free(pbi->mt_uabove_row);
+ pbi->mt_uabove_row = NULL ;
+ }
- mbd->mode_info_context++; // Skip border mb
+ if (pbi->mt_vabove_row)
+ {
+ for (i=0; i< mb_rows; i++)
+ {
+ if (pbi->mt_vabove_row[i])
+ {
+ vpx_free(pbi->mt_vabove_row[i]);
+ pbi->mt_vabove_row[i] = NULL ;
+ }
+ }
+ vpx_free(pbi->mt_vabove_row);
+ pbi->mt_vabove_row = NULL ;
+ }
- y_ptr += post->y_stride * 16 * (pbi->decoding_thread_count + 1) - post->y_width;
- u_ptr += post->uv_stride * 8 * (pbi->decoding_thread_count + 1) - post->uv_width;
- v_ptr += post->uv_stride * 8 * (pbi->decoding_thread_count + 1) - post->uv_width;
+ // Free left_col buffers.
+ if (pbi->mt_yleft_col)
+ {
+ for (i=0; i< mb_rows; i++)
+ {
+ if (pbi->mt_yleft_col[i])
+ {
+ vpx_free(pbi->mt_yleft_col[i]);
+ pbi->mt_yleft_col[i] = NULL ;
+ }
+ }
+ vpx_free(pbi->mt_yleft_col);
+ pbi->mt_yleft_col = NULL ;
+ }
- mbd->mode_info_context += pbi->decoding_thread_count * mbd->mode_info_stride; // Skip border mb
+ if (pbi->mt_uleft_col)
+ {
+ for (i=0; i< mb_rows; i++)
+ {
+ if (pbi->mt_uleft_col[i])
+ {
+ vpx_free(pbi->mt_uleft_col[i]);
+ pbi->mt_uleft_col[i] = NULL ;
}
}
+ vpx_free(pbi->mt_uleft_col);
+ pbi->mt_uleft_col = NULL ;
}
- // add this to each frame
- if ((mbrd->mb_row == pbi->common.mb_rows-1) || ((mbrd->mb_row == pbi->common.mb_rows-2) && (pbi->common.mb_rows % (pbi->decoding_thread_count+1))==1))
+ if (pbi->mt_vleft_col)
{
- sem_post(&pbi->h_event_end_lpf);
+ for (i=0; i< mb_rows; i++)
+ {
+ if (pbi->mt_vleft_col[i])
+ {
+ vpx_free(pbi->mt_vleft_col[i]);
+ pbi->mt_vleft_col[i] = NULL ;
+ }
+ }
+ vpx_free(pbi->mt_vleft_col);
+ pbi->mt_vleft_col = NULL ;
}
+ }
#else
(void) pbi;
#endif
}
-void vp8_decoder_create_threads(VP8D_COMP *pbi)
+
+int vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows)
{
#if CONFIG_MULTITHREAD
- int core_count = 0;
- int ithread;
-
- pbi->b_multithreaded_rd = 0;
- pbi->b_multithreaded_lf = 0;
- pbi->allocated_decoding_thread_count = 0;
- core_count = (pbi->max_threads > 16) ? 16 : pbi->max_threads;
+ VP8_COMMON *const pc = & pbi->common;
+ int i;
+ int uv_width;
- if (core_count > 1)
+ if (pbi->b_multithreaded_rd)
{
- pbi->b_multithreaded_rd = 1;
- pbi->b_multithreaded_lf = 1; // this can be merged with pbi->b_multithreaded_rd ?
- pbi->decoding_thread_count = core_count -1;
+ vp8mt_de_alloc_temp_buffers(pbi, prev_mb_rows);
- CHECK_MEM_ERROR(pbi->h_decoding_thread, vpx_malloc(sizeof(pthread_t) * pbi->decoding_thread_count));
- CHECK_MEM_ERROR(pbi->h_event_start_decoding, vpx_malloc(sizeof(sem_t) * pbi->decoding_thread_count));
- CHECK_MEM_ERROR(pbi->mb_row_di, vpx_memalign(32, sizeof(MB_ROW_DEC) * pbi->decoding_thread_count));
- vpx_memset(pbi->mb_row_di, 0, sizeof(MB_ROW_DEC) * pbi->decoding_thread_count);
- CHECK_MEM_ERROR(pbi->de_thread_data, vpx_malloc(sizeof(DECODETHREAD_DATA) * pbi->decoding_thread_count));
+ // our internal buffers are always multiples of 16
+ if ((width & 0xf) != 0)
+ width += 16 - (width & 0xf);
- CHECK_MEM_ERROR(pbi->current_mb_col, vpx_malloc(sizeof(int) * MAX_ROWS)); // pc->mb_rows));
- CHECK_MEM_ERROR(pbi->h_event_start_lpf, vpx_malloc(sizeof(sem_t) * pbi->decoding_thread_count));
+ uv_width = width >>1;
- for (ithread = 0; ithread < pbi->decoding_thread_count; ithread++)
- {
- sem_init(&pbi->h_event_start_decoding[ithread], 0, 0);
- sem_init(&pbi->h_event_start_lpf[ithread], 0, 0);
+ // Allocate an int for each mb row.
+ CHECK_MEM_ERROR(pbi->mt_current_mb_col, vpx_malloc(sizeof(int) * pc->mb_rows));
- pbi->de_thread_data[ithread].ithread = ithread;
- pbi->de_thread_data[ithread].ptr1 = (void *)pbi;
- pbi->de_thread_data[ithread].ptr2 = (void *) &pbi->mb_row_di[ithread];
+ // Allocate memory for above_row buffers.
+ CHECK_MEM_ERROR(pbi->mt_yabove_row, vpx_malloc(sizeof(unsigned char *) * pc->mb_rows));
+ for (i=0; i< pc->mb_rows; i++)
+ CHECK_MEM_ERROR(pbi->mt_yabove_row[i], vpx_calloc(sizeof(unsigned char) * (width + (VP8BORDERINPIXELS<<1)), 1));
- pthread_create(&pbi->h_decoding_thread[ithread], 0, vp8_thread_decoding_proc, (&pbi->de_thread_data[ithread]));
- }
+ CHECK_MEM_ERROR(pbi->mt_uabove_row, vpx_malloc(sizeof(unsigned char *) * pc->mb_rows));
+ for (i=0; i< pc->mb_rows; i++)
+ CHECK_MEM_ERROR(pbi->mt_uabove_row[i], vpx_calloc(sizeof(unsigned char) * (uv_width + VP8BORDERINPIXELS), 1));
- sem_init(&pbi->h_event_end_decoding, 0, 0);
- sem_init(&pbi->h_event_end_lpf, 0, 0);
+ CHECK_MEM_ERROR(pbi->mt_vabove_row, vpx_malloc(sizeof(unsigned char *) * pc->mb_rows));
+ for (i=0; i< pc->mb_rows; i++)
+ CHECK_MEM_ERROR(pbi->mt_vabove_row[i], vpx_calloc(sizeof(unsigned char) * (uv_width + VP8BORDERINPIXELS), 1));
- pbi->allocated_decoding_thread_count = pbi->decoding_thread_count;
- }
+ // Allocate memory for left_col buffers.
+ CHECK_MEM_ERROR(pbi->mt_yleft_col, vpx_malloc(sizeof(unsigned char *) * pc->mb_rows));
+ for (i=0; i< pc->mb_rows; i++)
+ CHECK_MEM_ERROR(pbi->mt_yleft_col[i], vpx_calloc(sizeof(unsigned char) * 16, 1));
+ CHECK_MEM_ERROR(pbi->mt_uleft_col, vpx_malloc(sizeof(unsigned char *) * pc->mb_rows));
+ for (i=0; i< pc->mb_rows; i++)
+ CHECK_MEM_ERROR(pbi->mt_uleft_col[i], vpx_calloc(sizeof(unsigned char) * 8, 1));
+
+ CHECK_MEM_ERROR(pbi->mt_vleft_col, vpx_malloc(sizeof(unsigned char *) * pc->mb_rows));
+ for (i=0; i< pc->mb_rows; i++)
+ CHECK_MEM_ERROR(pbi->mt_vleft_col[i], vpx_calloc(sizeof(unsigned char) * 8, 1));
+ }
+ return 0;
#else
(void) pbi;
+ (void) width;
#endif
}
+
void vp8_decoder_remove_threads(VP8D_COMP *pbi)
{
#if CONFIG_MULTITHREAD
- if (pbi->b_multithreaded_lf)
- {
- int i;
- pbi->b_multithreaded_lf = 0;
-
- for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
- sem_destroy(&pbi->h_event_start_lpf[i]);
-
- sem_destroy(&pbi->h_event_end_lpf);
- }
-
//shutdown MB Decoding thread;
if (pbi->b_multithreaded_rd)
{
pbi->h_event_start_decoding = NULL;
}
- if (pbi->h_event_start_lpf)
- {
- vpx_free(pbi->h_event_start_lpf);
- pbi->h_event_start_lpf = NULL;
- }
-
if (pbi->mb_row_di)
{
vpx_free(pbi->mb_row_di);
vpx_free(pbi->de_thread_data);
pbi->de_thread_data = NULL;
}
-
- if (pbi->current_mb_col)
- {
- vpx_free(pbi->current_mb_col);
- pbi->current_mb_col = NULL ;
- }
}
#else
(void) pbi;
}
-void vp8_start_lfthread(VP8D_COMP *pbi)
+void vp8mt_lpf_init( VP8D_COMP *pbi, int default_filt_lvl)
{
#if CONFIG_MULTITHREAD
- /*
- memcpy(&pbi->lpfmb, &pbi->mb, sizeof(pbi->mb));
- pbi->last_mb_row_decoded = 0;
- sem_post(&pbi->h_event_start_lpf);
- */
- (void) pbi;
-#else
- (void) pbi;
-#endif
-}
+ VP8_COMMON *cm = &pbi->common;
+ MACROBLOCKD *mbd = &pbi->mb;
+ //YV12_BUFFER_CONFIG *post = &cm->new_frame; //frame_to_show;
+ loop_filter_info *lfi = cm->lf_info;
+ int frame_type = cm->frame_type;
-void vp8_stop_lfthread(VP8D_COMP *pbi)
-{
-#if CONFIG_MULTITHREAD
- /*
- struct vpx_usec_timer timer;
+ //int mb_row;
+ //int mb_col;
+ //int baseline_filter_level[MAX_MB_SEGMENTS];
+ int filter_level;
+ int alt_flt_enabled = mbd->segmentation_enabled;
- vpx_usec_timer_start(&timer);
+ int i;
+ //unsigned char *y_ptr, *u_ptr, *v_ptr;
- sem_wait(&pbi->h_event_end_lpf);
+ // Note the baseline filter values for each segment
+ if (alt_flt_enabled)
+ {
+ for (i = 0; i < MAX_MB_SEGMENTS; i++)
+ {
+ // Abs value
+ if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
+ pbi->mt_baseline_filter_level[i] = mbd->segment_feature_data[MB_LVL_ALT_LF][i];
+ // Delta Value
+ else
+ {
+ pbi->mt_baseline_filter_level[i] = default_filt_lvl + mbd->segment_feature_data[MB_LVL_ALT_LF][i];
+ pbi->mt_baseline_filter_level[i] = (pbi->mt_baseline_filter_level[i] >= 0) ? ((pbi->mt_baseline_filter_level[i] <= MAX_LOOP_FILTER) ? pbi->mt_baseline_filter_level[i] : MAX_LOOP_FILTER) : 0; // Clamp to valid range
+ }
+ }
+ }
+ else
+ {
+ for (i = 0; i < MAX_MB_SEGMENTS; i++)
+ pbi->mt_baseline_filter_level[i] = default_filt_lvl;
+ }
- vpx_usec_timer_mark(&timer);
- pbi->time_loop_filtering += vpx_usec_timer_elapsed(&timer);
- */
- (void) pbi;
+ // Initialize the loop filter for this frame.
+ if ((cm->last_filter_type != cm->filter_type) || (cm->last_sharpness_level != cm->sharpness_level))
+ vp8_init_loop_filter(cm);
+ else if (frame_type != cm->last_frame_type)
+ vp8_frame_init_loop_filter(lfi, frame_type);
#else
(void) pbi;
+ (void) default_filt_lvl;
#endif
}
-void vp8_mtdecode_mb_rows(VP8D_COMP *pbi,
- MACROBLOCKD *xd)
+void vp8mt_decode_mb_rows( VP8D_COMP *pbi, MACROBLOCKD *xd)
{
#if CONFIG_MULTITHREAD
int mb_row;
int ibc = 0;
int num_part = 1 << pbi->common.multi_token_partition;
- int i;
+ int i, j;
volatile int *last_row_current_mb_col = NULL;
+ int filter_level;
+ loop_filter_info *lfi = pc->lf_info;
+ int alt_flt_enabled = xd->segmentation_enabled;
+ int Segment;
+
+ if(pbi->common.filter_level)
+ {
+ //Set above_row buffer to 127 for decoding first MB row
+ vpx_memset(pbi->mt_yabove_row[0] + VP8BORDERINPIXELS-1, 127, pc->yv12_fb[pc->lst_fb_idx].y_width + 5);
+ vpx_memset(pbi->mt_uabove_row[0] + (VP8BORDERINPIXELS>>1)-1, 127, (pc->yv12_fb[pc->lst_fb_idx].y_width>>1) +5);
+ vpx_memset(pbi->mt_vabove_row[0] + (VP8BORDERINPIXELS>>1)-1, 127, (pc->yv12_fb[pc->lst_fb_idx].y_width>>1) +5);
+
+ for (i=1; i<pc->mb_rows; i++)
+ {
+ vpx_memset(pbi->mt_yabove_row[i] + VP8BORDERINPIXELS-1, (unsigned char)129, 1);
+ vpx_memset(pbi->mt_uabove_row[i] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
+ vpx_memset(pbi->mt_vabove_row[i] + (VP8BORDERINPIXELS>>1)-1, (unsigned char)129, 1);
+ }
+
+ //Set left_col to 129 initially
+ for (i=0; i<pc->mb_rows; i++)
+ {
+ vpx_memset(pbi->mt_yleft_col[i], (unsigned char)129, 16);
+ vpx_memset(pbi->mt_uleft_col[i], (unsigned char)129, 8);
+ vpx_memset(pbi->mt_vleft_col[i], (unsigned char)129, 8);
+ }
+ vp8mt_lpf_init(pbi, pc->filter_level);
+ }
+
vp8_setup_decoding_thread_data(pbi, xd, pbi->mb_row_di, pbi->decoding_thread_count);
for (i = 0; i < pbi->decoding_thread_count; i++)
// volatile int *last_row_current_mb_col = NULL;
if (mb_row > 0)
- last_row_current_mb_col = &pbi->current_mb_col[mb_row -1];
+ last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];
vpx_memset(&pc->left_context, 0, sizeof(pc->left_context));
recon_yoffset = mb_row * recon_y_stride * 16;
}
}
+ if(pbi->common.filter_level)
+ {
+ //update loopfilter info
+ Segment = (alt_flt_enabled) ? xd->mode_info_context->mbmi.segment_id : 0;
+ filter_level = pbi->mt_baseline_filter_level[Segment];
+ // Distance of Mb to the various image edges.
+ // These specified to 8th pel as they are always compared to values that are in 1/8th pel units
+ // Apply any context driven MB level adjustment
+ vp8_adjust_mb_lf_value(xd, &filter_level);
+ }
+
// Distance of Mb to the various image edges.
// These specified to 8th pel as they are always compared to values that are in 1/8th pel units
xd->mb_to_left_edge = -((mb_col * 16) << 3);
xd->pre.v_buffer = pc->yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;
vp8_build_uvmvs(xd, pc->full_pixel);
+ vp8mt_decode_macroblock(pbi, xd, mb_row, mb_col);
+
+ if (pbi->common.filter_level)
+ {
+ //Save decoded MB last row data for next-row decoding
+ if(mb_row != pc->mb_rows-1)
+ {
+ vpx_memcpy((pbi->mt_yabove_row[mb_row +1] + 32 + mb_col*16), (xd->dst.y_buffer + 15 * recon_y_stride), 16);
+ vpx_memcpy((pbi->mt_uabove_row[mb_row +1] + 16 + mb_col*8), (xd->dst.u_buffer + 7 * recon_uv_stride), 8);
+ vpx_memcpy((pbi->mt_vabove_row[mb_row +1] + 16 + mb_col*8), (xd->dst.v_buffer + 7 * recon_uv_stride), 8);
+ }
+
+ //save left_col for next MB decoding
+ if(mb_col != pc->mb_cols-1)
+ {
+ MODE_INFO *next = xd->mode_info_context +1;
+
+ if (xd->frame_type == KEY_FRAME || next->mbmi.ref_frame == INTRA_FRAME)
+ {
+ for (i = 0; i < 16; i++)
+ pbi->mt_yleft_col[mb_row][i] = xd->dst.y_buffer [i* recon_y_stride + 15];
+ for (i = 0; i < 8; i++)
+ {
+ pbi->mt_uleft_col[mb_row][i] = xd->dst.u_buffer [i* recon_uv_stride + 7];
+ pbi->mt_vleft_col[mb_row][i] = xd->dst.v_buffer [i* recon_uv_stride + 7];
+ }
+ }
+ }
+
+ // loopfilter on this macroblock.
+ if (filter_level)
+ {
+ if (mb_col > 0)
+ pc->lf_mbv(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
- vp8_decode_macroblock(pbi, xd);
+ if (xd->mode_info_context->mbmi.dc_diff > 0)
+ pc->lf_bv(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+
+ // don't apply across umv border
+ if (mb_row > 0)
+ pc->lf_mbh(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+
+ if (xd->mode_info_context->mbmi.dc_diff > 0)
+ pc->lf_bh(xd->dst.y_buffer, xd->dst.u_buffer, xd->dst.v_buffer, recon_y_stride, recon_uv_stride, &lfi[filter_level], pc->simpler_lpf);
+ }
+ }
recon_yoffset += 16;
recon_uvoffset += 8;
xd->above_context++;
- //pbi->current_mb_col_main = mb_col;
- pbi->current_mb_col[mb_row] = mb_col;
+ pbi->mt_current_mb_col[mb_row] = mb_col;
}
// adjust to the next row of mbs
- vp8_extend_mb_row(
- &pc->yv12_fb[dst_fb_idx],
- xd->dst.y_buffer + 16, xd->dst.u_buffer + 8, xd->dst.v_buffer + 8
- );
+ if (pbi->common.filter_level)
+ {
+ if(mb_row != pc->mb_rows-1)
+ {
+ int lasty = pc->yv12_fb[ref_fb_idx].y_width + VP8BORDERINPIXELS;
+ int lastuv = (pc->yv12_fb[ref_fb_idx].y_width>>1) + (VP8BORDERINPIXELS>>1);
- ++xd->mode_info_context; /* skip prediction column */
+ for (i = 0; i < 4; i++)
+ {
+ pbi->mt_yabove_row[mb_row +1][lasty + i] = pbi->mt_yabove_row[mb_row +1][lasty -1];
+ pbi->mt_uabove_row[mb_row +1][lastuv + i] = pbi->mt_uabove_row[mb_row +1][lastuv -1];
+ pbi->mt_vabove_row[mb_row +1][lastuv + i] = pbi->mt_vabove_row[mb_row +1][lastuv -1];
+ }
+ }
+ }else
+ vp8_extend_mb_row(&pc->yv12_fb[dst_fb_idx], xd->dst.y_buffer + 16, xd->dst.u_buffer + 8, xd->dst.v_buffer + 8);
- pbi->last_mb_row_decoded = mb_row;
+ ++xd->mode_info_context; /* skip prediction column */
}
xd->mode_info_context += xd->mode_info_stride * pbi->decoding_thread_count;
}
(void) xd;
#endif
}
-
-
-void vp8_mt_loop_filter_frame( VP8D_COMP *pbi)
-{
-#if CONFIG_MULTITHREAD
- VP8_COMMON *cm = &pbi->common;
- MACROBLOCKD *mbd = &pbi->mb;
- int default_filt_lvl = pbi->common.filter_level;
-
- YV12_BUFFER_CONFIG *post = cm->frame_to_show;
- loop_filter_info *lfi = cm->lf_info;
- int frame_type = cm->frame_type;
-
- int mb_row;
- int mb_col;
-
- int filter_level;
- int alt_flt_enabled = mbd->segmentation_enabled;
-
- int i;
- unsigned char *y_ptr, *u_ptr, *v_ptr;
-
- volatile int *last_row_current_mb_col=NULL;
-
- vp8_setup_loop_filter_thread_data(pbi, mbd, pbi->mb_row_di, pbi->decoding_thread_count);
-
- mbd->mode_info_context = cm->mi; // Point at base of Mb MODE_INFO list
-
- // Note the baseline filter values for each segment
- if (alt_flt_enabled)
- {
- for (i = 0; i < MAX_MB_SEGMENTS; i++)
- {
- // Abs value
- if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
- pbi->mt_baseline_filter_level[i] = mbd->segment_feature_data[MB_LVL_ALT_LF][i];
- // Delta Value
- else
- {
- pbi->mt_baseline_filter_level[i] = default_filt_lvl + mbd->segment_feature_data[MB_LVL_ALT_LF][i];
- pbi->mt_baseline_filter_level[i] = (pbi->mt_baseline_filter_level[i] >= 0) ? ((pbi->mt_baseline_filter_level[i] <= MAX_LOOP_FILTER) ? pbi->mt_baseline_filter_level[i] : MAX_LOOP_FILTER) : 0; // Clamp to valid range
- }
- }
- }
- else
- {
- for (i = 0; i < MAX_MB_SEGMENTS; i++)
- pbi->mt_baseline_filter_level[i] = default_filt_lvl;
- }
-
- // Initialize the loop filter for this frame.
- if ((cm->last_filter_type != cm->filter_type) || (cm->last_sharpness_level != cm->sharpness_level))
- vp8_init_loop_filter(cm);
- else if (frame_type != cm->last_frame_type)
- vp8_frame_init_loop_filter(lfi, frame_type);
-
- for (i = 0; i < pbi->decoding_thread_count; i++)
- sem_post(&pbi->h_event_start_lpf[i]);
- // sem_post(&pbi->h_event_start_lpf);
-
- // Set up the buffer pointers
- y_ptr = post->y_buffer;
- u_ptr = post->u_buffer;
- v_ptr = post->v_buffer;
-
- // vp8_filter each macro block
- for (mb_row = 0; mb_row < cm->mb_rows; mb_row+= (pbi->decoding_thread_count + 1))
- {
- if (mb_row > 0)
- last_row_current_mb_col = &pbi->current_mb_col[mb_row -1];
-
- for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
- {
- int Segment = (alt_flt_enabled) ? mbd->mode_info_context->mbmi.segment_id : 0;
-
- if ( mb_row > 0 && (mb_col & 7) == 0){
- // if ( mb_row > 0 ){
- while (mb_col > (*last_row_current_mb_col-8) && *last_row_current_mb_col != cm->mb_cols - 1)
- {
- x86_pause_hint();
- thread_sleep(0);
- }
- }
-
- filter_level = pbi->mt_baseline_filter_level[Segment];
-
- // Distance of Mb to the various image edges.
- // These specified to 8th pel as they are always compared to values that are in 1/8th pel units
- // Apply any context driven MB level adjustment
- vp8_adjust_mb_lf_value(mbd, &filter_level);
-
- if (filter_level)
- {
- if (mb_col > 0)
- cm->lf_mbv(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
-
- if (mbd->mode_info_context->mbmi.dc_diff > 0)
- cm->lf_bv(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
-
- // don't apply across umv border
- if (mb_row > 0)
- cm->lf_mbh(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
-
- if (mbd->mode_info_context->mbmi.dc_diff > 0)
- cm->lf_bh(y_ptr, u_ptr, v_ptr, post->y_stride, post->uv_stride, &lfi[filter_level], cm->simpler_lpf);
- }
-
- y_ptr += 16;
- u_ptr += 8;
- v_ptr += 8;
-
- mbd->mode_info_context++; // step to next MB
- pbi->current_mb_col[mb_row] = mb_col;
- }
- mbd->mode_info_context++; // Skip border mb
-
- //update for multi-thread
- y_ptr += post->y_stride * 16 * (pbi->decoding_thread_count + 1) - post->y_width;
- u_ptr += post->uv_stride * 8 * (pbi->decoding_thread_count + 1) - post->uv_width;
- v_ptr += post->uv_stride * 8 * (pbi->decoding_thread_count + 1) - post->uv_width;
- mbd->mode_info_context += pbi->decoding_thread_count * mbd->mode_info_stride;
- }
-
- sem_wait(&pbi->h_event_end_lpf);
-#else
- (void) pbi;
-#endif
-}