Search in sources :

Example 26 with Size

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

the class SurfaceUtils method checkConstrainedHighSpeedSurfaces.

/**
     * Verify that that the surfaces are valid for high-speed recording mode,
     * and that the FPS range is supported
     *
     * @param surfaces the surfaces to verify as valid in terms of size and format
     * @param fpsRange the target high-speed FPS range to validate
     * @param config The stream configuration map for the device in question
     */
public static void checkConstrainedHighSpeedSurfaces(Collection<Surface> surfaces, Range<Integer> fpsRange, StreamConfigurationMap config) {
    if (surfaces == null || surfaces.size() == 0 || surfaces.size() > 2) {
        throw new IllegalArgumentException("Output target surface list must not be null and" + " the size must be 1 or 2");
    }
    List<Size> highSpeedSizes = null;
    if (fpsRange == null) {
        highSpeedSizes = Arrays.asList(config.getHighSpeedVideoSizes());
    } else {
        // Check the FPS range first if provided
        Range<Integer>[] highSpeedFpsRanges = config.getHighSpeedVideoFpsRanges();
        if (!Arrays.asList(highSpeedFpsRanges).contains(fpsRange)) {
            throw new IllegalArgumentException("Fps range " + fpsRange.toString() + " in the" + " request is not a supported high speed fps range " + Arrays.toString(highSpeedFpsRanges));
        }
        highSpeedSizes = Arrays.asList(config.getHighSpeedVideoSizesFor(fpsRange));
    }
    for (Surface surface : surfaces) {
        checkHighSpeedSurfaceFormat(surface);
        // Surface size must be supported high speed sizes.
        Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
        if (!highSpeedSizes.contains(surfaceSize)) {
            throw new IllegalArgumentException("Surface size " + surfaceSize.toString() + " is" + " not part of the high speed supported size list " + Arrays.toString(highSpeedSizes.toArray()));
        }
        // Each output surface must be either preview surface or recording surface.
        if (!SurfaceUtils.isSurfaceForPreview(surface) && !SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
            throw new IllegalArgumentException("This output surface is neither preview nor " + "hardware video encoding surface");
        }
        if (SurfaceUtils.isSurfaceForPreview(surface) && SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
            throw new IllegalArgumentException("This output surface can not be both preview" + " and hardware video encoding surface");
        }
    }
    // For 2 output surface case, they shouldn't be same type.
    if (surfaces.size() == 2) {
        // Up to here, each surface can only be either preview or recording.
        Iterator<Surface> iterator = surfaces.iterator();
        boolean isFirstSurfacePreview = SurfaceUtils.isSurfaceForPreview(iterator.next());
        boolean isSecondSurfacePreview = SurfaceUtils.isSurfaceForPreview(iterator.next());
        if (isFirstSurfacePreview == isSecondSurfacePreview) {
            throw new IllegalArgumentException("The 2 output surfaces must have different" + " type");
        }
    }
}
Also used : Size(android.util.Size) Range(android.util.Range) Surface(android.view.Surface)

Example 27 with Size

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

the class StreamConfigurationMap method appendOutputsString.

private void appendOutputsString(StringBuilder sb) {
    sb.append("Outputs(");
    int[] formats = getOutputFormats();
    for (int format : formats) {
        Size[] sizes = getOutputSizes(format);
        for (Size size : sizes) {
            long minFrameDuration = getOutputMinFrameDuration(format, size);
            long stallDuration = getOutputStallDuration(format, size);
            sb.append(String.format("[w:%d, h:%d, format:%s(%d), min_duration:%d, " + "stall:%d], ", size.getWidth(), size.getHeight(), formatToString(format), format, minFrameDuration, stallDuration));
        }
    }
    // Remove the pending ", "
    if (sb.charAt(sb.length() - 1) == ' ') {
        sb.delete(sb.length() - 2, sb.length());
    }
    sb.append(")");
}
Also used : Size(android.util.Size)

Example 28 with Size

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

the class StreamConfigurationMap method appendHighResOutputsString.

private void appendHighResOutputsString(StringBuilder sb) {
    sb.append("HighResolutionOutputs(");
    int[] formats = getOutputFormats();
    for (int format : formats) {
        Size[] sizes = getHighResolutionOutputSizes(format);
        if (sizes == null)
            continue;
        for (Size size : sizes) {
            long minFrameDuration = getOutputMinFrameDuration(format, size);
            long stallDuration = getOutputStallDuration(format, size);
            sb.append(String.format("[w:%d, h:%d, format:%s(%d), min_duration:%d, " + "stall:%d], ", size.getWidth(), size.getHeight(), formatToString(format), format, minFrameDuration, stallDuration));
        }
    }
    // Remove the pending ", "
    if (sb.charAt(sb.length() - 1) == ' ') {
        sb.delete(sb.length() - 2, sb.length());
    }
    sb.append(")");
}
Also used : Size(android.util.Size)

Example 29 with Size

use of android.util.Size in project android_frameworks_base by DirtyUnicorns.

the class CameraTooTest method compareSizesByArea.

@Test
public void compareSizesByArea() {
    Size empty = new Size(0, 0), fatAndFlat = new Size(100, 0), tallAndThin = new Size(0, 100);
    Size smallSquare = new Size(4, 4), horizRect = new Size(8, 2), vertRect = new Size(2, 8);
    Size largeSquare = new Size(5, 5);
    Comparator<Size> rel = new CameraTooActivity.CompareSizesByArea();
    assertComparatorEq(empty, fatAndFlat, rel);
    assertComparatorEq(empty, tallAndThin, rel);
    assertComparatorEq(fatAndFlat, empty, rel);
    assertComparatorEq(fatAndFlat, tallAndThin, rel);
    assertComparatorEq(tallAndThin, empty, rel);
    assertComparatorEq(tallAndThin, fatAndFlat, rel);
    assertComparatorEq(smallSquare, horizRect, rel);
    assertComparatorEq(smallSquare, vertRect, rel);
    assertComparatorEq(horizRect, smallSquare, rel);
    assertComparatorEq(horizRect, vertRect, rel);
    assertComparatorEq(vertRect, smallSquare, rel);
    assertComparatorEq(vertRect, horizRect, rel);
    assertComparatorLt(empty, smallSquare, rel);
    assertComparatorLt(empty, horizRect, rel);
    assertComparatorLt(empty, vertRect, rel);
    assertComparatorLt(fatAndFlat, smallSquare, rel);
    assertComparatorLt(fatAndFlat, horizRect, rel);
    assertComparatorLt(fatAndFlat, vertRect, rel);
    assertComparatorLt(tallAndThin, smallSquare, rel);
    assertComparatorLt(tallAndThin, horizRect, rel);
    assertComparatorLt(tallAndThin, vertRect, rel);
    assertComparatorLt(empty, largeSquare, rel);
    assertComparatorLt(fatAndFlat, largeSquare, rel);
    assertComparatorLt(tallAndThin, largeSquare, rel);
    assertComparatorLt(smallSquare, largeSquare, rel);
    assertComparatorLt(horizRect, largeSquare, rel);
    assertComparatorLt(vertRect, largeSquare, rel);
}
Also used : Size(android.util.Size) Test(org.junit.Test)

Example 30 with Size

use of android.util.Size in project android_frameworks_base by DirtyUnicorns.

the class Utils method parseSizeRange.

static Pair<Size, Size> parseSizeRange(Object o) {
    try {
        String s = (String) o;
        int ix = s.indexOf('-');
        if (ix >= 0) {
            return Pair.create(Size.parseSize(s.substring(0, ix)), Size.parseSize(s.substring(ix + 1)));
        }
        Size value = Size.parseSize(s);
        return Pair.create(value, value);
    } catch (ClassCastException e) {
    } catch (NumberFormatException e) {
    } catch (NullPointerException e) {
        return null;
    } catch (IllegalArgumentException e) {
    }
    Log.w(TAG, "could not parse size range '" + o + "'");
    return null;
}
Also used : Size(android.util.Size)

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