Video capture PipeWire: clear notifier after use and upon destruction

Make sure the notifier is reset when tearing down the camera portal and also when we already called it. Destruction of camera portal will be mostly invoked by an object holding it and serving as an implementation of the notifier interface and in such case we have to make sure it will
not get called at this moment.

Bug: webrtc:15407
Change-Id: If0c1fb1493d64d5e1f0228ed71813abbb9280083
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/315420
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#41167}
diff --git a/modules/video_capture/linux/camera_portal.cc b/modules/video_capture/linux/camera_portal.cc
index 85b9f20..106ca16 100644
--- a/modules/video_capture/linux/camera_portal.cc
+++ b/modules/video_capture/linux/camera_portal.cc
@@ -15,6 +15,7 @@
 
 #include "modules/portal/pipewire_utils.h"
 #include "modules/portal/xdg_desktop_portal_utils.h"
+#include "rtc_base/synchronization/mutex.h"
 
 namespace webrtc {
 
@@ -54,7 +55,9 @@
                              GAsyncResult* result,
                              gpointer user_data);
 
-  CameraPortal::PortalNotifier* notifier_ = nullptr;
+  webrtc::Mutex notifier_lock_;
+  CameraPortal::PortalNotifier* notifier_ RTC_GUARDED_BY(&notifier_lock_) =
+      nullptr;
 
   GDBusConnection* connection_ = nullptr;
   GDBusProxy* proxy_ = nullptr;
@@ -66,6 +69,11 @@
     : notifier_(notifier) {}
 
 CameraPortalPrivate::~CameraPortalPrivate() {
+  {
+    webrtc::MutexLock lock(&notifier_lock_);
+    notifier_ = nullptr;
+  }
+
   if (access_request_signal_id_) {
     g_dbus_connection_signal_unsubscribe(connection_,
                                          access_request_signal_id_);
@@ -229,7 +237,11 @@
 }
 
 void CameraPortalPrivate::OnPortalDone(RequestResponse result, int fd) {
-  notifier_->OnCameraRequestResult(result, fd);
+  webrtc::MutexLock lock(&notifier_lock_);
+  if (notifier_) {
+    notifier_->OnCameraRequestResult(result, fd);
+    notifier_ = nullptr;
+  }
 }
 
 CameraPortal::CameraPortal(PortalNotifier* notifier)