[DataChannelController] Don't fire events from within a loop

Removes a couple of temporary workarounds added in this CL:
https://webrtc-review.googlesource.com/c/src/+/297981

Bug: webrtc:15004
Change-Id: I93e025725be1db56528726cc9f79740e366b8a68
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/298200
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39602}
This commit is contained in:
Tommi 2023-03-20 10:26:19 +01:00 committed by WebRTC LUCI CQ
parent 75990b9a8f
commit dc90a9c583
2 changed files with 17 additions and 14 deletions

View File

@ -100,11 +100,9 @@ void DataChannelController::OnDataReceived(
RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK_RUN_ON(signaling_thread());
// TODO(bugs.webrtc.org/11547): The data being received should be // TODO(bugs.webrtc.org/11547): The data being received should be
// delivered on the network thread. // delivered on the network thread.
auto copy = sctp_data_channels_; auto it = FindChannel(StreamId(channel_id));
for (const auto& channel : copy) { if (it != sctp_data_channels_.end())
if (channel->id() == channel_id) (*it)->OnDataReceived(type, buffer);
channel->OnDataReceived(type, buffer);
}
})); }));
} }
@ -114,11 +112,9 @@ void DataChannelController::OnChannelClosing(int channel_id) {
SafeTask(signaling_safety_.flag(), [this, channel_id] { SafeTask(signaling_safety_.flag(), [this, channel_id] {
RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK_RUN_ON(signaling_thread());
// TODO(bugs.webrtc.org/11547): Should run on the network thread. // TODO(bugs.webrtc.org/11547): Should run on the network thread.
auto copy = sctp_data_channels_; auto it = FindChannel(StreamId(channel_id));
for (const auto& channel : copy) { if (it != sctp_data_channels_.end())
if (channel->id() == channel_id) (*it)->OnClosingProcedureStartedRemotely();
channel->OnClosingProcedureStartedRemotely();
}
})); }));
} }
@ -127,10 +123,7 @@ void DataChannelController::OnChannelClosed(int channel_id) {
signaling_thread()->PostTask( signaling_thread()->PostTask(
SafeTask(signaling_safety_.flag(), [this, channel_id] { SafeTask(signaling_safety_.flag(), [this, channel_id] {
RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK_RUN_ON(signaling_thread());
auto it = absl::c_find_if(sctp_data_channels_, [&](const auto& c) { auto it = FindChannel(StreamId(channel_id));
return c->id() == channel_id;
});
// Remove the channel from our list, close it and free up resources. // Remove the channel from our list, close it and free up resources.
if (it != sctp_data_channels_.end()) { if (it != sctp_data_channels_.end()) {
rtc::scoped_refptr<SctpDataChannel> channel = std::move(*it); rtc::scoped_refptr<SctpDataChannel> channel = std::move(*it);
@ -418,6 +411,13 @@ void DataChannelController::NotifyDataChannelsOfTransportCreated() {
})); }));
} }
std::vector<rtc::scoped_refptr<SctpDataChannel>>::iterator
DataChannelController::FindChannel(StreamId stream_id) {
RTC_DCHECK_RUN_ON(signaling_thread());
return absl::c_find_if(sctp_data_channels_,
[&](const auto& c) { return c->sid() == stream_id; });
}
rtc::Thread* DataChannelController::network_thread() const { rtc::Thread* DataChannelController::network_thread() const {
return pc_->network_thread(); return pc_->network_thread();
} }

View File

@ -134,6 +134,9 @@ class DataChannelController : public SctpDataChannelControllerInterface,
// (calls OnTransportChannelCreated on the signaling thread). // (calls OnTransportChannelCreated on the signaling thread).
void NotifyDataChannelsOfTransportCreated(); void NotifyDataChannelsOfTransportCreated();
std::vector<rtc::scoped_refptr<SctpDataChannel>>::iterator FindChannel(
StreamId stream_id);
rtc::Thread* network_thread() const; rtc::Thread* network_thread() const;
rtc::Thread* signaling_thread() const; rtc::Thread* signaling_thread() const;