VideoRtpReceiver & AudioRtpReceiver threading fixes.

For implementations where the signaling and worker threads are not
the same thread, this significantly cuts down on Thread::Invoke()s that
would block the signaling thread while waiting for the worker thread.

For Audio and Video Rtp receivers, the following methods now do not
block the signaling thread:
* GetParameters
* SetJitterBufferMinimumDelay
* GetSources
* SetFrameDecryptor / GetFrameDecryptor
* SetDepacketizerToDecoderFrameTransformer

Importantly this change also makes the track() accessor accessible
directly from the application thread (bypassing the proxy) since
for receiver objects, the track object is const.

Other changes:

* Remove RefCountedObject inheritance, use make_ref_counted instead.
* Every member variable in the rtp receiver classes is now RTC_GUARDED
* Stop() now fully clears up worker thread state, and Stop() is
  consistently called before destruction. This means that there's one
  thread hop instead of at least 4 before (sometimes more), per receiver.
* OnChanged triggered volume for audio tracks is done asynchronously.
* Deleted most of the JitterBufferDelay implementation. Turns out that
  it was largely unnecessary overhead and complexity.

It seems that these two classes are copy/pasted to a large extent
so further refactoring would be good in the future, as to not have to
fix each issue twice.

Bug: chromium:1184611
Change-Id: I1ba5c3abbd1b0571f7d12850d64004fd2d83e5e2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/218605
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#34022}
diff --git a/pc/remote_audio_source.cc b/pc/remote_audio_source.cc
index 9e65f67..dc890e7 100644
--- a/pc/remote_audio_source.cc
+++ b/pc/remote_audio_source.cc
@@ -61,7 +61,7 @@
 }
 
 RemoteAudioSource::~RemoteAudioSource() {
-  RTC_DCHECK(main_thread_->IsCurrent());
+  RTC_DCHECK_RUN_ON(main_thread_);
   RTC_DCHECK(audio_observers_.empty());
   if (!sinks_.empty()) {
     RTC_LOG(LS_WARNING)
@@ -71,32 +71,28 @@
 
 void RemoteAudioSource::Start(cricket::VoiceMediaChannel* media_channel,
                               absl::optional<uint32_t> ssrc) {
-  RTC_DCHECK_RUN_ON(main_thread_);
-  RTC_DCHECK(media_channel);
+  RTC_DCHECK_RUN_ON(worker_thread_);
 
   // Register for callbacks immediately before AddSink so that we always get
   // notified when a channel goes out of scope (signaled when "AudioDataProxy"
   // is destroyed).
-  worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] {
-    ssrc ? media_channel->SetRawAudioSink(
-               *ssrc, std::make_unique<AudioDataProxy>(this))
-         : media_channel->SetDefaultRawAudioSink(
-               std::make_unique<AudioDataProxy>(this));
-  });
+  RTC_DCHECK(media_channel);
+  ssrc ? media_channel->SetRawAudioSink(*ssrc,
+                                        std::make_unique<AudioDataProxy>(this))
+       : media_channel->SetDefaultRawAudioSink(
+             std::make_unique<AudioDataProxy>(this));
 }
 
 void RemoteAudioSource::Stop(cricket::VoiceMediaChannel* media_channel,
                              absl::optional<uint32_t> ssrc) {
-  RTC_DCHECK_RUN_ON(main_thread_);
+  RTC_DCHECK_RUN_ON(worker_thread_);
   RTC_DCHECK(media_channel);
-
-  worker_thread_->Invoke<void>(RTC_FROM_HERE, [&] {
-    ssrc ? media_channel->SetRawAudioSink(*ssrc, nullptr)
-         : media_channel->SetDefaultRawAudioSink(nullptr);
-  });
+  ssrc ? media_channel->SetRawAudioSink(*ssrc, nullptr)
+       : media_channel->SetDefaultRawAudioSink(nullptr);
 }
 
 void RemoteAudioSource::SetState(SourceState new_state) {
+  RTC_DCHECK_RUN_ON(main_thread_);
   if (state_ != new_state) {
     state_ = new_state;
     FireOnChanged();
@@ -104,12 +100,12 @@
 }
 
 MediaSourceInterface::SourceState RemoteAudioSource::state() const {
-  RTC_DCHECK(main_thread_->IsCurrent());
+  RTC_DCHECK_RUN_ON(main_thread_);
   return state_;
 }
 
 bool RemoteAudioSource::remote() const {
-  RTC_DCHECK(main_thread_->IsCurrent());
+  RTC_DCHECK_RUN_ON(main_thread_);
   return true;
 }
 
@@ -135,7 +131,7 @@
 }
 
 void RemoteAudioSource::AddSink(AudioTrackSinkInterface* sink) {
-  RTC_DCHECK(main_thread_->IsCurrent());
+  RTC_DCHECK_RUN_ON(main_thread_);
   RTC_DCHECK(sink);
 
   if (state_ != MediaSourceInterface::kLive) {
@@ -149,7 +145,7 @@
 }
 
 void RemoteAudioSource::RemoveSink(AudioTrackSinkInterface* sink) {
-  RTC_DCHECK(main_thread_->IsCurrent());
+  RTC_DCHECK_RUN_ON(main_thread_);
   RTC_DCHECK(sink);
 
   MutexLock lock(&sink_lock_);
@@ -184,7 +180,7 @@
 }
 
 void RemoteAudioSource::OnMessage(rtc::Message* msg) {
-  RTC_DCHECK(main_thread_->IsCurrent());
+  RTC_DCHECK_RUN_ON(main_thread_);
   sinks_.clear();
   SetState(MediaSourceInterface::kEnded);
   // Will possibly delete this RemoteAudioSource since it is reference counted