chenyeju295 / flutter_uvc_camera

Flutter package
https://pub.dev/packages/flutter_uvc_camera
MIT License
11 stars 11 forks source link

Camera opened, but the preview screen tearing and black screen. #20

Open YXwong01 opened 5 months ago

YXwong01 commented 5 months ago

I tried the demo project provided, and it works perfectly fine on my Samsung (Android 12), but I'm facing some issues on my other devices, namely Vivo (Android 12) and Honor (Android 12).

I've tried both frame formats: 0 and 1. With frame format 1, I get a black screen preview, and with frame format 0, I encounter tearing on the screen.

Below are my log messages and some pictures showing the tearing issue. Could you please assist me with this?

Here is the log when using fram formats 1

I/flutter (18399): ------> UVCCameraController init
I/PlatformViewsController(18399): Hosting view in view hierarchy for platform view: 1
I/BufferQueueConsumer(18399): [](id:47df00000004,api:0,p:-1,c:18399) connect: controlledByApp=true
D/Surface (18399): lockHardwareCanvas
I/BufferQueueProducer(18399): [SurfaceTexture-0-18399-2](id:47df00000004,api:1,p:18399,c:18399) connect: api=1 producerControlledByApp=true
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
D/Surface (18399): lockHardwareCanvas
D/TextureView(18399): getHardwareLayer, createNewSurface:true
I/BufferQueueConsumer(18399): [](id:47df00000005,api:0,p:-1,c:18399) connect: controlledByApp=true
V/USBMonitor(18399): USBMonitor:Constructor
V/USBMonitor(18399): USBMonitor:mUsbManager=android.hardware.usb.UsbManager@ba54858
I/MultiCameraClient(18399): register...
I/USBMonitor(18399): register:
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
I/GED     (18399): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 31, oppidx_max 31, oppidx_min 0
I/MultiCameraClient(18399): attach device name/pid/vid:/dev/bus/usb/001/008&37187&3034 
I/USBMonitor(18399): request permission, has permission: true
V/USBMonitor(18399): processConnect:device=/dev/bus/usb/001/008
I/USBMonitor(18399): UsbControlBlock:constructor
D/UsbDeviceConnectionJNI(18399): close
I/USBMonitor(18399): name=/dev/bus/usb/001/008,desc=158,busnum=1,devnum=8,rawDesc=
I/MultiCameraClient(18399): connect device name/pid/vid:/dev/bus/usb/001/008&37187&3034 
I/CameraView(18399): camera connection. pid: 37187, vid: 3034
I/AspectRatioTextureView(18399): AspectRatio = 1.3333333333333333
I/MultiCameraClient(18399): surface measure size (825, 618)
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
I/RenderManager(18399): create RenderManager, Open ES version is 3.2
D/libMEOW (18399): meow new tls: 0xb4000079cd2e6540
D/libMEOW (18399): applied 1 plugins for [com.example.flutter_uvc_camera_example]:
D/libMEOW (18399):   plugin 1: [libMEOW_gift.so]:
I/EGLEvn  (18399): Init EGL Success!
I/BufferQueueProducer(18399): [SurfaceTexture-0-18399-3](id:47df00000005,api:1,p:18399,c:18399) connect: api=1 producerControlledByApp=true
I/EGLEvn  (18399): setupSurface Success!
I/AbstractRender(18399): init surface texture render success!
I/AbstractRender(18399): create external texture, id = 1
I/AbstractRender(18399): init surface texture render success!
I/AbstractRender(18399): init surface texture render success!
I/BufferQueueConsumer(18399): [](id:47df00000006,api:0,p:-1,c:18399) connect: controlledByApp=true
D/UsbDeviceConnectionJNI(18399): close
I/libusb/core(18399): [19133*core.c:2085:libusb_init2]:libusb v1.0.19.10903
I/libusb/usbfs(18399): [19133*android_usbfs.c:504:op_init2]:start up hotplug event handler
I/libusb/usbfs(18399): [19133*android_usbfs.c:512:op_init2]:call android_scan_devices
I/UVCCamera(18399): open camera status: -5476376623639371264, size: {"formats":[{"index":1,"type":6,"default":1,"size":["1280x720","800x600","640x480","352x288","320x240","176x144","160x120"]},{"index":2,"type":4,"default":1,"size":["1280x720","800x600","640x480","352x288","320x240","176x144","160x120"]}]}
I/CameraUVC(18399): aspect ratio = null, getAllPreviewSizes = [PreviewSize(width=1280, height=720), PreviewSize(width=800, height=600), PreviewSize(width=640, height=480), PreviewSize(width=352, height=288), PreviewSize(width=320, height=240), PreviewSize(width=176, height=144), PreviewSize(width=160, height=120)], 
I/CameraUVC(18399): getSuitableSize: PreviewSize(width=640, height=480)
I/CameraUVC(18399): aspect ratio = null, getAllPreviewSizes = [PreviewSize(width=1280, height=720), PreviewSize(width=800, height=600), PreviewSize(width=640, height=480), PreviewSize(width=352, height=288), PreviewSize(width=320, height=240), PreviewSize(width=176, height=144), PreviewSize(width=160, height=120)], 
I/MultiCameraClient(18399): Audio record by using system mic
I/libUVCCamera(18399): [19136*UVCPreview.cpp:509:prepare_preview]:frameSize=(640,480)@MJPEG
I/libUVCCamera(18399): [19138*UVCPreview.cpp:267:callbackPixelFormatChanged]:PIXEL_FORMAT_RAW:
I/CameraUVC(18399):  start preview, name = /dev/bus/usb/001/008, preview=PreviewSize(width=640, height=480)
I/RenderManager(18399): create camera SurfaceTexture: android.graphics.SurfaceTexture@4c833f6
I/AbstractRender(18399): create texture, id = 2
I/CameraView(18399): ------>CameraState: OPENED
I/AbstractFboRender(18399): load fbo, textures: [I@f5743f7, buffers: [I@6e76264
I/AbstractRender(18399): create texture, id = 3
I/flutter (18399): Camera: OPENED
I/AbstractFboRender(18399): load fbo, textures: [I@dd78ccd, buffers: [I@53b9982
W/libUVCCamera(18399): [19137*UVCPreview.cpp:128:get_frame]:allocate new frame
W/libUVCCamera(18399): [19136*UVCPreview.cpp:128:get_frame]:allocate new frame
W/libUVCCamera(18399): [19137*UVCPreview.cpp:128:get_frame]:allocate new frame
I/BufferQueueProducer(18399): [SurfaceTexture-1-18399-4](id:47df00000006,api:2,p:18399,c:18399) connect: api=2 producerControlledByApp=true
I/RenderManager(18399): camera render frame rate is 1 fps-->gl_render
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
I/RenderManager(18399): camera render frame rate is 1 fps-->gl_render
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
I/RenderManager(18399): camera render frame rate is 2 fps-->gl_render
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
I/RenderManager(18399): camera render frame rate is 1 fps-->gl_render
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.
I/RenderManager(18399): camera render frame rate is 1 fps-->gl_render
D/Surface (18399): lockHardwareCanvas
E/FrameEvents(18399): updateAcquireFence: Did not find frame.

Here is the log when using frame format 0

I/flutter (26248): ------> UVCCameraController init
I/PlatformViewsController(26248): Hosting view in view hierarchy for platform view: 0
I/BufferQueueConsumer(26248): [](id:668800000012,api:0,p:-1,c:26248) connect(): controlledByApp=true
D/Surface (26248): lockHardwareCanvas
I/BufferQueueProducer(26248): [SurfaceTexture-0-26248-18](id:668800000012,api:1,p:26248,c:26248) connect(): api=1 producerControlledByApp=true
E/FrameEvents(26248): updateAcquireFence: Did not find frame.
D/Surface (26248): lockHardwareCanvas
E/FrameEvents(26248): updateAcquireFence: Did not find frame.
I/flutter (26248): Camera: CLOSED

======== Exception caught by image resource service ================================================
The following PathNotFoundException was thrown resolving an image codec:
Cannot retrieve length of file, path = '' (OS Error: No such file or directory, errno = 2)

When the exception was thrown, this was the stack: 
#0      _checkForErrorResponse (dart:io/common.dart:55:9)
#1      _File.length.<anonymous closure> (dart:io/file_impl.dart:389:7)
<asynchronous suspension>
#2      FileImage._loadAsync (package:flutter/src/painting/image_provider.dart:1481:31)
<asynchronous suspension>
#3      MultiFrameImageStreamCompleter._handleCodecReady (package:flutter/src/painting/image_stream.dart:969:3)
<asynchronous suspension>
Path: 
====================================================================================================
D/Surface (26248): lockHardwareCanvas
D/TextureView(26248): getHardwareLayer, createNewSurface:true
I/BufferQueueConsumer(26248): [](id:668800000013,api:0,p:-1,c:26248) connect(): controlledByApp=true
V/USBMonitor(26248): USBMonitor:Constructor
V/USBMonitor(26248): USBMonitor:mUsbManager=android.hardware.usb.UsbManager@973ffb
I/MultiCameraClient(26248): register...
I/USBMonitor(26248): register:
E/FrameEvents(26248): updateAcquireFence: Did not find frame.
D/Surface (26248): lockHardwareCanvas
E/FrameEvents(26248): updateAcquireFence: Did not find frame.
I/MultiCameraClient(26248): attach device name/pid/vid:/dev/bus/usb/001/010&37187&3034 
I/USBMonitor(26248): request permission, has permission: true
V/USBMonitor(26248): processConnect:device=/dev/bus/usb/001/010
I/USBMonitor(26248): UsbControlBlock:constructor
D/UsbDeviceConnectionJNI(26248): close
I/USBMonitor(26248): name=/dev/bus/usb/001/010,desc=138,busnum=1,devnum=10,rawDesc=
I/MultiCameraClient(26248): connect device name/pid/vid:/dev/bus/usb/001/010&37187&3034 
I/CameraView(26248): camera connection. pid: 37187, vid: 3034
I/AspectRatioTextureView(26248): AspectRatio = 1.3333333333333333
W/System.err(26248): java.util.concurrent.TimeoutException: Timeout waiting for task.
W/System.err(26248):    at com.jiangdg.ausbc.utils.SettableFuture$Sync.get(SettableFuture.kt:85)
W/System.err(26248):    at com.jiangdg.ausbc.utils.SettableFuture.get(SettableFuture.kt:47)
W/System.err(26248):    at com.jiangdg.ausbc.MultiCameraClient$ICamera.handleMessage(MultiCameraClient.kt:322)
W/System.err(26248):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(26248):    at android.os.Looper.loop(Looper.java:223)
W/System.err(26248):    at android.os.HandlerThread.run(HandlerThread.java:67)
I/MultiCameraClient(26248): surface measure size null
I/RenderManager(26248): create RenderManager, Open ES version is 3.2
I/EGLEvn  (26248): Init EGL Success!
I/BufferQueueProducer(26248): [SurfaceTexture-0-26248-19](id:668800000013,api:1,p:26248,c:26248) connect(): api=1 producerControlledByApp=true
I/EGLEvn  (26248): setupSurface Success!
I/AbstractRender(26248): init surface texture render success!
I/AbstractRender(26248): create external texture, id = 1
I/AbstractRender(26248): init surface texture render success!
I/AbstractRender(26248): init surface texture render success!
I/BufferQueueConsumer(26248): [](id:668800000014,api:0,p:-1,c:26248) connect(): controlledByApp=true
D/UsbDeviceConnectionJNI(26248): close
I/libusb/core(26248): [26467*core.c:2085:libusb_init2]:libusb v1.0.19.10903
I/libusb/usbfs(26248): [26467*android_usbfs.c:504:op_init2]:start up hotplug event handler
I/libusb/usbfs(26248): [26467*android_usbfs.c:512:op_init2]:call android_scan_devices
I/UVCCamera(26248): open camera status: -5476376651947905088, size: {"formats":[{"index":1,"type":6,"default":1,"size":["1280x720","800x600","640x480","352x288","320x240","176x144","160x120"]},{"index":2,"type":4,"default":1,"size":["1280x720","800x600","640x480","352x288","320x240","176x144","160x120"]}]}
I/CameraUVC(26248): aspect ratio = null, getAllPreviewSizes = [PreviewSize(width=1280, height=720), PreviewSize(width=800, height=600), PreviewSize(width=640, height=480), PreviewSize(width=352, height=288), PreviewSize(width=320, height=240), PreviewSize(width=176, height=144), PreviewSize(width=160, height=120)], 
I/CameraUVC(26248): getSuitableSize: PreviewSize(width=640, height=480)
I/CameraUVC(26248): aspect ratio = null, getAllPreviewSizes = [PreviewSize(width=1280, height=720), PreviewSize(width=800, height=600), PreviewSize(width=640, height=480), PreviewSize(width=352, height=288), PreviewSize(width=320, height=240), PreviewSize(width=176, height=144), PreviewSize(width=160, height=120)], 
I/MultiCameraClient(26248): Audio record by using system mic
I/libUVCCamera(26248): [26470*UVCPreview.cpp:509:prepare_preview]:frameSize=(640,480)@YUYV
I/libUVCCamera(26248): [26472*UVCPreview.cpp:267:callbackPixelFormatChanged]:PIXEL_FORMAT_RAW:
I/CameraUVC(26248):  start preview, name = /dev/bus/usb/001/010, preview=PreviewSize(width=640, height=480)
I/RenderManager(26248): create camera SurfaceTexture: android.graphics.SurfaceTexture@77fbd1e
I/AbstractRender(26248): create texture, id = 2
I/CameraView(26248): ------>CameraState: OPENED
I/AbstractFboRender(26248): load fbo, textures: [I@36d9ff, buffers: [I@800b3cc
I/AbstractRender(26248): create texture, id = 3
I/AbstractFboRender(26248): load fbo, textures: [I@adce615, buffers: [I@7668d2a
I/flutter (26248): Camera: OPENED

Untitled

chenyeju295 commented 5 months ago

@YXwong01 Hi! Some devices are not compatible, have you tried switching resolutions enough?