Moved VideoQuality to enums

pull/1/head
Mattia Iavarone 7 years ago
parent 324f0c8a47
commit b65e9e446d
  1. 26
      README.md
  2. 18
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  3. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraConstants.java
  4. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  5. 21
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  6. 86
      cameraview/src/main/options/com/otaliastudios/cameraview/VideoQuality.java
  7. 14
      cameraview/src/main/res/values/attrs.xml
  8. 17
      demo/src/main/java/com/otaliastudios/cameraview/demo/MainActivity.java

@ -297,7 +297,7 @@ Most camera parameters can be controlled through XML attributes or linked method
|[`cameraGrid`](#cameragrid)|`setGrid()`|`off` `draw3x3` `draw4x4` `drawPhi`|`off`|
|[`cameraCropOutput`](#cameracropoutput)|`setCropOutput()`|`true` `false`|`false`|
|[`cameraJpegQuality`](#camerajpegquality)|`setJpegQuality()`|`0 <= n <= 100`|`100`|
|[`cameraVideoQuality`](#cameravideoquality)|`setVideoQuality()`|`max480p` `max720p` `max1080p` `max2160p` `highest` `lowest`|`max480p`|
|[`cameraVideoQuality`](#cameravideoquality)|`setVideoQuality()`|`lowest` `highest` `maxQvga` `max480p` `max720p` `max1080p` `max2160p`|`max480p`|
|[`cameraWhiteBalance`](#camerawhitebalance)|`setWhiteBalance()`|`auto` `incandescent` `fluorescent` `daylight` `cloudy`|`auto`|
#### cameraSessionType
@ -364,13 +364,13 @@ cameraView.setJpegQuality(50);
Sets the desired video quality.
```java
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_480P);
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_720P);
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_1080P);
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_2160P);
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_LOWEST);
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_HIGHEST);
cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_QVGA);
cameraView.setVideoQuality(VideoQuality.LOWEST);
cameraView.setVideoQuality(VideoQuality.HIGHEST);
cameraView.setVideoQuality(VideoQuality.MAX_QVGA);
cameraView.setVideoQuality(VideoQuality.MAX_480P);
cameraView.setVideoQuality(VideoQuality.MAX_720P);
cameraView.setVideoQuality(VideoQuality.MAX_1080P);
cameraView.setVideoQuality(VideoQuality.MAX_2160P);
```
#### cameraWhiteBalance
@ -378,11 +378,11 @@ cameraView.setVideoQuality(CameraConstants.VIDEO_QUALITY_QVGA);
Sets the desired white balance for the current session.
```java
cameraView.setWhiteBalance(CameraConstants.WHITE_BALANCE_AUTO);
cameraView.setWhiteBalance(CameraConstants.WHITE_BALANCE_INCANDESCENT);
cameraView.setWhiteBalance(CameraConstants.WHITE_BALANCE_FLUORESCENT);
cameraView.setWhiteBalance(CameraConstants.WHITE_BALANCE_DAYLIGHT);
cameraView.setWhiteBalance(CameraConstants.WHITE_BALANCE_CLOUDY);
cameraView.setWhiteBalance(WhiteBalance.AUTO);
cameraView.setWhiteBalance(WhiteBalance.INCANDESCENT);
cameraView.setWhiteBalance(WhiteBalance.FLUORESCENT);
cameraView.setWhiteBalance(WhiteBalance.DAYLIGHT);
cameraView.setWhiteBalance(WhiteBalance.CLOUDY);
```
## Other APIs

@ -321,7 +321,7 @@ class Camera1 extends CameraController {
@Override
void setVideoQuality(int videoQuality) {
void setVideoQuality(VideoQuality videoQuality) {
if (mIsCapturingVideo) {
throw new IllegalStateException("Can't change video quality while recording a video.");
}
@ -588,43 +588,43 @@ class Camera1 extends CameraController {
@NonNull
private CamcorderProfile getCamcorderProfile(@VideoQuality int videoQuality) {
private CamcorderProfile getCamcorderProfile(VideoQuality videoQuality) {
switch (videoQuality) {
case CameraConstants.VIDEO_QUALITY_HIGHEST:
case HIGHEST:
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
case CameraConstants.VIDEO_QUALITY_2160P:
case MAX_2160P:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_2160P)) {
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_2160P);
}
// Don't break.
case CameraConstants.VIDEO_QUALITY_1080P:
case MAX_1080P:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) {
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_1080P);
}
// Don't break.
case CameraConstants.VIDEO_QUALITY_720P:
case MAX_720P:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_720P)) {
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_720P);
}
// Don't break.
case CameraConstants.VIDEO_QUALITY_480P:
case MAX_480P:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) {
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_480P);
}
// Don't break.
case CameraConstants.VIDEO_QUALITY_QVGA:
case MAX_QVGA:
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_QVGA)) {
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_QVGA);
}
// Don't break.
case CameraConstants.VIDEO_QUALITY_LOWEST:
case LOWEST:
default:
// Fallback to lowest.
return CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);

@ -10,17 +10,9 @@ public class CameraConstants {
public static final int SESSION_TYPE_PICTURE = 0;
public static final int SESSION_TYPE_VIDEO = 1;
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;
public static final int VIDEO_QUALITY_QVGA = 6;
static class Defaults {
static final int DEFAULT_VIDEO_QUALITY = VIDEO_QUALITY_480P;
static final int DEFAULT_SESSION_TYPE = SESSION_TYPE_PICTURE;
static final int DEFAULT_JPEG_QUALITY = 100;
static final boolean DEFAULT_CROP_OUTPUT = false;

@ -14,7 +14,7 @@ abstract class CameraController implements Preview.SurfaceCallback {
protected Facing mFacing;
protected Flash mFlash;
protected WhiteBalance mWhiteBalance;
@VideoQuality protected int mVideoQuality;
protected VideoQuality mVideoQuality;
@SessionType protected int mSessionType;
CameraController(CameraView.CameraCallbacks callback, Preview preview) {
@ -34,7 +34,7 @@ abstract class CameraController implements Preview.SurfaceCallback {
abstract void setFacing(Facing facing);
abstract void setFlash(Flash flash);
abstract void setWhiteBalance(WhiteBalance whiteBalance);
abstract void setVideoQuality(@VideoQuality int videoQuality);
abstract void setVideoQuality(VideoQuality videoQuality);
abstract void setSessionType(@SessionType int sessionType);
abstract void setLocation(double latitude, double longitude);
@ -56,11 +56,7 @@ abstract class CameraController implements Preview.SurfaceCallback {
final Facing getFacing() { return mFacing; }
final Flash getFlash() { return mFlash; }
final WhiteBalance getWhiteBalance() { return mWhiteBalance; }
@VideoQuality
final int getVideoQuality() {
return mVideoQuality;
}
final VideoQuality getVideoQuality() { return mVideoQuality; }
@SessionType
final int getSessionType() {

@ -96,8 +96,8 @@ public class CameraView extends FrameLayout {
Flash flash = Flash.fromValue(a.getInteger(R.styleable.CameraView_cameraFlash, Flash.DEFAULT.value()));
Grid grid = Grid.fromValue(a.getInteger(R.styleable.CameraView_cameraGrid, Grid.DEFAULT.value()));
WhiteBalance whiteBalance = WhiteBalance.fromValue(a.getInteger(R.styleable.CameraView_cameraWhiteBalance, WhiteBalance.DEFAULT.value()));
VideoQuality videoQuality = VideoQuality.fromValue(a.getInteger(R.styleable.CameraView_cameraVideoQuality, VideoQuality.DEFAULT.value()));
int sessionType = a.getInteger(R.styleable.CameraView_cameraSessionType, Defaults.DEFAULT_SESSION_TYPE);
int videoQuality = a.getInteger(R.styleable.CameraView_cameraVideoQuality, Defaults.DEFAULT_VIDEO_QUALITY);
mJpegQuality = a.getInteger(R.styleable.CameraView_cameraJpegQuality, Defaults.DEFAULT_JPEG_QUALITY);
mCropOutput = a.getBoolean(R.styleable.CameraView_cameraCropOutput, Defaults.DEFAULT_CROP_OUTPUT);
GestureAction tapGesture = GestureAction.fromValue(a.getInteger(R.styleable.CameraView_cameraGestureTap, GestureAction.DEFAULT_TAP.value()));
@ -838,17 +838,17 @@ public class CameraView extends FrameLayout {
* If it's not, a lower quality will be chosen, until a supported one is found.
* If sessionType is video, this might trigger a camera restart and a change in preview size.
*
* @see CameraConstants#VIDEO_QUALITY_LOWEST
* @see CameraConstants#VIDEO_QUALITY_QVGA
* @see CameraConstants#VIDEO_QUALITY_480P
* @see CameraConstants#VIDEO_QUALITY_720P
* @see CameraConstants#VIDEO_QUALITY_1080P
* @see CameraConstants#VIDEO_QUALITY_2160P
* @see CameraConstants#VIDEO_QUALITY_HIGHEST
* @see VideoQuality#LOWEST
* @see VideoQuality#HIGHEST
* @see VideoQuality#MAX_QVGA
* @see VideoQuality#MAX_480P
* @see VideoQuality#MAX_720P
* @see VideoQuality#MAX_1080P
* @see VideoQuality#MAX_2160P
*
* @param videoQuality requested video quality
*/
public void setVideoQuality(@VideoQuality int videoQuality) {
public void setVideoQuality(VideoQuality videoQuality) {
mCameraController.setVideoQuality(videoQuality);
}
@ -857,8 +857,7 @@ public class CameraView extends FrameLayout {
* Gets the current video quality.
* @return the current video quality
*/
@VideoQuality
public int getVideoQuality() {
public VideoQuality getVideoQuality() {
return mCameraController.getVideoQuality();
}

@ -1,19 +1,73 @@
package com.otaliastudios.cameraview;
import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_1080P;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_2160P;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_480P;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_720P;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_HIGHEST;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_LOWEST;
import static com.otaliastudios.cameraview.CameraConstants.VIDEO_QUALITY_QVGA;
@Retention(RetentionPolicy.SOURCE)
@IntDef({VIDEO_QUALITY_QVGA, VIDEO_QUALITY_480P, VIDEO_QUALITY_720P, VIDEO_QUALITY_1080P, VIDEO_QUALITY_2160P, VIDEO_QUALITY_HIGHEST, VIDEO_QUALITY_LOWEST})
public @interface VideoQuality {
/**
* Constants for selecting the quality of video recordings.
*
* @see CameraView#setVideoQuality(VideoQuality)
*/
public enum VideoQuality {
/**
* Quality level corresponding to the lowest available resolution.
*/
LOWEST(0),
/**
* Quality level corresponding to the highest available resolution.
*/
HIGHEST(1),
/**
* Quality level corresponding to the QVGA (320x240) resolution.
*/
MAX_QVGA(2),
/**
* Quality level corresponding to the 480p (720 x 480) resolution.
* Note that the horizontal resolution for 480p can also be other
* values, such as 640 or 704, instead of 720.
*/
MAX_480P(3),
/**
* Quality level corresponding to the 720p (1280 x 720) resolution.
*/
MAX_720P(4),
/**
* Quality level corresponding to the 1080p (1920 x 1080) resolution.
* Note that the vertical resolution for 1080p can also be 1088,
* instead of 1080 (used by some vendors to avoid cropping during
* video playback).
*/
MAX_1080P(5),
/**
* Quality level corresponding to the 2160p (3840x2160) resolution.
*/
MAX_2160P(6);
static final VideoQuality DEFAULT = MAX_480P;
private int value;
VideoQuality(int value) {
this.value = value;
}
int value() {
return value;
}
static VideoQuality fromValue(int value) {
VideoQuality[] list = VideoQuality.values();
for (VideoQuality action : list) {
if (action.value() == value) {
return action;
}
}
return null;
}
}

@ -62,13 +62,13 @@
<attr name="cameraJpegQuality" format="integer" />
<attr name="cameraVideoQuality" 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" />
<enum name="qvga" value="6" />
<enum name="lowest" value="0" />
<enum name="highest" value="1" />
<enum name="maxQvga" value="2" />
<enum name="max480p" value="3" />
<enum name="max720p" value="4" />
<enum name="max1080p" value="5" />
<enum name="max2160p" value="6" />
</attr>
<attr name="cameraCropOutput" format="boolean" />

@ -19,6 +19,7 @@ import com.otaliastudios.cameraview.CameraView;
import com.otaliastudios.cameraview.Facing;
import com.otaliastudios.cameraview.Grid;
import com.otaliastudios.cameraview.Size;
import com.otaliastudios.cameraview.VideoQuality;
import java.io.File;
@ -238,15 +239,15 @@ public class MainActivity extends AppCompatActivity implements View.OnLayoutChan
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (mCapturingVideo) return;
int videoQuality = CameraConstants.VIDEO_QUALITY_HIGHEST;
VideoQuality videoQuality = VideoQuality.HIGHEST;
switch (checkedId) {
case R.id.videoQualityLowest: videoQuality = CameraConstants.VIDEO_QUALITY_LOWEST; break;
case R.id.videoQualityQvga: videoQuality = CameraConstants.VIDEO_QUALITY_QVGA; break;
case R.id.videoQuality480p: videoQuality = CameraConstants.VIDEO_QUALITY_480P; break;
case R.id.videoQuality720p: videoQuality = CameraConstants.VIDEO_QUALITY_720P; break;
case R.id.videoQuality1080p: videoQuality = CameraConstants.VIDEO_QUALITY_1080P; break;
case R.id.videoQuality2160p: videoQuality = CameraConstants.VIDEO_QUALITY_2160P; break;
case R.id.videoQualityHighest: videoQuality = CameraConstants.VIDEO_QUALITY_HIGHEST; break;
case R.id.videoQualityLowest: videoQuality = VideoQuality.LOWEST; break;
case R.id.videoQualityQvga: videoQuality = VideoQuality.MAX_QVGA; break;
case R.id.videoQuality480p: videoQuality = VideoQuality.MAX_480P; break;
case R.id.videoQuality720p: videoQuality = VideoQuality.MAX_720P; break;
case R.id.videoQuality1080p: videoQuality = VideoQuality.MAX_1080P; break;
case R.id.videoQuality2160p: videoQuality = VideoQuality.MAX_2160P; break;
case R.id.videoQualityHighest: videoQuality = VideoQuality.HIGHEST; break;
}
camera.setVideoQuality(videoQuality);
message("Video quality changed!", false);

Loading…
Cancel
Save