fix: Fix UI Thread race condition in setFrameProcessor(...) (#265)
* fix: Fix UI Thread race condition in `setFrameProcessor(...)` * Revert "fix: Fix UI Thread race condition in `setFrameProcessor(...)`" This reverts commit 9c524e123cff6843d7d11db602a5027d1bb06b4b. * Use `setImmediate` to call `setFrameProcessor(...)` * Fix frame processor order of applying * Add `enableFrameProcessor` prop that defines if a FP is added * rename constant * Implement `enableFrameProcessor` prop for Android and make `frameProcessorFps` faster * link to troubleshooting guide * Update TROUBLESHOOTING.mdx * Add logs for use-cases * fix log * set initial frame processor in `onLayout` instead of `componentDidMount`
This commit is contained in:
@@ -30,8 +30,7 @@ void CameraView::registerNatives() {
|
||||
|
||||
void CameraView::frameProcessorCallback(const alias_ref<JImageProxy::javaobject>& frame) {
|
||||
if (frameProcessor_ == nullptr) {
|
||||
__android_log_write(ANDROID_LOG_WARN, TAG, "Frame Processor is null!");
|
||||
setEnableFrameProcessor(false);
|
||||
__android_log_write(ANDROID_LOG_WARN, TAG, "Called Frame Processor callback, but `frameProcessor` is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,24 +44,12 @@ void CameraView::frameProcessorCallback(const alias_ref<JImageProxy::javaobject>
|
||||
}
|
||||
}
|
||||
|
||||
void CameraView::setEnableFrameProcessor(bool enable) {
|
||||
if (enable) {
|
||||
__android_log_write(ANDROID_LOG_INFO, TAG, "Enabling Frame Processor Callback...");
|
||||
} else {
|
||||
__android_log_write(ANDROID_LOG_INFO, TAG, "Disabling Frame Processor Callback...");
|
||||
}
|
||||
static const auto javaMethod = javaPart_->getClass()->getMethod<void(bool)>("setEnableFrameProcessor");
|
||||
javaMethod(javaPart_.get(), enable);
|
||||
}
|
||||
|
||||
void CameraView::setFrameProcessor(const FrameProcessor&& frameProcessor) {
|
||||
frameProcessor_ = frameProcessor;
|
||||
setEnableFrameProcessor(true);
|
||||
}
|
||||
|
||||
void vision::CameraView::unsetFrameProcessor() {
|
||||
frameProcessor_ = nullptr;
|
||||
setEnableFrameProcessor(false);
|
||||
}
|
||||
|
||||
} // namespace vision
|
||||
|
||||
@@ -26,7 +26,6 @@ class CameraView : public jni::HybridClass<CameraView> {
|
||||
// TODO: Use template<> to avoid heap allocation for std::function<>
|
||||
void setFrameProcessor(const FrameProcessor&& frameProcessor);
|
||||
void unsetFrameProcessor();
|
||||
void setEnableFrameProcessor(bool enable);
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
|
||||
Reference in New Issue
Block a user