Program: 62845
Project: 62845
Buggy source:
private void changeSurfaceSize(){
  int dw=getWindow().getDecorView().getWidth();
  int dh=getWindow().getDecorView().getHeight();
  boolean isPortrait=getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
  if (dw > dh && isPortrait || dw < dh && !isPortrait) {
    int d=dw;
    dw=dh;
    dh=d;
  }
  if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) {
    Log.e(TAG,"String_Node_Str");
    return;
  }
  double ar, vw;
  double density=(double)mSarNum / (double)mSarDen;
  if (density == 1.0) {
    vw=mVideoVisibleWidth;
    ar=(double)mVideoVisibleWidth / (double)mVideoVisibleHeight;
  }
 else {
    vw=mVideoVisibleWidth * density;
    ar=vw / mVideoVisibleHeight;
  }
  double dar=(double)dw / (double)dh;
switch (mCurrentSize) {
case SURFACE_BEST_FIT:
    if (dar < ar)     dh=(int)(dw / ar);
 else     dw=(int)(dh * ar);
  break;
case SURFACE_FIT_HORIZONTAL:
dh=(int)(dw / ar);
break;
case SURFACE_FIT_VERTICAL:
dw=(int)(dh * ar);
break;
case SURFACE_FILL:
break;
case SURFACE_16_9:
ar=16.0 / 9.0;
if (dar < ar) dh=(int)(dw / ar);
 else dw=(int)(dh * ar);
break;
case SURFACE_4_3:
ar=4.0 / 3.0;
if (dar < ar) dh=(int)(dw / ar);
 else dw=(int)(dh * ar);
break;
case SURFACE_ORIGINAL:
dh=mVideoVisibleHeight;
dw=(int)vw;
break;
}
mSurfaceHolder.setFixedSize(mVideoWidth,mVideoHeight);
LayoutParams lp=mSurface.getLayoutParams();
lp.width=dw * mVideoWidth / mVideoVisibleWidth;
lp.height=dh * mVideoHeight / mVideoVisibleHeight;
mSurface.setLayoutParams(lp);
lp=mSurfaceFrame.getLayoutParams();
lp.width=dw;
lp.height=dh;
mSurfaceFrame.setLayoutParams(lp);
mSurface.invalidate();
}

Fixed version (ground truth):
private void changeSurfaceSize(){
  int sw=getWindow().getDecorView().getWidth();
  int sh=getWindow().getDecorView().getHeight();
  double dw=sw, dh=sh;
  boolean isPortrait=getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
  if (sw > sh && isPortrait || sw < sh && !isPortrait) {
    dw=sh;
    dh=sw;
  }
  if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) {
    Log.e(TAG,"String_Node_Str");
    return;
  }
  double ar, vw;
  double density=(double)mSarNum / (double)mSarDen;
  if (density == 1.0) {
    vw=mVideoVisibleWidth;
    ar=(double)mVideoVisibleWidth / (double)mVideoVisibleHeight;
  }
 else {
    vw=mVideoVisibleWidth * density;
    ar=vw / mVideoVisibleHeight;
  }
  double dar=dw / dh;
switch (mCurrentSize) {
case SURFACE_BEST_FIT:
    if (dar < ar)     dh=dw / ar;
 else     dw=dh * ar;
  break;
case SURFACE_FIT_HORIZONTAL:
dh=dw / ar;
break;
case SURFACE_FIT_VERTICAL:
dw=dh * ar;
break;
case SURFACE_FILL:
break;
case SURFACE_16_9:
ar=16.0 / 9.0;
if (dar < ar) dh=dw / ar;
 else dw=dh * ar;
break;
case SURFACE_4_3:
ar=4.0 / 3.0;
if (dar < ar) dh=dw / ar;
 else dw=dh * ar;
break;
case SURFACE_ORIGINAL:
dh=mVideoVisibleHeight;
dw=vw;
break;
}
mSurfaceHolder.setFixedSize(mVideoWidth,mVideoHeight);
LayoutParams lp=mSurface.getLayoutParams();
lp.width=(int)Math.ceil(dw * mVideoWidth / mVideoVisibleWidth);
lp.height=(int)Math.ceil(dh * mVideoHeight / mVideoVisibleHeight);
mSurface.setLayoutParams(lp);
lp=mSurfaceFrame.getLayoutParams();
lp.width=(int)Math.floor(dw);
lp.height=(int)Math.floor(dh);
mSurfaceFrame.setLayoutParams(lp);
mSurface.invalidate();
}