Search in sources :

Example 26 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 27 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project platform_frameworks_base by android.

the class CameraMetadata method getKeysStatic.

/**
     * Return a list of all the Key<?> that are declared as a field inside of the class
     * {@code type}.
     *
     * <p>
     * Optionally, if {@code instance} is not null, then filter out any keys with null values.
     * </p>
     *
     * <p>
     * Optionally, if {@code filterTags} is not {@code null}, then filter out any keys
     * whose native {@code tag} is not in {@code filterTags}. The {@code filterTags} array will be
     * sorted as a side effect.
     * </p>
     */
/*package*/
@SuppressWarnings("unchecked")
static <TKey> ArrayList<TKey> getKeysStatic(Class<?> type, Class<TKey> keyClass, CameraMetadata<TKey> instance, int[] filterTags) {
    if (DEBUG)
        Log.v(TAG, "getKeysStatic for " + type);
    // TotalCaptureResult does not have any of the keys on it, use CaptureResult instead
    if (type.equals(TotalCaptureResult.class)) {
        type = CaptureResult.class;
    }
    if (filterTags != null) {
        Arrays.sort(filterTags);
    }
    ArrayList<TKey> keyList = new ArrayList<TKey>();
    Field[] fields = type.getDeclaredFields();
    for (Field field : fields) {
        // Filter for Keys that are public
        if (field.getType().isAssignableFrom(keyClass) && (field.getModifiers() & Modifier.PUBLIC) != 0) {
            TKey key;
            try {
                key = (TKey) field.get(instance);
            } catch (IllegalAccessException e) {
                throw new AssertionError("Can't get IllegalAccessException", e);
            } catch (IllegalArgumentException e) {
                throw new AssertionError("Can't get IllegalArgumentException", e);
            }
            if (instance == null || instance.getProtected(key) != null) {
                if (shouldKeyBeAdded(key, field, filterTags)) {
                    keyList.add(key);
                    if (DEBUG) {
                        Log.v(TAG, "getKeysStatic - key was added - " + key);
                    }
                } else if (DEBUG) {
                    Log.v(TAG, "getKeysStatic - key was filtered - " + key);
                }
            }
        }
    }
    ArrayList<TKey> vendorKeys = CameraMetadataNative.getAllVendorKeys(keyClass);
    if (vendorKeys != null) {
        for (TKey k : vendorKeys) {
            String keyName;
            if (k instanceof CaptureRequest.Key<?>) {
                keyName = ((CaptureRequest.Key<?>) k).getName();
            } else if (k instanceof CaptureResult.Key<?>) {
                keyName = ((CaptureResult.Key<?>) k).getName();
            } else if (k instanceof CameraCharacteristics.Key<?>) {
                keyName = ((CameraCharacteristics.Key<?>) k).getName();
            } else {
                continue;
            }
            if (filterTags == null || Arrays.binarySearch(filterTags, CameraMetadataNative.getTag(keyName)) >= 0) {
                keyList.add(k);
            }
        }
    }
    return keyList;
}
Also used : ArrayList(java.util.ArrayList) Field(java.lang.reflect.Field) PublicKey(android.hardware.camera2.impl.PublicKey) SyntheticKey(android.hardware.camera2.impl.SyntheticKey)

Example 28 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project material-camera by afollestad.

the class Camera2Fragment method captureStillPicture.

/**
     * Capture a still picture. This method should be called when we get a response in
     * {@link #mCaptureCallback} from both {@link #takeStillshot()}.
     */
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());
        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setFlashMode(captureBuilder);
        // Orientation
        CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId());
        //noinspection ConstantConditions,ResourceType
        @Degrees.DegreeUnits final int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
        int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        // default camera orientation used to be 90 degrees, for Nexus 5X, 6P it is 270 degrees
        if (sensorOrientation == Degrees.DEGREES_270) {
            displayRotation += 2 % 3;
        }
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(displayRotation));
        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                Log.d("stillshot", "onCaptureCompleted");
                unlockFocus();
            }
        };
        mPreviewSession.stopRepeating();
        mPreviewSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
Also used : Activity(android.app.Activity) CameraManager(android.hardware.camera2.CameraManager) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CameraCaptureSession(android.hardware.camera2.CameraCaptureSession) Point(android.graphics.Point) CameraAccessException(android.hardware.camera2.CameraAccessException) NonNull(android.support.annotation.NonNull) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 29 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project platform_frameworks_base by android.

the class Camera2ReprocessCaptureTest method submitMixedCaptureBurstRequest.

/**
     * Submit a burst request mixed with regular and reprocess requests.
     *
     * @param outputs An array of output surfaces. One output surface will be used in one request
     *                so the length of the array is the number of requests in a burst request.
     * @param inputResults An array of input results. If it's null, all requests are regular
     *                     requests. If an element is null, that element represents a regular
     *                     request. If an element if not null, that element represents a reprocess
     *                     request.
     *
     */
private TotalCaptureResult[] submitMixedCaptureBurstRequest(Surface[] outputs, TotalCaptureResult[] inputResults) throws Exception {
    if (outputs == null || outputs.length <= 0) {
        throw new IllegalArgumentException("outputs must have at least 1 surface");
    } else if (inputResults != null && inputResults.length != outputs.length) {
        throw new IllegalArgumentException("The lengths of outputs and inputResults " + "don't match");
    }
    int numReprocessCaptures = 0;
    SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
    ArrayList<CaptureRequest> captureRequests = new ArrayList<>(outputs.length);
    // is based on inputResults array.
    for (int i = 0; i < outputs.length; i++) {
        CaptureRequest.Builder builder;
        boolean isReprocess = (inputResults != null && inputResults[i] != null);
        if (isReprocess) {
            builder = mCamera.createReprocessCaptureRequest(inputResults[i]);
            numReprocessCaptures++;
        } else {
            builder = mCamera.createCaptureRequest(CAPTURE_TEMPLATE);
        }
        builder.addTarget(outputs[i]);
        CaptureRequest request = builder.build();
        assertTrue("Capture request reprocess type " + request.isReprocess() + " is wrong.", request.isReprocess() == isReprocess);
        captureRequests.add(request);
    }
    if (captureRequests.size() == 1) {
        mSession.capture(captureRequests.get(0), captureCallback, mHandler);
    } else {
        mSession.captureBurst(captureRequests, captureCallback, mHandler);
    }
    TotalCaptureResult[] results;
    if (numReprocessCaptures == 0 || numReprocessCaptures == outputs.length) {
        results = new TotalCaptureResult[outputs.length];
        // If the requests are not mixed, they should come in order.
        for (int i = 0; i < results.length; i++) {
            results[i] = captureCallback.getTotalCaptureResultForRequest(captureRequests.get(i), CAPTURE_TIMEOUT_FRAMES);
        }
    } else {
        // If the requests are mixed, they may not come in order.
        results = captureCallback.getTotalCaptureResultsForRequests(captureRequests, CAPTURE_TIMEOUT_FRAMES * captureRequests.size());
    }
    // make sure all input surfaces are released.
    for (int i = 0; i < numReprocessCaptures; i++) {
        mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)

Example 30 with TotalCaptureResult

use of android.hardware.camera2.TotalCaptureResult in project platform_frameworks_base by android.

the class Camera2ReprocessCaptureTest method testReprocessMixedBurst.

/**
     * Test burst that is mixed with regular and reprocess capture requests.
     */
private void testReprocessMixedBurst(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize, int reprocessOutputFormat, Size previewSize, int numBurst) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessMixedBurst: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat + " previewSize: " + previewSize + " numBurst: " + numBurst);
    }
    boolean enablePreview = (previewSize != null);
    ImageResultHolder[] imageResultHolders = new ImageResultHolder[0];
    try {
        // totalNumBurst = number of regular burst + number of reprocess burst.
        int totalNumBurst = numBurst * 2;
        if (enablePreview) {
            updatePreviewSurface(previewSize);
        } else {
            mPreviewSurface = null;
        }
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat, totalNumBurst);
        setupReprocessableSession(mPreviewSurface, /*numImageWriterImages*/
        numBurst);
        if (enablePreview) {
            startPreview(mPreviewSurface);
        }
        // Prepare an array of booleans indicating each capture's type (regular or reprocess)
        boolean[] isReprocessCaptures = new boolean[totalNumBurst];
        for (int i = 0; i < totalNumBurst; i++) {
            if ((i & 1) == 0) {
                isReprocessCaptures[i] = true;
            } else {
                isReprocessCaptures[i] = false;
            }
        }
        imageResultHolders = doMixedReprocessBurstCapture(isReprocessCaptures);
        for (ImageResultHolder holder : imageResultHolders) {
            Image reprocessedImage = holder.getImage();
            TotalCaptureResult result = holder.getTotalCaptureResult();
            mCollector.expectImageProperties("testReprocessMixedBurst", 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, "/testReprocessMixedBurst_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)

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