Reorder block

pull/741/head
Mattia Iavarone 6 years ago
parent de455f1850
commit 96f6a20f6c
  1. 43
      cameraview/src/main/java/com/otaliastudios/cameraview/internal/DeviceEncoders.java

@ -261,29 +261,30 @@ public class DeviceEncoders {
" Range:" + mVideoCapabilities.getSupportedHeights()); " Range:" + mVideoCapabilities.getSupportedHeights());
} }
// It's still possible that we're unsupported for other reasons. // We cannot change the aspect ratio, but the max block count might also be the
if (!mVideoCapabilities.isSizeSupported(width, height)) { // issue. Try to find a width that contains a height that would accept our AR.
try { try {
if (!mVideoCapabilities.getSupportedHeightsFor(width).contains(height)) { if (!mVideoCapabilities.getSupportedHeightsFor(width).contains(height)) {
// We cannot change the aspect ratio, but the max block count might also be the int candidateWidth = width;
// issue. Try to find a width that contains a height that would accept our AR. int minWidth = mVideoCapabilities.getSupportedWidths().getLower();
int candidateWidth = width; int widthAlignment = mVideoCapabilities.getWidthAlignment();
int minWidth = mVideoCapabilities.getSupportedWidths().getLower(); while (candidateWidth >= minWidth) {
int widthAlignment = mVideoCapabilities.getWidthAlignment(); // Reduce by 32 and realign just in case, then check if our AR is now
while (candidateWidth >= minWidth) { // supported. If it is, restart from scratch to go through the other checks.
// Reduce by 32 and realign just in case, then check if our AR is now candidateWidth -= 32;
// supported. If it is, restart from scratch to go through the other checks. while (candidateWidth % widthAlignment != 0) candidateWidth--;
candidateWidth -= 32; int candidateHeight = (int) Math.round(candidateWidth / aspect);
while (candidateWidth % widthAlignment != 0) candidateWidth--; if (mVideoCapabilities.getSupportedHeightsFor(candidateWidth)
int candidateHeight = (int) Math.round(candidateWidth / aspect); .contains(candidateHeight)) {
if (mVideoCapabilities.getSupportedHeightsFor(candidateWidth) LOG.w("getSupportedVideoSize - restarting with smaller size.");
.contains(candidateHeight)) { return getSupportedVideoSize(new Size(candidateWidth, candidateHeight));
LOG.w("getSupportedVideoSize - restarting with smaller size.");
return getSupportedVideoSize(new Size(candidateWidth, candidateHeight));
}
} }
} }
} catch (IllegalArgumentException ignore) {} }
} catch (IllegalArgumentException ignore) {}
// It's still possible that we're unsupported for other reasons.
if (!mVideoCapabilities.isSizeSupported(width, height)) {
throw new VideoException("Size not supported for unknown reason." + throw new VideoException("Size not supported for unknown reason." +
" Might be an aspect ratio issue." + " Might be an aspect ratio issue." +
" Desired size:" + new Size(width, height)); " Desired size:" + new Size(width, height));

Loading…
Cancel
Save