From db0e66d74dee28a003a4de46ce468c1d90101a08 Mon Sep 17 00:00:00 2001 From: jiangdongguo <765067602@qq.com> Date: Wed, 22 Nov 2017 11:32:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=8E=E4=B8=BA=E3=80=81?= =?UTF-8?q?=E5=B0=8F=E7=B1=B3=E3=80=81vivo=E7=AD=89=E6=9C=BA=E5=9E=8B?= =?UTF-8?q?=EF=BC=8C=E9=87=8D=E5=A4=8D=E9=A2=84=E8=A7=88=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usbcamera/view/USBCameraActivity.java | 45 +++++++++++++------ .../usb/widget/UVCCameraTextureView.java | 19 ++++---- 2 files changed, 39 insertions(+), 25 deletions(-) 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 b1acd93..0da2000 100644 --- a/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java +++ b/app/src/main/java/com/jiangdg/usbcamera/view/USBCameraActivity.java @@ -9,6 +9,7 @@ import android.support.annotation.Nullable; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Surface; import android.view.View; import android.widget.Button; import android.widget.Toast; @@ -119,10 +120,38 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog setContentView(R.layout.activity_usbcamera); ButterKnife.bind(this); mUVCCameraView = (CameraViewInterface) mTextureView; + mUVCCameraView.setCallback(new CameraViewInterface.Callback() { + @Override + public void onSurfaceCreated(CameraViewInterface view, Surface surface) { + if(!isPreview && mUSBManager.isCameraOpened()) { + mUSBManager.startPreview(mUVCCameraView, new AbstractUVCCameraHandler.OnPreViewResultListener() { + @Override + public void onPreviewResult(boolean result) { + + } + }); + isPreview = true; + } + } + + @Override + public void onSurfaceChanged(CameraViewInterface view, Surface surface, int width, int height) { + + } + + @Override + public void onSurfaceDestroy(CameraViewInterface view, Surface surface) { + if(isPreview && mUSBManager.isCameraOpened()) { + mUSBManager.stopPreview(); + isPreview = false; + } + } + }); // 初始化引擎 mUSBManager = USBCameraManager.getInstance(); mUSBManager.initUSBMonitor(this,listener); mUSBManager.createUVCCamera(mUVCCameraView); + } @Override @@ -132,16 +161,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog return; // 注册USB事件广播监听器 mUSBManager.registerUSB(); - if(!isPreview && mUSBManager.isCameraOpened()) { - mUSBManager.startPreview(mUVCCameraView, new AbstractUVCCameraHandler.OnPreViewResultListener() { - @Override - public void onPreviewResult(boolean result) { - - } - }); - isPreview = true; - } - + mUVCCameraView.onResume(); } @Override @@ -151,10 +171,7 @@ public class USBCameraActivity extends AppCompatActivity implements CameraDialog if(mUSBManager != null){ mUSBManager.unregisterUSB(); } - if(isPreview && mUSBManager.isCameraOpened()) { - mUSBManager.stopPreview(); - isPreview = false; - } + mUVCCameraView.onPause(); } @OnClick({ R.id.btn_contrast,R.id.btn_brightness,R.id.btn_capture_pic, R.id.btn_rec_video,R.id.btn_update_resolution,R.id.btn_restart_camera}) diff --git a/libusbcamera/src/main/java/com/serenegiant/usb/widget/UVCCameraTextureView.java b/libusbcamera/src/main/java/com/serenegiant/usb/widget/UVCCameraTextureView.java index 16ab871..42529e7 100644 --- a/libusbcamera/src/main/java/com/serenegiant/usb/widget/UVCCameraTextureView.java +++ b/libusbcamera/src/main/java/com/serenegiant/usb/widget/UVCCameraTextureView.java @@ -79,10 +79,7 @@ public class UVCCameraTextureView extends AspectRatioTextureView // API >= 14 @Override public void onResume() { if (DEBUG) Log.v(TAG, "onResume:"); -// if (mHasSurface) { -// mRenderHandler = RenderHandler.createHandler(mFpsCounter, super.getSurfaceTexture(), getWidth(), getHeight()); -// } - if (mRenderHandler == null) { + if (mHasSurface) { mRenderHandler = RenderHandler.createHandler(mFpsCounter, super.getSurfaceTexture(), getWidth(), getHeight()); } } @@ -90,10 +87,10 @@ public class UVCCameraTextureView extends AspectRatioTextureView // API >= 14 @Override public void onPause() { if (DEBUG) Log.v(TAG, "onPause:"); -// if (mRenderHandler != null) { -// mRenderHandler.release(); -// mRenderHandler = null; -// } + if (mRenderHandler != null) { + mRenderHandler.release(); + mRenderHandler = null; + } if (mTempBitmap != null) { mTempBitmap.recycle(); mTempBitmap = null; @@ -102,7 +99,7 @@ public class UVCCameraTextureView extends AspectRatioTextureView // API >= 14 @Override public void onSurfaceTextureAvailable(final SurfaceTexture surface, final int width, final int height) { - if (DEBUG) Log.v(TAG, "onSurfaceTextureAvailable:" + surface); + if (DEBUG) Log.i(TAG, "onSurfaceTextureAvailable:" + surface); if (mRenderHandler == null) { mRenderHandler = RenderHandler.createHandler(mFpsCounter, surface, width, height); } else { @@ -116,7 +113,7 @@ public class UVCCameraTextureView extends AspectRatioTextureView // API >= 14 @Override public void onSurfaceTextureSizeChanged(final SurfaceTexture surface, final int width, final int height) { - if (DEBUG) Log.v(TAG, "onSurfaceTextureSizeChanged:" + surface); + if (DEBUG) Log.i(TAG, "onSurfaceTextureSizeChanged:" + surface); if (mRenderHandler != null) { mRenderHandler.resize(width, height); } @@ -127,7 +124,7 @@ public class UVCCameraTextureView extends AspectRatioTextureView // API >= 14 @Override public boolean onSurfaceTextureDestroyed(final SurfaceTexture surface) { - if (DEBUG) Log.v(TAG, "onSurfaceTextureDestroyed:" + surface); + if (DEBUG) Log.i(TAG, "onSurfaceTextureDestroyed:" + surface); if (mRenderHandler != null) { mRenderHandler.release(); mRenderHandler = null;