Bug 1192203 - Extract a robust version of getSupportedPreviewFpsRange. r=jesup
authorGian-Carlo Pascutto <gcp@mozilla.com>
Wed, 16 Sep 2015 16:17:49 +0200
changeset 297314 2ec5cb2beea7dd3a0ddcea712a4370d639284633
parent 297313 ec9dc8f952c507d16bc65b30ca768201aac860c5
child 297315 d60f93efd7afdcc6bf085dfd4d290e460102f578
push id962
push userjlund@mozilla.com
push dateFri, 04 Dec 2015 23:28:54 +0000
treeherdermozilla-release@23a2d286e80f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1192203
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1192203 - Extract a robust version of getSupportedPreviewFpsRange. r=jesup
media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java
@@ -31,16 +31,17 @@ import android.view.Surface;
 import android.view.SurfaceHolder.Callback;
 import android.view.SurfaceHolder;
 import android.view.WindowManager;
 
 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,
 // the entry points to this class are all synchronized.  This shouldn't present
 // a performance bottleneck because only onPreviewFrame() is called more than
 // once (and is called serially on a single thread), so the lock should be
 // uncontended.  Note that each of these synchronized methods must check
 // |camera| for null to account for having possibly waited for stopCapture() to
@@ -264,17 +265,18 @@ public class VideoCaptureAndroid impleme
         if (focusModeList.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
             parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
         }
       }
       parameters.setPreviewSize(width, height);
 
       // 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);
         if (range[Parameters.PREVIEW_FPS_MIN_INDEX] == min_mfps &&
             range[Parameters.PREVIEW_FPS_MAX_INDEX] == max_mfps) {
           frameDropRatio = 1;
           break;
         }
--- a/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
+++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/java/src/org/webrtc/videoengine/VideoCaptureDeviceInfoAndroid.java
@@ -29,16 +29,47 @@ public class VideoCaptureDeviceInfoAndro
   }
 
   private static String deviceUniqueName(int index, CameraInfo info) {
     return "Camera " + index +", Facing " +
         (isFrontFacing(info) ? "front" : "back") +
         ", 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
   // marked "private" as it is only called by native code.
   @WebRTCJNITarget
   private static CaptureCapabilityAndroid[] getDeviceInfo() {
       ArrayList<CaptureCapabilityAndroid> allDevices = new ArrayList<CaptureCapabilityAndroid>();
       int numCameras = 1;
@@ -62,41 +93,17 @@ public class VideoCaptureDeviceInfoAndro
               Camera camera = null;
               if (android.os.Build.VERSION.SDK_INT >= 9) {
                   camera = Camera.open(i);
               } else {
                   camera = Camera.open();
               }
               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) {
               Log.e(TAG, "Failed to open " + uniqueName + ", skipping due to: "
                     + e.getLocalizedMessage());
               continue;
           }