@Override
  public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters params = camera.getParameters();
    int w = params.getPreviewSize().width;
    int h = params.getPreviewSize().height;
    int format = params.getPreviewFormat();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    YuvImage image = new YuvImage(data, format, w, h, null);
    Rect area = new Rect(0, 0, w, h);

    long start = System.currentTimeMillis();
    image.compressToJpeg(area, imageQuality, out);
    long end = System.currentTimeMillis();

    long pingTime = ServerConnector.getInstance().getPingTime() + (end - start);
    if (pingTime > 50 && imageQuality > 25) {
      imageQuality--;
    } else if (pingTime < 50 && imageQuality < 100) {
      imageQuality++;
    }

    Log.i("image", "" + imageQuality);

    ServerConnector.getInstance().pushImage(out.toByteArray());
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.controller);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    // CameraView
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layout);
    CameraSurfaceView cameraSurfaceView = new CameraSurfaceView(this);
    cameraSurfaceView.setPreviewCallback(this);
    linearLayout.addView(cameraSurfaceView);
    BluetoothConnector.getInstance().open(this);
    ServerConnector.getInstance().setServerCallback(this);
    // TODO Get GPS
    // getGPS();
    // gdg.androidrccarcontroller.tool.gps.GetLocations();
  }