Commit 9f73252e authored by mcasas's avatar mcasas Committed by Commit bot

Android Video Capture: use tightest fps Range available on allocate()

From the bug descr:

> N7 camera list capabilities are like (extracted):
>
> D/VideoCaptureAndroid(30916): Format 640x480 @ [15000-15000]
> D/VideoCaptureAndroid(30916): Format 640x480 @ [24000-24000]
> D/VideoCaptureAndroid(30916): Format 640x480 @ [15000-30000]
> D/VideoCaptureAndroid(30916): Format 640x480 @ [30000-30000]
>
> where the second numbers are the frame rate _ranges_. The algorithm for
> selecting FPS range in [1] would select the 3rd enumerated range when
> fed with a desired frame rate of 30, while the 4th range would be more
> appropriate.

[1] https://code.google.com/p/chromium/codesearch#chromium/src/media/base/android/java/src/org/chromium/media/VideoCapture.java&sq=package:chromium&type=cs&q=videocapture.java&l=130

TBR=qinmin@chromium.org
BUG=418911

Review URL: https://codereview.chromium.org/614003002

Cr-Commit-Position: refs/heads/master@{#297414}
parent 4499156f
......@@ -134,19 +134,22 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
Log.e(TAG, "allocate: no fps range found");
return false;
}
int frameRateInMs = frameRate * 1000;
// Use the first range as default.
int[] fpsMinMax = listFpsRange.get(0);
int newFrameRate = (fpsMinMax[0] + 999) / 1000;
// Use the first range as the default chosen range.
int[] chosenFpsRange = listFpsRange.get(0);
int chosenFrameRate = (chosenFpsRange[0] + 999) / 1000;
int fpsRangeSize = Integer.MAX_VALUE;
// API fps ranges are scaled up x1000 to avoid floating point.
int frameRateScaled = frameRate * 1000;
for (int[] fpsRange : listFpsRange) {
if (fpsRange[0] <= frameRateInMs && frameRateInMs <= fpsRange[1]) {
fpsMinMax = fpsRange;
newFrameRate = frameRate;
break;
if (fpsRange[0] <= frameRateScaled && frameRateScaled <= fpsRange[1] &&
(fpsRange[1] - fpsRange[0]) <= fpsRangeSize) {
chosenFpsRange = fpsRange;
chosenFrameRate = frameRate;
fpsRangeSize = fpsRange[1] - fpsRange[0];
}
}
frameRate = newFrameRate;
Log.d(TAG, "allocate: fps set to " + frameRate);
Log.d(TAG, "allocate: fps set to " + chosenFrameRate + ", [" +
chosenFpsRange[0] + "-" + chosenFpsRange[1] + "]");
// Calculate size.
List<android.hardware.Camera.Size> listCameraSize =
......@@ -183,10 +186,10 @@ public abstract class VideoCapture implements android.hardware.Camera.PreviewCal
Log.d(TAG, "Image stabilization not supported.");
}
setCaptureParameters(matchedWidth, matchedHeight, frameRate, parameters);
setCaptureParameters(matchedWidth, matchedHeight, chosenFrameRate, parameters);
parameters.setPreviewSize(mCaptureFormat.mWidth,
mCaptureFormat.mHeight);
parameters.setPreviewFpsRange(fpsMinMax[0], fpsMinMax[1]);
parameters.setPreviewFpsRange(chosenFpsRange[0], chosenFpsRange[1]);
parameters.setPreviewFormat(mCaptureFormat.mPixelFormat);
try {
mCamera.setParameters(parameters);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment