use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.
the class Camera2SurfaceViewTestCase method prepareCaptureAndStartPreview.
/**
* Setup single capture configuration and start preview.
*
* @param previewRequest The capture request to be used for preview
* @param stillRequest The capture request to be used for still capture
* @param previewSz Preview size
* @param captureSz Still capture size
* @param format The single capture image format
* @param resultListener Capture result listener
* @param maxNumImages The max number of images set to the image reader
* @param imageListener The single capture capture image listener
*/
protected void prepareCaptureAndStartPreview(CaptureRequest.Builder previewRequest, CaptureRequest.Builder stillRequest, Size previewSz, Size captureSz, int format, CaptureCallback resultListener, int maxNumImages, ImageReader.OnImageAvailableListener imageListener) throws Exception {
if (VERBOSE) {
Log.v(TAG, String.format("Prepare single capture (%s) and preview (%s)", captureSz.toString(), previewSz.toString()));
}
// Update preview size.
updatePreviewSurface(previewSz);
// Create ImageReader.
createImageReader(captureSz, format, maxNumImages, imageListener);
// Configure output streams with preview and jpeg streams.
List<Surface> outputSurfaces = new ArrayList<Surface>();
outputSurfaces.add(mPreviewSurface);
outputSurfaces.add(mReaderSurface);
mSessionListener = new BlockingSessionCallback();
mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
// Configure the requests.
previewRequest.addTarget(mPreviewSurface);
stillRequest.addTarget(mPreviewSurface);
stillRequest.addTarget(mReaderSurface);
// Start preview.
mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
}
use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.
the class Camera2StillCaptureTest method fullRawCaptureTestByCamera.
private void fullRawCaptureTestByCamera() throws Exception {
Size maxPreviewSz = mOrderedPreviewSizes.get(0);
Size maxStillSz = mOrderedStillSizes.get(0);
SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
SimpleImageReaderListener jpegListener = new SimpleImageReaderListener();
SimpleImageReaderListener rawListener = new SimpleImageReaderListener();
Size size = mStaticInfo.getRawDimensChecked();
if (VERBOSE) {
Log.v(TAG, "Testing multi capture with size " + size.toString() + ", preview size " + maxPreviewSz);
}
// Prepare raw capture and start preview.
CaptureRequest.Builder previewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
CaptureRequest.Builder multiBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
ImageReader rawReader = null;
ImageReader jpegReader = null;
try {
// Create ImageReaders.
rawReader = makeImageReader(size, ImageFormat.RAW_SENSOR, MAX_READER_IMAGES, rawListener, mHandler);
jpegReader = makeImageReader(maxStillSz, ImageFormat.JPEG, MAX_READER_IMAGES, jpegListener, mHandler);
updatePreviewSurface(maxPreviewSz);
// Configure output streams with preview and jpeg streams.
List<Surface> outputSurfaces = new ArrayList<Surface>();
outputSurfaces.add(rawReader.getSurface());
outputSurfaces.add(jpegReader.getSurface());
outputSurfaces.add(mPreviewSurface);
mSessionListener = new BlockingSessionCallback();
mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
// Configure the requests.
previewBuilder.addTarget(mPreviewSurface);
multiBuilder.addTarget(mPreviewSurface);
multiBuilder.addTarget(rawReader.getSurface());
multiBuilder.addTarget(jpegReader.getSurface());
// Start preview.
mSession.setRepeatingRequest(previewBuilder.build(), null, mHandler);
// Poor man's 3A, wait 2 seconds for AE/AF (if any) to settle.
// TODO: Do proper 3A trigger and lock (see testTakePictureTest).
Thread.sleep(3000);
multiBuilder.set(CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE, CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE_ON);
CaptureRequest multiRequest = multiBuilder.build();
mSession.capture(multiRequest, resultListener, mHandler);
CaptureResult result = resultListener.getCaptureResultForRequest(multiRequest, NUM_RESULTS_WAIT_TIMEOUT);
Image jpegImage = jpegListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
basicValidateJpegImage(jpegImage, maxStillSz);
Image rawImage = rawListener.getImage(CAPTURE_IMAGE_TIMEOUT_MS);
validateRaw16Image(rawImage, size);
verifyRawCaptureResult(multiRequest, result);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (DngCreator dngCreator = new DngCreator(mStaticInfo.getCharacteristics(), result)) {
dngCreator.writeImage(outputStream, rawImage);
}
if (DEBUG) {
byte[] rawBuffer = outputStream.toByteArray();
String rawFileName = DEBUG_FILE_NAME_BASE + "/raw16_" + TAG + size.toString() + "_cam_" + mCamera.getId() + ".dng";
Log.d(TAG, "Dump raw file into " + rawFileName);
dumpFile(rawFileName, rawBuffer);
byte[] jpegBuffer = getDataFromImage(jpegImage);
String jpegFileName = DEBUG_FILE_NAME_BASE + "/jpeg_" + TAG + size.toString() + "_cam_" + mCamera.getId() + ".jpg";
Log.d(TAG, "Dump jpeg file into " + rawFileName);
dumpFile(jpegFileName, jpegBuffer);
}
stopPreview();
} finally {
CameraTestUtils.closeImageReader(rawReader);
CameraTestUtils.closeImageReader(jpegReader);
rawReader = null;
jpegReader = null;
}
}
use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by AOSPA.
the class Camera2RecordingTest method startSlowMotionRecording.
private void startSlowMotionRecording(boolean useMediaRecorder, int videoFrameRate, int captureRate, Range<Integer> fpsRange, CameraCaptureSession.CaptureCallback listener, boolean useHighSpeedSession) throws Exception {
List<Surface> outputSurfaces = new ArrayList<Surface>(2);
assertTrue("Both preview and recording surfaces should be valid", mPreviewSurface.isValid() && mRecordingSurface.isValid());
outputSurfaces.add(mPreviewSurface);
outputSurfaces.add(mRecordingSurface);
// Video snapshot surface
if (mReaderSurface != null) {
outputSurfaces.add(mReaderSurface);
}
mSessionListener = new BlockingSessionCallback();
mSession = configureCameraSession(mCamera, outputSurfaces, useHighSpeedSession, mSessionListener, mHandler);
// Create slow motion request list
List<CaptureRequest> slowMoRequests = null;
if (useHighSpeedSession) {
CaptureRequest.Builder requestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
requestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
requestBuilder.addTarget(mPreviewSurface);
requestBuilder.addTarget(mRecordingSurface);
slowMoRequests = ((CameraConstrainedHighSpeedCaptureSession) mSession).createHighSpeedRequestList(requestBuilder.build());
} else {
CaptureRequest.Builder recordingRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
recordingRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
recordingRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
CaptureRequest.Builder recordingOnlyBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
recordingOnlyBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_USE_SCENE_MODE);
recordingOnlyBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CaptureRequest.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO);
int slowMotionFactor = captureRate / videoFrameRate;
// Make sure camera output frame rate is set to correct value.
recordingRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
recordingRequestBuilder.addTarget(mRecordingSurface);
recordingRequestBuilder.addTarget(mPreviewSurface);
recordingOnlyBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
recordingOnlyBuilder.addTarget(mRecordingSurface);
slowMoRequests = new ArrayList<CaptureRequest>();
// Preview + recording.
slowMoRequests.add(recordingRequestBuilder.build());
for (int i = 0; i < slowMotionFactor - 1; i++) {
// Recording only.
slowMoRequests.add(recordingOnlyBuilder.build());
}
}
mSession.setRepeatingBurst(slowMoRequests, listener, mHandler);
if (useMediaRecorder) {
mMediaRecorder.start();
} else {
// TODO: need implement MediaCodec path.
}
}
use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by AOSPA.
the class Camera2SurfaceViewTestCase method configurePreviewOutput.
/**
* Configure the preview output stream.
*
* @param request The request to be configured with preview surface
*/
protected void configurePreviewOutput(CaptureRequest.Builder request) throws CameraAccessException {
List<Surface> outputSurfaces = new ArrayList<Surface>(/*capacity*/
1);
outputSurfaces.add(mPreviewSurface);
mSessionListener = new BlockingSessionCallback();
mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
request.addTarget(mPreviewSurface);
}
use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by AOSPA.
the class Camera2RecordingTest method startRecording.
private void startRecording(boolean useMediaRecorder, CameraCaptureSession.CaptureCallback listener, boolean useVideoStab) throws Exception {
if (!mStaticInfo.isVideoStabilizationSupported() && useVideoStab) {
throw new IllegalArgumentException("Video stabilization is not supported");
}
List<Surface> outputSurfaces = new ArrayList<Surface>(2);
assertTrue("Both preview and recording surfaces should be valid", mPreviewSurface.isValid() && mRecordingSurface.isValid());
outputSurfaces.add(mPreviewSurface);
outputSurfaces.add(mRecordingSurface);
// Video snapshot surface
if (mReaderSurface != null) {
outputSurfaces.add(mReaderSurface);
}
mSessionListener = new BlockingSessionCallback();
mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
CaptureRequest.Builder recordingRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
// Make sure camera output frame rate is set to correct value.
Range<Integer> fpsRange = Range.create(mVideoFrameRate, mVideoFrameRate);
recordingRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
if (useVideoStab) {
recordingRequestBuilder.set(CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_ON);
}
recordingRequestBuilder.addTarget(mRecordingSurface);
recordingRequestBuilder.addTarget(mPreviewSurface);
mSession.setRepeatingRequest(recordingRequestBuilder.build(), listener, mHandler);
if (useMediaRecorder) {
mMediaRecorder.start();
} else {
// TODO: need implement MediaCodec path.
}
mRecordingStartTime = SystemClock.elapsedRealtime();
}
Aggregations