From b811c7aa9a64af7ec3a0c1df4aa92223be305f09 Mon Sep 17 00:00:00 2001 From: jiangdg Date: Tue, 26 Jul 2022 14:41:54 +0800 Subject: [PATCH] [fix] try to fix verify preview size failed --- app/build.gradle | 4 +-- .../com/jiangdg/ausbc/MultiCameraClient.kt | 3 +- .../jiangdg/ausbc/camera/CameraUvcStrategy.kt | 31 +++++++++---------- .../java/com/serenegiant/usb/UVCCamera.java | 4 --- settings.gradle | 10 +++--- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a9e388d62..af3f6ff08 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -60,8 +60,8 @@ dependencies { implementation "com.tencent.bugly:nativecrashreport:$bugly_native_version" // For debug online -// implementation project(':libausbc') + implementation project(':libausbc') // demo - implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.2' +// implementation 'com.github.jiangdongguo.AndroidUSBCamera:libausbc:3.2.2' } diff --git a/libausbc/src/main/java/com/jiangdg/ausbc/MultiCameraClient.kt b/libausbc/src/main/java/com/jiangdg/ausbc/MultiCameraClient.kt index 67da771ca..fa05f9843 100644 --- a/libausbc/src/main/java/com/jiangdg/ausbc/MultiCameraClient.kt +++ b/libausbc/src/main/java/com/jiangdg/ausbc/MultiCameraClient.kt @@ -715,12 +715,11 @@ class MultiCameraClient(ctx: Context, callback: IDeviceConnectCallBack?) { */ fun getAllPreviewSizes(aspectRatio: Double? = null): MutableList { val previewSizeList = arrayListOf() - if (mUvcCamera?.isMJPEGFormatSupported == true) { + if (mUvcCamera?.supportedSizeList?.isNotEmpty() == true) { mUvcCamera?.supportedSizeList } else { mUvcCamera?.getSupportedSizeList(UVCCamera.FRAME_FORMAT_YUYV) }.also { sizeList -> - Logger.i(TAG, "mUvcCamera?.supportedSizeList = $sizeList") sizeList?.forEach { size -> val width = size.width val height = size.height diff --git a/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt b/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt index c17cb9fca..77e3084f7 100644 --- a/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt +++ b/libausbc/src/main/java/com/jiangdg/ausbc/camera/CameraUvcStrategy.kt @@ -58,7 +58,6 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { } private var mUsbMonitor: USBMonitor? = null private var mUVCCamera: UVCCamera? = null - private var mPreviewFrameFormat: Int = UVCCamera.FRAME_FORMAT_MJPEG private var mDevConnectCallBack: IDeviceConnectCallBack? = null private var mCacheDeviceList: MutableList = arrayListOf() @@ -138,11 +137,6 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { mUVCCamera = UVCCamera().apply { open(ctrlBlock) } - mPreviewFrameFormat = if (mUVCCamera?.isMJPEGFormatSupported == true) { - UVCCamera.FRAME_FORMAT_MJPEG - } else { - UVCCamera.FRAME_FORMAT_YUYV - } if (! isPreviewSizeSupported(previewWidth, previewHeight)) { postCameraStatus(CameraStatus(CameraStatus.ERROR_PREVIEW_SIZE, "unsupported preview size(${request.previewWidth}, ${request.previewHeight})")) Logger.e(TAG, " unsupported preview size(${request.previewWidth}, ${request.previewHeight})") @@ -154,13 +148,12 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { request.previewHeight, MIN_FS, MAX_FS, - mPreviewFrameFormat, + UVCCamera.FRAME_FORMAT_MJPEG, UVCCamera.DEFAULT_BANDWIDTH ) } catch (e: Exception) { try { Logger.w(TAG, " setPreviewSize failed ${e.localizedMessage}, try yuv format...") - mPreviewFrameFormat = UVCCamera.FRAME_FORMAT_YUYV if (! isPreviewSizeSupported(previewWidth, previewHeight)) { postCameraStatus(CameraStatus(CameraStatus.ERROR_PREVIEW_SIZE, "unsupported preview size(${request.previewWidth}, ${request.previewHeight})")) Logger.e(TAG, " unsupported preview size(${request.previewWidth}, ${request.previewHeight})") @@ -171,7 +164,7 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { request.previewHeight, MIN_FS, MAX_FS, - mPreviewFrameFormat, + UVCCamera.FRAME_FORMAT_YUYV, UVCCamera.DEFAULT_BANDWIDTH ) } catch (e: Exception) { @@ -352,16 +345,22 @@ class CameraUvcStrategy(ctx: Context) : ICameraStrategy(ctx) { val previewSizeList = cameraInfo?.cameraPreviewSizes ?: mutableListOf() if (previewSizeList.isEmpty()) { Logger.i(TAG, "getAllPreviewSizes = ${mUVCCamera?.supportedSizeList}") - mUVCCamera?.getSupportedSizeList(mPreviewFrameFormat)?.forEach { size -> - previewSizeList.find { - it.width == size.width && it.height == size.height - }.also { - if (it == null) { - previewSizeList.add(PreviewSize(size.width, size.height)) + if (mUVCCamera?.supportedSizeList?.isNotEmpty() == true) { + mUVCCamera?.supportedSizeList + } else { + mUVCCamera?.getSupportedSizeList(UVCCamera.FRAME_FORMAT_YUYV) + }.also { sizeList -> + sizeList?.forEach { size -> + previewSizeList.find { + it.width == size.width && it.height == size.height + }.also { + if (it == null) { + previewSizeList.add(PreviewSize(size.width, size.height)) + } } } + cameraInfo?.cameraPreviewSizes = previewSizeList } - cameraInfo?.cameraPreviewSizes = previewSizeList } aspectRatio ?: return previewSizeList // aspect ratio list or all diff --git a/libuvc/src/main/java/com/serenegiant/usb/UVCCamera.java b/libuvc/src/main/java/com/serenegiant/usb/UVCCamera.java index 21227e653..08dc73cc2 100644 --- a/libuvc/src/main/java/com/serenegiant/usb/UVCCamera.java +++ b/libuvc/src/main/java/com/serenegiant/usb/UVCCamera.java @@ -350,10 +350,6 @@ public void setPreviewSize(final int width, final int height, final int min_fps, } } - public boolean isMJPEGFormatSupported() { - return ! getSupportedSize(FRAME_FORMAT_MJPEG, mSupportedSize).isEmpty(); - } - public List getSupportedSizeList() { final int type = (mCurrentFrameFormat > 0) ? 6 : 4; return getSupportedSize(type, mSupportedSize); diff --git a/settings.gradle b/settings.gradle index fa7133e78..ccd1174f3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,8 @@ include ':app' // For debug online -//include ':libausbc' -//include ':libuvc' -//include ':libpush' -//include ':libnative' -//include ':libuvccommon' \ No newline at end of file +include ':libausbc' +include ':libuvc' +include ':libpush' +include ':libnative' +include ':libuvccommon' \ No newline at end of file