use of android.hardware.camera2.CameraCaptureSession in project android_packages_apps_Snap by LineageOS.
the class Camera2GraphView method applyZoomAndUpdate.
private void applyZoomAndUpdate(int id) {
if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
return;
}
applyZoom(mPreviewRequestBuilder[id], id);
try {
if (id == MONO_ID && !canStartMonoPreview()) {
mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback, mCameraHandler);
} else {
CameraCaptureSession session = mCaptureSession[id];
if (session instanceof CameraConstrainedHighSpeedCaptureSession) {
List list = CameraUtil.createHighSpeedRequestList(mPreviewRequestBuilder[id].build(), id);
((CameraConstrainedHighSpeedCaptureSession) session).setRepeatingBurst(list, mCaptureCallback, mCameraHandler);
} else {
mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id].build(), mCaptureCallback, mCameraHandler);
}
}
} catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
use of android.hardware.camera2.CameraCaptureSession in project robolectric by robolectric.
the class ShadowCameraDeviceImpl method createCaptureSession.
@Implementation(minSdk = VERSION_CODES.P)
protected void createCaptureSession(List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler) throws CameraAccessException {
checkIfCameraClosedOrInError();
CameraCaptureSession session = createCameraCaptureSession(callback);
handler.post(() -> callback.onConfigured(session));
}
use of android.hardware.camera2.CameraCaptureSession in project robolectric by robolectric.
the class ShadowCameraDeviceImpl method createCameraCaptureSession.
private CameraCaptureSession createCameraCaptureSession(CameraCaptureSession.StateCallback callback) {
CameraCaptureSession sess = Shadow.newInstanceOf(CameraCaptureSessionImpl.class);
ReflectionHelpers.setField(CameraCaptureSessionImpl.class, sess, "mStateCallback", callback);
ReflectionHelpers.setField(CameraCaptureSessionImpl.class, sess, "mDeviceImpl", realObject);
return sess;
}
use of android.hardware.camera2.CameraCaptureSession in project react-native-camera by lwansbrough.
the class Camera2 method setFocusArea.
/**
* Auto focus on input coordinates
*/
// Much credit - https://gist.github.com/royshil/8c760c2485257c85a11cafd958548482
void setFocusArea(float x, float y) {
if (mCaptureSession == null) {
return;
}
CameraCaptureSession.CaptureCallback captureCallbackHandler = new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
super.onCaptureCompleted(session, request, result);
if (request.getTag() == "FOCUS_TAG") {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null);
try {
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null, null);
} catch (CameraAccessException e) {
Log.e(TAG, "Failed to manual focus.", e);
}
}
}
@Override
public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request, CaptureFailure failure) {
super.onCaptureFailed(session, request, failure);
Log.e(TAG, "Manual AF failure: " + failure);
}
};
try {
mCaptureSession.stopRepeating();
} catch (CameraAccessException e) {
Log.e(TAG, "Failed to manual focus.", e);
}
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
try {
mCaptureSession.capture(mPreviewRequestBuilder.build(), captureCallbackHandler, null);
} catch (CameraAccessException e) {
Log.e(TAG, "Failed to manual focus.", e);
}
if (isMeteringAreaAFSupported()) {
MeteringRectangle focusAreaTouch = calculateFocusArea(x, y);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[] { focusAreaTouch });
}
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
mPreviewRequestBuilder.setTag("FOCUS_TAG");
try {
mCaptureSession.capture(mPreviewRequestBuilder.build(), captureCallbackHandler, null);
} catch (CameraAccessException e) {
Log.e(TAG, "Failed to manual focus.", e);
}
}
use of android.hardware.camera2.CameraCaptureSession in project collect by opendatakit.
the class Camera2VideoFragment method startRecordingVideo.
private void startRecordingVideo() {
if (null == cameraDevice || !textureView.isAvailable() || null == previewSize) {
return;
}
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(), getActivity().getString(R.string.stop_video_capture_instruction));
}
});
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
Activity activity = getActivity();
if (null != activity) {
ToastUtils.showShortToast(getActivity(), "Failed");
}
}
}, backgroundHandler);
} catch (CameraAccessException | IOException e) {
Timber.e(e);
}
}
Aggregations