Search in sources :

Example 71 with StreamConfigurationMap

use of android.hardware.camera2.params.StreamConfigurationMap in project android_frameworks_base by ResurrectionRemix.

the class StaticMetadata method getAvailableSizesForFormatChecked.

/**
     * Get available sizes for given format and direction, and whether to limit to slow or fast
     * resolutions.
     *
     * @param format The format for the requested size array.
     * @param direction The stream direction, input or output.
     * @param fastSizes whether to include getOutputSizes() sizes (generally faster)
     * @param slowSizes whether to include getHighResolutionOutputSizes() sizes (generally slower)
     * @return The sizes of the given format, empty array if no available size is found.
     */
public Size[] getAvailableSizesForFormatChecked(int format, StreamDirection direction, boolean fastSizes, boolean slowSizes) {
    Key<StreamConfigurationMap> key = CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP;
    StreamConfigurationMap config = getValueFromKeyNonNull(key);
    if (config == null) {
        return new Size[0];
    }
    Size[] sizes = null;
    switch(direction) {
        case Output:
            Size[] fastSizeList = null;
            Size[] slowSizeList = null;
            if (fastSizes) {
                fastSizeList = config.getOutputSizes(format);
            }
            if (slowSizes) {
                slowSizeList = config.getHighResolutionOutputSizes(format);
            }
            if (fastSizeList != null && slowSizeList != null) {
                sizes = new Size[slowSizeList.length + fastSizeList.length];
                System.arraycopy(fastSizeList, 0, sizes, 0, fastSizeList.length);
                System.arraycopy(slowSizeList, 0, sizes, fastSizeList.length, slowSizeList.length);
            } else if (fastSizeList != null) {
                sizes = fastSizeList;
            } else if (slowSizeList != null) {
                sizes = slowSizeList;
            }
            break;
        case Input:
            sizes = config.getInputSizes(format);
            break;
        default:
            throw new IllegalArgumentException("direction must be output or input");
    }
    if (sizes == null) {
        sizes = new Size[0];
    }
    return sizes;
}
Also used : Size(android.util.Size) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 72 with StreamConfigurationMap

use of android.hardware.camera2.params.StreamConfigurationMap in project android_frameworks_base by ResurrectionRemix.

the class StaticMetadata method getValidOutputFormatsForInput.

/**
     * Get valid output formats for a given input format.
     *
     * @param inputFormat The input format used to produce the output images.
     * @return The output formats for the given input format, empty array if
     *         no available format is found.
     */
public int[] getValidOutputFormatsForInput(int inputFormat) {
    Key<StreamConfigurationMap> key = CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP;
    StreamConfigurationMap config = getValueFromKeyNonNull(key);
    if (config == null) {
        return new int[0];
    }
    return config.getValidOutputFormatsForInput(inputFormat);
}
Also used : StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 73 with StreamConfigurationMap

use of android.hardware.camera2.params.StreamConfigurationMap in project android_frameworks_base by ResurrectionRemix.

the class StaticMetadata method getAvailableMinFrameDurationsForFormatChecked.

/**
     * Get available minimal frame durations for a given format.
     *
     * @param format One of the format from {@link ImageFormat}.
     * @return HashMap of minimal frame durations for different sizes, empty HashMap
     *         if availableMinFrameDurations is null.
     */
public HashMap<Size, Long> getAvailableMinFrameDurationsForFormatChecked(int format) {
    HashMap<Size, Long> minDurationMap = new HashMap<Size, Long>();
    Key<StreamConfigurationMap> key = CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP;
    StreamConfigurationMap config = getValueFromKeyNonNull(key);
    if (config == null) {
        return minDurationMap;
    }
    for (Size size : getAvailableSizesForFormatChecked(format, StreamDirection.Output)) {
        long minFrameDuration = config.getOutputMinFrameDuration(format, size);
        if (minFrameDuration != 0) {
            minDurationMap.put(new Size(size.getWidth(), size.getHeight()), minFrameDuration);
        }
    }
    return minDurationMap;
}
Also used : HashMap(java.util.HashMap) Size(android.util.Size) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 74 with StreamConfigurationMap

use of android.hardware.camera2.params.StreamConfigurationMap in project android_frameworks_base by ResurrectionRemix.

the class StaticMetadata method getAvailableFormats.

/**
     * Get available formats for a given direction.
     *
     * @param direction The stream direction, input or output.
     * @return The formats of the given direction, empty array if no available format is found.
     */
public int[] getAvailableFormats(StreamDirection direction) {
    Key<StreamConfigurationMap> key = CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP;
    StreamConfigurationMap config = getValueFromKeyNonNull(key);
    if (config == null) {
        return new int[0];
    }
    switch(direction) {
        case Output:
            return config.getOutputFormats();
        case Input:
            return config.getInputFormats();
        default:
            throw new IllegalArgumentException("direction must be output or input");
    }
}
Also used : StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 75 with StreamConfigurationMap

use of android.hardware.camera2.params.StreamConfigurationMap in project android_frameworks_base by ResurrectionRemix.

the class CameraConstrainedHighSpeedCaptureSessionImpl method createHighSpeedRequestList.

@Override
public List<CaptureRequest> createHighSpeedRequestList(CaptureRequest request) throws CameraAccessException {
    if (request == null) {
        throw new IllegalArgumentException("Input capture request must not be null");
    }
    Collection<Surface> outputSurfaces = request.getTargets();
    Range<Integer> fpsRange = request.get(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE);
    StreamConfigurationMap config = mCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    SurfaceUtils.checkConstrainedHighSpeedSurfaces(outputSurfaces, fpsRange, config);
    // Request list size: to limit the preview to 30fps, need use maxFps/30; to maximize
    // the preview frame rate, should use maxBatch size for that high speed stream
    // configuration. We choose the former for now.
    int requestListSize = fpsRange.getUpper() / 30;
    List<CaptureRequest> requestList = new ArrayList<CaptureRequest>();
    // Prepare the Request builders: need carry over the request controls.
    // First, create a request builder that will only include preview or recording target.
    CameraMetadataNative requestMetadata = new CameraMetadataNative(request.getNativeCopy());
    // Note that after this step, the requestMetadata is mutated (swapped) and can not be used
    // for next request builder creation.
    CaptureRequest.Builder singleTargetRequestBuilder = new CaptureRequest.Builder(requestMetadata, /*reprocess*/
    false, CameraCaptureSession.SESSION_ID_NONE);
    // Overwrite the capture intent to make sure a good value is set.
    Iterator<Surface> iterator = outputSurfaces.iterator();
    Surface firstSurface = iterator.next();
    Surface secondSurface = null;
    if (outputSurfaces.size() == 1 && SurfaceUtils.isSurfaceForHwVideoEncoder(firstSurface)) {
        singleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);
    } else {
        // Video only, or preview + video
        singleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
    }
    singleTargetRequestBuilder.setPartOfCHSRequestList(/*partOfCHSList*/
    true);
    // Second, Create a request builder that will include both preview and recording targets.
    CaptureRequest.Builder doubleTargetRequestBuilder = null;
    if (outputSurfaces.size() == 2) {
        // Have to create a new copy, the original one was mutated after a new
        // CaptureRequest.Builder creation.
        requestMetadata = new CameraMetadataNative(request.getNativeCopy());
        doubleTargetRequestBuilder = new CaptureRequest.Builder(requestMetadata, /*reprocess*/
        false, CameraCaptureSession.SESSION_ID_NONE);
        doubleTargetRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
        doubleTargetRequestBuilder.addTarget(firstSurface);
        secondSurface = iterator.next();
        doubleTargetRequestBuilder.addTarget(secondSurface);
        doubleTargetRequestBuilder.setPartOfCHSRequestList(/*partOfCHSList*/
        true);
        // Make sure singleTargetRequestBuilder contains only recording surface for
        // preview + recording case.
        Surface recordingSurface = firstSurface;
        if (!SurfaceUtils.isSurfaceForHwVideoEncoder(recordingSurface)) {
            recordingSurface = secondSurface;
        }
        singleTargetRequestBuilder.addTarget(recordingSurface);
    } else {
        // Single output case: either recording or preview.
        singleTargetRequestBuilder.addTarget(firstSurface);
    }
    // Generate the final request list.
    for (int i = 0; i < requestListSize; i++) {
        if (i == 0 && doubleTargetRequestBuilder != null) {
            // First request should be recording + preview request
            requestList.add(doubleTargetRequestBuilder.build());
        } else {
            requestList.add(singleTargetRequestBuilder.build());
        }
    }
    return Collections.unmodifiableList(requestList);
}
Also used : ArrayList(java.util.ArrayList) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap) Surface(android.view.Surface) CaptureRequest(android.hardware.camera2.CaptureRequest)

Aggregations

StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)81 Size (android.util.Size)46 ArrayList (java.util.ArrayList)23 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)16 Surface (android.view.Surface)15 Point (android.graphics.Point)11 StreamConfiguration (android.hardware.camera2.params.StreamConfiguration)10 StreamConfigurationDuration (android.hardware.camera2.params.StreamConfigurationDuration)10 Range (android.util.Range)10 MediaRecorder (android.media.MediaRecorder)6 Camera (android.hardware.Camera)5 CaptureRequest (android.hardware.camera2.CaptureRequest)5 MarshalQueryableHighSpeedVideoConfiguration (android.hardware.camera2.marshal.impl.MarshalQueryableHighSpeedVideoConfiguration)5 MarshalQueryableReprocessFormatsMap (android.hardware.camera2.marshal.impl.MarshalQueryableReprocessFormatsMap)5 MarshalQueryableStreamConfiguration (android.hardware.camera2.marshal.impl.MarshalQueryableStreamConfiguration)5 MarshalQueryableStreamConfigurationDuration (android.hardware.camera2.marshal.impl.MarshalQueryableStreamConfigurationDuration)5 HighSpeedVideoConfiguration (android.hardware.camera2.params.HighSpeedVideoConfiguration)5 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)5 ReprocessFormatsMap (android.hardware.camera2.params.ReprocessFormatsMap)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5