From 3e1e831ae391ae3df62d7770bea2b478d2747c1a Mon Sep 17 00:00:00 2001 From: Peter Hanspers Date: Tue, 5 Sep 2023 17:55:34 +0200 Subject: [PATCH] Reland "ConnectionContext: remove media engine without blocking." This reverts commit 2d71807fe09aad67efcd660fe286044ff10982ba. Reason for revert: With the new AsyncAudioProcessing API, the issue that was introduced can now be worked around. Original change's description: > Revert "ConnectionContext: remove media engine without blocking." > > This reverts commit 2ba941e6bc1d20acb9cfda4b87ba53c80640bbcb. > > Reason for revert: Temporarily reverting due to b/269628432. > > Original change's description: > > ConnectionContext: remove media engine without blocking. > > > > Bug: webrtc:14449 > > Change-Id: I445114c14f4d440a5a8cac003266047fe4588dab > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/288580 > > Reviewed-by: Harald Alvestrand > > Commit-Queue: Markus Handell > > Cr-Commit-Position: refs/heads/main@{#38928} > > Bug: webrtc:14449 > Change-Id: If2f23662e486a1c1f85c318fc98c441aab9ace31 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295862 > Reviewed-by: Harald Alvestrand > Auto-Submit: Markus Handell > Commit-Queue: Harald Alvestrand > Cr-Commit-Position: refs/heads/main@{#39454} Bug: webrtc:14449 Change-Id: I43bb7a3b366eb60b3dc4b88dd9d47d570bb99bc2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/311941 Reviewed-by: Harald Alvestrand Reviewed-by: Markus Handell Commit-Queue: Peter Hanspers Cr-Commit-Position: refs/heads/main@{#40705} --- pc/connection_context.cc | 11 ++--------- pc/connection_context.h | 4 +++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/pc/connection_context.cc b/pc/connection_context.cc index 661550e2d4..f436e27c0a 100644 --- a/pc/connection_context.cc +++ b/pc/connection_context.cc @@ -174,15 +174,8 @@ ConnectionContext::ConnectionContext( ConnectionContext::~ConnectionContext() { RTC_DCHECK_RUN_ON(signaling_thread_); - worker_thread_->BlockingCall([&] { - RTC_DCHECK_RUN_ON(worker_thread()); - // While `media_engine_` is const throughout the ConnectionContext's - // lifetime, it requires destruction to happen on the worker thread. Instead - // of marking the pointer as non-const, we live with this const_cast<> in - // the destructor. - const_cast&>(media_engine_) - .reset(); - }); + // `media_engine_` requires destruction to happen on the worker thread. + worker_thread_->PostTask([media_engine = std::move(media_engine_)] {}); // Make sure `worker_thread()` and `signaling_thread()` outlive // `default_socket_factory_` and `default_network_manager_`. diff --git a/pc/connection_context.h b/pc/connection_context.h index 38a6f8e514..399e7c2b45 100644 --- a/pc/connection_context.h +++ b/pc/connection_context.h @@ -125,7 +125,9 @@ class ConnectionContext final // Accessed both on signaling thread and worker thread. std::unique_ptr const trials_; - const std::unique_ptr media_engine_; + // This object is const over the lifetime of the ConnectionContext, and is + // only altered in the destructor. + std::unique_ptr media_engine_; // This object should be used to generate any SSRC that is not explicitly // specified by the user (or by the remote party).