Trying to prevent crash if capture is stopped by onDisconnect or onError callback that isn't on the same thread
J'essaie de résoudre ce crash qui arrive super souvent : https://play.google.com/console/u/0/developers/9021452841763971947/app/4974848917115858452/vitals/crashes/7580bc019d0b5c1c5158c0bcda66dd26/details?days=28
backtrace:
#00 pc 0x00000000000ec464 /apex/com.android.runtime/lib64/bionic/libc.so (pthread_mutex_lock+8)
#01 pc 0x0000000000007168 /data/app/~~ijfCPcR-r7lSmi1KeaEh5g==/org.linphone-6ONLbR8WfaGGpNdGemufWA==/split_config.arm64_v8a.apk (android_camera2_capture_stop(AndroidCamera2Context*)+540)
#02 pc 0x00000000000293f0 /system/lib64/libcamera2ndk.so (android::acam::CameraDevice::CallbackHandler::onMessageReceived(android::sp<android::AMessage> const&)+932)
#03 pc 0x0000000000018884 /system/lib64/libstagefright_foundation.so (android::AHandler::deliverMessage(android::sp<android::AMessage> const&)+84)
#04 pc 0x000000000001e650 /system/lib64/libstagefright_foundation.so (android::AMessage::deliver()+188)
#05 pc 0x0000000000019bcc /system/lib64/libstagefright_foundation.so (android::ALooper::loop()+592)
#06 pc 0x0000000000012170 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+460)
#07 pc 0x00000000000beecc /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+144)
#08 pc 0x0000000000011960 /system/lib64/libutils.so (thread_data_t::trampoline(thread_data_t const*)+404)
#09 pc 0x00000000000eb6b0 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+264)
#10 pc 0x000000000008af4c /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)
Je viens de voir dans https://android.googlesource.com/platform/frameworks/av/+/master/camera/ndk/impl/ACameraDevice.cpp que les callbacks sont appelées depuis un autre thread:
// Setup looper thread to perfrom device callbacks to app
mCbLooper = new ALooper;
mCbLooper->setName("C2N-dev-looper");
status_t err = mCbLooper->start(
/*runOnCallingThread*/false,
/*canCallJava*/ true,
PRIORITY_DEFAULT);
if (err != OK) {
ALOGE("%s: Unable to start camera device callback looper: %s (%d)",
__FUNCTION__, strerror(-err), err);
setCameraDeviceErrorLocked(ACAMERA_ERROR_CAMERA_DEVICE);
}
mHandler = new CallbackHandler(id);
mCbLooper->registerHandler(mHandler);
Du coup j'ai essayé de faire comme tu avais fait dans le filtre TextureView d'Android.