Search in sources :

Example 21 with Parameters

use of android.hardware.Camera.Parameters in project android_frameworks_base by AOSPA.

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 22 with Parameters

use of android.hardware.Camera.Parameters in project android_frameworks_base by AOSPA.

the class CameraStressTest method testStressCameraSceneModes.

/**
     * Stress test iterating on the various scene modes (action, night, party, etc.)
     */
@LargeTest
public void testStressCameraSceneModes() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        List<String> supportedSceneModes = params.getSupportedSceneModes();
        assertNotNull("No scene modes supported", supportedSceneModes);
        mOutput.write("Total number of loops: " + (NUMBER_OF_SCENE_MODE_LOOPS * supportedSceneModes.size()) + "\n");
        Log.v(TAG, "Start preview");
        mOutput.write("No of loop: ");
        for (int i = 0; i < supportedSceneModes.size(); i++) {
            for (int j = 0; j < NUMBER_OF_SCENE_MODE_LOOPS; j++) {
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mCameraTestHelper.setupCameraTest();
                    }
                });
                Log.v(TAG, "Setting scene mode to " + supportedSceneModes.get(i));
                params.setSceneMode(supportedSceneModes.get(i));
                mCameraTestHelper.setParameters(params);
                mCameraTestHelper.startCameraPreview(surfaceHolder);
                mCameraTestHelper.capturePhoto();
                if (i == 0 && j == 0) {
                    mOutput.write(Integer.toString(j + i * NUMBER_OF_SCENE_MODE_LOOPS));
                } else {
                    mOutput.write(", " + (j + i * NUMBER_OF_SCENE_MODE_LOOPS));
                }
            }
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera scene mode test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 23 with Parameters

use of android.hardware.Camera.Parameters in project android_frameworks_base by AOSPA.

the class CameraStressTest method testStressCameraZoom.

/**
     * Stress test iterating on the range of supported camera zoom levels
     */
@LargeTest
public void testStressCameraZoom() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        if (!params.isSmoothZoomSupported() && !params.isZoomSupported()) {
            Log.v(TAG, "Device camera does not support zoom");
            fail("Camera zoom stress test failed due to unsupported feature");
        } else {
            Log.v(TAG, "Device camera does support zoom");
            Log.v(TAG, "Start preview");
            mOutput.write("Total number of loops: " + NUMBER_OF_ZOOM_LOOPS + "\n");
            mOutput.write("No of loops: ");
            int nextZoomLevel = 0;
            for (int i = 0; i < NUMBER_OF_ZOOM_LOOPS; i++) {
                runOnLooper(new Runnable() {

                    @Override
                    public void run() {
                        mCameraTestHelper.setupCameraTest();
                    }
                });
                mCameraTestHelper.startCameraPreview(surfaceHolder);
                params = mCameraTestHelper.mCamera.getParameters();
                int currentZoomLevel = params.getZoom();
                if (nextZoomLevel >= params.getMaxZoom()) {
                    nextZoomLevel = 0;
                }
                ++nextZoomLevel;
                if (params.isSmoothZoomSupported()) {
                    mCameraTestHelper.mCamera.startSmoothZoom(nextZoomLevel);
                } else {
                    params.setZoom(nextZoomLevel);
                    mCameraTestHelper.setParameters(params);
                }
                mCameraTestHelper.capturePhoto();
                if (i == 0) {
                    mOutput.write(Integer.toString(i));
                } else {
                    mOutput.write(", " + i);
                }
            }
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera zoom stress test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 24 with Parameters

use of android.hardware.Camera.Parameters in project android_frameworks_base by AOSPA.

the class CameraFunctionalTest method testFunctionalCameraFocusModes.

/**
     * Functional test iterating on the various focus modes (auto, infinitiy, macro, etc.)
     */
@LargeTest
public void testFunctionalCameraFocusModes() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        List<String> supportedFocusModes = params.getSupportedFocusModes();
        assertNotNull("No focus modes supported", supportedFocusModes);
        for (int i = 0; i < supportedFocusModes.size(); i++) {
            runOnLooper(new Runnable() {

                @Override
                public void run() {
                    mCameraTestHelper.setupCameraTest();
                }
            });
            Log.v(TAG, "Setting focus mode to: " + supportedFocusModes.get(i));
            params.setFocusMode(supportedFocusModes.get(i));
            mCameraTestHelper.setParameters(params);
            mCameraTestHelper.startCameraPreview(surfaceHolder);
            mCameraTestHelper.capturePhoto();
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera focus modes test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 25 with Parameters

use of android.hardware.Camera.Parameters in project android_frameworks_base by AOSPA.

the class CameraFunctionalTest method testFunctionalCameraExposureCompensation.

/**
     * Functional test iterating on the range of supported exposure compensation levels
     */
@LargeTest
public void testFunctionalCameraExposureCompensation() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        int min = params.getMinExposureCompensation();
        int max = params.getMaxExposureCompensation();
        assertFalse("Adjusting exposure not supported", (max == 0 && min == 0));
        float step = params.getExposureCompensationStep();
        int stepsPerEV = (int) Math.round(Math.pow((double) step, -1));
        // only get integer values for exposure compensation
        for (int i = min; i <= max; i += stepsPerEV) {
            runOnLooper(new Runnable() {

                @Override
                public void run() {
                    mCameraTestHelper.setupCameraTest();
                }
            });
            Log.v(TAG, "Setting exposure compensation index to " + i);
            params.setExposureCompensation(i);
            mCameraTestHelper.setParameters(params);
            mCameraTestHelper.startCameraPreview(surfaceHolder);
            mCameraTestHelper.capturePhoto();
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera exposure compensation test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

Parameters (android.hardware.Camera.Parameters)72 LargeTest (android.test.suitebuilder.annotation.LargeTest)36 SurfaceHolder (android.view.SurfaceHolder)36 Camera (android.hardware.Camera)16 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)15 Rect (android.graphics.Rect)10 CaptureRequest (android.hardware.camera2.CaptureRequest)10 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)10 Size (android.util.Size)10 IOException (java.io.IOException)10 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)5 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)5 Location (android.location.Location)5 Range (android.util.Range)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Size (android.hardware.Camera.Size)4 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Point (android.graphics.Point)1