Search in sources :

Example 46 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method testCameraInfo.

@SmallTest
public void testCameraInfo() throws RemoteException {
    CameraMetadataNative info = mCameraUser.getCameraInfo();
    assertFalse(info.isEmpty());
    assertNotNull(info.get(CameraCharacteristics.SCALER_AVAILABLE_FORMATS));
}
Also used : CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 47 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method createDefaultBuilder.

private CaptureRequest.Builder createDefaultBuilder(boolean needStream) throws Exception {
    CameraMetadataNative metadata = null;
    assertTrue(metadata.isEmpty());
    metadata = mCameraUser.createDefaultRequest(TEMPLATE_PREVIEW);
    assertFalse(metadata.isEmpty());
    CaptureRequest.Builder request = new CaptureRequest.Builder(metadata, /*reprocess*/
    false, CameraCaptureSession.SESSION_ID_NONE);
    assertFalse(request.isEmpty());
    assertFalse(metadata.isEmpty());
    if (needStream) {
        int streamId = mCameraUser.createStream(mOutputConfiguration);
        assertEquals(0, streamId);
        request.addTarget(mSurface);
    }
    return request;
}
Also used : CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) CaptureRequest(android.hardware.camera2.CaptureRequest)

Example 48 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method testCameraCharacteristics.

@SmallTest
public void testCameraCharacteristics() throws RemoteException {
    CameraMetadataNative info = mUtils.getCameraService().getCameraCharacteristics(mCameraId);
    assertFalse(info.isEmpty());
    assertNotNull(info.get(CameraCharacteristics.SCALER_AVAILABLE_FORMATS));
}
Also used : CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 49 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project android_frameworks_base by DirtyUnicorns.

the class CameraDeviceBinderTest method testCreateDefaultRequest.

@SmallTest
public void testCreateDefaultRequest() throws Exception {
    CameraMetadataNative metadata = null;
    assertTrue(metadata.isEmpty());
    metadata = mCameraUser.createDefaultRequest(TEMPLATE_PREVIEW);
    assertFalse(metadata.isEmpty());
}
Also used : CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 50 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project android_frameworks_base by DirtyUnicorns.

the class LegacyMetadataMapper method mapScalerStreamConfigs.

private static void mapScalerStreamConfigs(CameraMetadataNative m, Camera.Parameters p) {
    ArrayList<StreamConfiguration> availableStreamConfigs = new ArrayList<>();
    /*
         * Implementation-defined (preview, recording, etc) -> use camera1 preview sizes
         * YUV_420_888 cpu callbacks -> use camera1 preview sizes
         * Other preview callbacks (CPU) -> use camera1 preview sizes
         * JPEG still capture -> use camera1 still capture sizes
         *
         * Use platform-internal format constants here, since StreamConfigurationMap does the
         * remapping to public format constants.
         */
    List<Camera.Size> previewSizes = p.getSupportedPreviewSizes();
    List<Camera.Size> jpegSizes = p.getSupportedPictureSizes();
    /*
         * Work-around for b/17589233:
         * - Some HALs's largest preview size aspect ratio does not match the largest JPEG size AR
         * - This causes a large amount of problems with focus/metering because it's relative to
         *   preview, making the difference between the JPEG and preview viewport inaccessible
         * - This boils down to metering or focusing areas being "arbitrarily" cropped
         *   in the capture result.
         * - Work-around the HAL limitations by removing all of the largest preview sizes
         *   until we get one with the same aspect ratio as the jpeg size.
         */
    {
        SizeAreaComparator areaComparator = new SizeAreaComparator();
        // Sort preview to min->max
        Collections.sort(previewSizes, areaComparator);
        Camera.Size maxJpegSize = SizeAreaComparator.findLargestByArea(jpegSizes);
        float jpegAspectRatio = maxJpegSize.width * 1.0f / maxJpegSize.height;
        if (DEBUG) {
            Log.v(TAG, String.format("mapScalerStreamConfigs - largest JPEG area %dx%d, AR=%f", maxJpegSize.width, maxJpegSize.height, jpegAspectRatio));
        }
        // Now remove preview sizes from the end (largest->smallest) until aspect ratio matches
        while (!previewSizes.isEmpty()) {
            // max is always at the end
            int index = previewSizes.size() - 1;
            Camera.Size size = previewSizes.get(index);
            float previewAspectRatio = size.width * 1.0f / size.height;
            if (Math.abs(jpegAspectRatio - previewAspectRatio) >= PREVIEW_ASPECT_RATIO_TOLERANCE) {
                // Assume removing from end is O(1)
                previewSizes.remove(index);
                if (DEBUG) {
                    Log.v(TAG, String.format("mapScalerStreamConfigs - removed preview size %dx%d, AR=%f " + "was not the same", size.width, size.height, previewAspectRatio));
                }
            } else {
                break;
            }
        }
        if (previewSizes.isEmpty()) {
            // Fall-back to the original faulty behavior, but at least work
            Log.w(TAG, "mapScalerStreamConfigs - failed to find any preview size matching " + "JPEG aspect ratio " + jpegAspectRatio);
            previewSizes = p.getSupportedPreviewSizes();
        }
        // Sort again, this time in descending order max->min
        Collections.sort(previewSizes, Collections.reverseOrder(areaComparator));
    }
    appendStreamConfig(availableStreamConfigs, HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, previewSizes);
    appendStreamConfig(availableStreamConfigs, ImageFormat.YUV_420_888, previewSizes);
    for (int format : p.getSupportedPreviewFormats()) {
        if (ImageFormat.isPublicFormat(format) && format != ImageFormat.NV21) {
            appendStreamConfig(availableStreamConfigs, format, previewSizes);
        } else if (DEBUG) {
            /*
                 *  Do not add any formats unknown to us
                 * (since it would fail runtime checks in StreamConfigurationMap)
                 */
            Log.v(TAG, String.format("mapStreamConfigs - Skipping format %x", format));
        }
    }
    appendStreamConfig(availableStreamConfigs, HAL_PIXEL_FORMAT_BLOB, p.getSupportedPictureSizes());
    /*
         * scaler.availableStreamConfigurations
         */
    m.set(SCALER_AVAILABLE_STREAM_CONFIGURATIONS, availableStreamConfigs.toArray(new StreamConfiguration[0]));
    /*
         * scaler.availableMinFrameDurations
         */
    // No frame durations available
    m.set(SCALER_AVAILABLE_MIN_FRAME_DURATIONS, new StreamConfigurationDuration[0]);
    StreamConfigurationDuration[] jpegStalls = new StreamConfigurationDuration[jpegSizes.size()];
    int i = 0;
    long longestStallDuration = -1;
    for (Camera.Size s : jpegSizes) {
        long stallDuration = calculateJpegStallDuration(s);
        jpegStalls[i++] = new StreamConfigurationDuration(HAL_PIXEL_FORMAT_BLOB, s.width, s.height, stallDuration);
        if (longestStallDuration < stallDuration) {
            longestStallDuration = stallDuration;
        }
    }
    /*
         * scaler.availableStallDurations
         */
    // Set stall durations for jpeg, other formats use default stall duration
    m.set(SCALER_AVAILABLE_STALL_DURATIONS, jpegStalls);
    /*
         * sensor.info.maxFrameDuration
         */
    m.set(SENSOR_INFO_MAX_FRAME_DURATION, longestStallDuration);
}
Also used : StreamConfigurationDuration(android.hardware.camera2.params.StreamConfigurationDuration) Size(android.util.Size) ArrayList(java.util.ArrayList) StreamConfiguration(android.hardware.camera2.params.StreamConfiguration) Camera(android.hardware.Camera)

Aggregations

CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)55 Camera (android.hardware.Camera)20 CaptureRequest (android.hardware.camera2.CaptureRequest)20 Size (android.util.Size)20 ArrayList (java.util.ArrayList)20 Rect (android.graphics.Rect)15 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)15 ServiceSpecificException (android.os.ServiceSpecificException)15 SmallTest (android.test.suitebuilder.annotation.SmallTest)15 Parameters (android.hardware.Camera.Parameters)10 ICameraService (android.hardware.ICameraService)10 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 RemoteException (android.os.RemoteException)10 NonNull (android.annotation.NonNull)5 CameraInfo (android.hardware.CameraInfo)5 Face (android.hardware.camera2.params.Face)5 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)5 StreamConfiguration (android.hardware.camera2.params.StreamConfiguration)5 StreamConfigurationDuration (android.hardware.camera2.params.StreamConfigurationDuration)5 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)5