add variable video quality

pull/1/head
Dylan McIntyre 8 years ago
parent 0f2c695c5c
commit e87d8feb4c
  1. 59
      camerakit/src/main/api16/com/flurgle/camerakit/Camera1.java
  2. 5
      camerakit/src/main/api21/com/flurgle/camerakit/Camera2.java
  3. 1
      camerakit/src/main/base/com/flurgle/camerakit/CameraImpl.java
  4. 8
      camerakit/src/main/java/com/flurgle/camerakit/CameraKit.java
  5. 10
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
  6. 9
      camerakit/src/main/res/values/attrs.xml
  7. 18
      camerakit/src/main/types/com/flurgle/camerakit/VideoQuality.java

@ -8,7 +8,6 @@ import android.media.MediaRecorder;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
@ -59,6 +58,9 @@ public class Camera1 extends CameraImpl {
@Zoom
private int mZoom;
@VideoQuality
private int mVideoQuality;
Camera1(CameraListener callback, PreviewImpl preview) {
super(callback, preview);
preview.setCallback(new PreviewImpl.Callback() {
@ -192,6 +194,11 @@ public class Camera1 extends CameraImpl {
this.mZoom = zoom;
}
@Override
void setVideoQuality(int videoQuality) {
this.mVideoQuality = videoQuality;
}
@Override
void captureImage() {
switch (mMethod) {
@ -402,7 +409,8 @@ public class Camera1 extends CameraImpl {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setProfile(CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH));
mMediaRecorder.setProfile(getCamcorderProfile(mVideoQuality));
mVideoFile = new File(mPreview.getView().getContext().getExternalFilesDir(null), "video.mp4");
mMediaRecorder.setOutputFile(mVideoFile.getAbsolutePath());
@ -419,6 +427,53 @@ public class Camera1 extends CameraImpl {
}
}
private CamcorderProfile getCamcorderProfile(@VideoQuality int videoQuality) {
CamcorderProfile camcorderProfile = null;
switch (videoQuality) {
case CameraKit.Constants.VIDEO_QUALITY_480P:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) {
camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_480P);
} else {
return getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_LOWEST);
}
break;
case CameraKit.Constants.VIDEO_QUALITY_720P:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_720P)) {
camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_720P);
} else {
return getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_480P);
}
break;
case CameraKit.Constants.VIDEO_QUALITY_1080P:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) {
camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_1080P);
} else {
return getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_720P);
}
break;
case CameraKit.Constants.VIDEO_QUALITY_2160P:
try {
camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_2160P);
} catch (Exception e) {
return getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_HIGHEST);
}
break;
case CameraKit.Constants.VIDEO_QUALITY_HIGHEST:
camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
break;
case CameraKit.Constants.VIDEO_QUALITY_LOWEST:
camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);
break;
}
return camcorderProfile;
}
void setTapToAutofocusListener(Camera.AutoFocusCallback callback) {
if (this.mFocus != FOCUS_TAP) {
throw new IllegalArgumentException("Please set the camera to FOCUS_TAP.");

@ -119,6 +119,11 @@ class Camera2 extends CameraImpl {
}
@Override
void setVideoQuality(int videoQuality) {
}
@Override
void captureImage() {

@ -20,6 +20,7 @@ abstract class CameraImpl {
abstract void setFocus(@Focus int focus);
abstract void setMethod(@Method int method);
abstract void setZoom(@Zoom int zoom);
abstract void setVideoQuality(@VideoQuality int videoQuality);
abstract void captureImage();
abstract void startVideo();

@ -38,6 +38,13 @@ public class CameraKit {
public static final int PERMISSIONS_LAZY = 1;
public static final int PERMISSIONS_PICTURE = 2;
public static final int VIDEO_QUALITY_480P = 0;
public static final int VIDEO_QUALITY_720P = 1;
public static final int VIDEO_QUALITY_1080P = 2;
public static final int VIDEO_QUALITY_2160P = 3;
public static final int VIDEO_QUALITY_HIGHEST = 4;
public static final int VIDEO_QUALITY_LOWEST = 5;
}
static class Defaults {
@ -48,6 +55,7 @@ public class CameraKit {
static final int DEFAULT_ZOOM = Constants.ZOOM_OFF;
static final int DEFAULT_METHOD = Constants.METHOD_STANDARD;
static final int DEFAULT_PERMISSIONS = Constants.PERMISSIONS_STRICT;
static final int DEFAULT_VIDEO_QUALITY = Constants.VIDEO_QUALITY_480P;
static final int DEFAULT_JPEG_QUALITY = 100;
static final boolean DEFAULT_CROP_OUTPUT = false;

@ -53,6 +53,9 @@ public class CameraView extends FrameLayout {
@Permissions
private int mPermissions;
@VideoQuality
private int mVideoQuality;
private int mJpegQuality;
private boolean mCropOutput;
private boolean mAdjustViewBounds;
@ -83,6 +86,7 @@ public class CameraView extends FrameLayout {
mMethod = a.getInteger(R.styleable.CameraView_ckMethod, CameraKit.Defaults.DEFAULT_METHOD);
mZoom = a.getInteger(R.styleable.CameraView_ckZoom, CameraKit.Defaults.DEFAULT_ZOOM);
mPermissions = a.getInteger(R.styleable.CameraView_ckPermissions, CameraKit.Defaults.DEFAULT_PERMISSIONS);
mVideoQuality = a.getInteger(R.styleable.CameraView_ckVideoQuality, CameraKit.Defaults.DEFAULT_VIDEO_QUALITY);
mJpegQuality = a.getInteger(R.styleable.CameraView_ckJpegQuality, CameraKit.Defaults.DEFAULT_JPEG_QUALITY);
mCropOutput = a.getBoolean(R.styleable.CameraView_ckCropOutput, CameraKit.Defaults.DEFAULT_CROP_OUTPUT);
mAdjustViewBounds = a.getBoolean(R.styleable.CameraView_android_adjustViewBounds, CameraKit.Defaults.DEFAULT_ADJUST_VIEW_BOUNDS);
@ -102,6 +106,7 @@ public class CameraView extends FrameLayout {
setMethod(mMethod);
setZoom(mZoom);
setPermissions(mPermissions);
setVideoQuality(mVideoQuality);
mDisplayOrientationDetector = new DisplayOrientationDetector(context) {
@Override
@ -256,6 +261,11 @@ public class CameraView extends FrameLayout {
this.mPermissions = permissions;
}
public void setVideoQuality(@VideoQuality int videoQuality) {
this.mVideoQuality = videoQuality;
mCameraImpl.setVideoQuality(mVideoQuality);
}
public void setJpegQuality(int jpegQuality) {
this.mJpegQuality = jpegQuality;
}

@ -43,6 +43,15 @@
<enum name="picture" value="2" />
</attr>
<attr name="ckVideoQuality" format="enum">
<enum name="max480p" value="0" />
<enum name="max720p" value="1" />
<enum name="max1080p" value="2" />
<enum name="max2160p" value="3" />
<enum name="highest" value="4" />
<enum name="lowest" value="5" />
</attr>
<attr name="ckJpegQuality" format="integer" />
<attr name="ckCropOutput" format="boolean" />

@ -0,0 +1,18 @@
package com.flurgle.camerakit;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static com.flurgle.camerakit.CameraKit.Constants.VIDEO_QUALITY_1080P;
import static com.flurgle.camerakit.CameraKit.Constants.VIDEO_QUALITY_2160P;
import static com.flurgle.camerakit.CameraKit.Constants.VIDEO_QUALITY_480P;
import static com.flurgle.camerakit.CameraKit.Constants.VIDEO_QUALITY_720P;
import static com.flurgle.camerakit.CameraKit.Constants.VIDEO_QUALITY_HIGHEST;
import static com.flurgle.camerakit.CameraKit.Constants.VIDEO_QUALITY_LOWEST;
@Retention(RetentionPolicy.SOURCE)
@IntDef({VIDEO_QUALITY_480P, VIDEO_QUALITY_720P, VIDEO_QUALITY_1080P, VIDEO_QUALITY_2160P, VIDEO_QUALITY_HIGHEST, VIDEO_QUALITY_LOWEST})
public @interface VideoQuality {
}
Loading…
Cancel
Save