|
@ -8,6 +8,7 @@ import android.os.Environment; |
|
|
|
|
|
|
|
|
import com.jiangdg.libusbcamera.R; |
|
|
import com.jiangdg.libusbcamera.R; |
|
|
import com.serenegiant.usb.DeviceFilter; |
|
|
import com.serenegiant.usb.DeviceFilter; |
|
|
|
|
|
import com.serenegiant.usb.Size; |
|
|
import com.serenegiant.usb.USBMonitor; |
|
|
import com.serenegiant.usb.USBMonitor; |
|
|
import com.serenegiant.usb.common.AbstractUVCCameraHandler; |
|
|
import com.serenegiant.usb.common.AbstractUVCCameraHandler; |
|
|
import com.serenegiant.usb.common.UVCCameraHandler; |
|
|
import com.serenegiant.usb.common.UVCCameraHandler; |
|
@ -194,9 +195,7 @@ public class USBCameraManager{ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// 返回USB设备列表数量
|
|
|
* 返回 |
|
|
|
|
|
* */ |
|
|
|
|
|
public int getUsbDeviceCount(){ |
|
|
public int getUsbDeviceCount(){ |
|
|
List<UsbDevice> devList = getUsbDeviceList(); |
|
|
List<UsbDevice> devList = getUsbDeviceList(); |
|
|
if(devList==null || devList.size() ==0){ |
|
|
if(devList==null || devList.size() ==0){ |
|
@ -205,6 +204,7 @@ public class USBCameraManager{ |
|
|
return devList.size(); |
|
|
return devList.size(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 返回USB设备列表
|
|
|
private List<UsbDevice> getUsbDeviceList(){ |
|
|
private List<UsbDevice> getUsbDeviceList(){ |
|
|
List<DeviceFilter> deviceFilters = DeviceFilter.getDeviceFilters(mContext, R.xml.device_filter); |
|
|
List<DeviceFilter> deviceFilters = DeviceFilter.getDeviceFilters(mContext, R.xml.device_filter); |
|
|
if(mUSBMonitor == null || deviceFilters == null) |
|
|
if(mUSBMonitor == null || deviceFilters == null) |
|
@ -212,28 +212,28 @@ public class USBCameraManager{ |
|
|
return mUSBMonitor.getDeviceList(deviceFilters.get(0)); |
|
|
return mUSBMonitor.getDeviceList(deviceFilters.get(0)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// 拍照
|
|
|
* 抓拍照片 |
|
|
|
|
|
* */ |
|
|
|
|
|
public void capturePicture(String savePath){ |
|
|
public void capturePicture(String savePath){ |
|
|
if(mCameraHandler != null && mCameraHandler.isOpened()){ |
|
|
if(mCameraHandler != null && mCameraHandler.isOpened()){ |
|
|
mCameraHandler.captureStill(savePath); |
|
|
mCameraHandler.captureStill(savePath); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 开始录像
|
|
|
public void startRecording(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener){ |
|
|
public void startRecording(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener){ |
|
|
if(mCameraHandler != null && ! isRecording()){ |
|
|
if(mCameraHandler != null && ! isRecording()){ |
|
|
mCameraHandler.startRecording(params,listener); |
|
|
mCameraHandler.startRecording(params,listener); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 停止录像
|
|
|
public void stopRecording(){ |
|
|
public void stopRecording(){ |
|
|
if(mCameraHandler != null && isRecording()){ |
|
|
if(mCameraHandler != null && isRecording()){ |
|
|
mCameraHandler.stopRecording(); |
|
|
mCameraHandler.stopRecording(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 是否正在录像
|
|
|
public boolean isRecording(){ |
|
|
public boolean isRecording(){ |
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
return mCameraHandler.isRecording(); |
|
|
return mCameraHandler.isRecording(); |
|
@ -241,6 +241,7 @@ public class USBCameraManager{ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 是否打开Camera
|
|
|
public boolean isCameraOpened(){ |
|
|
public boolean isCameraOpened(){ |
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
return mCameraHandler.isOpened(); |
|
|
return mCameraHandler.isOpened(); |
|
@ -248,11 +249,7 @@ public class USBCameraManager{ |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 释放资源
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 释放资源 |
|
|
|
|
|
* */ |
|
|
|
|
|
public void release(){ |
|
|
public void release(){ |
|
|
// 关闭摄像头
|
|
|
// 关闭摄像头
|
|
|
closeCamera(); |
|
|
closeCamera(); |
|
@ -272,23 +269,39 @@ public class USBCameraManager{ |
|
|
return mUSBMonitor; |
|
|
return mUSBMonitor; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 关闭Camera
|
|
|
public void closeCamera() { |
|
|
public void closeCamera() { |
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.close(); |
|
|
mCameraHandler.close(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 打开Camera
|
|
|
private void openCamera(USBMonitor.UsbControlBlock ctrlBlock) { |
|
|
private void openCamera(USBMonitor.UsbControlBlock ctrlBlock) { |
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.open(ctrlBlock); |
|
|
mCameraHandler.open(ctrlBlock); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 开始预览
|
|
|
public void startPreview(CameraViewInterface cameraView,AbstractUVCCameraHandler.OnPreViewResultListener mPreviewListener) { |
|
|
public void startPreview(CameraViewInterface cameraView,AbstractUVCCameraHandler.OnPreViewResultListener mPreviewListener) { |
|
|
SurfaceTexture st = cameraView.getSurfaceTexture(); |
|
|
SurfaceTexture st = cameraView.getSurfaceTexture(); |
|
|
if(mCameraHandler != null){ |
|
|
if(mCameraHandler != null){ |
|
|
mCameraHandler.startPreview(st,mPreviewListener); |
|
|
mCameraHandler.startPreview(st,mPreviewListener); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Camera对焦
|
|
|
|
|
|
public void startCameraFoucs(){ |
|
|
|
|
|
if(mCameraHandler != null){ |
|
|
|
|
|
mCameraHandler.startCameraFoucs(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取Camera支持的所有分辨率参数
|
|
|
|
|
|
public List<Size> getSupportedPreviewSizes(){ |
|
|
|
|
|
if(mCameraHandler == null) |
|
|
|
|
|
return null; |
|
|
|
|
|
return mCameraHandler.getSupportedPreviewSizes(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|