|
|
@ -32,7 +32,6 @@ import com.seu.magicfilter.utils.MagicFilterFactory;
|
|
|
|
import com.seu.magicfilter.utils.MagicFilterType;
|
|
|
|
import com.seu.magicfilter.utils.MagicFilterType;
|
|
|
|
import com.seu.magicfilter.utils.OpenGLUtils;
|
|
|
|
import com.seu.magicfilter.utils.OpenGLUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import java.nio.IntBuffer;
|
|
|
|
import java.nio.IntBuffer;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
@ -63,8 +62,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
private float[] mProjectionMatrix = new float[16];
|
|
|
|
private float[] mProjectionMatrix = new float[16];
|
|
|
|
private float[] mSurfaceMatrix = new float[16];
|
|
|
|
private float[] mSurfaceMatrix = new float[16];
|
|
|
|
private float[] mTransformMatrix = new float[16];
|
|
|
|
private float[] mTransformMatrix = new float[16];
|
|
|
|
|
|
|
|
|
|
|
|
private Camera mCamera;
|
|
|
|
|
|
|
|
private ByteBuffer mGLPreviewBuffer;
|
|
|
|
private ByteBuffer mGLPreviewBuffer;
|
|
|
|
private int mCamId = -1;
|
|
|
|
private int mCamId = -1;
|
|
|
|
private int mPreviewRotation = 90;
|
|
|
|
private int mPreviewRotation = 90;
|
|
|
@ -95,6 +92,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
setEGLContextClientVersion(2);
|
|
|
|
setEGLContextClientVersion(2);
|
|
|
|
setRenderer(this);
|
|
|
|
setRenderer(this);
|
|
|
|
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
|
|
|
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
|
|
|
|
|
|
|
|
initCameraData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -114,15 +112,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
requestRender();
|
|
|
|
requestRender();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// For camera preview on activity creation
|
|
|
|
// For camera preview on activity creation
|
|
|
|
if (mCamera != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
mCamera.setPreviewTexture(surfaceTexture);
|
|
|
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
|
|
|
ioe.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -177,32 +167,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
mPrevCb = cb;
|
|
|
|
mPrevCb = cb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Camera getCamera() {
|
|
|
|
|
|
|
|
return this.mCamera;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setPreviewCallback(Camera.PreviewCallback previewCallback) {
|
|
|
|
|
|
|
|
this.mCamera.setPreviewCallback(previewCallback);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置预览宽高
|
|
|
|
|
|
|
|
public int[] setPreviewResolution2(int width, int height) {
|
|
|
|
|
|
|
|
mPreviewWidth = width;
|
|
|
|
|
|
|
|
mPreviewHeight = height;
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// String s = cameraManager.getCameraIdList()[1];
|
|
|
|
|
|
|
|
// CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(s);
|
|
|
|
|
|
|
|
// //获取StreamConfigurationMap,它是管理摄像头支持的所有输出格式和尺寸
|
|
|
|
|
|
|
|
// StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
|
|
|
|
|
|
|
// //根据TextureView的尺寸设置预览尺寸
|
|
|
|
|
|
|
|
// Size mPreviewSize = getOptimalSize(map.getOutputSizes(SurfaceTexture.class), width, height);
|
|
|
|
|
|
|
|
// mPreviewWidth = mPreviewSize.getWidth();
|
|
|
|
|
|
|
|
// mPreviewHeight = mPreviewSize.getHeight();
|
|
|
|
|
|
|
|
return new int[]{mPreviewWidth, mPreviewHeight};
|
|
|
|
|
|
|
|
// } catch (CameraAccessException e) {
|
|
|
|
|
|
|
|
// throw new RuntimeException(e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//选择sizeMap中大于并且接近width和height的size
|
|
|
|
//选择sizeMap中大于并且接近width和height的size
|
|
|
|
private Size getOptimalSize(Size[] outputSizes, int width, int height) {
|
|
|
|
private Size getOptimalSize(Size[] outputSizes, int width, int height) {
|
|
|
@ -250,6 +214,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
public int[] setPreviewResolution(int width, int height) {
|
|
|
|
public int[] setPreviewResolution(int width, int height) {
|
|
|
|
// mCamera = openCamera();
|
|
|
|
// mCamera = openCamera();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPreviewWidth = width;
|
|
|
|
mPreviewWidth = width;
|
|
|
|
mPreviewHeight = height;
|
|
|
|
mPreviewHeight = height;
|
|
|
|
// Camera.Size rs = adaptPreviewResolution(mCamera.new Size(width, height));
|
|
|
|
// Camera.Size rs = adaptPreviewResolution(mCamera.new Size(width, height));
|
|
|
@ -269,9 +234,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean setFilter(final MagicFilterType type) {
|
|
|
|
public boolean setFilter(final MagicFilterType type) {
|
|
|
|
if (mCamera == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queueEvent(new Runnable() {
|
|
|
|
queueEvent(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -309,12 +271,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
setPreviewOrientation(mPreviewOrientation);
|
|
|
|
setPreviewOrientation(mPreviewOrientation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setCameraId2(int id) {
|
|
|
|
|
|
|
|
stopTorch();
|
|
|
|
|
|
|
|
mCamId = id;
|
|
|
|
|
|
|
|
setPreviewOrientation(mPreviewOrientation);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int getRotateDeg() {
|
|
|
|
protected int getRotateDeg() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int rotate = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRotation();
|
|
|
|
int rotate = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRotation();
|
|
|
@ -337,49 +293,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
|
|
|
|
|
|
|
|
public void setPreviewOrientation(int orientation) {
|
|
|
|
public void setPreviewOrientation(int orientation) {
|
|
|
|
mPreviewOrientation = orientation;
|
|
|
|
mPreviewOrientation = orientation;
|
|
|
|
try {
|
|
|
|
setRotation(180);
|
|
|
|
String s = cameraManager.getCameraIdList()[1];
|
|
|
|
|
|
|
|
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(s);
|
|
|
|
|
|
|
|
Integer integer = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING);
|
|
|
|
|
|
|
|
if (integer == CameraCharacteristics.LENS_FACING_BACK) {
|
|
|
|
|
|
|
|
Log.e("yyy", "fds");
|
|
|
|
|
|
|
|
} else if (integer == CameraCharacteristics.LENS_FACING_BACK) {
|
|
|
|
|
|
|
|
Log.e("yyy", "fds");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.e("yyy", "fds");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (CameraAccessException e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setPreviewOrientation2(int orientation) {
|
|
|
|
|
|
|
|
mPreviewOrientation = orientation;
|
|
|
|
|
|
|
|
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
|
|
|
|
|
|
Camera.getCameraInfo(mCamId, info);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int rotateDeg = getRotateDeg();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
|
|
|
|
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
|
|
|
|
|
|
|
mPreviewRotation = info.orientation % 360;
|
|
|
|
|
|
|
|
mPreviewRotation = (360 - mPreviewRotation) % 360; // compensate the mirror
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mPreviewRotation = (info.orientation + 360) % 360;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
|
|
|
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
|
|
|
|
|
|
|
mPreviewRotation = (info.orientation - 90) % 360;
|
|
|
|
|
|
|
|
mPreviewRotation = (360 - mPreviewRotation) % 360; // compensate the mirror
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mPreviewRotation = (info.orientation + 90) % 360;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rotateDeg > 0) {
|
|
|
|
|
|
|
|
mPreviewRotation = mPreviewRotation % rotateDeg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getCameraId() {
|
|
|
|
public int getCameraId() {
|
|
|
@ -467,10 +381,9 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
// SurfaceTexture surfaceTexture=new SurfaceTexture();
|
|
|
|
// SurfaceTexture surfaceTexture=new SurfaceTexture();
|
|
|
|
// assert surfaceTexture!=null;
|
|
|
|
// assert surfaceTexture!=null;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// surfaceTexture.setDefaultBufferSize(imageDimension.getWidth(),imageDimension.getHeight());
|
|
|
|
surfaceTexture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
|
|
|
|
//预览的输出画面
|
|
|
|
//预览的输出画面
|
|
|
|
Surface surface = new Surface(surfaceTexture);
|
|
|
|
Surface surface = new Surface(surfaceTexture);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//预览请求
|
|
|
|
//预览请求
|
|
|
|
captureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
|
|
|
|
captureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
|
|
|
@ -514,8 +427,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
curItem = itemlist.get(0);
|
|
|
|
curItem = itemlist.get(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//通过cameraId获取Camera参数
|
|
|
|
//通过cameraId获取Camera参数
|
|
|
|
// String cameraId = curItem.getId();
|
|
|
|
String cameraId = curItem.getId();
|
|
|
|
String cameraId = cameraManager.getCameraIdList()[1];
|
|
|
|
|
|
|
|
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
|
|
|
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
|
|
|
|
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
|
|
|
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
|
|
|
|
imageDimension = map.getOutputSizes(SurfaceTexture.class)[0];
|
|
|
|
imageDimension = map.getOutputSizes(SurfaceTexture.class)[0];
|
|
|
@ -530,135 +442,20 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean startCamera2() {
|
|
|
|
|
|
|
|
// if (mCamera == null) {
|
|
|
|
|
|
|
|
// mCamera = openCamera();
|
|
|
|
|
|
|
|
// if (mCamera == null) {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Camera.Parameters params = mCamera.getParameters();
|
|
|
|
|
|
|
|
//params.setPictureSize(mPreviewWidth, mPreviewHeight);
|
|
|
|
|
|
|
|
params.setPreviewSize(mPreviewWidth, mPreviewHeight);
|
|
|
|
|
|
|
|
int[] range = adaptFpsRange(SrsEncoder.VFPS, params.getSupportedPreviewFpsRange());
|
|
|
|
|
|
|
|
params.setPreviewFpsRange(range[0], range[1]);
|
|
|
|
|
|
|
|
params.setPreviewFormat(ImageFormat.NV21);
|
|
|
|
|
|
|
|
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
|
|
|
|
|
|
|
params.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
|
|
|
|
|
|
|
|
params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
|
|
|
|
|
|
|
|
params.setRecordingHint(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> supportedFocusModes = params.getSupportedFocusModes();
|
|
|
|
|
|
|
|
if (supportedFocusModes != null && !supportedFocusModes.isEmpty()) {
|
|
|
|
|
|
|
|
if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
|
|
|
|
|
|
|
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
|
|
|
|
|
|
|
|
} else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
|
|
|
|
|
|
|
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
|
|
|
|
|
|
|
|
mCamera.autoFocus(null);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
params.setFocusMode(supportedFocusModes.get(0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> supportedFlashModes = params.getSupportedFlashModes();
|
|
|
|
|
|
|
|
if (supportedFlashModes != null && !supportedFlashModes.isEmpty()) {
|
|
|
|
|
|
|
|
if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
|
|
|
|
|
|
|
|
if (mIsTorchOn) {
|
|
|
|
|
|
|
|
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
params.setFlashMode(supportedFlashModes.get(0));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cameraCallbacksHandler.onCameraParameters(params);
|
|
|
|
|
|
|
|
mCamera.setParameters(params);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCamera.setDisplayOrientation(mPreviewRotation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
mCamera.setPreviewTexture(surfaceTexture);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mCamera.startPreview();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stopCamera() {
|
|
|
|
public void stopCamera() {
|
|
|
|
disableEncoding();
|
|
|
|
disableEncoding();
|
|
|
|
stopTorch();
|
|
|
|
stopTorch();
|
|
|
|
mCameraDevice.close();
|
|
|
|
if (cameraCaptureSession != null) {
|
|
|
|
}
|
|
|
|
cameraCaptureSession.close();
|
|
|
|
|
|
|
|
cameraCaptureSession = null;
|
|
|
|
public void stopCamera2() {
|
|
|
|
|
|
|
|
disableEncoding();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stopTorch();
|
|
|
|
|
|
|
|
if (mCamera != null) {
|
|
|
|
|
|
|
|
mCamera.setPreviewCallback(null);
|
|
|
|
|
|
|
|
mCamera.stopPreview();
|
|
|
|
|
|
|
|
mCamera.release();
|
|
|
|
|
|
|
|
mCamera = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCameraDevice != null) {
|
|
|
|
}
|
|
|
|
mCameraDevice.close();
|
|
|
|
|
|
|
|
mCameraDevice = null;
|
|
|
|
protected Camera openCamera2() {
|
|
|
|
|
|
|
|
Camera camera = null;
|
|
|
|
|
|
|
|
if (mCamId < 0) {
|
|
|
|
|
|
|
|
Camera.CameraInfo info = new Camera.CameraInfo();
|
|
|
|
|
|
|
|
int numCameras = Camera.getNumberOfCameras();
|
|
|
|
|
|
|
|
int frontCamId = -1;
|
|
|
|
|
|
|
|
int backCamId = -1;
|
|
|
|
|
|
|
|
int otherCamId = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < numCameras; i++) {
|
|
|
|
|
|
|
|
Camera.getCameraInfo(i, info);
|
|
|
|
|
|
|
|
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
|
|
|
|
|
|
|
|
backCamId = i;
|
|
|
|
|
|
|
|
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
|
|
|
|
|
|
|
|
frontCamId = i;
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
otherCamId = i;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frontCamId != -1) {
|
|
|
|
|
|
|
|
mCamId = frontCamId;
|
|
|
|
|
|
|
|
} else if (backCamId != -1) {
|
|
|
|
|
|
|
|
mCamId = backCamId;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mCamId = otherCamId;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// if (mCamId == 0) {
|
|
|
|
|
|
|
|
// camera = Camera.open(2);
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
camera.stopPreview();
|
|
|
|
|
|
|
|
camera.release();
|
|
|
|
|
|
|
|
camera = Camera.open();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
camera.setErrorCallback(new Camera.ErrorCallback() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onError(int error, Camera camera) {
|
|
|
|
|
|
|
|
//may be Camera.CAMERA_ERROR_EVICTED - Camera was disconnected due to use by higher priority user
|
|
|
|
|
|
|
|
stopCamera();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return camera;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<CameraItemData> getCameraData() {
|
|
|
|
public List<CameraItemData> initCameraData() {
|
|
|
|
itemlist = new ArrayList();
|
|
|
|
itemlist = new ArrayList();
|
|
|
|
cameraManager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);//获取摄像头管理类
|
|
|
|
cameraManager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);//获取摄像头管理类
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -717,21 +514,9 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
return itemlist;
|
|
|
|
return itemlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Camera.Size adaptPreviewResolution(Camera.Size resolution) {
|
|
|
|
|
|
|
|
float diff = 100f;
|
|
|
|
public List<CameraItemData> getCameraData() {
|
|
|
|
float xdy = (float) resolution.width / (float) resolution.height;
|
|
|
|
return itemlist;
|
|
|
|
Camera.Size best = null;
|
|
|
|
|
|
|
|
for (Camera.Size size : mCamera.getParameters().getSupportedPreviewSizes()) {
|
|
|
|
|
|
|
|
if (size.equals(resolution)) {
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
float tmp = Math.abs(((float) size.width / (float) size.height) - xdy);
|
|
|
|
|
|
|
|
if (tmp < diff) {
|
|
|
|
|
|
|
|
diff = tmp;
|
|
|
|
|
|
|
|
best = size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int[] adaptFpsRange(int expectedFps, List<int[]> fpsRanges) {
|
|
|
|
private int[] adaptFpsRange(int expectedFps, List<int[]> fpsRanges) {
|
|
|
@ -750,31 +535,16 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
|
|
|
|
return closestRange;
|
|
|
|
return closestRange;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean startTorch() {
|
|
|
|
|
|
|
|
if (mCamera != null) {
|
|
|
|
|
|
|
|
Camera.Parameters params = mCamera.getParameters();
|
|
|
|
|
|
|
|
List<String> supportedFlashModes = params.getSupportedFlashModes();
|
|
|
|
|
|
|
|
if (supportedFlashModes != null && !supportedFlashModes.isEmpty()) {
|
|
|
|
|
|
|
|
if (supportedFlashModes.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
|
|
|
|
|
|
|
|
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
|
|
|
|
|
|
|
|
mCamera.setParameters(params);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stopTorch() {
|
|
|
|
public void stopTorch() {
|
|
|
|
if (mCamera != null) {
|
|
|
|
// if (mCamera != null) {
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
Camera.Parameters params = mCamera.getParameters();
|
|
|
|
// Camera.Parameters params = mCamera.getParameters();
|
|
|
|
params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
|
|
|
// params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
|
|
|
mCamera.setParameters(params);
|
|
|
|
// mCamera.setParameters(params);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// } catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface PreviewCallback {
|
|
|
|
public interface PreviewCallback {
|
|
|
|