Search in sources :

Example 16 with Size

use of android.util.Size in project platform_frameworks_base by android.

the class Camera2SwitchPreviewTest method updatePreviewSurfaceWithVideo.

/**
     * Update preview size with video size.
     *
     * <p>Preview size will be capped with max preview size.</p>
     *
     * @param videoSize The video size used for preview.
     * @param videoFrameRate The video frame rate
     *
     */
private void updatePreviewSurfaceWithVideo(Size videoSize, int videoFrameRate) throws Exception {
    if (mOrderedPreviewSizes == null) {
        throw new IllegalStateException("supported preview size list is not initialized yet");
    }
    final float FRAME_DURATION_TOLERANCE = 0.01f;
    long videoFrameDuration = (long) (1e9 / videoFrameRate * (1.0 + FRAME_DURATION_TOLERANCE));
    HashMap<Size, Long> minFrameDurationMap = mStaticInfo.getAvailableMinFrameDurationsForFormatChecked(ImageFormat.PRIVATE);
    Size maxPreviewSize = mOrderedPreviewSizes.get(0);
    Size previewSize = null;
    if (videoSize.getWidth() > maxPreviewSize.getWidth() || videoSize.getHeight() > maxPreviewSize.getHeight()) {
        for (Size s : mOrderedPreviewSizes) {
            Long frameDuration = minFrameDurationMap.get(s);
            if (mStaticInfo.isHardwareLevelLegacy()) {
                // Legacy doesn't report min frame duration
                frameDuration = new Long(0);
            }
            assertTrue("Cannot find minimum frame duration for private size" + s, frameDuration != null);
            if (frameDuration <= videoFrameDuration && s.getWidth() <= videoSize.getWidth() && s.getHeight() <= videoSize.getHeight()) {
                Log.w(TAG, "Overwrite preview size from " + videoSize.toString() + " to " + s.toString());
                previewSize = s;
                break;
            // If all preview size doesn't work then we fallback to video size
            }
        }
    }
    if (previewSize == null) {
        previewSize = videoSize;
    }
    updatePreviewSurface(previewSize);
}
Also used : Size(android.util.Size)

Example 17 with Size

use of android.util.Size in project platform_frameworks_base by android.

the class Camera2SwitchPreviewTest method prepareCapturePreview.

protected void prepareCapturePreview(CaptureRequest.Builder previewRequest, CaptureRequest.Builder stillRequest, CaptureCallback resultListener, ImageReader.OnImageAvailableListener imageListener) throws Exception {
    Size captureSz = mOrderedStillSizes.get(0);
    Size previewSz = mOrderedPreviewSizes.get(1);
    if (VERBOSE) {
        Log.v(TAG, String.format("Prepare single capture (%s) and preview (%s)", captureSz.toString(), previewSz.toString()));
    }
    // Update preview size.
    updatePreviewSurface(previewSz);
    // Create ImageReader.
    createImageReader(captureSz, ImageFormat.JPEG, MAX_READER_IMAGES, imageListener);
    // Configure output streams with preview and jpeg streams.
    List<Surface> outputSurfaces = new ArrayList<Surface>();
    outputSurfaces.add(mPreviewSurface);
    outputSurfaces.add(mReaderSurface);
    mSessionListener = new BlockingSessionCallback();
    mSession = configureCameraSession(mCamera, outputSurfaces, mSessionListener, mHandler);
    // Configure the requests.
    previewRequest.addTarget(mPreviewSurface);
    stillRequest.addTarget(mPreviewSurface);
    stillRequest.addTarget(mReaderSurface);
    // Start preview.
    mSession.setRepeatingRequest(previewRequest.build(), resultListener, mHandler);
}
Also used : BlockingSessionCallback(com.android.ex.camera2.blocking.BlockingSessionCallback) Size(android.util.Size) ArrayList(java.util.ArrayList) Surface(android.view.Surface)

Example 18 with Size

use of android.util.Size in project platform_frameworks_base by android.

the class CameraMetadataTest method checkStreamConfigurationMapDurationByFormatSize.

private static void checkStreamConfigurationMapDurationByFormatSize(StreamConfigurationMap configMap, int format, int width, int height, Duration durationKind, long expectedDuration) {
    /** arbitrary class for which StreamConfigurationMap#isOutputSupportedFor(Class) is true */
    final Class<?> IMPLEMENTATION_DEFINED_OUTPUT_CLASS = SurfaceTexture.class;
    long actualDuration;
    android.util.Size size = new android.util.Size(width, height);
    switch(durationKind) {
        case MinFrame:
            if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
                actualDuration = configMap.getOutputMinFrameDuration(IMPLEMENTATION_DEFINED_OUTPUT_CLASS, size);
            } else {
                actualDuration = configMap.getOutputMinFrameDuration(format, size);
            }
            break;
        case Stall:
            if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
                actualDuration = configMap.getOutputStallDuration(IMPLEMENTATION_DEFINED_OUTPUT_CLASS, size);
            } else {
                actualDuration = configMap.getOutputStallDuration(format, size);
            }
            break;
        default:
            throw new AssertionError();
    }
    assertEquals("Expected " + durationKind + " to match actual value", expectedDuration, actualDuration);
}
Also used : SurfaceTexture(android.graphics.SurfaceTexture) Size(android.util.Size) Size(android.util.Size)

Example 19 with Size

use of android.util.Size in project platform_frameworks_base by android.

the class CameraTooTest method assertOptimalSize.

private void assertOptimalSize(Size[] options, int minWidth, int minHeight, Size expected) {
    Size verdict = CameraTooActivity.chooseBigEnoughSize(options, minWidth, minHeight);
    assertEquals(String.format("Expected optimal size %s but got %s", expected, verdict), verdict, expected);
}
Also used : Size(android.util.Size)

Example 20 with Size

use of android.util.Size in project platform_frameworks_base by android.

the class CameraDeviceImpl method checkInputConfiguration.

private void checkInputConfiguration(InputConfiguration inputConfig) {
    if (inputConfig != null) {
        StreamConfigurationMap configMap = mCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        int[] inputFormats = configMap.getInputFormats();
        boolean validFormat = false;
        for (int format : inputFormats) {
            if (format == inputConfig.getFormat()) {
                validFormat = true;
            }
        }
        if (validFormat == false) {
            throw new IllegalArgumentException("input format " + inputConfig.getFormat() + " is not valid");
        }
        boolean validSize = false;
        Size[] inputSizes = configMap.getInputSizes(inputConfig.getFormat());
        for (Size s : inputSizes) {
            if (inputConfig.getWidth() == s.getWidth() && inputConfig.getHeight() == s.getHeight()) {
                validSize = true;
            }
        }
        if (validSize == false) {
            throw new IllegalArgumentException("input size " + inputConfig.getWidth() + "x" + inputConfig.getHeight() + " is not valid");
        }
    }
}
Also used : Size(android.util.Size) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Aggregations

Size (android.util.Size)320 ArrayList (java.util.ArrayList)66 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)41 Rect (android.graphics.Rect)40 CaptureRequest (android.hardware.camera2.CaptureRequest)40 Range (android.util.Range)40 Surface (android.view.Surface)35 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)35 Camera (android.hardware.Camera)30 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)26 Point (android.graphics.Point)22 Image (android.media.Image)21 SimpleImageReaderListener (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleImageReaderListener)20 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)15 CamcorderProfile (android.media.CamcorderProfile)15 Pair (android.util.Pair)15 CameraTestUtils.getDataFromImage (com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage)15 SurfaceTexture (android.graphics.SurfaceTexture)10 Parameters (android.hardware.Camera.Parameters)10 CaptureResult (android.hardware.camera2.CaptureResult)10