threading.c 36.9 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9 10 11 12 13 14
 */


#ifndef WIN32
# include <unistd.h>
#endif
15 16 17
#ifdef __APPLE__
#include <mach/mach_init.h>
#endif
John Koleszar's avatar
John Koleszar committed
18 19 20 21 22 23 24
#include "onyxd_int.h"
#include "vpx_mem/vpx_mem.h"
#include "threading.h"

#include "loopfilter.h"
#include "extend.h"
#include "vpx_ports/vpx_timer.h"
25 26 27
#include "detokenize.h"
#include "reconinter.h"
#include "reconintra_mt.h"
John Koleszar's avatar
John Koleszar committed
28

29 30
extern void mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
extern void clamp_mvs(MACROBLOCKD *xd);
John Koleszar's avatar
John Koleszar committed
31 32
extern void vp8_build_uvmvs(MACROBLOCKD *x, int fullpixel);

33 34 35 36 37
#if CONFIG_RUNTIME_CPU_DETECT
#define RTCD_VTABLE(x) (&(pbi)->common.rtcd.x)
#else
#define RTCD_VTABLE(x) NULL
#endif
38

John Koleszar's avatar
John Koleszar committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
void vp8_setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
{
#if CONFIG_MULTITHREAD
    VP8_COMMON *const pc = & pbi->common;
    int i, j;

    for (i = 0; i < count; i++)
    {
        MACROBLOCKD *mbd = &mbrd[i].mbd;
#if CONFIG_RUNTIME_CPU_DETECT
        mbd->rtcd = xd->rtcd;
#endif
        mbd->subpixel_predict        = xd->subpixel_predict;
        mbd->subpixel_predict8x4     = xd->subpixel_predict8x4;
        mbd->subpixel_predict8x8     = xd->subpixel_predict8x8;
        mbd->subpixel_predict16x16   = xd->subpixel_predict16x16;

        mbd->mode_info_context = pc->mi   + pc->mode_info_stride * (i + 1);
        mbd->mode_info_stride  = pc->mode_info_stride;

        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;

63 64
        mbd->pre = pc->yv12_fb[pc->lst_fb_idx];
        mbd->dst = pc->yv12_fb[pc->new_fb_idx];
John Koleszar's avatar
John Koleszar committed
65 66 67 68 69 70 71

        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));

72
        /*signed char ref_lf_deltas[MAX_REF_LF_DELTAS];*/
73
        vpx_memcpy(mbd->ref_lf_deltas, xd->ref_lf_deltas, sizeof(xd->ref_lf_deltas));
74
        /*signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];*/
75
        vpx_memcpy(mbd->mode_lf_deltas, xd->mode_lf_deltas, sizeof(xd->mode_lf_deltas));
76 77
        /*unsigned char mode_ref_lf_delta_enabled;
        unsigned char mode_ref_lf_delta_update;*/
78 79 80
        mbd->mode_ref_lf_delta_enabled    = xd->mode_ref_lf_delta_enabled;
        mbd->mode_ref_lf_delta_update    = xd->mode_ref_lf_delta_update;

John Koleszar's avatar
John Koleszar committed
81 82 83 84 85 86 87 88
        mbd->current_bc = &pbi->bc2;

        for (j = 0; j < 25; j++)
        {
            mbd->block[j].dequant = xd->block[j].dequant;
        }
    }

89
    for (i=0; i< pc->mb_rows; i++)
90
        pbi->mt_current_mb_col[i]=-1;
John Koleszar's avatar
John Koleszar committed
91 92 93 94 95 96 97 98
#else
    (void) pbi;
    (void) xd;
    (void) mbrd;
    (void) count;
#endif
}

99 100

void vp8mt_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd, int mb_row, int mb_col)
101 102
{
#if CONFIG_MULTITHREAD
103 104 105
    int eobtotal = 0;
    int i, do_clamp = xd->mode_info_context->mbmi.need_to_clamp_mvs;
    VP8_COMMON *pc = &pbi->common;
106

107
    if (xd->mode_info_context->mbmi.mb_skip_coeff)
108
    {
109 110 111 112 113 114
        vp8_reset_mb_tokens_context(xd);
    }
    else
    {
        eobtotal = vp8_decode_mb_tokens(pbi, xd);
    }
115

116
    /* Perform temporary clamping of the MV to be used for prediction */
117 118 119 120
    if (do_clamp)
    {
        clamp_mvs(xd);
    }
121

122
    xd->mode_info_context->mbmi.dc_diff = 1;
123

124 125 126
    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;
127

128
        /*mt_skip_recon_mb(pbi, xd, mb_row, mb_col);*/
129 130 131 132 133 134 135 136 137 138 139
        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;
    }
140

141 142
    if (xd->segmentation_enabled)
        mb_init_dequantizer(pbi, xd);
143

144
    /* do prediction */
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    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);
    }
160

161
    /* dequantization and idct */
162 163 164 165
    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);
166

167
        /* do 2nd order transform on the dc block */
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
        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)
187
                        (xd->qcoeff, xd->block[0].dequant,
188 189
                         xd->predictor, xd->dst.y_buffer,
                         xd->dst.y_stride, xd->eobs, xd->block[24].diff);
190
    }
191 192 193 194 195 196
    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);
197

198 199 200
            if (xd->eobs[i] > 1)
            {
                DEQUANT_INVOKE(&pbi->dequant, idct_add)
201
                    (b->qcoeff, b->dequant,  b->predictor,
202 203 204 205 206
                    *(b->base_dst) + b->dst, 16, b->dst_stride);
            }
            else
            {
                IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)
207
                    (b->qcoeff[0] * b->dequant[0], b->predictor,
208 209 210 211 212 213 214 215
                    *(b->base_dst) + b->dst, 16, b->dst_stride);
                ((int *)b->qcoeff)[0] = 0;
            }
        }
    }
    else
    {
        DEQUANT_INVOKE (&pbi->dequant, idct_add_y_block)
216
                        (xd->qcoeff, xd->block[0].dequant,
217 218 219 220 221
                         xd->predictor, xd->dst.y_buffer,
                         xd->dst.y_stride, xd->eobs);
    }

    DEQUANT_INVOKE (&pbi->dequant, idct_add_uv_block)
222
                    (xd->qcoeff+16*16, xd->block[16].dequant,
223 224
                     xd->predictor+16*16, xd->dst.u_buffer, xd->dst.v_buffer,
                     xd->dst.uv_stride, xd->eobs+16);
225 226 227
#else
    (void) pbi;
    (void) xd;
228 229
    (void) mb_row;
    (void) mb_col;
230 231
#endif
}
John Koleszar's avatar
John Koleszar committed
232

233

John Koleszar's avatar
John Koleszar committed
234 235 236 237 238 239
THREAD_FUNCTION vp8_thread_decoding_proc(void *p_data)
{
#if CONFIG_MULTITHREAD
    int ithread = ((DECODETHREAD_DATA *)p_data)->ithread;
    VP8D_COMP *pbi = (VP8D_COMP *)(((DECODETHREAD_DATA *)p_data)->ptr1);
    MB_ROW_DEC *mbrd = (MB_ROW_DEC *)(((DECODETHREAD_DATA *)p_data)->ptr2);
240
    ENTROPY_CONTEXT_PLANES mb_row_left_context;
John Koleszar's avatar
John Koleszar committed
241 242 243 244 245 246

    while (1)
    {
        if (pbi->b_multithreaded_rd == 0)
            break;

247
        /*if(WaitForSingleObject(pbi->h_event_start_decoding[ithread], INFINITE) == WAIT_OBJECT_0)*/
248
        if (sem_wait(&pbi->h_event_start_decoding[ithread]) == 0)
John Koleszar's avatar
John Koleszar committed
249 250 251 252 253 254 255 256
        {
            if (pbi->b_multithreaded_rd == 0)
                break;
            else
            {
                VP8_COMMON *pc = &pbi->common;
                MACROBLOCKD *xd = &mbrd->mbd;

257 258
                int mb_row;
                int num_part = 1 << pbi->common.multi_token_partition;
John Koleszar's avatar
John Koleszar committed
259
                volatile int *last_row_current_mb_col;
260
                int nsync = pbi->sync_range;
John Koleszar's avatar
John Koleszar committed
261

262
                for (mb_row = ithread+1; mb_row < pc->mb_rows; mb_row += (pbi->decoding_thread_count + 1))
John Koleszar's avatar
John Koleszar committed
263
                {
264 265 266 267 268 269 270 271
                    int i;
                    int recon_yoffset, recon_uvoffset;
                    int mb_col;
                    int ref_fb_idx = pc->lst_fb_idx;
                    int dst_fb_idx = pc->new_fb_idx;
                    int recon_y_stride = pc->yv12_fb[ref_fb_idx].y_stride;
                    int recon_uv_stride = pc->yv12_fb[ref_fb_idx].uv_stride;

272 273 274 275 276
                    int filter_level;
                    loop_filter_info *lfi = pc->lf_info;
                    int alt_flt_enabled = xd->segmentation_enabled;
                    int Segment;

277 278 279
                    pbi->mb_row_di[ithread].mb_row = mb_row;
                    pbi->mb_row_di[ithread].mbd.current_bc =  &pbi->mbc[mb_row%num_part];

280
                    last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];
281 282 283

                    recon_yoffset = mb_row * recon_y_stride * 16;
                    recon_uvoffset = mb_row * recon_uv_stride * 8;
284
                    /* reset above block coeffs */
285

286 287 288
                    xd->above_context = pc->above_context;
                    xd->left_context = &mb_row_left_context;
                    vpx_memset(&mb_row_left_context, 0, sizeof(mb_row_left_context));
289 290 291 292 293 294
                    xd->up_available = (mb_row != 0);

                    xd->mb_to_top_edge = -((mb_row * 16)) << 3;
                    xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;

                    for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)
John Koleszar's avatar
John Koleszar committed
295
                    {
296
                        if ((mb_col & (nsync-1)) == 0)
297
                        {
298
                            while (mb_col > (*last_row_current_mb_col - nsync) && *last_row_current_mb_col != pc->mb_cols - 1)
299 300 301 302 303
                            {
                                x86_pause_hint();
                                thread_sleep(0);
                            }
                        }
John Koleszar's avatar
John Koleszar committed
304

305
                        if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)
John Koleszar's avatar
John Koleszar committed
306
                        {
307 308 309 310 311
                            for (i = 0; i < 16; i++)
                            {
                                BLOCKD *d = &xd->block[i];
                                vpx_memcpy(&d->bmi, &xd->mode_info_context->bmi[i], sizeof(B_MODE_INFO));
                            }
John Koleszar's avatar
John Koleszar committed
312 313
                        }

314 315
                        if(pbi->common.filter_level)
                        {
316
                            /*update loopfilter info*/
317 318
                            Segment = (alt_flt_enabled) ? xd->mode_info_context->mbmi.segment_id : 0;
                            filter_level = pbi->mt_baseline_filter_level[Segment];
319 320 321 322
                            /* Distance of Mb to the various image edges.
                             * These are 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
                             */
323 324 325
                            vp8_adjust_mb_lf_value(xd, &filter_level);
                        }

326 327 328
                        /* Distance of Mb to the various image edges.
                         * These are specified to 8th pel as they are always compared to values that are in 1/8th pel units
                         */
329 330
                        xd->mb_to_left_edge = -((mb_col * 16) << 3);
                        xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;
John Koleszar's avatar
John Koleszar committed
331

332 333 334
                        xd->dst.y_buffer = pc->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
                        xd->dst.u_buffer = pc->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
                        xd->dst.v_buffer = pc->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;
John Koleszar's avatar
John Koleszar committed
335

336
                        xd->left_available = (mb_col != 0);
337

338
                        /* Select the appropriate reference frame for this MB */
339
                        if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME)
340
                            ref_fb_idx = pc->lst_fb_idx;
341
                        else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME)
342 343 344
                            ref_fb_idx = pc->gld_fb_idx;
                        else
                            ref_fb_idx = pc->alt_fb_idx;
John Koleszar's avatar
John Koleszar committed
345

346 347 348
                        xd->pre.y_buffer = pc->yv12_fb[ref_fb_idx].y_buffer + recon_yoffset;
                        xd->pre.u_buffer = pc->yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset;
                        xd->pre.v_buffer = pc->yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;
John Koleszar's avatar
John Koleszar committed
349

350
                        vp8_build_uvmvs(xd, pc->full_pixel);
351
                        vp8mt_decode_macroblock(pbi, xd, mb_row, mb_col);
John Koleszar's avatar
John Koleszar committed
352

353 354 355 356
                        if (pbi->common.filter_level)
                        {
                            if( mb_row != pc->mb_rows-1 )
                            {
357
                                /* Save decoded MB last row data for next-row decoding */
358 359 360 361 362
                                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);
                            }

363
                            /* save left_col for next MB decoding */
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
                            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];
                                    }
                                }
                            }

380
                          /* loopfilter on this macroblock. */
381 382 383 384 385 386 387 388
                            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);

389
                                /* don't apply across umv border */
390 391 392 393 394 395 396
                                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);
                            }
                        }
John Koleszar's avatar
John Koleszar committed
397

398 399
                        recon_yoffset += 16;
                        recon_uvoffset += 8;
John Koleszar's avatar
John Koleszar committed
400

401
                        ++xd->mode_info_context;  /* next mb */
John Koleszar's avatar
John Koleszar committed
402

403
                        xd->above_context++;
John Koleszar's avatar
John Koleszar committed
404

405
                        /*pbi->mb_row_di[ithread].current_mb_col = mb_col;*/
406
                        pbi->mt_current_mb_col[mb_row] = mb_col;
407
                    }
John Koleszar's avatar
John Koleszar committed
408

409
                    /* adjust to the next row of mbs */
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
                    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);
John Koleszar's avatar
John Koleszar committed
426

427
                    ++xd->mode_info_context;      /* skip prediction column */
John Koleszar's avatar
John Koleszar committed
428

429
                    /* since we have multithread */
430
                    xd->mode_info_context += xd->mode_info_stride * pbi->decoding_thread_count;
John Koleszar's avatar
John Koleszar committed
431 432 433
                }
            }
        }
434
        /*  add this to each frame */
435 436
        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))
        {
437
            /*SetEvent(pbi->h_event_end_decoding);*/
438 439 440
            sem_post(&pbi->h_event_end_decoding);
        }
    }
John Koleszar's avatar
John Koleszar committed
441 442 443 444 445 446 447
#else
    (void) p_data;
#endif

    return 0 ;
}

448

449
void vp8_decoder_create_threads(VP8D_COMP *pbi)
John Koleszar's avatar
John Koleszar committed
450 451
{
#if CONFIG_MULTITHREAD
452 453
    int core_count = 0;
    int ithread;
John Koleszar's avatar
John Koleszar committed
454

455 456 457
    pbi->b_multithreaded_rd = 0;
    pbi->allocated_decoding_thread_count = 0;
    core_count = (pbi->max_threads > 16) ? 16 : pbi->max_threads;
John Koleszar's avatar
John Koleszar committed
458

459 460 461 462
    if (core_count > 1)
    {
        pbi->b_multithreaded_rd = 1;
        pbi->decoding_thread_count = core_count -1;
John Koleszar's avatar
John Koleszar committed
463

464 465 466 467 468
        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));
John Koleszar's avatar
John Koleszar committed
469

470 471 472
        for (ithread = 0; ithread < pbi->decoding_thread_count; ithread++)
        {
            sem_init(&pbi->h_event_start_decoding[ithread], 0, 0);
John Koleszar's avatar
John Koleszar committed
473

474 475 476
            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];
John Koleszar's avatar
John Koleszar committed
477

478 479
            pthread_create(&pbi->h_decoding_thread[ithread], 0, vp8_thread_decoding_proc, (&pbi->de_thread_data[ithread]));
        }
480

481
        sem_init(&pbi->h_event_end_decoding, 0, 0);
John Koleszar's avatar
John Koleszar committed
482

483 484
        pbi->allocated_decoding_thread_count = pbi->decoding_thread_count;
    }
John Koleszar's avatar
John Koleszar committed
485

486 487 488 489
#else
    (void) pbi;
#endif
}
John Koleszar's avatar
John Koleszar committed
490 491


492 493 494 495 496
void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows)
{
#if CONFIG_MULTITHREAD
    VP8_COMMON *const pc = & pbi->common;
    int i;
John Koleszar's avatar
John Koleszar committed
497

498 499 500 501 502 503 504
    if (pbi->b_multithreaded_rd)
    {
        if (pbi->mt_current_mb_col)
        {
            vpx_free(pbi->mt_current_mb_col);
            pbi->mt_current_mb_col = NULL ;
        }
John Koleszar's avatar
John Koleszar committed
505

506
        /* Free above_row buffers. */
507 508 509 510 511 512 513 514 515 516 517 518 519
        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 ;
        }
John Koleszar's avatar
John Koleszar committed
520

521 522 523 524 525 526 527 528 529 530 531 532 533
        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 ;
        }
John Koleszar's avatar
John Koleszar committed
534

535 536 537 538 539 540 541 542 543 544 545 546 547
        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 ;
        }
John Koleszar's avatar
John Koleszar committed
548

549
        /* Free left_col buffers. */
550 551 552 553 554 555 556 557 558 559 560 561 562
        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 ;
        }
John Koleszar's avatar
John Koleszar committed
563

564 565 566 567 568 569 570 571
        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 ;
572 573
                }
            }
574 575
            vpx_free(pbi->mt_uleft_col);
            pbi->mt_uleft_col = NULL ;
John Koleszar's avatar
John Koleszar committed
576 577
        }

578
        if (pbi->mt_vleft_col)
579
        {
580 581 582 583 584 585 586 587 588 589
            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 ;
590
        }
591
    }
John Koleszar's avatar
John Koleszar committed
592
#else
593
    (void) pbi;
John Koleszar's avatar
John Koleszar committed
594 595 596
#endif
}

597

598
void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows)
John Koleszar's avatar
John Koleszar committed
599 600
{
#if CONFIG_MULTITHREAD
601 602 603
    VP8_COMMON *const pc = & pbi->common;
    int i;
    int uv_width;
John Koleszar's avatar
John Koleszar committed
604

605
    if (pbi->b_multithreaded_rd)
John Koleszar's avatar
John Koleszar committed
606
    {
607
        vp8mt_de_alloc_temp_buffers(pbi, prev_mb_rows);
John Koleszar's avatar
John Koleszar committed
608

609
        /* our internal buffers are always multiples of 16 */
610 611
        if ((width & 0xf) != 0)
            width += 16 - (width & 0xf);
John Koleszar's avatar
John Koleszar committed
612

613 614 615 616 617
        if (width < 640) pbi->sync_range = 1;
        else if (width <= 1280) pbi->sync_range = 8;
        else if (width <= 2560) pbi->sync_range =16;
        else pbi->sync_range = 32;

618
        uv_width = width >>1;
619

620
        /* Allocate an int for each mb row. */
621
        CHECK_MEM_ERROR(pbi->mt_current_mb_col, vpx_malloc(sizeof(int) * pc->mb_rows));
John Koleszar's avatar
John Koleszar committed
622

623
        /* Allocate memory for above_row buffers. */
624 625 626
        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));
John Koleszar's avatar
John Koleszar committed
627

628 629 630
        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));
John Koleszar's avatar
John Koleszar committed
631

632 633 634
        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));
635

636
        /* Allocate memory for left_col buffers. */
637 638 639
        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));
John Koleszar's avatar
John Koleszar committed
640

641 642 643 644 645 646 647 648
        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));
    }
John Koleszar's avatar
John Koleszar committed
649 650
#else
    (void) pbi;
651
    (void) width;
John Koleszar's avatar
John Koleszar committed
652 653 654
#endif
}

655

John Koleszar's avatar
John Koleszar committed
656 657 658 659
void vp8_decoder_remove_threads(VP8D_COMP *pbi)
{
#if CONFIG_MULTITHREAD

660
    /* shutdown MB Decoding thread; */
John Koleszar's avatar
John Koleszar committed
661 662
    if (pbi->b_multithreaded_rd)
    {
663 664
        int i;

John Koleszar's avatar
John Koleszar committed
665
        pbi->b_multithreaded_rd = 0;
666

667
        /* allow all threads to exit */
668
        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
John Koleszar's avatar
John Koleszar committed
669
        {
670 671
            sem_post(&pbi->h_event_start_decoding[i]);
            pthread_join(pbi->h_decoding_thread[i], NULL);
John Koleszar's avatar
John Koleszar committed
672 673
        }

674 675 676
        for (i = 0; i < pbi->allocated_decoding_thread_count; i++)
        {
            sem_destroy(&pbi->h_event_start_decoding[i]);
John Koleszar's avatar
John Koleszar committed
677 678
        }

679
        sem_destroy(&pbi->h_event_end_decoding);
John Koleszar's avatar
John Koleszar committed
680 681 682 683 684 685 686

        if (pbi->h_decoding_thread)
        {
            vpx_free(pbi->h_decoding_thread);
            pbi->h_decoding_thread = NULL;
        }

687
        if (pbi->h_event_start_decoding)
John Koleszar's avatar
John Koleszar committed
688
        {
689 690 691 692
            vpx_free(pbi->h_event_start_decoding);
            pbi->h_event_start_decoding = NULL;
        }

John Koleszar's avatar
John Koleszar committed
693 694 695 696 697 698 699 700 701 702 703
        if (pbi->mb_row_di)
        {
            vpx_free(pbi->mb_row_di);
            pbi->mb_row_di = NULL ;
        }

        if (pbi->de_thread_data)
        {
            vpx_free(pbi->de_thread_data);
            pbi->de_thread_data = NULL;
        }
704
    }
John Koleszar's avatar
John Koleszar committed
705 706 707 708 709 710
#else
    (void) pbi;
#endif
}


711
void vp8mt_lpf_init( VP8D_COMP *pbi, int default_filt_lvl)
John Koleszar's avatar
John Koleszar committed
712 713
{
#if CONFIG_MULTITHREAD
714 715
    VP8_COMMON *cm  = &pbi->common;
    MACROBLOCKD *mbd = &pbi->mb;
716
    /*YV12_BUFFER_CONFIG *post = &cm->new_frame;*/  /*frame_to_show;*/
717
    loop_filter_info *lfi = cm->lf_info;
718
    FRAME_TYPE frame_type = cm->frame_type;
John Koleszar's avatar
John Koleszar committed
719

720 721 722
    /*int mb_row;
    int mb_col;
    int baseline_filter_level[MAX_MB_SEGMENTS];*/
723
    int alt_flt_enabled = mbd->segmentation_enabled;
John Koleszar's avatar
John Koleszar committed
724

725
    int i;
726
    /*unsigned char *y_ptr, *u_ptr, *v_ptr;*/
John Koleszar's avatar
John Koleszar committed
727

728
    /* Note the baseline filter values for each segment */
729 730 731 732
    if (alt_flt_enabled)
    {
        for (i = 0; i < MAX_MB_SEGMENTS; i++)
        {
733
            /* Abs value */
734 735
            if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
                pbi->mt_baseline_filter_level[i] = mbd->segment_feature_data[MB_LVL_ALT_LF][i];
736
            /* Delta Value */
737 738 739
            else
            {
                pbi->mt_baseline_filter_level[i] = default_filt_lvl + mbd->segment_feature_data[MB_LVL_ALT_LF][i];
740
                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 */
741 742 743 744 745 746 747 748
            }
        }
    }
    else
    {
        for (i = 0; i < MAX_MB_SEGMENTS; i++)
            pbi->mt_baseline_filter_level[i] = default_filt_lvl;
    }
John Koleszar's avatar
John Koleszar committed
749

750
    /* Initialize the loop filter for this frame. */
751 752 753 754
    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);
John Koleszar's avatar
John Koleszar committed
755 756
#else
    (void) pbi;
757
    (void) default_filt_lvl;
John Koleszar's avatar
John Koleszar committed
758 759 760 761
#endif
}


762
void vp8mt_decode_mb_rows( VP8D_COMP *pbi, MACROBLOCKD *xd)
John Koleszar's avatar
John Koleszar committed
763 764 765 766 767 768 769
{
#if CONFIG_MULTITHREAD
    int mb_row;
    VP8_COMMON *pc = &pbi->common;

    int ibc = 0;
    int num_part = 1 << pbi->common.multi_token_partition;
Henrik Lundin's avatar
Henrik Lundin committed
770
    int i;
771
    volatile int *last_row_current_mb_col = NULL;
772
    int nsync = pbi->sync_range;
John Koleszar's avatar
John Koleszar committed
773

774 775 776 777 778 779 780
    int filter_level;
    loop_filter_info *lfi = pc->lf_info;
    int alt_flt_enabled = xd->segmentation_enabled;
    int Segment;

    if(pbi->common.filter_level)
    {
781
        /* Set above_row buffer to 127 for decoding first MB row */
782 783 784 785 786 787 788 789 790 791 792
        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);
        }

793
        /* Set left_col to 129 initially */
794 795 796 797 798 799 800 801 802
        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);
    }

John Koleszar's avatar
John Koleszar committed
803 804
    vp8_setup_decoding_thread_data(pbi, xd, pbi->mb_row_di, pbi->decoding_thread_count);

805 806 807
    for (i = 0; i < pbi->decoding_thread_count; i++)
        sem_post(&pbi->h_event_start_decoding[i]);

John Koleszar's avatar
John Koleszar committed
808 809 810
    for (mb_row = 0; mb_row < pc->mb_rows; mb_row += (pbi->decoding_thread_count + 1))
    {

811
        xd->current_bc = &pbi->mbc[mb_row%num_part];
John Koleszar's avatar
John Koleszar committed
812

813
        /* vp8_decode_mb_row(pbi, pc, mb_row, xd); */
John Koleszar's avatar
John Koleszar committed
814
        {
815 816 817 818 819 820 821 822
            int i;
            int recon_yoffset, recon_uvoffset;
            int mb_col;
            int ref_fb_idx = pc->lst_fb_idx;
            int dst_fb_idx = pc->new_fb_idx;
            int recon_y_stride = pc->yv12_fb[ref_fb_idx].y_stride;
            int recon_uv_stride = pc->yv12_fb[ref_fb_idx].uv_stride;

823
           /* volatile int *last_row_current_mb_col = NULL; */
824
            if (mb_row > 0)
825
                last_row_current_mb_col = &pbi->mt_current_mb_col[mb_row -1];
826

827
            vpx_memset(&pc->left_context, 0, sizeof(pc->left_context));
828 829
            recon_yoffset = mb_row * recon_y_stride * 16;
            recon_uvoffset = mb_row * recon_uv_stride * 8;
830
            /* reset above block coeffs */
831

832
            xd->above_context = pc->above_context;
833 834 835 836 837 838 839
            xd->up_available = (mb_row != 0);

            xd->mb_to_top_edge = -((mb_row * 16)) << 3;
            xd->mb_to_bottom_edge = ((pc->mb_rows - 1 - mb_row) * 16) << 3;

            for (mb_col = 0; mb_col < pc->mb_cols; mb_col++)
            {
840 841
                if ( mb_row > 0 && (mb_col & (nsync-1)) == 0){
                    while (mb_col > (*last_row_current_mb_col - nsync) && *last_row_current_mb_col != pc->mb_cols - 1)
842 843 844 845
                    {
                        x86_pause_hint();
                        thread_sleep(0);
                    }
846
                }
John Koleszar's avatar
John Koleszar committed
847

848
                if (xd->mode_info_context->mbmi.mode == SPLITMV || xd->mode_info_context->mbmi.mode == B_PRED)
849 850 851 852 853 854 855 856
                {
                    for (i = 0; i < 16; i++)
                    {
                        BLOCKD *d = &xd->block[i];
                        vpx_memcpy(&d->bmi, &xd->mode_info_context->bmi[i], sizeof(B_MODE_INFO));
                    }
                }

857 858
                if(pbi->common.filter_level)
                {
859
                    /* update loopfilter info */
860 861
                    Segment = (alt_flt_enabled) ? xd->mode_info_context->mbmi.segment_id : 0;
                    filter_level = pbi->mt_baseline_filter_level[Segment];
862 863 864 865
                    /* Distance of Mb to the various image edges.
                     * These are 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
                     */
866 867 868
                    vp8_adjust_mb_lf_value(xd, &filter_level);
                }

869 870 871
                /* Distance of Mb to the various image edges.
                 * These are specified to 8th pel as they are always compared to values that are in 1/8th pel units
                 */
872 873 874 875 876 877 878 879 880
                xd->mb_to_left_edge = -((mb_col * 16) << 3);
                xd->mb_to_right_edge = ((pc->mb_cols - 1 - mb_col) * 16) << 3;

                xd->dst.y_buffer = pc->yv12_fb[dst_fb_idx].y_buffer + recon_yoffset;
                xd->dst.u_buffer = pc->yv12_fb[dst_fb_idx].u_buffer + recon_uvoffset;
                xd->dst.v_buffer = pc->yv12_fb[dst_fb_idx].v_buffer + recon_uvoffset;

                xd->left_available = (mb_col != 0);

881
                /* Select the appropriate reference frame for this MB */
882
                if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME)
883
                    ref_fb_idx = pc->lst_fb_idx;
884
                else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME)
885 886 887 888 889 890 891 892 893
                    ref_fb_idx = pc->gld_fb_idx;
                else
                    ref_fb_idx = pc->alt_fb_idx;

                xd->pre.y_buffer = pc->yv12_fb[ref_fb_idx].y_buffer + recon_yoffset;
                xd->pre.u_buffer = pc->yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset;
                xd->pre.v_buffer = pc->yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;

                vp8_build_uvmvs(xd, pc->full_pixel);
894 895 896 897
                vp8mt_decode_macroblock(pbi, xd, mb_row, mb_col);

                if (pbi->common.filter_level)
                {
898
                    /* Save decoded MB last row data for next-row decoding */
899 900 901 902 903 904 905
                    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);
                    }

906
                    /* save left_col for next MB decoding */
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922
                    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];
                            }
                        }
                    }

923
                    /* loopfilter on this macroblock. */
924 925 926 927
                    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);
928

929 930 931
                        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);

932
                        /* don't apply across umv border */
933 934 935 936 937 938 939
                        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);
                    }
                }
940 941 942 943 944 945

                recon_yoffset += 16;
                recon_uvoffset += 8;

                ++xd->mode_info_context;  /* next mb */

946
                xd->above_context++;
947

948
                pbi->mt_current_mb_col[mb_row] = mb_col;
949 950
            }

951
            /* adjust to the next row of mbs */
952 953 954 955 956 957
            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);
John Koleszar's avatar
John Koleszar committed