Allow concurrent desktop_capture instances on X11

I would like to run a separate capturer for each desktop on Linux and
I ran into the DCHECK in XErrorTrap when I was prototyping that
solution.  I addressed it by using a Mutex and then experienced and
occasional hang when capturing which I traced down to
SharedXDisplay::ProcessPendingXEvents(), this is a shared display
instance used by each unique capturer instance so I added a mutex
there as well.

I ran 2 capturer instances concurrently for well over an hour and did
not experience any hangs or capture artifacts.

Bug: webrtc:2022
Change-Id: Ia6778cae4bbae48886fe45f2991f02e0ea08fef6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/271920
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Joe Downing <joedow@google.com>
Cr-Commit-Position: refs/heads/main@{#37892}
This commit is contained in:
Joe Downing
2022-08-18 13:01:47 -07:00
committed by WebRTC LUCI CQ
parent 97bdfa32d4
commit bd616ecd64
5 changed files with 52 additions and 29 deletions

View File

@ -17,7 +17,9 @@
#include "absl/strings/string_view.h"
#include "api/ref_counted_base.h"
#include "api/scoped_refptr.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/thread_annotations.h"
// Including Xlib.h will involve evil defines (Bool, Status, True, False), which
// easily conflict with other headers.
@ -76,7 +78,9 @@ class RTC_EXPORT SharedXDisplay
Display* display_;
EventHandlersMap event_handlers_;
Mutex mutex_;
EventHandlersMap event_handlers_ RTC_GUARDED_BY(mutex_);
};
} // namespace webrtc