-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}] |
90 changes: 90 additions & 0 deletions
90
hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderCodecInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.hbisoft.hbrecorder; | ||
|
||
import android.content.Context; | ||
import android.content.res.Configuration; | ||
import android.media.CamcorderProfile; | ||
import android.util.DisplayMetrics; | ||
import android.view.WindowManager; | ||
|
||
import static android.content.Context.WINDOW_SERVICE; | ||
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; | ||
|
||
public class HBRecorderCodecInfo { | ||
|
||
int getMaxSupportedWidth(){ | ||
RecordingInfo recordingInfo = getRecordingInfo(); | ||
return recordingInfo.width; | ||
} | ||
|
||
int getMaxSupportedHeight(){ | ||
RecordingInfo recordingInfo = getRecordingInfo(); | ||
return recordingInfo.height; | ||
} | ||
|
||
private RecordingInfo getRecordingInfo() { | ||
DisplayMetrics displayMetrics = new DisplayMetrics(); | ||
WindowManager wm = (WindowManager) context.getSystemService(WINDOW_SERVICE); | ||
wm.getDefaultDisplay().getRealMetrics(displayMetrics); | ||
int displayWidth = displayMetrics.widthPixels; | ||
int displayHeight = displayMetrics.heightPixels; | ||
int displayDensity = displayMetrics.densityDpi; | ||
|
||
Configuration configuration = context.getResources().getConfiguration(); | ||
boolean isLandscape = configuration.orientation == ORIENTATION_LANDSCAPE; | ||
|
||
CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); | ||
int cameraWidth = camcorderProfile != null ? camcorderProfile.videoFrameWidth : -1; | ||
int cameraHeight = camcorderProfile != null ? camcorderProfile.videoFrameHeight : -1; | ||
int cameraFrameRate = camcorderProfile != null ? camcorderProfile.videoFrameRate : 30; | ||
|
||
|
||
return calculateRecordingInfo(displayWidth, displayHeight, displayDensity, isLandscape, | ||
cameraWidth, cameraHeight, cameraFrameRate, 100); | ||
} | ||
|
||
private Context context; | ||
|
||
public void setContext(Context c) { | ||
context = c; | ||
} | ||
|
||
static final class RecordingInfo { | ||
final int width; | ||
final int height; | ||
final int frameRate; | ||
final int density; | ||
|
||
RecordingInfo(int width, int height, int frameRate, int density) { | ||
this.width = width; | ||
this.height = height; | ||
this.frameRate = frameRate; | ||
this.density = density; | ||
} | ||
} | ||
|
||
static RecordingInfo calculateRecordingInfo(int displayWidth, int displayHeight, int displayDensity, boolean isLandscapeDevice, int cameraWidth, int cameraHeight, int cameraFrameRate, int sizePercentage) { | ||
// Scale the display size before any maximum size calculations. | ||
displayWidth = displayWidth * sizePercentage / 100; | ||
displayHeight = displayHeight * sizePercentage / 100; | ||
|
||
if (cameraWidth == -1 && cameraHeight == -1) { | ||
// No cameras. Fall back to the display size. | ||
return new RecordingInfo(displayWidth, displayHeight, cameraFrameRate, displayDensity); | ||
} | ||
|
||
int frameWidth = isLandscapeDevice ? cameraWidth : cameraHeight; | ||
int frameHeight = isLandscapeDevice ? cameraHeight : cameraWidth; | ||
if (frameWidth >= displayWidth && frameHeight >= displayHeight) { | ||
// Frame can hold the entire display. Use exact values. | ||
return new RecordingInfo(displayWidth, displayHeight, cameraFrameRate, displayDensity); | ||
} | ||
|
||
// Calculate new width or height to preserve aspect ratio. | ||
if (isLandscapeDevice) { | ||
frameWidth = displayWidth * frameHeight / displayHeight; | ||
} else { | ||
frameHeight = displayHeight * frameWidth / displayWidth; | ||
} | ||
return new RecordingInfo(frameWidth, frameHeight, cameraFrameRate, displayDensity); | ||
} | ||
} |