OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.media; | 5 package org.chromium.media; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.ImageFormat; | 8 import android.graphics.ImageFormat; |
9 import android.graphics.SurfaceTexture; | 9 import android.graphics.SurfaceTexture; |
10 import android.opengl.GLES20; | 10 import android.opengl.GLES20; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return false; | 115 return false; |
116 } | 116 } |
117 | 117 |
118 // getSupportedPreviewFpsRange() returns a List with at least one | 118 // getSupportedPreviewFpsRange() returns a List with at least one |
119 // element, but when camera is in bad state, it can return null pointer. | 119 // element, but when camera is in bad state, it can return null pointer. |
120 List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange(); | 120 List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange(); |
121 if (listFpsRange == null || listFpsRange.size() == 0) { | 121 if (listFpsRange == null || listFpsRange.size() == 0) { |
122 Log.e(TAG, "allocate: no fps range found"); | 122 Log.e(TAG, "allocate: no fps range found"); |
123 return false; | 123 return false; |
124 } | 124 } |
125 int frameRateInMs = frameRate * 1000; | 125 // Use the first range as the default chosen range. |
126 // Use the first range as default. | 126 int[] chosenFpsRange = listFpsRange.get(0); |
127 int[] fpsMinMax = listFpsRange.get(0); | 127 int chosenFrameRate = (chosenFpsRange[0] + 999) / 1000; |
128 int newFrameRate = (fpsMinMax[0] + 999) / 1000; | 128 int fpsRangeSize = Integer.MAX_VALUE; |
| 129 // API fps ranges are scaled up x1000 to avoid floating point. |
| 130 int frameRateScaled = frameRate * 1000; |
129 for (int[] fpsRange : listFpsRange) { | 131 for (int[] fpsRange : listFpsRange) { |
130 if (fpsRange[0] <= frameRateInMs && frameRateInMs <= fpsRange[1]) { | 132 if (fpsRange[0] <= frameRateScaled && frameRateScaled <= fpsRange[1]
&& |
131 fpsMinMax = fpsRange; | 133 (fpsRange[1] - fpsRange[0]) <= fpsRangeSize) { |
132 newFrameRate = frameRate; | 134 chosenFpsRange = fpsRange; |
133 break; | 135 chosenFrameRate = frameRate; |
| 136 fpsRangeSize = fpsRange[1] - fpsRange[0]; |
134 } | 137 } |
135 } | 138 } |
136 frameRate = newFrameRate; | 139 Log.d(TAG, "allocate: fps set to " + chosenFrameRate + ", [" + |
137 Log.d(TAG, "allocate: fps set to " + frameRate); | 140 chosenFpsRange[0] + "-" + chosenFpsRange[1] + "]"); |
138 | 141 |
139 // Calculate size. | 142 // Calculate size. |
140 List<android.hardware.Camera.Size> listCameraSize = | 143 List<android.hardware.Camera.Size> listCameraSize = |
141 parameters.getSupportedPreviewSizes(); | 144 parameters.getSupportedPreviewSizes(); |
142 int minDiff = Integer.MAX_VALUE; | 145 int minDiff = Integer.MAX_VALUE; |
143 int matchedWidth = width; | 146 int matchedWidth = width; |
144 int matchedHeight = height; | 147 int matchedHeight = height; |
145 for (android.hardware.Camera.Size size : listCameraSize) { | 148 for (android.hardware.Camera.Size size : listCameraSize) { |
146 int diff = Math.abs(size.width - width) + | 149 int diff = Math.abs(size.width - width) + |
147 Math.abs(size.height - height); | 150 Math.abs(size.height - height); |
(...skipping 16 matching lines...) Expand all Loading... |
164 Log.d(TAG, "allocate: matched (" + matchedWidth + "x" + matchedHeight +
")"); | 167 Log.d(TAG, "allocate: matched (" + matchedWidth + "x" + matchedHeight +
")"); |
165 | 168 |
166 if (parameters.isVideoStabilizationSupported()) { | 169 if (parameters.isVideoStabilizationSupported()) { |
167 Log.d(TAG, "Image stabilization supported, currently: " + | 170 Log.d(TAG, "Image stabilization supported, currently: " + |
168 parameters.getVideoStabilization() + ", setting it."); | 171 parameters.getVideoStabilization() + ", setting it."); |
169 parameters.setVideoStabilization(true); | 172 parameters.setVideoStabilization(true); |
170 } else { | 173 } else { |
171 Log.d(TAG, "Image stabilization not supported."); | 174 Log.d(TAG, "Image stabilization not supported."); |
172 } | 175 } |
173 | 176 |
174 setCaptureParameters(matchedWidth, matchedHeight, frameRate, parameters)
; | 177 setCaptureParameters(matchedWidth, matchedHeight, chosenFrameRate, param
eters); |
175 parameters.setPreviewSize(mCaptureFormat.mWidth, | 178 parameters.setPreviewSize(mCaptureFormat.mWidth, |
176 mCaptureFormat.mHeight); | 179 mCaptureFormat.mHeight); |
177 parameters.setPreviewFpsRange(fpsMinMax[0], fpsMinMax[1]); | 180 parameters.setPreviewFpsRange(chosenFpsRange[0], chosenFpsRange[1]); |
178 parameters.setPreviewFormat(mCaptureFormat.mPixelFormat); | 181 parameters.setPreviewFormat(mCaptureFormat.mPixelFormat); |
179 try { | 182 try { |
180 mCamera.setParameters(parameters); | 183 mCamera.setParameters(parameters); |
181 } catch (RuntimeException ex) { | 184 } catch (RuntimeException ex) { |
182 Log.e(TAG, "setParameters: " + ex); | 185 Log.e(TAG, "setParameters: " + ex); |
183 return false; | 186 return false; |
184 } | 187 } |
185 | 188 |
186 // Set SurfaceTexture. Android Capture needs a SurfaceTexture even if | 189 // Set SurfaceTexture. Android Capture needs a SurfaceTexture even if |
187 // it is not going to be used. | 190 // it is not going to be used. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 android.hardware.Camera.CameraInfo cameraInfo = new android.hardware.Cam
era.CameraInfo(); | 375 android.hardware.Camera.CameraInfo cameraInfo = new android.hardware.Cam
era.CameraInfo(); |
373 try { | 376 try { |
374 android.hardware.Camera.getCameraInfo(id, cameraInfo); | 377 android.hardware.Camera.getCameraInfo(id, cameraInfo); |
375 } catch (RuntimeException ex) { | 378 } catch (RuntimeException ex) { |
376 Log.e(TAG, "getCameraInfo: android.hardware.Camera.getCameraInfo: "
+ ex); | 379 Log.e(TAG, "getCameraInfo: android.hardware.Camera.getCameraInfo: "
+ ex); |
377 return null; | 380 return null; |
378 } | 381 } |
379 return cameraInfo; | 382 return cameraInfo; |
380 } | 383 } |
381 } | 384 } |
OLD | NEW |