Search in sources :

Example 21 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by DirtyUnicorns.

the class Camera2ReprocessCaptureTest method testReprocessJpegExif.

/**
     * Test JPEG tags for reprocess requests. Reprocess result's JPEG tags and JPEG image's tags
     * match reprocess request's JPEG tags.
     */
private void testReprocessJpegExif(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessJpegExif: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize);
    }
    Size[] thumbnailSizes = mStaticInfo.getAvailableThumbnailSizesChecked();
    Size[] testThumbnailSizes = new Size[EXIF_TEST_DATA.length];
    Arrays.fill(testThumbnailSizes, thumbnailSizes[thumbnailSizes.length - 1]);
    // Make sure thumbnail size (0, 0) is covered.
    testThumbnailSizes[0] = new Size(0, 0);
    try {
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, ImageFormat.JPEG, EXIF_TEST_DATA.length);
        setupReprocessableSession(/*previewSurface*/
        null, EXIF_TEST_DATA.length);
        // Prepare reprocess capture requests.
        ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(EXIF_TEST_DATA.length);
        for (int i = 0; i < EXIF_TEST_DATA.length; 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());
            // set jpeg keys
            setJpegKeys(builder, EXIF_TEST_DATA[i], testThumbnailSizes[i], mCollector);
            reprocessRequests.add(builder.build());
        }
        // Submit reprocess requests.
        SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
        mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
        TotalCaptureResult[] reprocessResults = captureCallback.getTotalCaptureResultsForRequests(reprocessRequests, CAPTURE_TIMEOUT_FRAMES);
        for (int i = 0; i < EXIF_TEST_DATA.length; i++) {
            // Verify output image's and result's JPEG EXIF data.
            Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
            verifyJpegKeys(image, reprocessResults[i], reprocessOutputSize, testThumbnailSizes[i], EXIF_TEST_DATA[i], mStaticInfo, mCollector);
            image.close();
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : Size(android.util.Size) ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Example 22 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by crdroidandroid.

the class Camera2ReprocessCaptureTest method testReprocess.

/**
     * Test a sequences of reprocess capture requests.
     */
private void testReprocess(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat, Size previewSize, int numReprocessCaptures) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocess: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat + " previewSize: " + previewSize);
    }
    boolean enablePreview = (previewSize != null);
    try {
        if (enablePreview) {
            updatePreviewSurface(previewSize);
        } else {
            mPreviewSurface = null;
        }
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, /*maxImages*/
        1);
        setupReprocessableSession(mPreviewSurface, /*numImageWriterImages*/
        1);
        if (enablePreview) {
            startPreview(mPreviewSurface);
        }
        for (int i = 0; i < numReprocessCaptures; i++) {
            ImageResultHolder imageResultHolder = null;
            try {
                imageResultHolder = doReprocessCapture();
                Image reprocessedImage = imageResultHolder.getImage();
                TotalCaptureResult result = imageResultHolder.getTotalCaptureResult();
                mCollector.expectImageProperties("testReprocess", reprocessedImage, reprocessOutputFormat, reprocessOutputSize, result.get(CaptureResult.SENSOR_TIMESTAMP));
                if (DEBUG) {
                    Log.d(TAG, String.format("camera %s in %dx%d %d out %dx%d %d", cameraId, inputSize.getWidth(), inputSize.getHeight(), inputFormat, reprocessOutputSize.getWidth(), reprocessOutputSize.getHeight(), reprocessOutputFormat));
                    dumpImage(reprocessedImage, "/testReprocess_camera" + cameraId + "_" + mDumpFrameCount);
                    mDumpFrameCount++;
                }
            } finally {
                if (imageResultHolder != null) {
                    imageResultHolder.getImage().close();
                }
            }
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Example 23 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by crdroidandroid.

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 24 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project android_frameworks_base by crdroidandroid.

the class Camera2ReprocessCaptureTest method testReprocessBurst.

/**
     * Test burst of reprocess capture requests.
     */
private void testReprocessBurst(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat, Size previewSize, int numBurst) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessBurst: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat + " previewSize: " + previewSize + " numBurst: " + numBurst);
    }
    boolean enablePreview = (previewSize != null);
    ImageResultHolder[] imageResultHolders = new ImageResultHolder[0];
    try {
        if (enablePreview) {
            updatePreviewSurface(previewSize);
        } else {
            mPreviewSurface = null;
        }
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, numBurst);
        setupReprocessableSession(mPreviewSurface, numBurst);
        if (enablePreview) {
            startPreview(mPreviewSurface);
        }
        imageResultHolders = doReprocessBurstCapture(numBurst);
        for (ImageResultHolder holder : imageResultHolders) {
            Image reprocessedImage = holder.getImage();
            TotalCaptureResult result = holder.getTotalCaptureResult();
            mCollector.expectImageProperties("testReprocessBurst", reprocessedImage, reprocessOutputFormat, reprocessOutputSize, result.get(CaptureResult.SENSOR_TIMESTAMP));
            if (DEBUG) {
                Log.d(TAG, String.format("camera %s in %dx%d %d out %dx%d %d", cameraId, inputSize.getWidth(), inputSize.getHeight(), inputFormat, reprocessOutputSize.getWidth(), reprocessOutputSize.getHeight(), reprocessOutputFormat));
                dumpImage(reprocessedImage, "/testReprocessBurst_camera" + cameraId + "_" + mDumpFrameCount);
                mDumpFrameCount++;
            }
        }
    } finally {
        for (ImageResultHolder holder : imageResultHolders) {
            holder.getImage().close();
        }
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Example 25 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult 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)

Aggregations

TotalCaptureResult (android.hardware.camera2.TotalCaptureResult)46 Image (android.media.Image)30 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)30 ArrayList (java.util.ArrayList)30 CaptureRequest (android.hardware.camera2.CaptureRequest)26 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)25 CaptureFailure (android.hardware.camera2.CaptureFailure)5 PublicKey (android.hardware.camera2.impl.PublicKey)5 SyntheticKey (android.hardware.camera2.impl.SyntheticKey)5 Size (android.util.Size)5 Surface (android.view.Surface)5 Field (java.lang.reflect.Field)5 Activity (android.app.Activity)1 Point (android.graphics.Point)1 CameraAccessException (android.hardware.camera2.CameraAccessException)1 CameraCaptureSession (android.hardware.camera2.CameraCaptureSession)1 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)1 CameraManager (android.hardware.camera2.CameraManager)1 NonNull (android.support.annotation.NonNull)1