Skip to content

Commit

Permalink
[fix] try to fix verify preview size failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangdg committed Jul 26, 2022
1 parent f00ab0a commit b811c7a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,11 @@ class MultiCameraClient(ctx: Context, callback: IDeviceConnectCallBack?) {
*/
fun getAllPreviewSizes(aspectRatio: Double? = null): MutableList<PreviewSize> {
val previewSizeList = arrayListOf<PreviewSize>()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsbDevice> = arrayListOf()

Expand Down Expand Up @@ -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})")
Expand All @@ -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})")
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions libuvc/src/main/java/com/serenegiant/usb/UVCCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Size> getSupportedSizeList() {
final int type = (mCurrentFrameFormat > 0) ? 6 : 4;
return getSupportedSize(type, mSupportedSize);
Expand Down
10 changes: 5 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include ':app'

// For debug online
//include ':libausbc'
//include ':libuvc'
//include ':libpush'
//include ':libnative'
//include ':libuvccommon'
include ':libausbc'
include ':libuvc'
include ':libpush'
include ':libnative'
include ':libuvccommon'

0 comments on commit b811c7a

Please sign in to comment.