Fix crash in setPictureSize on Galaxy Nexus.
This cl tries to find the best supported pictureSize before setting it. BUG=4197 R=magjed@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45419004 Cr-Commit-Position: refs/heads/master@{#8571} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8571 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
be00e3c198
commit
a1c9803e32
@ -247,7 +247,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
json_format.put("framerate", (format.maxFramerate + 999) / 1000);
|
||||
json_formats.put(json_format);
|
||||
}
|
||||
Log.d(TAG, "Supported formats: " + json_formats.toString(2));
|
||||
Log.d(TAG, "Supported formats for camera " + id + ": "
|
||||
+ json_formats.toString(2));
|
||||
return json_formats.toString();
|
||||
}
|
||||
|
||||
@ -265,8 +266,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
if (listFpsRange != null)
|
||||
range = listFpsRange.get(listFpsRange.size() -1);
|
||||
|
||||
List<Camera.Size> supportedSizes =
|
||||
parameters.getSupportedPreviewSizes();
|
||||
List<Camera.Size> supportedSizes = parameters.getSupportedPreviewSizes();
|
||||
for (Camera.Size size : supportedSizes) {
|
||||
if (size.width % 16 != 0) {
|
||||
// If the width is not a multiple of 16, the frames received from the
|
||||
@ -394,7 +394,8 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
range[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
|
||||
range[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
|
||||
}
|
||||
parameters.setPictureSize(width, height);
|
||||
Camera.Size pictureSize = getPictureSize(parameters, width, height);
|
||||
parameters.setPictureSize(pictureSize.width, pictureSize.height);
|
||||
parameters.setPreviewSize(width, height);
|
||||
int format = ImageFormat.YV12;
|
||||
parameters.setPreviewFormat(format);
|
||||
@ -516,6 +517,22 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
return bestRange;
|
||||
}
|
||||
|
||||
private static Camera.Size getPictureSize(Camera.Parameters parameters,
|
||||
int width, int height) {
|
||||
int bestAreaDiff = Integer.MAX_VALUE;
|
||||
Camera.Size bestSize = null;
|
||||
int requestedArea = width * height;
|
||||
for (Camera.Size pictureSize : parameters.getSupportedPictureSizes()) {
|
||||
int areaDiff = abs(requestedArea
|
||||
- pictureSize.width * pictureSize.height);
|
||||
if (areaDiff < bestAreaDiff) {
|
||||
bestAreaDiff = areaDiff;
|
||||
bestSize = pictureSize;
|
||||
}
|
||||
}
|
||||
return bestSize;
|
||||
}
|
||||
|
||||
// Called on cameraThread so must not "synchronized".
|
||||
@Override
|
||||
public void onPreviewFrame(byte[] data, Camera callbackCamera) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user