Updating OnDemuxerCriteria* notifications to be on the same thread.

This makes things slightly simpler for the time being as surrounding
code is being refactored. This also removes a PostTask which has the
effect of shrinking the window between the Pending/Complete
notifications slightly since there's no additional async task
for the 'complete' step.

Bug: webrtc:11993
Change-Id: Ia86779b21c6f87301f37d763f89ace722e06e563
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/244081
Auto-Submit: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35609}
This commit is contained in:
Tomas Gunnarsson
2022-01-02 15:57:28 +00:00
committed by WebRTC LUCI CQ
parent 4163a3dae8
commit f643aea8ac
3 changed files with 13 additions and 10 deletions

View File

@ -208,11 +208,14 @@ class MediaChannel {
// Resets any cached StreamParams for an unsignaled RecvStream, and removes // Resets any cached StreamParams for an unsignaled RecvStream, and removes
// any existing unsignaled streams. // any existing unsignaled streams.
virtual void ResetUnsignaledRecvStream() = 0; virtual void ResetUnsignaledRecvStream() = 0;
// Informs the media channel when the transport's demuxer criteria is updated. // This is currently a workaround because of the demuxer state being managed
// across two separate threads. Once the state is consistently managed on
// the same thread (network), this workaround can be removed.
// These two notifications inform the media channel when the transport's
// demuxer criteria is being updated.
// * OnDemuxerCriteriaUpdatePending() happens on the same thread that the // * OnDemuxerCriteriaUpdatePending() happens on the same thread that the
// channel's streams are added and removed (worker thread). // channel's streams are added and removed (worker thread).
// * OnDemuxerCriteriaUpdateComplete() happens on the thread where the demuxer // * OnDemuxerCriteriaUpdateComplete() happens on the same thread.
// lives (network thread).
// Because the demuxer is updated asynchronously, there is a window of time // Because the demuxer is updated asynchronously, there is a window of time
// where packets are arriving to the channel for streams that have already // where packets are arriving to the channel for streams that have already
// been removed on the worker thread. It is important NOT to treat these as // been removed on the worker thread. It is important NOT to treat these as

View File

@ -1593,11 +1593,8 @@ void WebRtcVideoChannel::OnDemuxerCriteriaUpdatePending() {
} }
void WebRtcVideoChannel::OnDemuxerCriteriaUpdateComplete() { void WebRtcVideoChannel::OnDemuxerCriteriaUpdateComplete() {
RTC_DCHECK_RUN_ON(&network_thread_checker_); RTC_DCHECK_RUN_ON(&thread_checker_);
worker_thread_->PostTask(ToQueuedTask(task_safety_, [this] { ++demuxer_criteria_completed_id_;
RTC_DCHECK_RUN_ON(&thread_checker_);
++demuxer_criteria_completed_id_;
}));
} }
bool WebRtcVideoChannel::SetSink( bool WebRtcVideoChannel::SetSink(

View File

@ -499,7 +499,7 @@ bool BaseChannel::RegisterRtpDemuxerSink_w() {
media_channel_->OnDemuxerCriteriaUpdatePending(); media_channel_->OnDemuxerCriteriaUpdatePending();
// Copy demuxer criteria, since they're a worker-thread variable // Copy demuxer criteria, since they're a worker-thread variable
// and we want to pass them to the network thread // and we want to pass them to the network thread
return network_thread_->Invoke<bool>( bool ret = network_thread_->Invoke<bool>(
RTC_FROM_HERE, [this, demuxer_criteria = demuxer_criteria_] { RTC_FROM_HERE, [this, demuxer_criteria = demuxer_criteria_] {
RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK_RUN_ON(network_thread());
RTC_DCHECK(rtp_transport_); RTC_DCHECK(rtp_transport_);
@ -510,9 +510,12 @@ bool BaseChannel::RegisterRtpDemuxerSink_w() {
} else { } else {
previous_demuxer_criteria_ = {}; previous_demuxer_criteria_ = {};
} }
media_channel_->OnDemuxerCriteriaUpdateComplete();
return result; return result;
}); });
media_channel_->OnDemuxerCriteriaUpdateComplete();
return ret;
} }
void BaseChannel::EnableMedia_w() { void BaseChannel::EnableMedia_w() {