diff --git a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java index 1f28e2d..6873691 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java +++ b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java @@ -16,6 +16,7 @@ import com.jiangdg.usbcamera.FileUtils; import com.jiangdg.usbcamera.R; import com.jiangdg.usbcamera.USBCameraManager; import com.serenegiant.usb.CameraDialog; +import com.serenegiant.usb.Size; import com.serenegiant.usb.USBMonitor; import com.serenegiant.usb.common.AbstractUVCCameraHandler; import com.serenegiant.usb.encoder.RecordParams; @@ -26,6 +27,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; @@ -147,16 +149,19 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog } }); break; - // 开启或关闭Camera + // 点击后自动对焦 case R.id.camera_view: -// if(mUSBManager != null){ -// boolean isOpened = mUSBManager.isCameraOpened(); -// if(! isOpened){ -// CameraDialog.showDialog(USBCameraActivity.this); -// }else { -// mUSBManager.closeCamera(); -// } -// } + if(mUSBManager == null) + return; +// mUSBManager.startCameraFoucs(); +// showShortMsg("对焦相机"); + List list = mUSBManager.getSupportedPreviewSizes(); + StringBuilder sb = new StringBuilder(); + for(Size size:list){ + sb.append(size.width+"x"+size.height); + sb.append("\n"); + } + showShortMsg(sb.toString()); break; case R.id.btn_capture_pic: if(mUSBManager == null || ! mUSBManager.isCameraOpened()){ diff --git a/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java b/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java index 9c72938..4fd4a05 100644 --- a/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java +++ b/libusbcamera/src/main/java/com/jiangdg/usbcamera/USBCameraManager.java @@ -8,6 +8,7 @@ import android.os.Environment; import com.jiangdg.libusbcamera.R; import com.serenegiant.usb.DeviceFilter; +import com.serenegiant.usb.Size; import com.serenegiant.usb.USBMonitor; import com.serenegiant.usb.common.AbstractUVCCameraHandler; import com.serenegiant.usb.common.UVCCameraHandler; @@ -194,9 +195,7 @@ public class USBCameraManager{ } } - /** - * 返回 - * */ + // 返回USB设备列表数量 public int getUsbDeviceCount(){ List devList = getUsbDeviceList(); if(devList==null || devList.size() ==0){ @@ -205,6 +204,7 @@ public class USBCameraManager{ return devList.size(); } + // 返回USB设备列表 private List getUsbDeviceList(){ List deviceFilters = DeviceFilter.getDeviceFilters(mContext, R.xml.device_filter); if(mUSBMonitor == null || deviceFilters == null) @@ -212,28 +212,28 @@ public class USBCameraManager{ return mUSBMonitor.getDeviceList(deviceFilters.get(0)); } - /** - * 抓拍照片 - * */ + // 拍照 public void capturePicture(String savePath){ if(mCameraHandler != null && mCameraHandler.isOpened()){ mCameraHandler.captureStill(savePath); } } + // 开始录像 public void startRecording(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener){ if(mCameraHandler != null && ! isRecording()){ mCameraHandler.startRecording(params,listener); } } - + // 停止录像 public void stopRecording(){ if(mCameraHandler != null && isRecording()){ mCameraHandler.stopRecording(); } } + // 是否正在录像 public boolean isRecording(){ if(mCameraHandler != null){ return mCameraHandler.isRecording(); @@ -241,6 +241,7 @@ public class USBCameraManager{ return false; } + // 是否打开Camera public boolean isCameraOpened(){ if(mCameraHandler != null){ return mCameraHandler.isOpened(); @@ -248,11 +249,7 @@ public class USBCameraManager{ return false; } - - - /** - * 释放资源 - * */ + // 释放资源 public void release(){ // 关闭摄像头 closeCamera(); @@ -272,23 +269,39 @@ public class USBCameraManager{ return mUSBMonitor; } - + // 关闭Camera public void closeCamera() { if(mCameraHandler != null){ mCameraHandler.close(); } } + // 打开Camera private void openCamera(USBMonitor.UsbControlBlock ctrlBlock) { if(mCameraHandler != null){ mCameraHandler.open(ctrlBlock); } } + // 开始预览 public void startPreview(CameraViewInterface cameraView,AbstractUVCCameraHandler.OnPreViewResultListener mPreviewListener) { SurfaceTexture st = cameraView.getSurfaceTexture(); if(mCameraHandler != null){ mCameraHandler.startPreview(st,mPreviewListener); } } + + // Camera对焦 + public void startCameraFoucs(){ + if(mCameraHandler != null){ + mCameraHandler.startCameraFoucs(); + } + } + + // 获取Camera支持的所有分辨率参数 + public List getSupportedPreviewSizes(){ + if(mCameraHandler == null) + return null; + return mCameraHandler.getSupportedPreviewSizes(); + } } diff --git a/libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java b/libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java index d9bacab..8bbd649 100644 --- a/libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java +++ b/libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java @@ -18,6 +18,7 @@ import android.view.SurfaceHolder; import com.jiangdg.usbcamera.FileUtils; import com.serenegiant.usb.IFrameCallback; +import com.serenegiant.usb.Size; import com.serenegiant.usb.USBMonitor; import com.serenegiant.usb.UVCCamera; import com.serenegiant.usb.encoder.MediaAudioEncoder; @@ -42,6 +43,7 @@ import java.lang.reflect.InvocationTargetException; import java.nio.ByteBuffer; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -54,6 +56,7 @@ public abstract class AbstractUVCCameraHandler extends Handler { private static final boolean DEBUG = true; // TODO set false on release private static final String TAG = "AbsUVCCameraHandler"; + // 对外回调接口 public interface CameraCallback { public void onOpen(); @@ -85,6 +88,7 @@ public abstract class AbstractUVCCameraHandler extends Handler { private static final int MSG_CAPTURE_STOP = 6; private static final int MSG_MEDIA_UPDATE = 7; private static final int MSG_RELEASE = 9; + private static final int MSG_CAMERA_FOUCS = 10; // 音频线程 // private static final int MSG_AUDIO_START = 10; // private static final int MSG_AUDIO_STOP = 11; @@ -225,6 +229,14 @@ public abstract class AbstractUVCCameraHandler extends Handler { sendEmptyMessage(MSG_CAPTURE_STOP); } + public void startCameraFoucs(){ + sendEmptyMessage(MSG_CAMERA_FOUCS); + } + + public List getSupportedPreviewSizes(){ + return mWeakThread.get().getSupportedSizes(); + } + // // 启动音频线程 // public void startAudioThread(){ // sendEmptyMessage(MSG_AUDIO_START); @@ -350,6 +362,10 @@ public abstract class AbstractUVCCameraHandler extends Handler { case MSG_RELEASE: thread.handleRelease(); break; + // 自动对焦 + case MSG_CAMERA_FOUCS: + thread.handleCameraFoucs(); + break; // 音频线程 // case MSG_AUDIO_START: // thread.startAudioRecord(); @@ -820,6 +836,21 @@ public abstract class AbstractUVCCameraHandler extends Handler { if (DEBUG) Log.v(TAG_THREAD, "handleRelease:finished"); } + // 自动对焦 + public void handleCameraFoucs() { + if (DEBUG) Log.v(TAG_THREAD, "handleStartPreview:"); + if ((mUVCCamera == null) || !mIsPreviewing) + return; + mUVCCamera.setAutoFocus(true); + } + + // 获取支持的分辨率 + public List getSupportedSizes() { + if ((mUVCCamera == null) || !mIsPreviewing) + return null; + return mUVCCamera.getSupportedSizeList(); + } + private final MediaEncoder.MediaEncoderListener mMediaEncoderListener = new MediaEncoder.MediaEncoderListener() { @Override public void onPrepared(final MediaEncoder encoder) { diff --git a/libusbcamera/src/main/java/com/serenegiant/usb/common/UVCCameraHandler.java b/libusbcamera/src/main/java/com/serenegiant/usb/common/UVCCameraHandler.java index 7617b60..55f9121 100644 --- a/libusbcamera/src/main/java/com/serenegiant/usb/common/UVCCameraHandler.java +++ b/libusbcamera/src/main/java/com/serenegiant/usb/common/UVCCameraHandler.java @@ -132,4 +132,9 @@ public class UVCCameraHandler extends AbstractUVCCameraHandler { public void captureStill(final String path) { super.captureStill(path); } + + @Override + public void startCameraFoucs() { + super.startCameraFoucs(); + } }