Skip to content

fix to VideoQuality.determineClosestSupportedResolution #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/net/majorkernelpanic/streaming/video/VideoQuality.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ public String toString() {
**/
public static VideoQuality determineClosestSupportedResolution(Camera.Parameters parameters, VideoQuality quality) {
VideoQuality v = quality.clone();
int minDist = Integer.MAX_VALUE;
float minDist = Float.MAX_VALUE;
String supportedSizesStr = "Supported resolutions: ";
List<Size> supportedSizes = parameters.getSupportedPreviewSizes();
for (Iterator<Size> it = supportedSizes.iterator(); it.hasNext();) {
Size size = it.next();
supportedSizesStr += size.width+"x"+size.height+(it.hasNext()?", ":"");
int dist = Math.abs(quality.resX - size.width);
float dist = (float) Math.sqrt(Math.pow(quality.resX - size.width, 2) + Math.pow(quality.resY - size.height, 2));
if (dist<minDist) {
minDist = dist;
v.resX = size.width;
Expand Down Expand Up @@ -144,4 +144,31 @@ public static int[] determineMaximumSupportedFramerate(Camera.Parameters paramet
return maxFps;
}

/**
* Compares the framerate requested by the session with the ones available by the camera
* Since we're comparing a single value with the interval, it chooses intervals whose average
* fps value is closest to the requested one, e.g., if one requests 30fps and the camera
* supports 15-30,30-30, and 60-60. It will select 30-30;
* Given these are fps ranges of real cameras we should not see troublesome situations like a
* choice between 15-45 and 30-30, which in this case would give precedence to the first.
**/
public static int[] determineClosestSupportedFramerate(Camera.Parameters parameters, VideoQuality quality) {
int[] fps = new int[]{0,0};
int fr = quality.framerate * 1000;
float dist = Float.MAX_VALUE;
String supportedFpsRangesStr = "Supported frame rates: ";
List<int[]> supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
for (Iterator<int[]> it = supportedFpsRanges.iterator(); it.hasNext();) {
int[] interval = it.next();
// Intervals are returned as integers, for example "29970" means "29.970" FPS.
supportedFpsRangesStr += interval[0]/1000+"-"+interval[1]/1000+"fps"+(it.hasNext()?", ":"");
float testDist = Math.abs((interval[0] + interval[1])/2 - fr);
if(testDist < dist) {
fps = interval;
dist = testDist;
}
}
Log.v(TAG,supportedFpsRangesStr);
return fps;
}
}