|
@ -130,15 +130,13 @@ public class USBCameraManager{ |
|
|
public void createUVCCamera(CameraViewInterface cameraView) { |
|
|
public void createUVCCamera(CameraViewInterface cameraView) { |
|
|
if(cameraView == null) |
|
|
if(cameraView == null) |
|
|
throw new NullPointerException("CameraViewInterface cannot be null!"); |
|
|
throw new NullPointerException("CameraViewInterface cannot be null!"); |
|
|
this.cameraView = cameraView; |
|
|
|
|
|
// 关闭摄像头
|
|
|
|
|
|
closeCamera(); |
|
|
|
|
|
// 释放CameraHandler占用的相关资源
|
|
|
// 释放CameraHandler占用的相关资源
|
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.release(); |
|
|
mCameraHandler.release(); |
|
|
mCameraHandler = null; |
|
|
mCameraHandler = null; |
|
|
} |
|
|
} |
|
|
// 重新初始化mCameraHandler
|
|
|
// 重新初始化mCameraHandler
|
|
|
|
|
|
this.cameraView = cameraView; |
|
|
cameraView.setAspectRatio(previewWidth / (float)previewHeight); |
|
|
cameraView.setAspectRatio(previewWidth / (float)previewHeight); |
|
|
mCameraHandler = UVCCameraHandler.createHandler(mActivity,cameraView,ENCODER_TYPE, |
|
|
mCameraHandler = UVCCameraHandler.createHandler(mActivity,cameraView,ENCODER_TYPE, |
|
|
previewWidth,previewHeight,PREVIEW_FORMAT); |
|
|
previewWidth,previewHeight,PREVIEW_FORMAT); |
|
@ -152,8 +150,6 @@ public class USBCameraManager{ |
|
|
} |
|
|
} |
|
|
this.previewWidth = width; |
|
|
this.previewWidth = width; |
|
|
this.previewHeight = height; |
|
|
this.previewHeight = height; |
|
|
// 关闭摄像头
|
|
|
|
|
|
closeCamera(); |
|
|
|
|
|
// 释放CameraHandler占用的相关资源
|
|
|
// 释放CameraHandler占用的相关资源
|
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.release(); |
|
|
mCameraHandler.release(); |
|
@ -176,17 +172,6 @@ public class USBCameraManager{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void restartUSBCamera(CameraViewInterface cameraView,final OnPreviewListener mPreviewListener){ |
|
|
public void restartUSBCamera(CameraViewInterface cameraView,final OnPreviewListener mPreviewListener){ |
|
|
// // 关闭摄像头
|
|
|
|
|
|
// closeCamera();
|
|
|
|
|
|
// // 释放CameraHandler占用的相关资源
|
|
|
|
|
|
// if(mCameraHandler != null){
|
|
|
|
|
|
// mCameraHandler.release();
|
|
|
|
|
|
// mCameraHandler = null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // 重新初始化mCameraHandler
|
|
|
|
|
|
// cameraView.setAspectRatio(previewWidth / (float)previewHeight);
|
|
|
|
|
|
// mCameraHandler = UVCCameraHandler.createHandler(activity,cameraView,ENCODER_TYPE,
|
|
|
|
|
|
// previewWidth,previewHeight,PREVIEW_FORMAT);
|
|
|
|
|
|
// 创建Camera管理线程
|
|
|
// 创建Camera管理线程
|
|
|
createUVCCamera(cameraView); |
|
|
createUVCCamera(cameraView); |
|
|
// 创建Camera
|
|
|
// 创建Camera
|
|
@ -293,8 +278,6 @@ public class USBCameraManager{ |
|
|
|
|
|
|
|
|
// 释放资源
|
|
|
// 释放资源
|
|
|
public void release(){ |
|
|
public void release(){ |
|
|
// 关闭摄像头
|
|
|
|
|
|
closeCamera(); |
|
|
|
|
|
//释放CameraHandler占用的相关资源
|
|
|
//释放CameraHandler占用的相关资源
|
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.release(); |
|
|
mCameraHandler.release(); |
|
@ -314,7 +297,7 @@ public class USBCameraManager{ |
|
|
// 关闭Camera
|
|
|
// 关闭Camera
|
|
|
public void closeCamera() { |
|
|
public void closeCamera() { |
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.close(); |
|
|
mCameraHandler.release(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|