use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
the class CameraTestUtils method configureReprocessableCameraSession.
public static CameraCaptureSession configureReprocessableCameraSession(CameraDevice camera, InputConfiguration inputConfiguration, List<Surface> outputSurfaces, CameraCaptureSession.StateCallback listener, Handler handler) throws CameraAccessException {
BlockingSessionCallback sessionListener = new BlockingSessionCallback(listener);
camera.createReprocessableCaptureSession(inputConfiguration, outputSurfaces, sessionListener, handler);
Integer[] sessionStates = { BlockingSessionCallback.SESSION_READY, BlockingSessionCallback.SESSION_CONFIGURE_FAILED };
int state = sessionListener.getStateWaiter().waitForAnyOfStates(Arrays.asList(sessionStates), SESSION_CONFIGURE_TIMEOUT_MS);
assertTrue("Creating a reprocessable session failed.", state == BlockingSessionCallback.SESSION_READY);
CameraCaptureSession session = sessionListener.waitAndGetSession(SESSION_CONFIGURE_TIMEOUT_MS);
assertTrue("Camera session should be a reprocessable session", session.isReprocessable());
return session;
}
use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.
the class Camera2Source method onOpen.
@Override
protected void onOpen() {
mLooperThread = new CameraTestThread();
Handler mHandler;
try {
mHandler = mLooperThread.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(e);
}
try {
String backCameraId = "0";
BlockingCameraManager blkManager = new BlockingCameraManager(mCameraManager);
mCamera = blkManager.openCamera(backCameraId, /*listener*/
null, mHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (BlockingOpenException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
Element ele = Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV);
rgbConverter = ScriptIntrinsicYuvToRGB.create(mRS, ele);
Type.Builder yuvBuilder = new Type.Builder(mRS, ele);
yuvBuilder.setYuvFormat(ImageFormat.YUV_420_888);
yuvBuilder.setX(mWidth);
yuvBuilder.setY(mHeight);
mAllocationIn = Allocation.createTyped(mRS, yuvBuilder.create(), Allocation.USAGE_SCRIPT | Allocation.USAGE_IO_INPUT);
mSurface = mAllocationIn.getSurface();
mAllocationIn.setOnBufferAvailableListener(this);
rgbConverter.setInput(mAllocationIn);
mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
mAllocationOut = Allocation.createFromBitmap(mRS, mBitmap);
Log.v(TAG, "mcamera: " + mCamera);
List<Surface> surfaces = new ArrayList<Surface>();
surfaces.add(mSurface);
CaptureRequest.Builder mCaptureRequest = null;
try {
BlockingSessionCallback blkSession = new BlockingSessionCallback();
mCamera.createCaptureSession(surfaces, blkSession, mHandler);
mCaptureRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mCaptureRequest.addTarget(mSurface);
mCameraSession = blkSession.waitAndGetSession(SESSION_TIMEOUT_MS);
} catch (CameraAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
try {
mCameraSession.setRepeatingRequest(mCaptureRequest.build(), new MyCaptureCallback(), mHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
mProperties = null;
try {
mProperties = mCameraManager.getCameraCharacteristics(mCamera.getId());
} catch (CameraAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of com.android.ex.camera2.blocking.BlockingSessionCallback in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
the class Camera2ReprocessCaptureTest method setupReprocessableSession.
/**
* Set up a reprocessable session and create an ImageWriter with the sessoin's input surface.
*/
private void setupReprocessableSession(Surface previewSurface, int numImageWriterImages) throws Exception {
// create a reprocessable capture session
List<Surface> outSurfaces = new ArrayList<Surface>();
outSurfaces.add(mFirstImageReader.getSurface());
if (!mShareOneImageReader) {
outSurfaces.add(mSecondImageReader.getSurface());
}
if (previewSurface != null) {
outSurfaces.add(previewSurface);
}
InputConfiguration inputConfig = new InputConfiguration(mFirstImageReader.getWidth(), mFirstImageReader.getHeight(), mFirstImageReader.getImageFormat());
String inputConfigString = inputConfig.toString();
if (VERBOSE) {
Log.v(TAG, "InputConfiguration: " + inputConfigString);
}
assertTrue(String.format("inputConfig is wrong: %dx%d format %d. Expect %dx%d format %d", inputConfig.getWidth(), inputConfig.getHeight(), inputConfig.getFormat(), mFirstImageReader.getWidth(), mFirstImageReader.getHeight(), mFirstImageReader.getImageFormat()), inputConfig.getWidth() == mFirstImageReader.getWidth() && inputConfig.getHeight() == mFirstImageReader.getHeight() && inputConfig.getFormat() == mFirstImageReader.getImageFormat());
mSessionListener = new BlockingSessionCallback();
mSession = configureReprocessableCameraSession(mCamera, inputConfig, outSurfaces, mSessionListener, mHandler);
// create an ImageWriter
mInputSurface = mSession.getInputSurface();
mImageWriter = ImageWriter.newInstance(mInputSurface, numImageWriterImages);
mImageWriterListener = new SimpleImageWriterListener(mImageWriter);
mImageWriter.setOnImageReleasedListener(mImageWriterListener, mHandler);
}
Aggregations