static int rv34_decode_mv(RV34DecContext *r, int block_type)

{

    MpegEncContext *s = &r->s;

    GetBitContext *gb = &s->gb;

    int i, j, k, l;

    int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;

    int next_bt;



    memset(r->dmv, 0, sizeof(r->dmv));

    for(i = 0; i < num_mvs[block_type]; i++){

        r->dmv[i][0] = get_interleaved_se_golomb(gb);

        r->dmv[i][1] = get_interleaved_se_golomb(gb);







    switch(block_type){

    case RV34_MB_TYPE_INTRA:

    case RV34_MB_TYPE_INTRA16x16:

        ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        return 0;

    case RV34_MB_SKIP:

        if(s->pict_type == AV_PICTURE_TYPE_P){

            ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

            rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0);

            break;


    case RV34_MB_B_DIRECT:

        //surprisingly, it uses motion scheme from next reference frame

        /* wait for the current mb row to be finished */

        if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))

            ff_thread_await_progress(&s->next_picture_ptr->tf, FFMAX(0, s->mb_y-1), 0);



        next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride];

        if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){

            ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

            ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        }else

            for(j = 0; j < 2; j++)

                for(i = 0; i < 2; i++)

                    for(k = 0; k < 2; k++)

                        for(l = 0; l < 2; l++)

                            s->current_picture_ptr->motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k]);

        if(!(IS_16X8(next_bt) || IS_8X16(next_bt) || IS_8X8(next_bt))) //we can use whole macroblock MC

            rv34_mc_2mv(r, block_type);

        else

            rv34_mc_2mv_skip(r);

        ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        break;

    case RV34_MB_P_16x16:

    case RV34_MB_P_MIX16x16:

        rv34_pred_mv(r, block_type, 0, 0);

        rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0);

        break;

    case RV34_MB_B_FORWARD:

    case RV34_MB_B_BACKWARD:

        r->dmv[1][0] = r->dmv[0][0];

        r->dmv[1][1] = r->dmv[0][1];

        if(r->rv30)

            rv34_pred_mv_rv3(r, block_type, block_type == RV34_MB_B_BACKWARD);

        else

            rv34_pred_mv_b  (r, block_type, block_type == RV34_MB_B_BACKWARD);

        rv34_mc_1mv     (r, block_type, 0, 0, 0, 2, 2, block_type == RV34_MB_B_BACKWARD);

        break;

    case RV34_MB_P_16x8:

    case RV34_MB_P_8x16:

        rv34_pred_mv(r, block_type, 0, 0);

        rv34_pred_mv(r, block_type, 1 + (block_type == RV34_MB_P_16x8), 1);

        if(block_type == RV34_MB_P_16x8){

            rv34_mc_1mv(r, block_type, 0, 0, 0,            2, 1, 0);

            rv34_mc_1mv(r, block_type, 0, 8, s->b8_stride, 2, 1, 0);


        if(block_type == RV34_MB_P_8x16){

            rv34_mc_1mv(r, block_type, 0, 0, 0, 1, 2, 0);

            rv34_mc_1mv(r, block_type, 8, 0, 1, 1, 2, 0);


        break;

    case RV34_MB_B_BIDIR:

        rv34_pred_mv_b  (r, block_type, 0);

        rv34_pred_mv_b  (r, block_type, 1);

        rv34_mc_2mv     (r, block_type);

        break;

    case RV34_MB_P_8x8:

        for(i=0;i< 4;i++){

            rv34_pred_mv(r, block_type, i, i);

            rv34_mc_1mv (r, block_type, (i&1)<<3, (i&2)<<2, (i&1)+(i>>1)*s->b8_stride, 1, 1, 0);


        break;




    return 0;

static int rv34_decode_mv(RV34DecContext *r, int block_type)

{

    MpegEncContext *s = &r->s;

    GetBitContext *gb = &s->gb;

    int i, j, k, l;

    int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;

    int next_bt;



    memset(r->dmv, 0, sizeof(r->dmv));

    for(i = 0; i < num_mvs[block_type]; i++){

        r->dmv[i][0] = get_interleaved_se_golomb(gb);

        r->dmv[i][1] = get_interleaved_se_golomb(gb);







    switch(block_type){

    case RV34_MB_TYPE_INTRA:

    case RV34_MB_TYPE_INTRA16x16:

        ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        return 0;

    case RV34_MB_SKIP:

        if(s->pict_type == AV_PICTURE_TYPE_P){

            ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

            rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0);

            break;


    case RV34_MB_B_DIRECT:

        

        

        if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))

            ff_thread_await_progress(&s->next_picture_ptr->tf, FFMAX(0, s->mb_y-1), 0);



        next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride];

        if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){

            ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

            ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        }else

            for(j = 0; j < 2; j++)

                for(i = 0; i < 2; i++)

                    for(k = 0; k < 2; k++)

                        for(l = 0; l < 2; l++)

                            s->current_picture_ptr->motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k]);

        if(!(IS_16X8(next_bt) || IS_8X16(next_bt) || IS_8X8(next_bt))) 

            rv34_mc_2mv(r, block_type);

        else

            rv34_mc_2mv_skip(r);

        ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        break;

    case RV34_MB_P_16x16:

    case RV34_MB_P_MIX16x16:

        rv34_pred_mv(r, block_type, 0, 0);

        rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0);

        break;

    case RV34_MB_B_FORWARD:

    case RV34_MB_B_BACKWARD:

        r->dmv[1][0] = r->dmv[0][0];

        r->dmv[1][1] = r->dmv[0][1];

        if(r->rv30)

            rv34_pred_mv_rv3(r, block_type, block_type == RV34_MB_B_BACKWARD);

        else

            rv34_pred_mv_b  (r, block_type, block_type == RV34_MB_B_BACKWARD);

        rv34_mc_1mv     (r, block_type, 0, 0, 0, 2, 2, block_type == RV34_MB_B_BACKWARD);

        break;

    case RV34_MB_P_16x8:

    case RV34_MB_P_8x16:

        rv34_pred_mv(r, block_type, 0, 0);

        rv34_pred_mv(r, block_type, 1 + (block_type == RV34_MB_P_16x8), 1);

        if(block_type == RV34_MB_P_16x8){

            rv34_mc_1mv(r, block_type, 0, 0, 0,            2, 1, 0);

            rv34_mc_1mv(r, block_type, 0, 8, s->b8_stride, 2, 1, 0);


        if(block_type == RV34_MB_P_8x16){

            rv34_mc_1mv(r, block_type, 0, 0, 0, 1, 2, 0);

            rv34_mc_1mv(r, block_type, 8, 0, 1, 1, 2, 0);


        break;

    case RV34_MB_B_BIDIR:

        rv34_pred_mv_b  (r, block_type, 0);

        rv34_pred_mv_b  (r, block_type, 1);

        rv34_mc_2mv     (r, block_type);

        break;

    case RV34_MB_P_8x8:

        for(i=0;i< 4;i++){

            rv34_pred_mv(r, block_type, i, i);

            rv34_mc_1mv (r, block_type, (i&1)<<3, (i&2)<<2, (i&1)+(i>>1)*s->b8_stride, 1, 1, 0);


        break;




    return 0;

static int FUNC_0(RV34DecContext *VAR_0, int VAR_1)

{

    MpegEncContext *s = &VAR_0->s;

    GetBitContext *gb = &s->gb;

    int VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6 = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;

    int VAR_7;



    memset(VAR_0->dmv, 0, sizeof(VAR_0->dmv));

    for(VAR_2 = 0; VAR_2 < num_mvs[VAR_1]; VAR_2++){

        VAR_0->dmv[VAR_2][0] = get_interleaved_se_golomb(gb);

        VAR_0->dmv[VAR_2][1] = get_interleaved_se_golomb(gb);







    switch(VAR_1){

    case RV34_MB_TYPE_INTRA:

    case RV34_MB_TYPE_INTRA16x16:

        ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        return 0;

    case RV34_MB_SKIP:

        if(s->pict_type == AV_PICTURE_TYPE_P){

            ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

            rv34_mc_1mv (VAR_0, VAR_1, 0, 0, 0, 2, 2, 0);

            break;


    case RV34_MB_B_DIRECT:

        

        

        if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))

            ff_thread_await_progress(&s->next_picture_ptr->tf, FFMAX(0, s->mb_y-1), 0);



        VAR_7 = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride];

        if(IS_INTRA(VAR_7) || IS_SKIP(VAR_7)){

            ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

            ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        }else

            for(VAR_3 = 0; VAR_3 < 2; VAR_3++)

                for(VAR_2 = 0; VAR_2 < 2; VAR_2++)

                    for(VAR_4 = 0; VAR_4 < 2; VAR_4++)

                        for(VAR_5 = 0; VAR_5 < 2; VAR_5++)

                            s->current_picture_ptr->motion_val[VAR_5][VAR_6 + VAR_2 + VAR_3*s->b8_stride][VAR_4] = calc_add_mv(VAR_0, VAR_5, s->next_picture_ptr->motion_val[0][VAR_6 + VAR_2 + VAR_3*s->b8_stride][VAR_4]);

        if(!(IS_16X8(VAR_7) || IS_8X16(VAR_7) || IS_8X8(VAR_7))) 

            rv34_mc_2mv(VAR_0, VAR_1);

        else

            rv34_mc_2mv_skip(VAR_0);

        ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride);

        break;

    case RV34_MB_P_16x16:

    case RV34_MB_P_MIX16x16:

        rv34_pred_mv(VAR_0, VAR_1, 0, 0);

        rv34_mc_1mv (VAR_0, VAR_1, 0, 0, 0, 2, 2, 0);

        break;

    case RV34_MB_B_FORWARD:

    case RV34_MB_B_BACKWARD:

        VAR_0->dmv[1][0] = VAR_0->dmv[0][0];

        VAR_0->dmv[1][1] = VAR_0->dmv[0][1];

        if(VAR_0->rv30)

            rv34_pred_mv_rv3(VAR_0, VAR_1, VAR_1 == RV34_MB_B_BACKWARD);

        else

            rv34_pred_mv_b  (VAR_0, VAR_1, VAR_1 == RV34_MB_B_BACKWARD);

        rv34_mc_1mv     (VAR_0, VAR_1, 0, 0, 0, 2, 2, VAR_1 == RV34_MB_B_BACKWARD);

        break;

    case RV34_MB_P_16x8:

    case RV34_MB_P_8x16:

        rv34_pred_mv(VAR_0, VAR_1, 0, 0);

        rv34_pred_mv(VAR_0, VAR_1, 1 + (VAR_1 == RV34_MB_P_16x8), 1);

        if(VAR_1 == RV34_MB_P_16x8){

            rv34_mc_1mv(VAR_0, VAR_1, 0, 0, 0,            2, 1, 0);

            rv34_mc_1mv(VAR_0, VAR_1, 0, 8, s->b8_stride, 2, 1, 0);


        if(VAR_1 == RV34_MB_P_8x16){

            rv34_mc_1mv(VAR_0, VAR_1, 0, 0, 0, 1, 2, 0);

            rv34_mc_1mv(VAR_0, VAR_1, 8, 0, 1, 1, 2, 0);


        break;

    case RV34_MB_B_BIDIR:

        rv34_pred_mv_b  (VAR_0, VAR_1, 0);

        rv34_pred_mv_b  (VAR_0, VAR_1, 1);

        rv34_mc_2mv     (VAR_0, VAR_1);

        break;

    case RV34_MB_P_8x8:

        for(VAR_2=0;VAR_2< 4;VAR_2++){

            rv34_pred_mv(VAR_0, VAR_1, VAR_2, VAR_2);

            rv34_mc_1mv (VAR_0, VAR_1, (VAR_2&1)<<3, (VAR_2&2)<<2, (VAR_2&1)+(VAR_2>>1)*s->b8_stride, 1, 1, 0);


        break;




    return 0;

static int FUNC_0(RV34DecContext *VAR_0, int VAR_1)
{ MpegEncContext *s = &VAR_0->s; GetBitContext *gb = &s->gb; int VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6 = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; int VAR_7; memset(VAR_0->dmv, 0, sizeof(VAR_0->dmv)); for(VAR_2 = 0; VAR_2 < num_mvs[VAR_1]; VAR_2++){ VAR_0->dmv[VAR_2][0] = get_interleaved_se_golomb(gb); VAR_0->dmv[VAR_2][1] = get_interleaved_se_golomb(gb); switch(VAR_1){ case RV34_MB_TYPE_INTRA:
case RV34_MB_TYPE_INTRA16x16:
ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); return 0; case RV34_MB_SKIP:
if(s->pict_type == AV_PICTURE_TYPE_P){ ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); rv34_mc_1mv (VAR_0, VAR_1, 0, 0, 0, 2, 2, 0); break; case RV34_MB_B_DIRECT:
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
ff_thread_await_progress(&s->next_picture_ptr->tf, FFMAX(0, s->mb_y-1), 0); VAR_7 = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride]; if(IS_INTRA(VAR_7) || IS_SKIP(VAR_7)){ ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); }else for(VAR_3 = 0; VAR_3 < 2; VAR_3++) for(VAR_2 = 0; VAR_2 < 2; VAR_2++) for(VAR_4 = 0; VAR_4 < 2; VAR_4++) for(VAR_5 = 0; VAR_5 < 2; VAR_5++) s->current_picture_ptr->motion_val[VAR_5][VAR_6 + VAR_2 + VAR_3*s->b8_stride][VAR_4] = calc_add_mv(VAR_0, VAR_5, s->next_picture_ptr->motion_val[0][VAR_6 + VAR_2 + VAR_3*s->b8_stride][VAR_4]); if(!(IS_16X8(VAR_7) || IS_8X16(VAR_7) || IS_8X8(VAR_7)))
rv34_mc_2mv(VAR_0, VAR_1); else
rv34_mc_2mv_skip(VAR_0); ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); break; case RV34_MB_P_16x16:
case RV34_MB_P_MIX16x16:
rv34_pred_mv(VAR_0, VAR_1, 0, 0); rv34_mc_1mv (VAR_0, VAR_1, 0, 0, 0, 2, 2, 0); break; case RV34_MB_B_FORWARD:
case RV34_MB_B_BACKWARD:
VAR_0->dmv[1][0] = VAR_0->dmv[0][0]; VAR_0->dmv[1][1] = VAR_0->dmv[0][1]; if(VAR_0->rv30)
rv34_pred_mv_rv3(VAR_0, VAR_1, VAR_1 == RV34_MB_B_BACKWARD); else
rv34_pred_mv_b  (VAR_0, VAR_1, VAR_1 == RV34_MB_B_BACKWARD); rv34_mc_1mv     (VAR_0, VAR_1, 0, 0, 0, 2, 2, VAR_1 == RV34_MB_B_BACKWARD); break; case RV34_MB_P_16x8:
case RV34_MB_P_8x16:
rv34_pred_mv(VAR_0, VAR_1, 0, 0); rv34_pred_mv(VAR_0, VAR_1, 1 + (VAR_1 == RV34_MB_P_16x8), 1); if(VAR_1 == RV34_MB_P_16x8){ rv34_mc_1mv(VAR_0, VAR_1, 0, 0, 0,            2, 1, 0); rv34_mc_1mv(VAR_0, VAR_1, 0, 8, s->b8_stride, 2, 1, 0); if(VAR_1 == RV34_MB_P_8x16){ rv34_mc_1mv(VAR_0, VAR_1, 0, 0, 0, 1, 2, 0); rv34_mc_1mv(VAR_0, VAR_1, 8, 0, 1, 1, 2, 0); break; case RV34_MB_B_BIDIR:
rv34_pred_mv_b  (VAR_0, VAR_1, 0); rv34_pred_mv_b  (VAR_0, VAR_1, 1); rv34_mc_2mv     (VAR_0, VAR_1); break; case RV34_MB_P_8x8:
for(VAR_2=0;VAR_2< 4;VAR_2++){ rv34_pred_mv(VAR_0, VAR_1, VAR_2, VAR_2); rv34_mc_1mv (VAR_0, VAR_1, (VAR_2&1)<<3, (VAR_2&2)<<2, (VAR_2&1)+(VAR_2>>1)*s->b8_stride, 1, 1, 0); break; return 0;