Declare BaseChannel::media_channel_ const
This makes it thread-safe to access, but not necessarily to use.
Bug: webrtc:12230
Change-Id: I6b48d86dff24b162d382135abeaf560971fdf614
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/196524
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32785}
diff --git a/pc/channel.cc b/pc/channel.cc
index 6ab4371..aad7c54 100644
--- a/pc/channel.cc
+++ b/pc/channel.cc
@@ -152,17 +152,12 @@
// Eats any outstanding messages or packets.
worker_thread_->Clear(&invoker_);
worker_thread_->Clear(this);
- // We must destroy the media channel before the transport channel, otherwise
- // the media channel may try to send on the dead transport channel. NULLing
- // is not an effective strategy since the sends will come on another thread.
- media_channel_.reset();
- RTC_LOG(LS_INFO) << "Destroyed channel: " << ToString();
+ // The media channel is destroyed at the end of the destructor, since it
+ // is a std::unique_ptr. The transport channel (rtp_transport) must outlive
+ // the media channel.
}
std::string BaseChannel::ToString() const {
- // TODO(bugs.webrtc.org/12230): When media_channel_ is guarded by
- // worker_thread(), rewrite this debug printout to not print the
- // media type when called from non-worker-thread.
rtc::StringBuilder sb;
sb << "{mid: " << content_name_;
if (media_channel_) {
diff --git a/pc/channel.h b/pc/channel.h
index ad75070..d9e6d9b 100644
--- a/pc/channel.h
+++ b/pc/channel.h
@@ -185,9 +185,6 @@
}
MediaChannel* media_channel() const override {
- // TODO(bugs.webrtc.org/12230): Called on multiple threads,
- // including from StatsCollector::ExtractMediaInfo.
- // RTC_DCHECK_RUN_ON(worker_thread());
return media_channel_.get();
}
@@ -348,9 +345,7 @@
// MediaChannel related members that should be accessed from the worker
// thread.
- // TODO(bugs.webrtc.org/12230): written on worker thread, accessed by
- // multiple threads.
- std::unique_ptr<MediaChannel> media_channel_;
+ const std::unique_ptr<MediaChannel> media_channel_;
// Currently the |enabled_| flag is accessed from the signaling thread as
// well, but it can be changed only when signaling thread does a synchronous
// call to the worker thread, so it should be safe.