Camera size validity check

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent 65472cc5c1
commit 6307f6c5ad

@ -194,26 +194,18 @@ public class MainActivity extends Activity implements SurfaceHolder.Callback, Ca
} }
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
/* preview size */
Size size = mCamera.new Size(SrsEncoder.VWIDTH, SrsEncoder.VHEIGHT);
if (!params.getSupportedPreviewSizes().contains(size)) {
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
new IllegalArgumentException(String.format("Unsupported preview size %dx%d", size.width, size.height)));
}
/* supported preview fps range */ /* picture size */
// List<int[]> spfr = params.getSupportedPreviewFpsRange(); if (!params.getSupportedPictureSizes().contains(size)) {
// Log.i("Cam", "! Supported Preview Fps Range:"); Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(),
// int rn = 0; new IllegalArgumentException(String.format("Unsupported picture size %dx%d", size.width, size.height)));
// for (int[] r : spfr) { }
// Log.i("Cam", "\tRange [" + rn++ + "]: " + r[0] + "~" + r[1]);
// }
// /* preview size */
// List<Size> sizes = params.getSupportedPreviewSizes();
// Log.i("Cam", "! Supported Preview Size:");
// for (int i = 0; i < sizes.size(); i++) {
// Log.i("Cam", "\tSize [" + i + "]: " + sizes.get(i).width + "x" + sizes.get(i).height);
// }
// /* picture size */
// sizes = params.getSupportedPictureSizes();
// Log.i("Cam", "! Supported Picture Size:");
// for (int i = 0; i < sizes.size(); i++) {
// Log.i("Cam", "\tSize [" + i + "]: " + sizes.get(i).width + "x" + sizes.get(i).height);
// }
/***** set parameters *****/ /***** set parameters *****/
//params.set("orientation", "portrait"); //params.set("orientation", "portrait");

@ -26,7 +26,7 @@ public class SrsEncoder {
public static int vbitrate = 500 * 1000; // 500kbps public static int vbitrate = 500 * 1000; // 500kbps
public static final int VENC_WIDTH = 384; // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK public static final int VENC_WIDTH = 384; // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
public static final int VENC_HEIGHT = 640; // Since Y component is quadruple size as U and V component, the stride must be set as 32x public static final int VENC_HEIGHT = 640; // Since Y component is quadruple size as U and V component, the stride must be set as 32x
public static final int VFPS = 20; public static final int VFPS = 10;
public static final int VGOP = 10; public static final int VGOP = 10;
public static int VFORMAT = ImageFormat.YV12; public static int VFORMAT = ImageFormat.YV12;
public static final int ASAMPLERATE = 44100; public static final int ASAMPLERATE = 44100;
@ -288,12 +288,12 @@ public class SrsEncoder {
// YUY2 -> YUV422SP yuyv yuyv // YUY2 -> YUV422SP yuyv yuyv
private byte[] cropYUV420SemiPlannerFrame(byte[] input, int iw, int ih, byte[] output, int ow, int oh) { private byte[] cropYUV420SemiPlannerFrame(byte[] input, int iw, int ih, byte[] output, int ow, int oh) {
if (iw < ow || ih < oh) { if (iw < ow || ih < oh) {
throw new AssertionError(); throw new AssertionError("Crop revolution size must be less than original one");
} }
if (ow % 32 != 0 || oh % 32 != 0) { if (ow % 32 != 0 || oh % 32 != 0) {
// Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
// Since Y component is quadruple size as U and V component, the stride must be set as 32x // Since Y component is quadruple size as U and V component, the stride must be set as 32x
throw new AssertionError(); throw new AssertionError("Crop revolution length must be 32x");
} }
int iFrameSize = iw * ih; int iFrameSize = iw * ih;
@ -320,12 +320,12 @@ public class SrsEncoder {
private byte[] cropYUV420PlannerFrame(byte[] input, int iw, int ih, byte[] output, int ow, int oh) { private byte[] cropYUV420PlannerFrame(byte[] input, int iw, int ih, byte[] output, int ow, int oh) {
if (iw < ow || ih < oh) { if (iw < ow || ih < oh) {
throw new AssertionError(); throw new AssertionError("Crop revolution size must be less than original one");
} }
if (ow % 32 != 0 || oh % 32 != 0) { if (ow % 32 != 0 || oh % 32 != 0) {
// Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK // Note: the stride of resolution must be set as 16x for hard encoding with some chip like MTK
// Since Y component is quadruple size as U and V component, the stride must be set as 32x // Since Y component is quadruple size as U and V component, the stride must be set as 32x
throw new AssertionError(); throw new AssertionError("Crop revolution length must be 32x");
} }
int iFrameSize = iw * ih; int iFrameSize = iw * ih;

Loading…
Cancel
Save