diff --git a/app/release/HBRecorderDemo.apk b/app/release/HBRecorderDemo.apk new file mode 100644 index 0000000..ba03f19 Binary files /dev/null and b/app/release/HBRecorderDemo.apk differ diff --git a/app/release/output.json b/app/release/output.json new file mode 100644 index 0000000..c429e31 --- /dev/null +++ b/app/release/output.json @@ -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":{}}] \ No newline at end of file diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderCodecInfo.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderCodecInfo.java new file mode 100644 index 0000000..e49a70f --- /dev/null +++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderCodecInfo.java @@ -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); + } +}