Skip to content

Commit

Permalink
Fix issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Feb 21, 2020
1 parent 321f62c commit ae2d439
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Binary file added app/release/HBRecorderDemo.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/release/output.json
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":{}}]
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);
}
}

0 comments on commit ae2d439

Please sign in to comment.