[Change]
开始USB摄像头的功能集成,还无法获取usb连接广播需要调试
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
(cherry picked from commit b10306fc45)
This commit is contained in:
@@ -5,7 +5,6 @@ import android.graphics.SurfaceTexture;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.os.Environment;
|
||||
|
||||
import org.easydarwin.sw.TxtOverlay;
|
||||
import com.serenegiant.usb.DeviceFilter;
|
||||
import com.serenegiant.usb.Size;
|
||||
import com.serenegiant.usb.USBMonitor;
|
||||
@@ -15,13 +14,15 @@ import com.serenegiant.usb.common.UVCCameraHandler;
|
||||
import com.serenegiant.usb.encoder.RecordParams;
|
||||
import com.serenegiant.usb.widget.CameraViewInterface;
|
||||
|
||||
import org.easydarwin.sw.TxtOverlay;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/** UVCCamera Helper class
|
||||
*
|
||||
/**
|
||||
* UVCCamera Helper class
|
||||
* <p>
|
||||
* Created by jiangdongguo on 2017/9/30.
|
||||
*/
|
||||
|
||||
@@ -121,8 +122,8 @@ public class UVCCameraHelper {
|
||||
startPreview(mCamView);
|
||||
}
|
||||
}).start();
|
||||
if(listener != null) {
|
||||
listener.onConnectDev(device,true);
|
||||
if (listener != null) {
|
||||
listener.onConnectDev(device, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +155,7 @@ public class UVCCameraHelper {
|
||||
mCameraHandler = null;
|
||||
}
|
||||
// initialize camera handler
|
||||
mCamView.setAspectRatio(previewWidth / (float)previewHeight);
|
||||
mCamView.setAspectRatio(previewWidth / (float) previewHeight);
|
||||
mCameraHandler = UVCCameraHandler.createHandler(mActivity, mCamView, 2,
|
||||
previewWidth, previewHeight, mFrameFormat);
|
||||
}
|
||||
@@ -169,8 +170,8 @@ public class UVCCameraHelper {
|
||||
mCameraHandler.release();
|
||||
mCameraHandler = null;
|
||||
}
|
||||
mCamView.setAspectRatio(previewWidth / (float)previewHeight);
|
||||
mCameraHandler = UVCCameraHandler.createHandler(mActivity,mCamView, 2,
|
||||
mCamView.setAspectRatio(previewWidth / (float) previewHeight);
|
||||
mCameraHandler = UVCCameraHandler.createHandler(mActivity, mCamView, 2,
|
||||
previewWidth, previewHeight, mFrameFormat);
|
||||
openCamera(mCtrlBlock);
|
||||
new Thread(new Runnable() {
|
||||
@@ -222,8 +223,9 @@ public class UVCCameraHelper {
|
||||
return;
|
||||
}
|
||||
int count = devList.size();
|
||||
if (index >= count)
|
||||
if (index >= count) {
|
||||
new IllegalArgumentException("index illegal,should be < devList.size()");
|
||||
}
|
||||
if (mUSBMonitor != null) {
|
||||
mUSBMonitor.requestPermission(getUsbDeviceList().get(index));
|
||||
}
|
||||
@@ -240,21 +242,22 @@ public class UVCCameraHelper {
|
||||
public List<UsbDevice> getUsbDeviceList() {
|
||||
List<DeviceFilter> deviceFilters = DeviceFilter
|
||||
.getDeviceFilters(mActivity.getApplicationContext(), R.xml.device_filter);
|
||||
if (mUSBMonitor == null || deviceFilters == null)
|
||||
// throw new NullPointerException("mUSBMonitor ="+mUSBMonitor+"deviceFilters=;"+deviceFilters);
|
||||
if (mUSBMonitor == null || deviceFilters == null) {
|
||||
// throw new NullPointerException("mUSBMonitor ="+mUSBMonitor+"deviceFilters=;"+deviceFilters);
|
||||
return null;
|
||||
}
|
||||
// matching all of filter devices
|
||||
return mUSBMonitor.getDeviceList(deviceFilters);
|
||||
}
|
||||
|
||||
public void capturePicture(String savePath,AbstractUVCCameraHandler.OnCaptureListener listener) {
|
||||
public void capturePicture(String savePath, AbstractUVCCameraHandler.OnCaptureListener listener) {
|
||||
if (mCameraHandler != null && mCameraHandler.isOpened()) {
|
||||
|
||||
File file = new File(savePath);
|
||||
if(! Objects.requireNonNull(file.getParentFile()).exists()) {
|
||||
if (!Objects.requireNonNull(file.getParentFile()).exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
mCameraHandler.captureStill(savePath,listener);
|
||||
mCameraHandler.captureStill(savePath, listener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +269,7 @@ public class UVCCameraHelper {
|
||||
|
||||
public void startPusher(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener) {
|
||||
if (mCameraHandler != null && !isPushing()) {
|
||||
if(params.isSupportOverlay()) {
|
||||
if (params.isSupportOverlay()) {
|
||||
TxtOverlay.install(mActivity.getApplicationContext());
|
||||
}
|
||||
mCameraHandler.startRecording(params, listener);
|
||||
@@ -309,7 +312,7 @@ public class UVCCameraHelper {
|
||||
}
|
||||
|
||||
public void setOnPreviewFrameListener(AbstractUVCCameraHandler.OnPreViewResultListener listener) {
|
||||
if(mCameraHandler != null) {
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.setOnPreViewResultListener(listener);
|
||||
}
|
||||
}
|
||||
@@ -346,8 +349,8 @@ public class UVCCameraHelper {
|
||||
return mCameraHandler.getSupportedPreviewSizes();
|
||||
}
|
||||
|
||||
public void setDefaultPreviewSize(int defaultWidth,int defaultHeight) {
|
||||
if(mUSBMonitor != null) {
|
||||
public void setDefaultPreviewSize(int defaultWidth, int defaultHeight) {
|
||||
if (mUSBMonitor != null) {
|
||||
throw new IllegalStateException("setDefaultPreviewSize should be call before initMonitor");
|
||||
}
|
||||
this.previewWidth = defaultWidth;
|
||||
@@ -355,7 +358,7 @@ public class UVCCameraHelper {
|
||||
}
|
||||
|
||||
public void setDefaultFrameFormat(int format) {
|
||||
if(mUSBMonitor != null) {
|
||||
if (mUSBMonitor != null) {
|
||||
throw new IllegalStateException("setDefaultFrameFormat should be call before initMonitor");
|
||||
}
|
||||
this.mFrameFormat = format;
|
||||
|
||||
Reference in New Issue
Block a user