Search in sources :

Example 81 with Size

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

the class Camera2RecordingTest method validateRecording.

private void validateRecording(Size sz, int expectedDurationMs) throws Exception {
    File outFile = new File(mOutMediaFileName);
    assertTrue("No video is recorded", outFile.exists());
    MediaExtractor extractor = new MediaExtractor();
    try {
        extractor.setDataSource(mOutMediaFileName);
        long durationUs = 0;
        int width = -1, height = -1;
        int numTracks = extractor.getTrackCount();
        final String VIDEO_MIME_TYPE = "video";
        for (int i = 0; i < numTracks; i++) {
            MediaFormat format = extractor.getTrackFormat(i);
            String mime = format.getString(MediaFormat.KEY_MIME);
            if (mime.contains(VIDEO_MIME_TYPE)) {
                Log.i(TAG, "video format is: " + format.toString());
                durationUs = format.getLong(MediaFormat.KEY_DURATION);
                width = format.getInteger(MediaFormat.KEY_WIDTH);
                height = format.getInteger(MediaFormat.KEY_HEIGHT);
                break;
            }
        }
        Size videoSz = new Size(width, height);
        assertTrue("Video size doesn't match, expected " + sz.toString() + " got " + videoSz.toString(), videoSz.equals(sz));
        int duration = (int) (durationUs / 1000);
        if (VERBOSE) {
            Log.v(TAG, String.format("Video duration: recorded %dms, expected %dms", duration, expectedDurationMs));
        }
        // TODO: Don't skip this for video snapshot
        if (!mStaticInfo.isHardwareLevelLegacy()) {
            assertTrue(String.format("Camera %s: Video duration doesn't match: recorded %dms, expected %dms.", mCamera.getId(), duration, expectedDurationMs), Math.abs(duration - expectedDurationMs) < DURATION_MARGIN * expectedDurationMs);
        }
    } finally {
        extractor.release();
        if (!DEBUG_DUMP) {
            outFile.delete();
        }
    }
}
Also used : MediaFormat(android.media.MediaFormat) Size(android.util.Size) MediaExtractor(android.media.MediaExtractor) File(java.io.File)

Example 82 with Size

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

the class Camera2ReprocessCaptureTest method testReprocessingMaxSizes.

/**
     * Test the input format and output format with the largest input and output sizes for a
     * certain test case.
     */
private void testReprocessingMaxSizes(String cameraId, int inputFormat, int reprocessOutputFormat, Size previewSize, CaptureTestCase captureTestCase) throws Exception {
    Size maxInputSize = getMaxSize(inputFormat, StaticMetadata.StreamDirection.Input);
    Size maxReprocessOutputSize = getMaxSize(reprocessOutputFormat, StaticMetadata.StreamDirection.Output);
    switch(captureTestCase) {
        case SINGLE_SHOT:
            testReprocess(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize, reprocessOutputFormat, previewSize, NUM_REPROCESS_CAPTURES);
            break;
        case ABORT_CAPTURE:
            testReprocessAbort(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize, reprocessOutputFormat);
            break;
        case TIMESTAMPS:
            testReprocessTimestamps(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize, reprocessOutputFormat);
            break;
        case JPEG_EXIF:
            testReprocessJpegExif(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize);
            break;
        case REQUEST_KEYS:
            testReprocessRequestKeys(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize, reprocessOutputFormat);
            break;
        default:
            throw new IllegalArgumentException("Invalid test case");
    }
}
Also used : Size(android.util.Size)

Example 83 with Size

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

the class Camera2ReprocessCaptureTest method testReprocessJpegExif.

/**
     * Test JPEG tags for reprocess requests. Reprocess result's JPEG tags and JPEG image's tags
     * match reprocess request's JPEG tags.
     */
private void testReprocessJpegExif(String cameraId, Size inputSize, int inputFormat, Size reprocessOutputSize) throws Exception {
    if (VERBOSE) {
        Log.v(TAG, "testReprocessJpegExif: cameraId: " + cameraId + " inputSize: " + inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " + reprocessOutputSize);
    }
    Size[] thumbnailSizes = mStaticInfo.getAvailableThumbnailSizesChecked();
    Size[] testThumbnailSizes = new Size[EXIF_TEST_DATA.length];
    Arrays.fill(testThumbnailSizes, thumbnailSizes[thumbnailSizes.length - 1]);
    // Make sure thumbnail size (0, 0) is covered.
    testThumbnailSizes[0] = new Size(0, 0);
    try {
        setupImageReaders(inputSize, inputFormat, reprocessOutputSize, ImageFormat.JPEG, EXIF_TEST_DATA.length);
        setupReprocessableSession(/*previewSurface*/
        null, EXIF_TEST_DATA.length);
        // Prepare reprocess capture requests.
        ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(EXIF_TEST_DATA.length);
        for (int i = 0; i < EXIF_TEST_DATA.length; i++) {
            TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(), /*inputResult*/
            null);
            mImageWriter.queueInputImage(mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
            CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
            builder.addTarget(getReprocessOutputImageReader().getSurface());
            // set jpeg keys
            setJpegKeys(builder, EXIF_TEST_DATA[i], testThumbnailSizes[i], mCollector);
            reprocessRequests.add(builder.build());
        }
        // Submit reprocess requests.
        SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
        mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
        TotalCaptureResult[] reprocessResults = captureCallback.getTotalCaptureResultsForRequests(reprocessRequests, CAPTURE_TIMEOUT_FRAMES);
        for (int i = 0; i < EXIF_TEST_DATA.length; i++) {
            // Verify output image's and result's JPEG EXIF data.
            Image image = getReprocessOutputImageReaderListener().getImage(CAPTURE_TIMEOUT_MS);
            verifyJpegKeys(image, reprocessResults[i], reprocessOutputSize, testThumbnailSizes[i], EXIF_TEST_DATA[i], mStaticInfo, mCollector);
            image.close();
        }
    } finally {
        closeReprossibleSession();
        closeImageReaders();
    }
}
Also used : Size(android.util.Size) ArrayList(java.util.ArrayList) TotalCaptureResult(android.hardware.camera2.TotalCaptureResult) CaptureRequest(android.hardware.camera2.CaptureRequest) SimpleCaptureCallback(com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback) CameraTestUtils.getDataFromImage(com.android.mediaframeworktest.helpers.CameraTestUtils.getDataFromImage) Image(android.media.Image)

Example 84 with Size

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

the class StaticMetadata method isHighSpeedVideoSupported.

/**
     * Check if high speed video is supported (HIGH_SPEED_VIDEO scene mode is
     * supported, supported high speed fps ranges and sizes are valid).
     *
     * @return true if high speed video is supported.
     */
public boolean isHighSpeedVideoSupported() {
    List<Integer> sceneModes = Arrays.asList(CameraTestUtils.toObject(getAvailableSceneModesChecked()));
    if (sceneModes.contains(CameraCharacteristics.CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO)) {
        StreamConfigurationMap config = getValueFromKeyNonNull(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (config == null) {
            return false;
        }
        Size[] availableSizes = config.getHighSpeedVideoSizes();
        if (availableSizes.length == 0) {
            return false;
        }
        for (Size size : availableSizes) {
            Range<Integer>[] availableFpsRanges = config.getHighSpeedVideoFpsRangesFor(size);
            if (availableFpsRanges.length == 0) {
                return false;
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : Size(android.util.Size) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) Range(android.util.Range)

Example 85 with Size

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

the class StaticMetadata method getActiveArraySizeChecked.

/**
     * Get and check active array size.
     */
public Rect getActiveArraySizeChecked() {
    Key<Rect> key = CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE;
    Rect activeArray = getValueFromKeyNonNull(key);
    if (activeArray == null) {
        return new Rect(0, 0, 0, 0);
    }
    Size pixelArraySize = getPixelArraySizeChecked();
    checkTrueForKey(key, "values left/top are invalid", activeArray.left >= 0 && activeArray.top >= 0);
    checkTrueForKey(key, "values width/height are invalid", activeArray.width() <= pixelArraySize.getWidth() && activeArray.height() <= pixelArraySize.getHeight());
    return activeArray;
}
Also used : Rect(android.graphics.Rect) 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