Search in sources :

Example 36 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project platform_frameworks_base by android.

the class LegacyResultMapper method cachedConvertResultMetadata.

/**
     * Generate capture result metadata from the legacy camera request.
     *
     * <p>This method caches and reuses the result from the previous call to this method if
     * the {@code parameters} of the subsequent {@link LegacyRequest} passed to this method
     * have not changed.</p>
     *
     * @param legacyRequest a non-{@code null} legacy request containing the latest parameters
     * @param timestamp the timestamp to use for this result in nanoseconds.
     *
     * @return {@link CameraMetadataNative} object containing result metadata.
     */
public CameraMetadataNative cachedConvertResultMetadata(LegacyRequest legacyRequest, long timestamp) {
    CameraMetadataNative result;
    boolean cached;
    /*
         * Attempt to look up the result from the cache if the parameters haven't changed
         */
    if (mCachedRequest != null && legacyRequest.parameters.same(mCachedRequest.parameters) && legacyRequest.captureRequest.equals(mCachedRequest.captureRequest)) {
        result = new CameraMetadataNative(mCachedResult);
        cached = true;
    } else {
        result = convertResultMetadata(legacyRequest);
        cached = false;
        // Always cache a *copy* of the metadata result,
        // since api2's client side takes ownership of it after it receives a result
        mCachedRequest = legacyRequest;
        mCachedResult = new CameraMetadataNative(result);
    }
    /*
         * Unconditionally set fields that change in every single frame
         */
    {
        // sensor.timestamp
        result.set(SENSOR_TIMESTAMP, timestamp);
    }
    if (DEBUG) {
        Log.v(TAG, "cachedConvertResultMetadata - cached? " + cached + " timestamp = " + timestamp);
        Log.v(TAG, "----- beginning of result dump ------");
        result.dumpToLog();
        Log.v(TAG, "----- end of result dump ------");
    }
    return result;
}
Also used : CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative)

Example 37 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project platform_frameworks_base by android.

the class LegacyResultMapper method convertResultMetadata.

/**
     * Generate capture result metadata from the legacy camera request.
     *
     * @param legacyRequest a non-{@code null} legacy request containing the latest parameters
     * @return a {@link CameraMetadataNative} object containing result metadata.
     */
private static CameraMetadataNative convertResultMetadata(LegacyRequest legacyRequest) {
    CameraCharacteristics characteristics = legacyRequest.characteristics;
    CaptureRequest request = legacyRequest.captureRequest;
    Size previewSize = legacyRequest.previewSize;
    Camera.Parameters params = legacyRequest.parameters;
    CameraMetadataNative result = new CameraMetadataNative();
    Rect activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    ZoomData zoomData = ParameterUtils.convertScalerCropRegion(activeArraySize, request.get(CaptureRequest.SCALER_CROP_REGION), previewSize, params);
    /*
         * colorCorrection
         */
    // colorCorrection.aberrationMode
    {
        result.set(COLOR_CORRECTION_ABERRATION_MODE, request.get(CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE));
    }
    /*
         * control
         */
    /*
         * control.ae*
         */
    mapAe(result, characteristics, request, activeArraySize, zoomData, /*out*/
    params);
    /*
         * control.af*
         */
    mapAf(result, activeArraySize, zoomData, /*out*/
    params);
    /*
         * control.awb*
         */
    mapAwb(result, /*out*/
    params);
    /*
         * control.captureIntent
         */
    {
        int captureIntent = ParamsUtils.getOrDefault(request, CaptureRequest.CONTROL_CAPTURE_INTENT, /*defaultValue*/
        CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);
        captureIntent = LegacyRequestMapper.filterSupportedCaptureIntent(captureIntent);
        result.set(CONTROL_CAPTURE_INTENT, captureIntent);
    }
    /*
         * control.mode
         */
    {
        int controlMode = ParamsUtils.getOrDefault(request, CaptureRequest.CONTROL_MODE, CONTROL_MODE_AUTO);
        if (controlMode == CaptureResult.CONTROL_MODE_USE_SCENE_MODE) {
            result.set(CONTROL_MODE, CONTROL_MODE_USE_SCENE_MODE);
        } else {
            result.set(CONTROL_MODE, CONTROL_MODE_AUTO);
        }
    }
    /*
         * control.sceneMode
         */
    {
        String legacySceneMode = params.getSceneMode();
        int mode = LegacyMetadataMapper.convertSceneModeFromLegacy(legacySceneMode);
        if (mode != LegacyMetadataMapper.UNKNOWN_MODE) {
            result.set(CaptureResult.CONTROL_SCENE_MODE, mode);
        // In case of SCENE_MODE == FACE_PRIORITY, LegacyFaceDetectMapper will override
        // the result to say SCENE_MODE == FACE_PRIORITY.
        } else {
            Log.w(TAG, "Unknown scene mode " + legacySceneMode + " returned by camera HAL, setting to disabled.");
            result.set(CaptureResult.CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_DISABLED);
        }
    }
    /*
         * control.effectMode
         */
    {
        String legacyEffectMode = params.getColorEffect();
        int mode = LegacyMetadataMapper.convertEffectModeFromLegacy(legacyEffectMode);
        if (mode != LegacyMetadataMapper.UNKNOWN_MODE) {
            result.set(CaptureResult.CONTROL_EFFECT_MODE, mode);
        } else {
            Log.w(TAG, "Unknown effect mode " + legacyEffectMode + " returned by camera HAL, setting to off.");
            result.set(CaptureResult.CONTROL_EFFECT_MODE, CONTROL_EFFECT_MODE_OFF);
        }
    }
    // control.videoStabilizationMode
    {
        int stabMode = (params.isVideoStabilizationSupported() && params.getVideoStabilization()) ? CONTROL_VIDEO_STABILIZATION_MODE_ON : CONTROL_VIDEO_STABILIZATION_MODE_OFF;
        result.set(CONTROL_VIDEO_STABILIZATION_MODE, stabMode);
    }
    /*
         * flash
         */
    {
    // flash.mode, flash.state mapped in mapAeAndFlashMode
    }
    /*
         * lens
         */
    // lens.focusDistance
    {
        if (Parameters.FOCUS_MODE_INFINITY.equals(params.getFocusMode())) {
            result.set(CaptureResult.LENS_FOCUS_DISTANCE, 0.0f);
        }
    }
    // lens.focalLength
    result.set(CaptureResult.LENS_FOCAL_LENGTH, params.getFocalLength());
    /*
         * request
         */
    // request.pipelineDepth
    result.set(REQUEST_PIPELINE_DEPTH, characteristics.get(CameraCharacteristics.REQUEST_PIPELINE_MAX_DEPTH));
    /*
         * scaler
         */
    mapScaler(result, zoomData, /*out*/
    params);
    /*
         * sensor
         */
    // sensor.timestamp varies every frame; mapping is done in #cachedConvertResultMetadata
    {
        // Unconditionally no test patterns
        result.set(SENSOR_TEST_PATTERN_MODE, SENSOR_TEST_PATTERN_MODE_OFF);
    }
    /*
         * jpeg
         */
    // jpeg.gpsLocation
    result.set(JPEG_GPS_LOCATION, request.get(CaptureRequest.JPEG_GPS_LOCATION));
    // jpeg.orientation
    result.set(JPEG_ORIENTATION, request.get(CaptureRequest.JPEG_ORIENTATION));
    // jpeg.quality
    result.set(JPEG_QUALITY, (byte) params.getJpegQuality());
    // jpeg.thumbnailQuality
    result.set(JPEG_THUMBNAIL_QUALITY, (byte) params.getJpegThumbnailQuality());
    // jpeg.thumbnailSize
    Camera.Size s = params.getJpegThumbnailSize();
    if (s != null) {
        result.set(JPEG_THUMBNAIL_SIZE, ParameterUtils.convertSize(s));
    } else {
        Log.w(TAG, "Null thumbnail size received from parameters.");
    }
    /*
         * noiseReduction.*
         */
    // noiseReduction.mode
    result.set(NOISE_REDUCTION_MODE, request.get(CaptureRequest.NOISE_REDUCTION_MODE));
    return result;
}
Also used : Parameters(android.hardware.Camera.Parameters) Rect(android.graphics.Rect) Size(android.util.Size) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) ZoomData(android.hardware.camera2.legacy.ParameterUtils.ZoomData) CaptureRequest(android.hardware.camera2.CaptureRequest) Camera(android.hardware.Camera)

Example 38 with CameraMetadataNative

use of android.hardware.camera2.impl.CameraMetadataNative in project platform_frameworks_base by android.

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 39 with CameraMetadataNative

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

the class CameraManager method getCameraCharacteristics.

/**
     * <p>Query the capabilities of a camera device. These capabilities are
     * immutable for a given camera.</p>
     *
     * @param cameraId The id of the camera device to query
     * @return The properties of the given camera
     *
     * @throws IllegalArgumentException if the cameraId does not match any
     *         known camera device.
     * @throws CameraAccessException if the camera device has been disconnected.
     *
     * @see #getCameraIdList
     * @see android.app.admin.DevicePolicyManager#setCameraDisabled
     */
@NonNull
public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId) throws CameraAccessException {
    CameraCharacteristics characteristics = null;
    synchronized (mLock) {
        if (!getOrCreateDeviceIdListLocked().contains(cameraId)) {
            throw new IllegalArgumentException(String.format("Camera id %s does not match any" + " currently connected camera device", cameraId));
        }
        int id = Integer.parseInt(cameraId);
        /*
             * Get the camera characteristics from the camera service directly if it supports it,
             * otherwise get them from the legacy shim instead.
             */
        ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
        if (cameraService == null) {
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable");
        }
        try {
            if (!supportsCamera2ApiLocked(cameraId)) {
                // Legacy backwards compatibility path; build static info from the camera
                // parameters
                String parameters = cameraService.getLegacyParameters(id);
                CameraInfo info = cameraService.getCameraInfo(id);
                characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info);
            } else {
                // Normal path: Get the camera characteristics directly from the camera service
                CameraMetadataNative info = cameraService.getCameraCharacteristics(id);
                characteristics = new CameraCharacteristics(info);
            }
        } catch (ServiceSpecificException e) {
            throwAsPublicException(e);
        } catch (RemoteException e) {
            // Camera service died - act as if the camera was disconnected
            throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable", e);
        }
    }
    return characteristics;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService) CameraInfo(android.hardware.CameraInfo) NonNull(android.annotation.NonNull)

Example 40 with CameraMetadataNative

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

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)

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