List of usage examples for android.graphics PixelFormat YCbCr_420_SP
int YCbCr_420_SP
To view the source code for android.graphics PixelFormat YCbCr_420_SP.
Click Source Link
From source file:com.gsma.rcs.ri.sharing.video.OutgoingVideoSharing.java
/** * Start the camera preview/*from w ww. j a v a2 s. c o m*/ */ private void startCameraPreview() { if (mCamera == null) { return; } // Camera settings Camera.Parameters p = mCamera.getParameters(); p.setPreviewFormat(PixelFormat.YCbCr_420_SP); // Orientation Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); switch (display.getRotation()) { case Surface.ROTATION_0: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_0"); } if (mOpenedCameraId == CameraOptions.FRONT) { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CCW); } else { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CW); } mCamera.setDisplayOrientation(90); break; case Surface.ROTATION_90: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_90"); } mVideoPlayer.setOrientation(Orientation.NONE); break; case Surface.ROTATION_180: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_180"); } if (mOpenedCameraId == CameraOptions.FRONT) { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CW); } else { mVideoPlayer.setOrientation(Orientation.ROTATE_90_CCW); } mCamera.setDisplayOrientation(270); break; case Surface.ROTATION_270: if (LogUtils.isActive) { Log.d(LOGTAG, "ROTATION_270"); } if (mOpenedCameraId == CameraOptions.FRONT) { mVideoPlayer.setOrientation(Orientation.ROTATE_180); } else { mVideoPlayer.setOrientation(Orientation.ROTATE_180); } mCamera.setDisplayOrientation(180); break; } // Check if preview size is supported if (isPreviewSizeSupported(p, mVideoWidth, mVideoHeight)) { // Use the existing size without resizing p.setPreviewSize(mVideoWidth, mVideoHeight); // TODO videoPlayer.activateResizing(videoWidth, videoHeight); // // same size = no // resizing if (LogUtils.isActive) { Log.d(LOGTAG, "Camera preview initialized with size " + mVideoWidth + "x" + mVideoHeight); } } else { // Check if can use a other known size (QVGA, CIF or VGA) int w = 0; int h = 0; for (Camera.Size size : p.getSupportedPreviewSizes()) { w = size.width; h = size.height; if ((w == H264Config.QVGA_WIDTH && h == H264Config.QVGA_HEIGHT) || (w == H264Config.CIF_WIDTH && h == H264Config.CIF_HEIGHT) || (w == H264Config.VGA_WIDTH && h == H264Config.VGA_HEIGHT)) { break; } } if (w != 0) { p.setPreviewSize(w, h); // TODO does not work if default sizes are not supported like // for Samsung S5 mini // mVideoPlayer.activateResizing(w, h); if (LogUtils.isActive) { Log.d(LOGTAG, "Camera preview initialized with size " + w + "x" + h + " with a resizing to " + mVideoWidth + "x" + mVideoHeight); } } else { // The camera don't have known size, we can't use it if (LogUtils.isActive) { Log.d(LOGTAG, "Camera preview can't be initialized with size " + mVideoWidth + "x" + mVideoHeight); } Toast.makeText(this, getString(R.string.label_session_failed, "Camera is not compatible"), Toast.LENGTH_SHORT).show(); quitSession(); return; } } // Set camera parameters mCamera.setParameters(p); try { mCamera.setPreviewDisplay(mVideoView.getHolder()); mCamera.startPreview(); mCameraPreviewRunning = true; } catch (Exception e) { mCamera = null; } }