/*!
 *************************************************************************************
 * \file mv_prediction.c
 *
 * \brief
 *    Motion Vector Prediction Functions
 *
 *  \author
 *      Main contributors (see contributors.h for copyright, address and affiliation details)
 *      - Alexis Michael Tourapis  <alexismt@ieee.org>
 *      - Karsten Sühring          <suehring@hhi.de>
 *************************************************************************************
 */

#include "global.h"
#include "mbuffer.h"
#include "mv_prediction.h"

/*!
 ************************************************************************
 * \brief
 *    Get motion vector predictor
 ************************************************************************
 */
#if DEPTH_BASED_MVP
static void GetMotionVectorPredictorMBAFF (Macroblock *currMB, 
										   PixelPos *block,        // <--> block neighbors
										   MotionVector *pmv,
										   short  ref_frame,
										   PicMotionParams **mv_info,
										   int    list,
										   int    mb_x,
										   int    mb_y,
										   int    blockshape_x,
										   int    blockshape_y,
										   int    depth_based_mvp)
#else
static void GetMotionVectorPredictorMBAFF (Macroblock *currMB, 
                                    PixelPos *block,        // <--> block neighbors
                                    MotionVector *pmv,
                                    short  ref_frame,
                                    PicMotionParams **mv_info,
                                    int    list,
                                    int    mb_x,
                                    int    mb_y,
                                    int    blockshape_x,
                                    int    blockshape_y)
#endif
{
  int mv_a, mv_b, mv_c, pred_vec=0;
  int mvPredType, rFrameL, rFrameU, rFrameUR;
  int hv;
  VideoParameters *p_Vid = currMB->p_Vid;

  mvPredType = MVPRED_MEDIAN;
#if DEPTH_BASED_MVP
  UNREFERENCED_PARAMETER(depth_based_mvp);
#endif

  if (currMB->mb_field)
  {
    rFrameL  = block[0].available
      ? (p_Vid->mb_data[block[0].mb_addr].mb_field
      ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list]
    : mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] * 2) : -1;
    rFrameU  = block[1].available
      ? (p_Vid->mb_data[block[1].mb_addr].mb_field
      ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list]
    : mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] * 2) : -1;
    rFrameUR = block[2].available
      ? (p_Vid->mb_data[block[2].mb_addr].mb_field
      ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list]
    : mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] * 2) : -1;
  }
  else
  {
    rFrameL = block[0].available
      ? (p_Vid->mb_data[block[0].mb_addr].mb_field
      ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] >>1
      : mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list]) : -1;
    rFrameU  = block[1].available
      ? (p_Vid->mb_data[block[1].mb_addr].mb_field
      ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] >>1
      : mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list]) : -1;
    rFrameUR = block[2].available
      ? (p_Vid->mb_data[block[2].mb_addr].mb_field
      ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] >>1
      : mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list]) : -1;
  }


  /* Prediction if only one of the neighbors uses the reference frame
  *  we are checking
  */
  if(rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame)       
    mvPredType = MVPRED_L;
  else if(rFrameL != ref_frame && rFrameU == ref_frame && rFrameUR != ref_frame)  
    mvPredType = MVPRED_U;
  else if(rFrameL != ref_frame && rFrameU != ref_frame && rFrameUR == ref_frame)  
    mvPredType = MVPRED_UR;
  // Directional predictions
  if(blockshape_x == 8 && blockshape_y == 16)
  {
    if(mb_x == 0)
    {
      if(rFrameL == ref_frame)
        mvPredType = MVPRED_L;
    }
    else
    {
      if( rFrameUR == ref_frame)
        mvPredType = MVPRED_UR;
    }
  }
  else if(blockshape_x == 16 && blockshape_y == 8)
  {
    if(mb_y == 0)
    {
      if(rFrameU == ref_frame)
        mvPredType = MVPRED_U;
    }
    else
    {
      if(rFrameL == ref_frame)
        mvPredType = MVPRED_L;
    }
  }

  for (hv=0; hv < 2; hv++)
  {
    if (hv == 0)
    {
      mv_a = block[0].available ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_x : 0;
      mv_b = block[1].available ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_x : 0;
      mv_c = block[2].available ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_x : 0;
    }
    else
    {
      if (currMB->mb_field)
      {
        mv_a = block[0].available  ? p_Vid->mb_data[block[0].mb_addr].mb_field
          ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y
        : mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y / 2
          : 0;
        mv_b = block[1].available  ? p_Vid->mb_data[block[1].mb_addr].mb_field
          ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y
        : mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y / 2
          : 0;
        mv_c = block[2].available  ? p_Vid->mb_data[block[2].mb_addr].mb_field
          ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y
        : mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y / 2
          : 0;
      }
      else
      {
        mv_a = block[0].available  ? p_Vid->mb_data[block[0].mb_addr].mb_field
          ? mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y * 2
          : mv_info[block[0].pos_y][block[0].pos_x].mv[list].mv_y
        : 0;
        mv_b = block[1].available  ? p_Vid->mb_data[block[1].mb_addr].mb_field
          ? mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y * 2
          : mv_info[block[1].pos_y][block[1].pos_x].mv[list].mv_y
        : 0;
        mv_c = block[2].available  ? p_Vid->mb_data[block[2].mb_addr].mb_field
          ? mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y * 2
          : mv_info[block[2].pos_y][block[2].pos_x].mv[list].mv_y
        : 0;
      }
    }

    switch (mvPredType)
    {
    case MVPRED_MEDIAN:
      if(!(block[1].available || block[2].available))
      {
        pred_vec = mv_a;
      }
      else
      {
        pred_vec = imedian(mv_a, mv_b, mv_c);
      }
      break;
    case MVPRED_L:
      pred_vec = mv_a;
      break;
    case MVPRED_U:
      pred_vec = mv_b;
      break;
    case MVPRED_UR:
      pred_vec = mv_c;
      break;
    default:
      break;
    }

    if (hv == 0)
      pmv->mv_x = (short) pred_vec;
    else
      pmv->mv_y = (short) pred_vec;
  }
}
#if DEPTH_BASED_MVP
/*!
************************************************************************
* \brief
*    Get motion vector predictor for inter-view reference
************************************************************************
*/
#if SAIT_SKIP_MVP_COMMENT_M24824 || !SAIT_INTER_VIEW_MVP_M24824
static void GetInterViewMotionVectorePredictionNormal(Macroblock*currMB,
  MotionVector*pmv,
  int mb_y,
  int mb_x,
  int blockshape_y,
  int blockshape_x,
  int* disparity_table)
{
	VideoParameters* p_Vid=currMB->p_Vid;
	imgpel**img_Y_depth=p_Vid->p_dual_picture->imgY;
	int threshold=12;
	
#if NOKIA_USTC_B_VSP_M26069
  int pix_y=(currMB->pix_y+mb_y)>>p_Vid->mixed_res;  // BUG_FIXED_v6_1
  int pix_x=(currMB->pix_x+mb_x)>>p_Vid->mixed_res;  // BUG_FIXED_v6_1
#else
  int pix_y=currMB->pix_y+mb_y;
  int pix_x=currMB->pix_x+mb_x;
#endif

	int		Sum=0;
	int		Avg=0;
	int		sad=0;


	int j,i;

#if NOKIA_USTC_B_VSP_M26069
  blockshape_x=(blockshape_x>>p_Vid->mixed_res); // BUG_FIXED_v6_1
  blockshape_y=(blockshape_y>>p_Vid->mixed_res); // BUG_FIXED_v6_1
#else

#if REDUCED_RES
	if(p_Vid->mixed_res)
	{
		assert(p_Vid->p_dual_picture->norm_res_depth_ok==1);
		img_Y_depth=p_Vid->p_dual_picture->imgY_norm_res_depth;
	}
	else
		img_Y_depth=p_Vid->p_dual_picture->imgY;
#endif
#endif

	for(j=pix_y;j<pix_y+blockshape_y;++j)
		for(i=pix_x;i<pix_x+blockshape_x;++i)
			Sum+=img_Y_depth[j][i];
	Avg=(int)(Sum/(double)(blockshape_y*blockshape_x)+0.5);

	for(j=pix_y;j<pix_y+blockshape_y;++j)
		for(i=pix_x;i<pix_x+blockshape_x;++i)
			sad+=abs(img_Y_depth[j][i]-Avg);

	sad=sad/(blockshape_y*blockshape_x);

	if(sad<=threshold)
	{

		//int disparity= disparity_table[Avg];

		pmv->mv_x=(short)disparity_table[Avg];//!<1/4 sub-pixel precision
		pmv->mv_y=0;

	}
	else
		*pmv=zero_mv;
}
#endif

#if SAIT_INTER_VIEW_MVP_M24824
/*!
************************************************************************
* \brief
*    Get motion vector predictor for inter-view reference
************************************************************************
*/
static void GetInterViewMotionVectorePredictionNormalMax(Macroblock*currMB,
													     MotionVector*pmv,
													     int mb_x,
													     int mb_y,
													     int blockshape_x,
													     int blockshape_y,
													     int* disparity_table)
{
	VideoParameters* p_Vid=currMB->p_Vid;
  imgpel**img_Y_depth=p_Vid->p_dual_picture->imgY;
#if NOKIA_USTC_B_VSP_M26069
#if MTK_SAIT_MB_LEVEL_MAX_DV_D0107
  int pix_y=(currMB->pix_y)>>p_Vid->mixed_res;
  int pix_x=(currMB->pix_x)>>p_Vid->mixed_res;
  int depth_MB_y=(MB_BLOCK_SIZE)>>p_Vid->mixed_res;
  int depth_MB_x=(MB_BLOCK_SIZE)>>p_Vid->mixed_res;
#else
  int pix_y=(currMB->pix_y+mb_y)>>p_Vid->mixed_res; // BUG_FIXED_v6_1
  int pix_x=(currMB->pix_x+mb_x)>>p_Vid->mixed_res; // BUG_FIXED_v6_1
#endif
#else
#if MTK_SAIT_MB_LEVEL_MAX_DV_D0107
  int pix_y=currMB->pix_y;
  int pix_x=currMB->pix_x;
  int depth_MB_y=MB_BLOCK_SIZE;
  int depth_MB_x=MB_BLOCK_SIZE;
#else
  int pix_y=currMB->pix_y+mb_y;
  int pix_x=currMB->pix_x+mb_x;
#endif
#endif
	int max=0;
	int j,i;

  UNREFERENCED_PARAMETER(mb_x);
  UNREFERENCED_PARAMETER(mb_y);
  UNREFERENCED_PARAMETER(blockshape_x);
  UNREFERENCED_PARAMETER(blockshape_y);

#if NOKIA_USTC_B_VSP_M26069
#if !MTK_SAIT_MB_LEVEL_MAX_DV_D0107
  blockshape_x=(blockshape_x>>p_Vid->mixed_res); //BUG_FIXED_v6_1
  blockshape_y=(blockshape_y>>p_Vid->mixed_res); // BUG_FIXED_v6_1
#endif
#else

#if REDUCED_RES
	if(p_Vid->mixed_res)
	{
		assert(p_Vid->p_dual_picture->norm_res_depth_ok==1);
		img_Y_depth=p_Vid->p_dual_picture->imgY_norm_res_depth;
	}
	else
		img_Y_depth=p_Vid->p_dual_picture->imgY;
#endif
#endif
#if MTK_SAIT_MB_LEVEL_MAX_DV_D0107
	for(j=pix_y;j<pix_y+depth_MB_y; j+= (depth_MB_y-1)) { 
		for(i=pix_x;i<pix_x+depth_MB_x; i+=(depth_MB_x-1)) {  
#else
#if MTK_MAX_DV_SIMP_A0046
  for(j=pix_y;j<pix_y+blockshape_y; j+= (blockshape_y-1)) {
    for(i=pix_x;i<pix_x+blockshape_x; i+=(blockshape_x-1)) {
#else
	for(j=pix_y;j<pix_y+blockshape_y;++j) {
		for(i=pix_x;i<pix_x+blockshape_x;++i) {
#endif
#endif
			if(img_Y_depth[j][i]>max) max=img_Y_depth[j][i];
		}
	}

	pmv->mv_x=(short)disparity_table[max];
	pmv->mv_y=0;
}
#endif
#endif

/*!
 ************************************************************************
 * \brief
 *    Get motion vector predictor
 ************************************************************************
 */
#if DEPTH_BASED_MVP
static void GetMotionVectorPredictorNormal (Macroblock *currMB, 
											PixelPos *block,      // <--> block neighbors
											MotionVector *pmv,
											short  ref_frame,
											PicMotionParams **mv_info,
											int    list,
											int    mb_x,
											int    mb_y,
											int    blockshape_x,
											int    blockshape_y,
											int    depth_based_mvp)
#else
static void GetMotionVectorPredictorNormal (Macroblock *currMB, 
                                            PixelPos *block,      // <--> block neighbors
                                            MotionVector *pmv,
                                            short  ref_frame,
                                            PicMotionParams **mv_info,
                                            int    list,
                                            int    mb_x,
                                            int    mb_y,
                                            int    blockshape_x,
                                            int    blockshape_y)
#endif
{
  int mvPredType = MVPRED_MEDIAN;

 

#if NOKIA_USTC_3DV
  VideoParameters*p_Vid      =currMB->p_Vid;
  int ref_view_id          =currMB->p_Slice->listX[list][ref_frame]->view_id;
  int is_interview_prediction =(ref_view_id!=currMB->p_Slice->view_id);
#if VISBD_VSP
  int is_virtual_ref_view   =currMB->p_Slice->listX[list][ref_frame]->is_virtual_view;
#endif
#endif

#if QC_GVSP_B0054
  int i=0, neighbor_from_virtual_view;
  int rFrameL, rFrameU, rFrameUR;
  int blk_idx;
#if !DEPTH_BASED_MVP
  VideoParameters*p_Vid			=currMB->p_Vid;
#endif
  for(i=0;i<4;++i)
  {
    if(block[i].available)
    {
      blk_idx = (block[i].x >> 1) + (block[i].y >> 1) * 2; 
      neighbor_from_virtual_view = p_Vid->mb_data[block[i].mb_addr].isPartVspRef[blk_idx];

      if(neighbor_from_virtual_view)
        block[i].available=0;			
    }
  }
  rFrameL    = block[0].available ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] : -1;
  rFrameU    = block[1].available ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] : -1;
  rFrameUR   = block[2].available ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] : -1;
#else
  int rFrameL    = block[0].available ? mv_info[block[0].pos_y][block[0].pos_x].ref_idx[list] : -1;
  int rFrameU    = block[1].available ? mv_info[block[1].pos_y][block[1].pos_x].ref_idx[list] : -1;
  int rFrameUR   = block[2].available ? mv_info[block[2].pos_y][block[2].pos_x].ref_idx[list] : -1;
#endif



  /* Prediction if only one of the neighbors uses the reference frame
  *  we are checking
  */
  if(rFrameL == ref_frame && rFrameU != ref_frame && rFrameUR != ref_frame)       
    mvPredType = MVPRED_L;
  else if(rFrameL != ref_frame && rFrameU == ref_frame && rFrameUR != ref_frame)  
    mvPredType = MVPRED_U;
  else if(rFrameL != ref_frame && rFrameU != ref_frame && rFrameUR == ref_frame)  
    mvPredType = MVPRED_UR;

  // Directional predictions
  if(blockshape_x == 8 && blockshape_y == 16)
  {
    if(mb_x == 0)
    {
      if(rFrameL == ref_frame)
        mvPredType = MVPRED_L;
    }
    else
    {
      if(rFrameUR == ref_frame)
        mvPredType = MVPRED_UR;
    }
  }
  else if(blockshape_x == 16 && blockshape_y == 8)
  {
    if(mb_y == 0)
    {
      if(rFrameU == ref_frame)
        mvPredType = MVPRED_U;
    }
    else
    {
      if(rFrameL == ref_frame)
        mvPredType = MVPRED_L;
    }
  }

  switch (mvPredType)
  {
  case MVPRED_MEDIAN:
#if SAIT_INTER_VIEW_MVP_M24824  
#if VISBD_VSP
	  if(depth_based_mvp&&!is_virtual_ref_view&&is_interview_prediction)
#else
	  if(depth_based_mvp&&is_interview_prediction)
#endif
	  {
		  MotionVector mv_a;
		  MotionVector mv_b;
		  MotionVector mv_c;

		  if(block[0].available && rFrameL == ref_frame) mv_a=mv_info[block[0].pos_y][block[0].pos_x].mv[list];
		  else currMB->GetInterviewMVPredictionMax(currMB,&mv_a,mb_x,mb_y,blockshape_x,blockshape_y,
			  (list==0)?p_Vid->forward_disparity_table:p_Vid->backward_disparity_table);

		  if(block[1].available && rFrameU == ref_frame) mv_b=mv_info[block[1].pos_y][block[1].pos_x].mv[list];
		  else currMB->GetInterviewMVPredictionMax(currMB,&mv_b,mb_x,mb_y,blockshape_x,blockshape_y,
			  (list==0)?p_Vid->forward_disparity_table:p_Vid->backward_disparity_table);

		  if(block[2].available && rFrameUR == ref_frame) mv_c=mv_info[block[2].pos_y][block[2].pos_x].mv[list];
		  else currMB->GetInterviewMVPredictionMax(currMB,&mv_c,mb_x,mb_y,blockshape_x,blockshape_y,
			  (list==0)?p_Vid->forward_disparity_table:p_Vid->backward_disparity_table);

		  pmv->mv_x = (short) imedian(mv_a.mv_x, mv_b.mv_x, mv_c.mv_x);
		  pmv->mv_y = (short) imedian(mv_a.mv_y, mv_b.mv_y, mv_c.mv_y);

		  break;
	  }
#endif

#if SAIT_TEMPORAL_MVP_B0153
	  if(depth_based_mvp&&!is_virtual_ref_view&&!is_interview_prediction) 
	  {
		  MotionInfo motion_interview[2];
		  MotionVector mv_a;
		  MotionVector mv_b;
		  MotionVector mv_c;

		  if(block[0].available && rFrameL == ref_frame) mv_a=mv_info[block[0].pos_y][block[0].pos_x].mv[list];
		  else 
		  {
#if SAIT_TEMPORAL_MVP_BUGFIX_V7
			  Get_InterViewMV_TemporalMVP(currMB, mb_x, mb_y, blockshape_x, blockshape_y, list, currMB->base_view_id, motion_interview, block);
#else
			  Get_InterViewMV_TemporalMVP(currMB, blockshape_x, blockshape_y, list, currMB->base_view_id, motion_interview, block);
#endif	
			  if(ref_frame==motion_interview[list].ref_idx) mv_a=motion_interview[list].mv;
			  else mv_a=zero_mv;
		  }

		  if(block[1].available && rFrameU == ref_frame) mv_b=mv_info[block[1].pos_y][block[1].pos_x].mv[list];
		  else 
		  {
#if SAIT_TEMPORAL_MVP_BUGFIX_V7
			  Get_InterViewMV_TemporalMVP(currMB, mb_x, mb_y, blockshape_x, blockshape_y, list, currMB->base_view_id, motion_interview, block);
#else
			  Get_InterViewMV_TemporalMVP(currMB, blockshape_x, blockshape_y, list, currMB->base_view_id, motion_interview, block);
#endif			  
			  if(ref_frame==motion_interview[list].ref_idx) mv_b=motion_interview[list].mv;
			  else mv_b=zero_mv;
		  }

		  if(block[2].available && rFrameUR == ref_frame) mv_c=mv_info[block[2].pos_y][block[2].pos_x].mv[list];
		  else 
		  {
#if SAIT_TEMPORAL_MVP_BUGFIX_V7
			  Get_InterViewMV_TemporalMVP(currMB, mb_x, mb_y, blockshape_x, blockshape_y, list, currMB->base_view_id, motion_interview, block);
#else
			  Get_InterViewMV_TemporalMVP(currMB, blockshape_x, blockshape_y, list, currMB->base_view_id, motion_interview, block);
#endif			  
			  if(ref_frame==motion_interview[list].ref_idx) mv_c=motion_interview[list].mv;
			  else mv_c=zero_mv;
		  }

		  pmv->mv_x = (short) imedian(mv_a.mv_x, mv_b.mv_x, mv_c.mv_x);
		  pmv->mv_y = (short) imedian(mv_a.mv_y, mv_b.mv_y, mv_c.mv_y);

		  break;
	  }
#endif

    if(!(block[1].available || block[2].available))
    {
      if (block[0].available)
      {
        *pmv = mv_info[block[0].pos_y][block[0].pos_x].mv[list];
      }
      else
      {
        *pmv = zero_mv;
#if DEPTH_BASED_MVP
#if !SAIT_INTER_VIEW_MVP_M24824 
#if VISBD_VSP
		if(depth_based_mvp&&!is_virtual_ref_view&&is_interview_prediction)
#else
		if(depth_based_mvp&&is_interview_prediction)
#endif
			currMB->GetInterviewMVPrediction(currMB,pmv,mb_y,mb_x,blockshape_y,blockshape_x,
			(list==0)?p_Vid->forward_disparity_table:p_Vid->backward_disparity_table);
#endif
#endif
      }        
    }
    else
    {

		MotionVector *mv_a = block[0].available ? &mv_info[block[0].pos_y][block[0].pos_x].mv[list] : (MotionVector *) &zero_mv;
		MotionVector *mv_b = block[1].available ? &mv_info[block[1].pos_y][block[1].pos_x].mv[list] : (MotionVector *) &zero_mv;
		MotionVector* mv_c = block[2].available ? &mv_info[block[2].pos_y][block[2].pos_x].mv[list] : (MotionVector *) &zero_mv;


		pmv->mv_x = (short) imedian(mv_a->mv_x, mv_b->mv_x, mv_c->mv_x);
		pmv->mv_y = (short) imedian(mv_a->mv_y, mv_b->mv_y, mv_c->mv_y);

    }    
    break;
  case MVPRED_L:
    if (block[0].available)
    {
      *pmv = mv_info[block[0].pos_y][block[0].pos_x].mv[list];
    }
    else
    {
      *pmv = zero_mv;
	  assert(0);
    }
    break;
  case MVPRED_U:
    if (block[1].available)
    {
      *pmv = mv_info[block[1].pos_y][block[1].pos_x].mv[list];
    }
    else
    {
      *pmv = zero_mv;
	  assert(0);
    }
    break;
  case MVPRED_UR:
    if (block[2].available)
    {
      *pmv = mv_info[block[2].pos_y][block[2].pos_x].mv[list];
    }
    else
    {
      *pmv = zero_mv;
	  assert(0);
    }
    break;
  default:
    break;
  }
#if NOKIA_USTC_B_VSP_M26069
  if (is_virtual_ref_view) 
    *pmv = zero_mv;
#endif
}

void init_motion_vector_prediction(Macroblock *currMB, int mb_aff_frame_flag)
{  
#if DEPTH_BASED_MVP
	if(mb_aff_frame_flag)
		currMB->GetMVPredictor=GetMotionVectorPredictorMBAFF;
	else
	{
		currMB->GetMVPredictor=GetMotionVectorPredictorNormal;
#if SAIT_SKIP_MVP_COMMENT_M24824 || !SAIT_INTER_VIEW_MVP_M24824
		if((!currMB->p_Slice->is_depth)&&(currMB->p_Slice->depth_based_mvp_flag))
			currMB->GetInterviewMVPrediction=GetInterViewMotionVectorePredictionNormal;
		else
			currMB->GetInterviewMVPrediction=NULL;
#endif
#if SAIT_INTER_VIEW_MVP_M24824
		if((!currMB->p_Slice->is_depth)&&(currMB->p_Slice->depth_based_mvp_flag))
			currMB->GetInterviewMVPredictionMax=GetInterViewMotionVectorePredictionNormalMax;
		else
			currMB->GetInterviewMVPredictionMax=NULL;
#endif
	}
#else
  if (mb_aff_frame_flag)
    currMB->GetMVPredictor = GetMotionVectorPredictorMBAFF;
  else
    currMB->GetMVPredictor = GetMotionVectorPredictorNormal;
#endif
}
