mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
6.64k stars 983 forks source link

🐛 Android ImageAnalysis setBackpressureStrategy STRATEGY_BLOCK_PRODUCER causing lag with OCR libraries #2826

Closed kevinranks closed 2 weeks ago

kevinranks commented 2 weeks ago

What's happening?

With the back pressure strategy set to STRATEGY_BLOCK_PRODUCER instead of STRATEGY_KEEP_ONLY_LATEST I'm experiencing camera lag while processing OCR unless I use runAsync(). I've confirmed that changing the strategy resolves the issue and runAsync() isn't required.

https://github.com/mrousavy/react-native-vision-camera/blob/main/package/android/src/main/java/com/mrousavy/camera/core/CameraSession.kt#L348

I previously opened issues in these two OCR repos prior to learning with Ismael on Discord that the issue was indeed the back pressure strategy:

Reproduceable Code

const frameProcessor = useFrameProcessor(frame => {
    'worklet';

    runAtTargetFps(1, () => {
      'worklet';
      const data = scanOCR(frame);
      //console.log('🚀 ~ frameProcessor ~ data:', JSON.stringify(data, null, 2));
    });

    // setOcrJS({...data});
  }, []);

Relevant log output

04-30 10:25:53.855  2370  4461 I Camera3-Status: markComponent: Component 3 is now idle - streamId = 0, format = 0x22(IMPL_DEF), width = 1440, height = 1080, option = 0x0, type = OUTPUT
04-30 10:25:53.855  2370  4461 I Camera3-IOStreamBase: FpsStats: stream 0, requested=37, received=37, valid=37, invalid=0
04-30 10:25:53.877 18968 19352 W ImageReader_JNI: Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers
04-30 10:25:53.878  1898  3597 E GME     : [ERROR][ChiNode] camxchinodegme.cpp:12842 CheckRemosaicCropVideo() MultiCameraSATNoGPUQuad0_com.qti.node.gme3_cam2 Zoom State vendor tag not present
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer: Failed to acquire image.
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer: java.lang.IllegalStateException: maxImages (6) has already been acquired, call #close before acquiring more.
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at android.media.ImageReader.acquireNextImage(ImageReader.java:661)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.AndroidImageReaderProxy.acquireNextImage(AndroidImageReaderProxy.java:88)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.SafeCloseImageReaderProxy.acquireNextImage(SafeCloseImageReaderProxy.java:88)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.ImageAnalysisBlockingAnalyzer.acquireImage(ImageAnalysisBlockingAnalyzer.java:41)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.ImageAnalysisAbstractAnalyzer.onImageAvailable(ImageAnalysisAbstractAnalyzer.java:128)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.SafeCloseImageReaderProxy.lambda$setOnImageAvailableListener$1$androidx-camera-core-SafeCloseImageReaderProxy(SafeCloseImageReaderProxy.java:213)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.SafeCloseImageReaderProxy$$ExternalSyntheticLambda1.onImageAvailable(Unknown Source:4)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.AndroidImageReaderProxy.lambda$setOnImageAvailableListener$0$androidx-camera-core-AndroidImageReaderProxy(AndroidImageReaderProxy.java:169)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.AndroidImageReaderProxy$$ExternalSyntheticLambda0.run(Unknown Source:4)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
04-30 10:25:53.878 18968 19352 E ImageAnalysisAnalyzer:     at java.lang.Thread.run(Thread.java:1012)
04-30 10:25:53.912  1898  3597 E GME     : [ERROR][ChiNode] camxchinodegme.cpp:12842 CheckRemosaicCropVideo() MultiCameraSATNoGPUQuad0_com.qti.node.gme3_cam2 Zoom State vendor tag not present
04-30 10:25:53.912  2370  4461 I Camera3-Status: markComponent: Component 4 is now idle - streamId = 1, format = 0x23(YUV_420_888), width = 3840, height = 2160, option = 0x0, type = OUTPUT
04-30 10:25:53.912  2370  4461 I Camera3-IOStreamBase: FpsStats: stream 1, requested=38, received=38, valid=38, invalid=0
04-30 10:25:53.912 18968 19352 W ImageReader_JNI: Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer: Failed to acquire image.
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer: java.lang.IllegalStateException: maxImages (6) has already been acquired, call #close before acquiring more.
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at android.media.ImageReader.acquireNextImage(ImageReader.java:661)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.AndroidImageReaderProxy.acquireNextImage(AndroidImageReaderProxy.java:88)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.SafeCloseImageReaderProxy.acquireNextImage(SafeCloseImageReaderProxy.java:88)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.ImageAnalysisBlockingAnalyzer.acquireImage(ImageAnalysisBlockingAnalyzer.java:41)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.ImageAnalysisAbstractAnalyzer.onImageAvailable(ImageAnalysisAbstractAnalyzer.java:128)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.SafeCloseImageReaderProxy.lambda$setOnImageAvailableListener$1$androidx-camera-core-SafeCloseImageReaderProxy(SafeCloseImageReaderProxy.java:213)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.SafeCloseImageReaderProxy$$ExternalSyntheticLambda1.onImageAvailable(Unknown Source:4)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.AndroidImageReaderProxy.lambda$setOnImageAvailableListener$0$androidx-camera-core-AndroidImageReaderProxy(AndroidImageReaderProxy.java:169)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at androidx.camera.core.AndroidImageReaderProxy$$ExternalSyntheticLambda0.run(Unknown Source:4)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
04-30 10:25:53.914 18968 19352 E ImageAnalysisAnalyzer:     at java.lang.Thread.run(Thread.java:1012)
04-30 10:25:53.929  1898  3600 E ChiX    : [ERROR][SBM    ] chxstreambuffermanager.cpp:1965 GetStreamBuffer() Can't get buffer for stream 0xb40000702978a918 : (0, 6, 0, 0, 8) : (avail, pending, used, psStatus, totalUnique), requestId 38, bufferMgrName MultiCameraSATNoGPUQuad0_IPE10_cam2_OutputPortId8_Display
04-30 10:25:53.929  1898  3600 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1752 BindImportedBuffer() [MultiCameraSATNoGPUQuad0_IPE10_cam2_OutputPortId8_Display] Failed to get buffer from stream buffer manager
04-30 10:25:53.929  1898  3600 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1823 BindImportedBuffer() [MultiCameraSATNoGPUQuad0_IPE10_cam2_OutputPortId8_Display][0xb400007179f5b590] Invalid Gralloc buffer [0x0] to import
04-30 10:25:53.930  1898  2342 E CamX    : [ERROR][CORE   ] camxnodelegacy.cpp:8211 CSLFenceCallback() Node::MultiCameraSATNoGPUQuad0_IPE10_cam2 : Type 65538 portId=8 Fence 45 signaled with failure 2 in node fence handler FOR 38
04-30 10:25:53.932  1898  3600 E CamX    : [ERROR][CORE   ] camxpipeline.cpp:5354 SinkPortFenceErrorSignaled() MultiCameraSATNoGPUQuad0_0_cam_2 Reporting stream done for stream=0, sequenceId=37 Buffer type=0 handle=0x0
04-30 10:25:53.932  1898  3600 E CamX    : [ERROR][CORE   ] camxsession.cpp:8659 InjectResult() Session 0xb40000720a24ab90 [MultiCameraSATNoGPUQuad0] Reporting a buffer error to the framework for streamIndex 0 SeqId: 37 <-> ReqId: 38
04-30 10:25:53.932  1898  3598 E ChiX    : [ERROR][F2Core ] chifeature2base.cpp:8397 ProcessErrorMessageFromDriver()  Base received error type:ERROR_BUFFER
04-30 10:25:53.933  1898  3598 E CamX    : [ERROR][HAL    ] camxhaldevice.cpp:931 Notify() type 00000001, frame_number 37, error_code 00000004, error_stream 0xb40000702978a918
04-30 10:25:53.933  2370  4461 E CameraDeviceClient: notifyError: pid=18968, errorCode=5, errorStreamId=0, frameNumber=37
04-30 10:25:53.933  2370  4461 E CameraDeviceClient: notifyError: pid=18968, skipClientNotification=false

...

04-30 10:25:57.163 13989 14126 W JniExecutor: Running after 19396ms in queue: celloMaybeStartRepeatingPushTaskTimer_31641038{not completed,timedOut,delayMs=30000,wait=19396ms}
04-30 10:25:57.172 13344 13344 I wpa_sslib: OEM DATA RESPONSE RECEIVED
04-30 10:25:57.193  1898  3600 E ChiX    : [ERROR][SBM    ] chxstreambuffermanager.cpp:1965 GetStreamBuffer() Can't get buffer for stream 0xb40000702976adb8 : (0, 8, 0, 0, 14) : (avail, pending, used, psStatus, totalUnique), requestId 53, bufferMgrName ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video
04-30 10:25:57.193  1898  3600 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1752 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video] Failed to get buffer from stream buffer manager
04-30 10:25:57.193  1898  3600 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1823 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video][0xb40000717a076540] Invalid Gralloc buffer [0x0] to import
04-30 10:25:57.194  1898  2342 E CamX    : [ERROR][CORE   ] camxnodelegacy.cpp:8211 CSLFenceCallback() Node::ZSLSnapshotYUVHAL1_IPE3_cam0 : Type 65538 portId=9 Fence 15 signaled with failure 2 in node fence handler FOR 53
04-30 10:25:57.194  1898  3597 E CamX    : [ERROR][CORE   ] camxpipeline.cpp:5354 SinkPortFenceErrorSignaled() ZSLSnapshotYUVHAL1_0_cam_0 Reporting stream done for stream=1, sequenceId=52 Buffer type=0 handle=0x0
04-30 10:25:57.194  1898  3597 E CamX    : [ERROR][CORE   ] camxsession.cpp:8659 InjectResult() Session 0xb40000720a61af60 [ZSLSnapshotYUVHAL1] Reporting a buffer error to the framework for streamIndex 1 SeqId: 52 <-> ReqId: 53
04-30 10:25:57.195  1898  3596 E ChiX    : [ERROR][F2Core ] chifeature2base.cpp:8397 ProcessErrorMessageFromDriver()  Base received error type:ERROR_BUFFER
04-30 10:25:57.195  1898  3596 E CamX    : [ERROR][HAL    ] camxhaldevice.cpp:931 Notify() type 00000001, frame_number 52, error_code 00000004, error_stream 0xb40000702976adb8
04-30 10:25:57.195  2370  7676 E CameraDeviceClient: notifyError: pid=18968, errorCode=5, errorStreamId=1, frameNumber=52
04-30 10:25:57.195  2370  7676 E CameraDeviceClient: notifyError: pid=18968, skipClientNotification=false
04-30 10:25:57.214 13989 14183 W TaskMonitor: 1 tasks running slow
04-30 10:25:57.214 13989 14183 W TaskMonitor: 1 tasks running slow
04-30 10:25:57.214 13989 14183 W TaskMonitor: [Task=29385016] Slow task still running after 19s, operation queue size 0. celloMaybeStartRepeatingPushTaskTimer_37725143{not started,timedOut,delayMs=30000}
04-30 10:25:57.214 13989 14183 W TaskMonitor: [Task=29385016] Slow task still running after 19s, operation queue size 0. celloMaybeStartRepeatingPushTaskTimer_37725143{not started,timedOut,delayMs=30000}
04-30 10:25:57.240  1898  3599 E ChiX    : [ERROR][SBM    ] chxstreambuffermanager.cpp:1965 GetStreamBuffer() Can't get buffer for stream 0xb40000702976adb8 : (0, 8, 0, 0, 14) : (avail, pending, used, psStatus, totalUnique), requestId 54, bufferMgrName ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video
04-30 10:25:57.240  1898  3599 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1752 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video] Failed to get buffer from stream buffer manager
04-30 10:25:57.240  1898  3599 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1823 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video][0xb400007179fd8350] Invalid Gralloc buffer [0x0] to import
04-30 10:25:57.240  1898  2342 E CamX    : [ERROR][CORE   ] camxnodelegacy.cpp:8211 CSLFenceCallback() Node::ZSLSnapshotYUVHAL1_IPE3_cam0 : Type 65538 portId=9 Fence 19 signaled with failure 2 in node fence handler FOR 54
04-30 10:25:57.241  1898  3598 E CamX    : [ERROR][CORE   ] camxpipeline.cpp:5354 SinkPortFenceErrorSignaled() ZSLSnapshotYUVHAL1_0_cam_0 Reporting stream done for stream=1, sequenceId=53 Buffer type=0 handle=0x0
04-30 10:25:57.241  1898  3598 E CamX    : [ERROR][CORE   ] camxsession.cpp:8659 InjectResult() Session 0xb40000720a61af60 [ZSLSnapshotYUVHAL1] Reporting a buffer error to the framework for streamIndex 1 SeqId: 53 <-> ReqId: 54
04-30 10:25:57.241  1898  3596 E ChiX    : [ERROR][F2Core ] chifeature2base.cpp:8397 ProcessErrorMessageFromDriver()  Base received error type:ERROR_BUFFER
04-30 10:25:57.241  1898  3596 E CamX    : [ERROR][HAL    ] camxhaldevice.cpp:931 Notify() type 00000001, frame_number 53, error_code 00000004, error_stream 0xb40000702976adb8
04-30 10:25:57.241  2370  7676 E CameraDeviceClient: notifyError: pid=18968, errorCode=5, errorStreamId=1, frameNumber=53
04-30 10:25:57.241  2370  7676 E CameraDeviceClient: notifyError: pid=18968, skipClientNotification=false
04-30 10:25:57.244  1840  3222 D SensorsFlicker: Als_common::readEvents, enabled : 1, data : 638.000000, 0.000000, 0.000000, 64.000000, 569.000000, 0.000000, 16384.000000
04-30 10:25:57.244  1898  3596 I SS_3A   :  INFO: AEC: TsAec_process_get_aec_info: 4151: [W][62]algo_out Av=1.695,g=5.812,e_t=0.01667,LLS=0x0,Bv=3.398,Ev=8.266,PEv=8.398,Cvgd=0,lux=237,FS=0,gam=0.0,lls=0x0,drc=5.491,PHdr=0.000,m=0 [m:W]
04-30 10:25:57.267  1898  3600 W IS_ALGO : IS1024: V3: is_valid_frame_times(3871): frame_id previous frame 59: Pause-resume use case was detected - : 2164516447349, 2164515747647
04-30 10:25:57.276  1898  3598 W IS_ALGO : IS1024: V3: is_valid_frame_times(3871): frame_id previous frame 59: Pause-resume use case was detected - : 2164516447349, 2164515747647
04-30 10:25:57.276  1898  3598 E GME     : [ERROR][ChiNode] camxchinodegme.cpp:12842 CheckRemosaicCropVideo() MultiCameraSATNoGPUQuad0_com.qti.node.gme3_cam2 Zoom State vendor tag not present
04-30 10:25:57.276  1898  3598 W IS_ALGO : IS1027: V3: eis3_pause_resume_or_new_stream(5517): Pause-Resume or New-Stream: 1, 0, 59, 0
04-30 10:25:57.276  1898  3598 W IS_ALGO : IS1024: V3: is_valid_frame_times(3871): frame_id  60: Pause-resume use case was detected - : 2164516447349, 2164515747647
04-30 10:25:57.286  1898  3599 E ChiX    : [ERROR][SBM    ] chxstreambuffermanager.cpp:1965 GetStreamBuffer() Can't get buffer for stream 0xb40000702976adb8 : (0, 8, 0, 0, 14) : (avail, pending, used, psStatus, totalUnique), requestId 55, bufferMgrName ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video
04-30 10:25:57.286  1898  3599 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1752 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video] Failed to get buffer from stream buffer manager
04-30 10:25:57.286  1898  3599 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1823 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video][0xb400007179f62830] Invalid Gralloc buffer [0x0] to import
04-30 10:25:57.287  1898  2342 E CamX    : [ERROR][CORE   ] camxnodelegacy.cpp:8211 CSLFenceCallback() Node::ZSLSnapshotYUVHAL1_IPE3_cam0 : Type 65538 portId=9 Fence 26 signaled with failure 2 in node fence handler FOR 55
04-30 10:25:57.287  1898  3600 E CamX    : [ERROR][CORE   ] camxpipeline.cpp:5354 SinkPortFenceErrorSignaled() ZSLSnapshotYUVHAL1_0_cam_0 Reporting stream done for stream=1, sequenceId=54 Buffer type=0 handle=0x0
04-30 10:25:57.287  1898  3600 E CamX    : [ERROR][CORE   ] camxsession.cpp:8659 InjectResult() Session 0xb40000720a61af60 [ZSLSnapshotYUVHAL1] Reporting a buffer error to the framework for streamIndex 1 SeqId: 54 <-> ReqId: 55
04-30 10:25:57.287  1898  3597 E ChiX    : [ERROR][F2Core ] chifeature2base.cpp:8397 ProcessErrorMessageFromDriver()  Base received error type:ERROR_BUFFER
04-30 10:25:57.287  1898  3597 E CamX    : [ERROR][HAL    ] camxhaldevice.cpp:931 Notify() type 00000001, frame_number 54, error_code 00000004, error_stream 0xb40000702976adb8
04-30 10:25:57.288  2370  2370 E CameraDeviceClient: notifyError: pid=18968, errorCode=5, errorStreamId=1, frameNumber=54
04-30 10:25:57.288  2370  2370 E CameraDeviceClient: notifyError: pid=18968, skipClientNotification=false
04-30 10:25:57.294  1898  3600 I SS_3A   :  INFO: AEC: TsAec_process_get_aec_info: 4151: [W][63]algo_out Av=1.695,g=5.642,e_t=0.01667,LLS=0x0,Bv=3.387,Ev=8.309,PEv=8.387,Cvgd=0,lux=237,FS=0,gam=0.0,lls=0x0,drc=5.476,PHdr=0.000,m=0 [m:W]
04-30 10:25:57.306  1898  3600 E GME     : [ERROR][ChiNode] camxchinodegme.cpp:12842 CheckRemosaicCropVideo() MultiCameraSATNoGPUQuad0_com.qti.node.gme3_cam2 Zoom State vendor tag not present
04-30 10:25:57.316 13989 16168 W ExecutorStatsObserver: Running after 19396ms in queue: celloMaybeStartRepeatingPushTaskTimer_37725143{success,timedOut,duration=19396ms,delayMs=30000,wait=19396ms}
04-30 10:25:57.316 13989 16168 W JniExecutor: Running after 19396ms in queue: celloMaybeStartRepeatingPushTaskTimer_37725143{success,timedOut,duration=19396ms,delayMs=30000,wait=19396ms}
04-30 10:25:57.332  1898  3598 E ChiX    : [ERROR][SBM    ] chxstreambuffermanager.cpp:1965 GetStreamBuffer() Can't get buffer for stream 0xb40000702976adb8 : (0, 8, 0, 0, 14) : (avail, pending, used, psStatus, totalUnique), requestId 56, bufferMgrName ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video
04-30 10:25:57.332  1898  3598 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1752 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video] Failed to get buffer from stream buffer manager
04-30 10:25:57.332  1898  3598 E CamX    : [ERROR][MEMMGR ] camximagebuffer.cpp:1823 BindImportedBuffer() [ZSLSnapshotYUVHAL1_IPE3_cam0_OutputPortId9_Video][0xb400007179fefbf0] Invalid Gralloc buffer [0x0] to import
04-30 10:25:57.333  1898  2342 E CamX    : [ERROR][CORE   ] camxnodelegacy.cpp:8211 CSLFenceCallback() Node::ZSLSnapshotYUVHAL1_IPE3_cam0 : Type 65538 portId=9 Fence 29 signaled with failure 2 in node fence handler FOR 56
04-30 10:25:57.333  1898  3597 E CamX    : [ERROR][CORE   ] camxpipeline.cpp:5354 SinkPortFenceErrorSignaled() ZSLSnapshotYUVHAL1_0_cam_0 Reporting stream done for stream=1, sequenceId=55 Buffer type=0 handle=0x0
04-30 10:25:57.333  1898  3597 E CamX    : [ERROR][CORE   ] camxsession.cpp:8659 InjectResult() Session 0xb40000720a61af60 [ZSLSnapshotYUVHAL1] Reporting a buffer error to the framework for streamIndex 1 SeqId: 55 <-> ReqId: 56
04-30 10:25:57.333  1898  3596 E ChiX    : [ERROR][F2Core ] chifeature2base.cpp:8397 ProcessErrorMessageFromDriver()  Base received error type:ERROR_BUFFER
04-30 10:25:57.333  1898  3596 E CamX    : [ERROR][HAL    ] camxhaldevice.cpp:931 Notify() type 00000001, frame_number 55, error_code 00000004, error_stream 0xb40000702976adb8
04-30 10:25:57.334  2370  7676 E CameraDeviceClient: notifyError: pid=18968, errorCode=5, errorStreamId=1, frameNumber=55
04-30 10:25:57.334  2370  7676 E CameraDeviceClient: notifyError: pid=18968, skipClientNotification=false
04-30 10:25:57.337  1898  3598 E GME     : [ERROR][ChiNode] camxchinodegme.cpp:12842 CheckRemosaicCropVideo() MultiCameraSATNoGPUQuad0_com.qti.node.gme3_cam2 Zoom State vendor tag not present
04-30 10:25:57.338  1898  3598 I SS_3A   :  INFO: AEC: TsAec_process_get_aec_info: 4151: [W][64]algo_out Av=1.695,g=5.536,e_t=0.01667,LLS=0x0,Bv=3.383,Ev=8.336,PEv=8.383,Cvgd=0,lux=237,FS=0,gam=0.0,lls=0x0,drc=5.432,PHdr=0.000,m=0 [m:W]
04-30 10:25:57.362 13989 14245 W TaskMonitor: 1 tasks running slow
04-30 10:25:57.362 13989 14245 W TaskMonitor: 1 tasks running slow

Camera Device

{
  "formats": [],
  "sensorOrientation": "landscape-left",
  "hardwareLevel": "full",
  "maxZoom": 10,
  "minZoom": 0.6000000238418579,
  "maxExposure": 20,
  "supportsLowLightBoost": true,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera",
    "ultra-wide-angle-camera",
    "wide-angle-camera",
    "telephoto-camera",
    "telephoto-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": true,
  "minFocusDistance": 10,
  "minExposure": -20,
  "name": "0 (BACK) androidx.camera.camera2",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Samsung Galaxy 24 Ultra

VisionCamera Version

4.0.1

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

mrousavy commented 2 weeks ago

I'm experiencing camera lag

What does that mean? What is camera lag? Is the FPS slow? Is it completely freezing after 6 images? Is it stuttering behind? Is it sometimes smooth sometimes stuttering? Post a video so I can see what you are talking about.

STRATEGY_BLOCK_PRODUCER is used intentionally, this is the behaviour a Frame Processor should have. This is the same strategy that is also used on iOS. It's what I'm trying to explain in the Frame Processor documentation page - frames stream in as often as they can (with fps={30}, 30 times a second, or every 33ms), and if your Frame Processor is not fast enough to finish executing before a new frame arrives, it might drop a new Frame.

STRATEGY_BLOCK_PRODUCER basically means that we push Frames into a queue, and if the queue is full we drop all Frames until a slot is free in the queue.

So if your queue is too slow, you need to do one of two things;

  1. Optimize your Frame Processor to make sure it finishes within 33ms (make scanOCR faster)
  2. Use runAsync to run something that takes longer asynchronously. If your FP is called 30 times a second and you use runAsync which takes longer than 33ms to execute, it will skip running that runAsync code until the Async Context is free again, which is exactly the same behaviour as using STRATEGY_KEEP_ONLY_LATEST. That's what the enableFpsGraph={true} should help you with. If you easily hit 30 or 60 there, you're good.

With the introduction of runAsync we have the power of using STRATEGY_BLOCK_PRODUCER by default, and STRATEGY_KEEP_ONLY_LATEST being opt in (aka using runAsync).

What STRATEGY_KEEP_ONLY_LATEST does is essentially just not calling the ImageAnalysis function if it is still busy. There is no magic behind it - it's simply dropping Frames and allowing the Preview to run freely, we can do the same thing with runAsync.


So I'm not sure if I understood your issue correctly, so curious to hear your thoughts on this after the above explanation as to why I think STRATEGY_KEEP_ONLY_LATEST is a bad idea. :)

mrousavy commented 2 weeks ago

As per the documentation of STRATEGY_KEEP_ONLY_LATEST: image

If only one image is delivered at a time, runAsync would effectively achieve nothing anymore, since no Frames can come in in parallel.

ismaelsousa commented 2 weeks ago

@mrousavy here are some videos and also two ways of handling this https://github.com/ismaelsousa/vision-camera-ocr/issues/9

mrousavy commented 2 weeks ago

Replied over in that issue. This is expected behaviour.