use of android.util.Size in project android_frameworks_base by AOSPA.
the class StreamConfigurationMap method isOutputSupportedFor.
/**
* Determine whether or not the {@code surface} in its current state is suitable to be included
* in a {@link CameraDevice#createCaptureSession capture session} as an output.
*
* <p>Not all surfaces are usable with the {@link CameraDevice}, and not all configurations
* of that {@code surface} are compatible. Some classes that provide the {@code surface} are
* compatible with the {@link CameraDevice} in general
* (see {@link #isOutputSupportedFor(Class)}, but it is the caller's responsibility to put the
* {@code surface} into a state that will be compatible with the {@link CameraDevice}.</p>
*
* <p>Reasons for a {@code surface} being specifically incompatible might be:
* <ul>
* <li>Using a format that's not listed by {@link #getOutputFormats}
* <li>Using a format/size combination that's not listed by {@link #getOutputSizes}
* <li>The {@code surface} itself is not in a state where it can service a new producer.</p>
* </li>
* </ul>
*
* <p>Surfaces from flexible sources will return true even if the exact size of the Surface does
* not match a camera-supported size, as long as the format (or class) is supported and the
* camera device supports a size that is equal to or less than 1080p in that format. If such as
* Surface is used to create a capture session, it will have its size rounded to the nearest
* supported size, below or equal to 1080p. Flexible sources include SurfaceView, SurfaceTexture,
* and ImageReader.</p>
*
* <p>This is not an exhaustive list; see the particular class's documentation for further
* possible reasons of incompatibility.</p>
*
* @param surface a non-{@code null} {@link Surface} object reference
* @return {@code true} if this is supported, {@code false} otherwise
*
* @throws NullPointerException if {@code surface} was {@code null}
* @throws IllegalArgumentException if the Surface endpoint is no longer valid
*
* @see CameraDevice#createCaptureSession
* @see #isOutputSupportedFor(Class)
*/
public boolean isOutputSupportedFor(Surface surface) {
checkNotNull(surface, "surface must not be null");
Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
int surfaceFormat = SurfaceUtils.getSurfaceFormat(surface);
int surfaceDataspace = SurfaceUtils.getSurfaceDataspace(surface);
// See if consumer is flexible.
boolean isFlexible = SurfaceUtils.isFlexibleConsumer(surface);
// Override RGB formats to IMPLEMENTATION_DEFINED, b/9487482
if ((surfaceFormat >= LegacyMetadataMapper.HAL_PIXEL_FORMAT_RGBA_8888 && surfaceFormat <= LegacyMetadataMapper.HAL_PIXEL_FORMAT_BGRA_8888)) {
surfaceFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
}
StreamConfiguration[] configs = surfaceDataspace != HAL_DATASPACE_DEPTH ? mConfigurations : mDepthConfigurations;
for (StreamConfiguration config : configs) {
if (config.getFormat() == surfaceFormat && config.isOutput()) {
// and a size no bigger than MAX_DIMEN_FOR_ROUNDING
if (config.getSize().equals(surfaceSize)) {
return true;
} else if (isFlexible && (config.getSize().getWidth() <= LegacyCameraDevice.MAX_DIMEN_FOR_ROUNDING)) {
return true;
}
}
}
return false;
}
use of android.util.Size in project android_frameworks_base by AOSPA.
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(")");
}
use of android.util.Size in project android_frameworks_base by AOSPA.
the class StreamConfigurationMap method getInternalFormatSizes.
private Size[] getInternalFormatSizes(int format, int dataspace, boolean output, boolean highRes) {
// All depth formats are non-high-res.
if (dataspace == HAL_DATASPACE_DEPTH && highRes) {
return new Size[0];
}
SparseIntArray formatsMap = !output ? mInputFormats : dataspace == HAL_DATASPACE_DEPTH ? mDepthOutputFormats : highRes ? mHighResOutputFormats : mOutputFormats;
int sizesCount = formatsMap.get(format);
if (((!output || dataspace == HAL_DATASPACE_DEPTH) && sizesCount == 0) || (output && dataspace != HAL_DATASPACE_DEPTH && mAllOutputFormats.get(format) == 0)) {
// Only throw if this is really not supported at all
throw new IllegalArgumentException("format not available");
}
Size[] sizes = new Size[sizesCount];
int sizeIndex = 0;
StreamConfiguration[] configurations = (dataspace == HAL_DATASPACE_DEPTH) ? mDepthConfigurations : mConfigurations;
StreamConfigurationDuration[] minFrameDurations = (dataspace == HAL_DATASPACE_DEPTH) ? mDepthMinFrameDurations : mMinFrameDurations;
for (StreamConfiguration config : configurations) {
int fmt = config.getFormat();
if (fmt == format && config.isOutput() == output) {
if (output && mListHighResolution) {
// Filter slow high-res output formats; include for
// highRes, remove for !highRes
long duration = 0;
for (int i = 0; i < minFrameDurations.length; i++) {
StreamConfigurationDuration d = minFrameDurations[i];
if (d.getFormat() == fmt && d.getWidth() == config.getSize().getWidth() && d.getHeight() == config.getSize().getHeight()) {
duration = d.getDuration();
break;
}
}
if (dataspace != HAL_DATASPACE_DEPTH && highRes != (duration > DURATION_20FPS_NS)) {
continue;
}
}
sizes[sizeIndex++] = config.getSize();
}
}
if (sizeIndex != sizesCount) {
throw new AssertionError("Too few sizes (expected " + sizesCount + ", actual " + sizeIndex + ")");
}
return sizes;
}
use of android.util.Size in project android_frameworks_base by AOSPA.
the class Camera2CaptureRequestTest method testAeModeAndLock.
/**
* Test AE mode and lock.
*
* <p>
* For AE lock, when it is locked, exposure parameters shouldn't be changed.
* For AE modes, each mode should satisfy the per frame controls defined in
* API specifications.
* </p>
*/
public void testAeModeAndLock() throws Exception {
for (int i = 0; i < mCameraIds.length; i++) {
try {
openDevice(mCameraIds[i]);
if (!mStaticInfo.isColorOutputSupported()) {
Log.i(TAG, "Camera " + mCameraIds[i] + " does not support color outputs, skipping");
continue;
}
// Max preview size.
Size maxPreviewSz = mOrderedPreviewSizes.get(0);
// Update preview surface with given size for all sub-tests.
updatePreviewSurface(maxPreviewSz);
// Test iteration starts...
for (int iteration = 0; iteration < getIterationCount(); ++iteration) {
Log.v(TAG, String.format("AE mode and lock: %d/%d", iteration + 1, getIterationCount()));
// Test aeMode and lock
int[] aeModes = mStaticInfo.getAeAvailableModesChecked();
for (int mode : aeModes) {
aeModeAndLockTestByMode(mode);
}
getResultPrinter().printStatus(getIterationCount(), iteration + 1, mCameraIds[i]);
Thread.sleep(getTestWaitIntervalMs());
}
} finally {
closeDevice();
}
}
}
use of android.util.Size in project android_frameworks_base by AOSPA.
the class LegacyRequestMapper method convertRequestMetadata.
/**
* Set the legacy parameters using the {@link LegacyRequest legacy request}.
*
* <p>The legacy request's parameters are changed as a side effect of calling this
* method.</p>
*
* @param legacyRequest a non-{@code null} legacy request
*/
public static void convertRequestMetadata(LegacyRequest legacyRequest) {
CameraCharacteristics characteristics = legacyRequest.characteristics;
CaptureRequest request = legacyRequest.captureRequest;
Size previewSize = legacyRequest.previewSize;
Camera.Parameters params = legacyRequest.parameters;
Rect activeArray = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
/*
* scaler.cropRegion
*/
ParameterUtils.ZoomData zoomData;
{
zoomData = ParameterUtils.convertScalerCropRegion(activeArray, request.get(SCALER_CROP_REGION), previewSize, params);
if (params.isZoomSupported()) {
params.setZoom(zoomData.zoomIndex);
} else if (DEBUG) {
Log.v(TAG, "convertRequestToMetadata - zoom is not supported");
}
}
/*
* colorCorrection.*
*/
// colorCorrection.aberrationMode
{
int aberrationMode = ParamsUtils.getOrDefault(request, COLOR_CORRECTION_ABERRATION_MODE, /*defaultValue*/
COLOR_CORRECTION_ABERRATION_MODE_FAST);
if (aberrationMode != COLOR_CORRECTION_ABERRATION_MODE_FAST && aberrationMode != COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY) {
Log.w(TAG, "convertRequestToMetadata - Ignoring unsupported " + "colorCorrection.aberrationMode = " + aberrationMode);
}
}
/*
* control.ae*
*/
// control.aeAntibandingMode
{
String legacyMode;
Integer antiBandingMode = request.get(CONTROL_AE_ANTIBANDING_MODE);
if (antiBandingMode != null) {
legacyMode = convertAeAntiBandingModeToLegacy(antiBandingMode);
} else {
legacyMode = ListUtils.listSelectFirstFrom(params.getSupportedAntibanding(), new String[] { Parameters.ANTIBANDING_AUTO, Parameters.ANTIBANDING_OFF, Parameters.ANTIBANDING_50HZ, Parameters.ANTIBANDING_60HZ });
}
if (legacyMode != null) {
params.setAntibanding(legacyMode);
}
}
/*
* control.aeRegions, afRegions
*/
{
// aeRegions
{
// Use aeRegions if available, fall back to using awbRegions if present
MeteringRectangle[] aeRegions = request.get(CONTROL_AE_REGIONS);
if (request.get(CONTROL_AWB_REGIONS) != null) {
Log.w(TAG, "convertRequestMetadata - control.awbRegions setting is not " + "supported, ignoring value");
}
int maxNumMeteringAreas = params.getMaxNumMeteringAreas();
List<Camera.Area> meteringAreaList = convertMeteringRegionsToLegacy(activeArray, zoomData, aeRegions, maxNumMeteringAreas, /*regionName*/
"AE");
// WAR: for b/17252693, some devices can't handle params.setFocusAreas(null).
if (maxNumMeteringAreas > 0) {
params.setMeteringAreas(meteringAreaList);
}
}
// afRegions
{
MeteringRectangle[] afRegions = request.get(CONTROL_AF_REGIONS);
int maxNumFocusAreas = params.getMaxNumFocusAreas();
List<Camera.Area> focusAreaList = convertMeteringRegionsToLegacy(activeArray, zoomData, afRegions, maxNumFocusAreas, /*regionName*/
"AF");
// WAR: for b/17252693, some devices can't handle params.setFocusAreas(null).
if (maxNumFocusAreas > 0) {
params.setFocusAreas(focusAreaList);
}
}
}
// control.aeTargetFpsRange
Range<Integer> aeFpsRange = request.get(CONTROL_AE_TARGET_FPS_RANGE);
if (aeFpsRange != null) {
int[] legacyFps = convertAeFpsRangeToLegacy(aeFpsRange);
int[] rangeToApply = null;
for (int[] range : params.getSupportedPreviewFpsRange()) {
// Round range up/down to integer FPS value
int intRangeLow = (int) Math.floor(range[0] / 1000.0) * 1000;
int intRangeHigh = (int) Math.ceil(range[1] / 1000.0) * 1000;
if (legacyFps[0] == intRangeLow && legacyFps[1] == intRangeHigh) {
rangeToApply = range;
break;
}
}
if (rangeToApply != null) {
params.setPreviewFpsRange(rangeToApply[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], rangeToApply[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
} else {
Log.w(TAG, "Unsupported FPS range set [" + legacyFps[0] + "," + legacyFps[1] + "]");
}
}
/*
* control
*/
// control.aeExposureCompensation
{
Range<Integer> compensationRange = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
int compensation = ParamsUtils.getOrDefault(request, CONTROL_AE_EXPOSURE_COMPENSATION, /*defaultValue*/
0);
if (!compensationRange.contains(compensation)) {
Log.w(TAG, "convertRequestMetadata - control.aeExposureCompensation " + "is out of range, ignoring value");
compensation = 0;
}
params.setExposureCompensation(compensation);
}
// control.aeLock
{
Boolean aeLock = getIfSupported(request, CONTROL_AE_LOCK, /*defaultValue*/
false, params.isAutoExposureLockSupported(), /*allowedValue*/
false);
if (aeLock != null) {
params.setAutoExposureLock(aeLock);
}
if (DEBUG) {
Log.v(TAG, "convertRequestToMetadata - control.aeLock set to " + aeLock);
}
// TODO: Don't add control.aeLock to availableRequestKeys if it's not supported
}
// control.aeMode, flash.mode
mapAeAndFlashMode(request, /*out*/
params);
// control.afMode
{
int afMode = ParamsUtils.getOrDefault(request, CONTROL_AF_MODE, /*defaultValue*/
CONTROL_AF_MODE_OFF);
String focusMode = LegacyMetadataMapper.convertAfModeToLegacy(afMode, params.getSupportedFocusModes());
if (focusMode != null) {
params.setFocusMode(focusMode);
}
if (DEBUG) {
Log.v(TAG, "convertRequestToMetadata - control.afMode " + afMode + " mapped to " + focusMode);
}
}
// control.awbMode
{
Integer awbMode = getIfSupported(request, CONTROL_AWB_MODE, /*defaultValue*/
CONTROL_AWB_MODE_AUTO, params.getSupportedWhiteBalance() != null, /*allowedValue*/
CONTROL_AWB_MODE_AUTO);
String whiteBalanceMode = null;
if (awbMode != null) {
// null iff AWB is not supported by camera1 api
whiteBalanceMode = convertAwbModeToLegacy(awbMode);
params.setWhiteBalance(whiteBalanceMode);
}
if (DEBUG) {
Log.v(TAG, "convertRequestToMetadata - control.awbMode " + awbMode + " mapped to " + whiteBalanceMode);
}
}
// control.awbLock
{
Boolean awbLock = getIfSupported(request, CONTROL_AWB_LOCK, /*defaultValue*/
false, params.isAutoWhiteBalanceLockSupported(), /*allowedValue*/
false);
if (awbLock != null) {
params.setAutoWhiteBalanceLock(awbLock);
}
// TODO: Don't add control.awbLock to availableRequestKeys if it's not supported
}
// control.captureIntent
{
int captureIntent = ParamsUtils.getOrDefault(request, CONTROL_CAPTURE_INTENT, /*defaultValue*/
CONTROL_CAPTURE_INTENT_PREVIEW);
captureIntent = filterSupportedCaptureIntent(captureIntent);
params.setRecordingHint(captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_RECORD || captureIntent == CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
}
// control.videoStabilizationMode
{
Integer stabMode = getIfSupported(request, CONTROL_VIDEO_STABILIZATION_MODE, /*defaultValue*/
CONTROL_VIDEO_STABILIZATION_MODE_OFF, params.isVideoStabilizationSupported(), /*allowedValue*/
CONTROL_VIDEO_STABILIZATION_MODE_OFF);
if (stabMode != null) {
params.setVideoStabilization(stabMode == CONTROL_VIDEO_STABILIZATION_MODE_ON);
}
}
// lens.focusDistance
{
boolean infinityFocusSupported = ListUtils.listContains(params.getSupportedFocusModes(), Parameters.FOCUS_MODE_INFINITY);
Float focusDistance = getIfSupported(request, LENS_FOCUS_DISTANCE, /*defaultValue*/
0f, infinityFocusSupported, /*allowedValue*/
0f);
if (focusDistance == null || focusDistance != 0f) {
Log.w(TAG, "convertRequestToMetadata - Ignoring android.lens.focusDistance " + infinityFocusSupported + ", only 0.0f is supported");
}
}
// control.sceneMode, control.mode
{
if (params.getSupportedSceneModes() != null) {
int controlMode = ParamsUtils.getOrDefault(request, CONTROL_MODE, /*defaultValue*/
CONTROL_MODE_AUTO);
String modeToSet;
switch(controlMode) {
case CONTROL_MODE_USE_SCENE_MODE:
{
int sceneMode = ParamsUtils.getOrDefault(request, CONTROL_SCENE_MODE, /*defaultValue*/
CONTROL_SCENE_MODE_DISABLED);
String legacySceneMode = LegacyMetadataMapper.convertSceneModeToLegacy(sceneMode);
if (legacySceneMode != null) {
modeToSet = legacySceneMode;
} else {
modeToSet = Parameters.SCENE_MODE_AUTO;
Log.w(TAG, "Skipping unknown requested scene mode: " + sceneMode);
}
break;
}
case CONTROL_MODE_AUTO:
{
modeToSet = Parameters.SCENE_MODE_AUTO;
break;
}
default:
{
Log.w(TAG, "Control mode " + controlMode + " is unsupported, defaulting to AUTO");
modeToSet = Parameters.SCENE_MODE_AUTO;
}
}
params.setSceneMode(modeToSet);
}
}
// control.effectMode
{
if (params.getSupportedColorEffects() != null) {
int effectMode = ParamsUtils.getOrDefault(request, CONTROL_EFFECT_MODE, /*defaultValue*/
CONTROL_EFFECT_MODE_OFF);
String legacyEffectMode = LegacyMetadataMapper.convertEffectModeToLegacy(effectMode);
if (legacyEffectMode != null) {
params.setColorEffect(legacyEffectMode);
} else {
params.setColorEffect(Parameters.EFFECT_NONE);
Log.w(TAG, "Skipping unknown requested effect mode: " + effectMode);
}
}
}
/*
* sensor
*/
// sensor.testPattern
{
int testPatternMode = ParamsUtils.getOrDefault(request, SENSOR_TEST_PATTERN_MODE, /*defaultValue*/
SENSOR_TEST_PATTERN_MODE_OFF);
if (testPatternMode != SENSOR_TEST_PATTERN_MODE_OFF) {
Log.w(TAG, "convertRequestToMetadata - ignoring sensor.testPatternMode " + testPatternMode + "; only OFF is supported");
}
}
/*
* jpeg.*
*/
// jpeg.gpsLocation
{
Location location = request.get(JPEG_GPS_LOCATION);
if (location != null) {
if (checkForCompleteGpsData(location)) {
params.setGpsAltitude(location.getAltitude());
params.setGpsLatitude(location.getLatitude());
params.setGpsLongitude(location.getLongitude());
params.setGpsProcessingMethod(location.getProvider().toUpperCase());
params.setGpsTimestamp(location.getTime());
} else {
Log.w(TAG, "Incomplete GPS parameters provided in location " + location);
}
} else {
params.removeGpsData();
}
}
// jpeg.orientation
{
Integer orientation = request.get(CaptureRequest.JPEG_ORIENTATION);
params.setRotation(ParamsUtils.getOrDefault(request, JPEG_ORIENTATION, (orientation == null) ? 0 : orientation));
}
// jpeg.quality
{
params.setJpegQuality(0xFF & ParamsUtils.getOrDefault(request, JPEG_QUALITY, DEFAULT_JPEG_QUALITY));
}
// jpeg.thumbnailQuality
{
params.setJpegThumbnailQuality(0xFF & ParamsUtils.getOrDefault(request, JPEG_THUMBNAIL_QUALITY, DEFAULT_JPEG_QUALITY));
}
// jpeg.thumbnailSize
{
List<Camera.Size> sizes = params.getSupportedJpegThumbnailSizes();
if (sizes != null && sizes.size() > 0) {
Size s = request.get(JPEG_THUMBNAIL_SIZE);
boolean invalidSize = (s == null) ? false : !ParameterUtils.containsSize(sizes, s.getWidth(), s.getHeight());
if (invalidSize) {
Log.w(TAG, "Invalid JPEG thumbnail size set " + s + ", skipping thumbnail...");
}
if (s == null || invalidSize) {
// (0,0) = "no thumbnail" in Camera API 1
params.setJpegThumbnailSize(/*width*/
0, /*height*/
0);
} else {
params.setJpegThumbnailSize(s.getWidth(), s.getHeight());
}
}
}
/*
* noiseReduction.*
*/
// noiseReduction.mode
{
int mode = ParamsUtils.getOrDefault(request, NOISE_REDUCTION_MODE, /*defaultValue*/
NOISE_REDUCTION_MODE_FAST);
if (mode != NOISE_REDUCTION_MODE_FAST && mode != NOISE_REDUCTION_MODE_HIGH_QUALITY) {
Log.w(TAG, "convertRequestToMetadata - Ignoring unsupported " + "noiseReduction.mode = " + mode);
}
}
}
Aggregations