Search in sources :

Example 31 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project android_frameworks_base by AOSPA.

the class Camera2SwitchPreviewTest method basicRecordingPreviewTestByCamera.

/**
     * Test camera recording preview by using each available CamcorderProfile for a
     * given camera. preview size is set to the video size.
     */
private void basicRecordingPreviewTestByCamera(int[] camcorderProfileList) throws Exception {
    Size maxPreviewSize = mOrderedPreviewSizes.get(0);
    List<Range<Integer>> fpsRanges = Arrays.asList(mStaticInfo.getAeAvailableTargetFpsRangesChecked());
    int cameraId = Integer.parseInt(mCamera.getId());
    int maxVideoFrameRate = -1;
    int profileId = camcorderProfileList[0];
    if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
        return;
    }
    CamcorderProfile profile = CamcorderProfile.get(cameraId, profileId);
    Size videoSz = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
    Range<Integer> fpsRange = new Range(profile.videoFrameRate, profile.videoFrameRate);
    if (maxVideoFrameRate < profile.videoFrameRate) {
        maxVideoFrameRate = profile.videoFrameRate;
    }
    if (mStaticInfo.isHardwareLevelLegacy() && (videoSz.getWidth() > maxPreviewSize.getWidth() || videoSz.getHeight() > maxPreviewSize.getHeight())) {
        // Skip. Legacy mode can only do recording up to max preview size
        return;
    }
    assertTrue("Video size " + videoSz.toString() + " for profile ID " + profileId + " must be one of the camera device supported video size!", mSupportedVideoSizes.contains(videoSz));
    assertTrue("Frame rate range " + fpsRange + " (for profile ID " + profileId + ") must be one of the camera device available FPS range!", fpsRanges.contains(fpsRange));
    if (VERBOSE) {
        Log.v(TAG, "Testing camera recording with video size " + videoSz.toString());
    }
    // Configure preview and recording surfaces.
    mOutMediaFileName = VIDEO_FILE_PATH + "/test_video.mp4";
    if (DEBUG_DUMP) {
        mOutMediaFileName = VIDEO_FILE_PATH + "/test_video_" + cameraId + "_" + videoSz.toString() + ".mp4";
    }
    prepareRecordingWithProfile(profile);
    // prepare preview surface by using video size.
    updatePreviewSurfaceWithVideo(videoSz, profile.videoFrameRate);
    CaptureRequest.Builder previewRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    CaptureRequest.Builder recordingRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
    SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
    SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
    prepareVideoPreview(previewRequest, recordingRequest, resultListener, imageListener);
    // Can reuse the MediaRecorder object after reset.
    mMediaRecorder.reset();
    if (maxVideoFrameRate != -1) {
        // At least one CamcorderProfile is present, check FPS
        assertTrue("At least one CamcorderProfile must support >= 24 FPS", maxVideoFrameRate >= 24);
    }
}
Also used : Size(android.util.Size) CamcorderProfile(android.media.CamcorderProfile) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) CaptureRequest(android.hardware.camera2.CaptureRequest) Range(android.util.Range) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) Point(android.graphics.Point)

Example 32 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project android_frameworks_base by AOSPA.

the class Camera2ReprocessCaptureTest method testReprocessAbort.

/**
     * Test aborting a burst reprocess capture and multiple single reprocess captures.
     */
private void testReprocessAbort(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessAbort: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
    }
    try {
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, NUM_REPROCESS_CAPTURES);
        setupReprocessableSession(/*previewSurface*/
        null, NUM_REPROCESS_CAPTURES);
        // Test two cases: submitting reprocess requests one by one and in a burst.
        boolean[] submitInBursts = { false, true };
        for (boolean submitInBurst : submitInBursts) {
            // Prepare reprocess capture requests.
            ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(NUM_REPROCESS_CAPTURES);
            for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
                TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
                null);
                mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
                CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
                builder.addTarget(getReprocessOutputImageReader().getSurface());
                reprocessRequests.add(builder.build());
            }
            SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
            // Submit reprocess capture requests.
            if (submitInBurst) {
                mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
            } else {
                for (CaptureRequest request : reprocessRequests) {
                    mSession.capture(request, captureCallback, mHandler);
                }
            }
            // Abort after getting the first result
            TotalCaptureResult reprocessResult = captureCallback.getTotalCaptureResultForRequest(reprocessRequests.get(0), CAPTURE_TIMEOUT_FRAMES);
            mSession.abortCaptures();
            // Wait until the session is ready again.
            mSessionListener.getStateWaiter().waitForState(BlockingSessionCallback.SESSION_READY, SESSION_CLOSE_TIMEOUT_MS);
            // Gather all failed requests.
            ArrayList<CaptureFailure> failures = captureCallback.getCaptureFailures(NUM_REPROCESS_CAPTURES - 1);
            ArrayList<CaptureRequest> failedRequests = new ArrayList<>();
            for (CaptureFailure failure : failures) {
                failedRequests.add(failure.getRequest());
            }
            // For each request that didn't fail must have a valid result.
            for (int i = 1; i < reprocessRequests.size(); i++) {
                CaptureRequest request = reprocessRequests.get(i);
                if (!failedRequests.contains(request)) {
                    captureCallback.getTotalCaptureResultForRequest(request, CAPTURE_TIMEOUT_FRAMES);
                }
            }
            // Drain the image reader listeners.
            mFirstImageReaderListener.drain();
            if (!mShareOneImageReader) {
                mSecondImageReaderListener.drain();
            }
            // Make sure all input surfaces are released.
            for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
                mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
            }
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : CaptureFailure(android.hardware.camera2.CaptureFailure) ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 33 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback 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;
    }
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Size(android.util.Size) DngCreator(android.hardware.camera2.DngCreator) CaptureResult(android.hardware.camera2.CaptureResult) ArrayList(java.util.ArrayList) SimpleImageReaderListener(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CameraTestUtils.basicValidateJpegImage(com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image) Surface(android.view.Surface) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) CameraTestUtils.makeImageReader(com.android.mediaframeworktest.helpers.CameraTestUtils.makeImageReader) ImageReader(android.media.ImageReader)

Example 34 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project platform_frameworks_base by android.

the class Camera2CaptureRequestTest method aeManualControlTest.

/**
     * Iterate through exposure times and sensitivities for manual AE control.
     * <p>
     * Use single request rather than repeating request to test manual exposure
     * value change per frame control.
     * </p>
     */
private void aeManualControlTest() throws Exception {
    CaptureRequest.Builder requestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CONTROL_AE_MODE_OFF);
    configurePreviewOutput(requestBuilder);
    SimpleCaptureCallback listener = new SimpleCaptureCallback();
    long[] expTimes = getExposureTimeTestValues();
    int[] sensitivities = getSensitivityTestValues();
    // Submit single request at a time, then verify the result.
    for (int i = 0; i < expTimes.length; i++) {
        for (int j = 0; j < sensitivities.length; j++) {
            if (VERBOSE) {
                Log.v(TAG, "Camera " + mCamera.getId() + ": Testing sensitivity " + sensitivities[j] + ", exposure time " + expTimes[i] + "ns");
            }
            changeExposure(requestBuilder, expTimes[i], sensitivities[j]);
            mSession.capture(requestBuilder.build(), listener, mHandler);
            // make sure timeout is long enough for long exposure time
            long timeout = WAIT_FOR_RESULT_TIMEOUT_MS + expTimes[i];
            CaptureResult result = listener.getCaptureResult(timeout);
            long resultExpTime = getValueNotNull(result, CaptureResult.SENSOR_EXPOSURE_TIME);
            int resultSensitivity = getValueNotNull(result, CaptureResult.SENSOR_SENSITIVITY);
            validateExposureTime(expTimes[i], resultExpTime);
            validateSensitivity(sensitivities[j], resultSensitivity);
            validateFrameDurationForCapture(result);
        }
    }
// TODO: Add another case to test where we can submit all requests, then wait for
// results, which will hide the pipeline latency. this is not only faster, but also
// test high speed per frame control and synchronization.
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 35 with SimpleCaptureCallback

use of com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback in project platform_frameworks_base by android.

the class Camera2CaptureRequestTest method autoAeMultipleCapturesThenTestLock.

/**
     * Issue multiple auto AE captures, then lock AE, validate the AE lock vs.
     * the first capture result after the AE lock. The right AE lock behavior is:
     * When it is locked, it locks to the current exposure value, and all subsequent
     * request with lock ON will have the same exposure value locked.
     */
private void autoAeMultipleCapturesThenTestLock(CaptureRequest.Builder requestBuilder, int aeMode, int numCapturesDuringLock) throws Exception {
    if (numCapturesDuringLock < 1) {
        throw new IllegalArgumentException("numCapturesBeforeLock must be no less than 1");
    }
    if (VERBOSE) {
        Log.v(TAG, "Camera " + mCamera.getId() + ": Testing auto AE mode and lock for mode " + aeMode + " with " + numCapturesDuringLock + " captures before lock");
    }
    final int NUM_CAPTURES_BEFORE_LOCK = 2;
    SimpleCaptureCallback listener = new SimpleCaptureCallback();
    CaptureResult[] resultsDuringLock = new CaptureResult[numCapturesDuringLock];
    boolean canSetAeLock = mStaticInfo.isAeLockSupported();
    // Reset the AE lock to OFF, since we are reusing this builder many times
    if (canSetAeLock) {
        requestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false);
    }
    // Just send several captures with auto AE, lock off.
    CaptureRequest request = requestBuilder.build();
    for (int i = 0; i < NUM_CAPTURES_BEFORE_LOCK; i++) {
        mSession.capture(request, listener, mHandler);
    }
    waitForNumResults(listener, NUM_CAPTURES_BEFORE_LOCK);
    if (!canSetAeLock) {
        // Without AE lock, the remaining tests items won't work
        return;
    }
    // Then fire several capture to lock the AE.
    requestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, true);
    int requestCount = captureRequestsSynchronized(requestBuilder.build(), numCapturesDuringLock, listener, mHandler);
    int[] sensitivities = new int[numCapturesDuringLock];
    long[] expTimes = new long[numCapturesDuringLock];
    Arrays.fill(sensitivities, -1);
    Arrays.fill(expTimes, -1L);
    // Get the AE lock on result and validate the exposure values.
    waitForNumResults(listener, requestCount - numCapturesDuringLock);
    for (int i = 0; i < resultsDuringLock.length; i++) {
        resultsDuringLock[i] = listener.getCaptureResult(WAIT_FOR_RESULT_TIMEOUT_MS);
    }
    for (int i = 0; i < numCapturesDuringLock; i++) {
        mCollector.expectKeyValueEquals(resultsDuringLock[i], CaptureResult.CONTROL_AE_LOCK, true);
    }
    // Can't read manual sensor/exposure settings without manual sensor
    if (mStaticInfo.isCapabilitySupported(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS)) {
        int sensitivityLocked = getValueNotNull(resultsDuringLock[0], CaptureResult.SENSOR_SENSITIVITY);
        long expTimeLocked = getValueNotNull(resultsDuringLock[0], CaptureResult.SENSOR_EXPOSURE_TIME);
        for (int i = 1; i < resultsDuringLock.length; i++) {
            mCollector.expectKeyValueEquals(resultsDuringLock[i], CaptureResult.SENSOR_EXPOSURE_TIME, expTimeLocked);
            mCollector.expectKeyValueEquals(resultsDuringLock[i], CaptureResult.SENSOR_SENSITIVITY, sensitivityLocked);
        }
    }
}
Also used : CaptureResult(android.hardware.camera2.CaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Aggregations

SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)70 CaptureRequest (android.hardware.camera2.CaptureRequest)60 Size (android.util.Size)35 ArrayList (java.util.ArrayList)35 CaptureResult (android.hardware.camera2.CaptureResult)25 TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)25 Image (android.media.Image)25 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)25 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)20 CamcorderProfile (android.media.CamcorderProfile)15 Range (android.util.Range)15 Point (android.graphics.Point)10 CameraTestUtils.basicValidateJpegImage (com.android.mediaframeworktest.helpers.CameraTestUtils.basicValidateJpegImage)10 CaptureFailure (android.hardware.camera2.CaptureFailure)5 DngCreator (android.hardware.camera2.DngCreator)5 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)5 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)5 ImageReader (android.media.ImageReader)5 MediaRecorder (android.media.MediaRecorder)5 Surface (android.view.Surface)5