Bug 1192203 - Extract a robust version of getSupportedPreviewFpsRange. r=jesup

This commit is contained in:
Gian-Carlo Pascutto 2015-09-16 16:17:49 +02:00
parent a6b399a434
commit 8bb4ebf977
2 changed files with 35 additions and 26 deletions

View File

@ -36,6 +36,7 @@ import org.mozilla.gecko.annotation.WebRTCJNITarget;
import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoAppShell.AppStateListener;
// Wrapper for android Camera, with support for direct local preview rendering.
// Threading notes: this class is called from ViE C++ code, and from Camera &
// SurfaceHolder Java callbacks. Since these calls happen on different threads,
@ -269,7 +270,8 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
// Check if requested fps range is supported by camera,
// otherwise calculate frame drop ratio.
List<int[]> supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
List<int[]> supportedFpsRanges =
VideoCaptureDeviceInfoAndroid.getFpsRangesRobust(parameters);
frameDropRatio = Integer.MAX_VALUE;
for (int i = 0; i < supportedFpsRanges.size(); i++) {
int[] range = supportedFpsRanges.get(i);

View File

@ -34,6 +34,37 @@ public class VideoCaptureDeviceInfoAndroid {
", Orientation "+ info.orientation;
}
@WebRTCJNITarget
public static List<int[]> getFpsRangesRobust(Camera.Parameters parameters) {
List<int[]> supportedFpsRanges = null;
if (android.os.Build.VERSION.SDK_INT >= 9) {
supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
}
// getSupportedPreviewFpsRange doesn't actually work on a bunch
// of Gingerbread devices.
if (supportedFpsRanges == null) {
supportedFpsRanges = new ArrayList<int[]>();
List<Integer> frameRates = parameters.getSupportedPreviewFrameRates();
if (frameRates != null) {
for (Integer rate: frameRates) {
int[] range = new int[2];
// minFPS = maxFPS, convert to milliFPS
range[0] = rate * 1000;
range[1] = rate * 1000;
supportedFpsRanges.add(range);
}
} else {
Log.e(TAG, "Camera doesn't know its own framerate, guessing 30fps.");
int[] range = new int[2];
// Your guess is as good as mine
range[0] = 30 * 1000;
range[1] = 30 * 1000;
supportedFpsRanges.add(range);
}
}
return supportedFpsRanges;
}
// Returns information about all cameras on the device.
// Since this reflects static information about the hardware present, there is
// no need to call this function more than once in a single process. It is
@ -67,31 +98,7 @@ public class VideoCaptureDeviceInfoAndroid {
}
Parameters parameters = camera.getParameters();
supportedSizes = parameters.getSupportedPreviewSizes();
if (android.os.Build.VERSION.SDK_INT >= 9) {
supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
}
// getSupportedPreviewFpsRange doesn't actually work on a bunch
// of Gingerbread devices.
if (supportedFpsRanges == null) {
supportedFpsRanges = new ArrayList<int[]>();
List<Integer> frameRates = parameters.getSupportedPreviewFrameRates();
if (frameRates != null) {
for (Integer rate: frameRates) {
int[] range = new int[2];
// minFPS = maxFPS, convert to milliFPS
range[0] = rate * 1000;
range[1] = rate * 1000;
supportedFpsRanges.add(range);
}
} else {
Log.e(TAG, "Camera doesn't know its own framerate, guessing 30fps.");
int[] range = new int[2];
// Your guess is as good as mine
range[0] = 30 * 1000;
range[1] = 30 * 1000;
supportedFpsRanges.add(range);
}
}
supportedFpsRanges = getFpsRangesRobust(parameters);
camera.release();
Log.d(TAG, uniqueName);
} catch (RuntimeException e) {