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");
}
}
}
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(")");
}
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(")");
}
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);
}
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;
}
Aggregations