List of usage examples for android.graphics SurfaceTexture setDefaultBufferSize
public void setDefaultBufferSize(int width, int height)
From source file:freed.cam.apis.camera2.modules.VideoModuleApi2.java
@TargetApi(VERSION_CODES.LOLLIPOP) @Override/* w w w.jav a2 s .c om*/ public void startPreview() { previewSize = new Size(currentVideoProfile.videoFrameWidth, currentVideoProfile.videoFrameHeight); int sensorOrientation = cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); int orientation = 0; switch (sensorOrientation) { case 90: orientation = 270; break; case 180: orientation = 0; break; case 270: orientation = 90; break; case 0: orientation = 180; break; } cameraHolder.CaptureSessionH.SetTextureViewSize(previewSize.getWidth(), previewSize.getHeight(), orientation, orientation + 180, true); SurfaceTexture texture = cameraHolder.CaptureSessionH.getSurfaceTexture(); texture.setDefaultBufferSize(currentVideoProfile.videoFrameWidth, currentVideoProfile.videoFrameHeight); previewsurface = new Surface(texture); cameraHolder.CaptureSessionH.AddSurface(previewsurface, true); cameraHolder.CaptureSessionH.CreateCaptureSession(); }
From source file:com.google.android.apps.watchme.StreamerActivity.java
void startPreview() { SurfaceTexture surfaceTexture = textureView.getSurfaceTexture(); surfaceTexture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight()); Surface previewSurface = new Surface(surfaceTexture); try {/* ww w . j av a 2 s. c o m*/ captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); captureRequestBuilder.addTarget(previewSurface); cameraDevice.createCaptureSession(Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession session) { try { session.setRepeatingRequest(captureRequestBuilder.build(), null, backgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } } @Override public void onConfigureFailed(@NonNull CameraCaptureSession session) { Toast.makeText(getApplicationContext(), "The preview failed to setup", Toast.LENGTH_SHORT).show(); } }, null); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.raulh82vlc.face_detection_sample.camera2.presentation.FDCamera2Presenter.java
private void createCameraPreview() { if (isViewAvailable()) { try {/*from w w w .ja va 2 s . co m*/ SurfaceTexture texture = activityView.getTextureView().getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight()); Surface surface = new Surface(texture); captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); captureRequestBuilder.addTarget(surface); cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { //The camera is already closed if (null == cameraDevice) { return; } // When the session is ready, we start displaying the preview. cameraCaptureSessions = cameraCaptureSession; updatePreview(); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { // Toast.makeText(this, "Configuration change", Toast.LENGTH_SHORT).show(); } }, null); } catch (CameraAccessException e) { e.printStackTrace(); } } }
From source file:wisc.drivesense.vediorecorder.CameraFragment.java
public void startRecordingVideo() { Log.d(TAG, "startRecordingVideo()"); if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;/*from ww w . j a v a2 s. c o m*/ } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.andrasta.dashi.MainActivity.java
@SuppressWarnings("MissingPermission") private void openCamera(int width, int height) { try {/* w ww . ja va2 s. c om*/ configBuilder = CameraUtils.initCameraConfig(this, display, width, height); onCameraOrientationSet(configBuilder.getCameraOrientation()); int cameraWidth = configBuilder.getSize().getWidth(); int cameraHeight = configBuilder.getSize().getHeight(); // We fit the aspect ratio of TextureView to the size of preview we picked. int orientation = this.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { textureView.setAspectRatio(cameraWidth, cameraHeight); laneView.setAspectRatio(cameraWidth, cameraHeight); } else { textureView.setAspectRatio(cameraHeight, cameraWidth); laneView.setAspectRatio(cameraHeight, cameraWidth); } Matrix matrix = CameraUtils.configureTransform(display.getRotation(), width, height, cameraWidth, cameraHeight); textureView.setTransform(matrix); SurfaceTexture texture = textureView.getSurfaceTexture(); if (texture == null) { Log.d(TAG, "No SurfaceTexture"); return; } // We configure the size of default buffer to be the size of camera preview we want. texture.setDefaultBufferSize(cameraWidth, cameraHeight); CameraConfig.Request request = new CameraConfig.Request(CameraDevice.TEMPLATE_PREVIEW, new Surface(texture)); request.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); configBuilder.addRequest(request); Log.d(TAG, "Display camera resolution " + cameraWidth + 'x' + cameraHeight); imageReader = ImageReader.newInstance(cameraRecSize.getWidth(), cameraRecSize.getHeight(), ImageFormat.YUV_420_888, alprHandler.getThreadsNum() + 1); imageReader.setOnImageAvailableListener(this, null); request = new CameraConfig.Request(CameraDevice.TEMPLATE_PREVIEW, imageReader.getSurface()); configBuilder.addRequest(request); Log.d(TAG, "Recognition camera resolution " + cameraRecSize.getWidth() + 'x' + cameraRecSize.getHeight()); camera.open(configBuilder.build()); Log.d(TAG, "Camera opened: " + configBuilder.getCameraId()); } catch (CameraAccessException e) { onError(false, e); } catch (NullPointerException e) { // Currently an NPE is thrown when the Camera2API is used but not supported on the device onError(true, e); } }
From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java
/** * Start the camera preview.//from w w w .jav a 2 s . co m */ private void startPreview() { if (null == cameraDevice || !textureView.isAvailable() || null == previewSize) { return; } try { closePreviewSession(); SurfaceTexture texture = textureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight()); previewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); Surface previewSurface = new Surface(texture); previewBuilder.addTarget(previewSurface); cameraDevice.createCaptureSession(Collections.singletonList(previewSurface), new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession session) { previewSession = session; updatePreview(); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession session) { Activity activity = getActivity(); if (null != activity) { ToastUtils.showShortToast("Failed"); } } }, backgroundHandler); } catch (CameraAccessException e) { Timber.e(e); } }
From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java
private void startRecordingVideo() { if (null == cameraDevice || !textureView.isAvailable() || null == previewSize) { return;/*from w w w . ja v a 2s.c o m*/ } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = textureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight()); previewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); previewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder Surface recorderSurface = mediaRecorder.getSurface(); surfaces.add(recorderSurface); previewBuilder.addTarget(recorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording cameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { previewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI isRecordingVideo = true; // Start recording mediaRecorder.start(); ToastUtils.showLongToast( getActivity().getString(R.string.stop_video_capture_instruction)); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { ToastUtils.showShortToast("Failed"); } } }, backgroundHandler); } catch (CameraAccessException | IOException e) { Timber.e(e); } }
From source file:com.example.anna_maria.myapplication.Camera2VideoFragment.java
/** * Start the camera preview./*ww w.j a va2s. co m*/ */ private void startPreview() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return; } try { setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<Surface>(); Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); } @Override public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java
/** * Start the camera preview.// www. j ava 2s . c om */ private void startPreview() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return; } try { closePreviewSession(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); Surface previewSurface = new Surface(texture); mPreviewBuilder.addTarget(previewSurface); mCameraDevice.createCaptureSession(Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); } @Override public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.example.android.camera2basic.Camera2VideoFragment.java
/** * Start the camera preview./* w w w . j a v a 2s . c o m*/ */ private void startPreview() { Log.d(TAG, "startPreview"); if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return; } try { setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<Surface>(); Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); } @Override public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }