Remove usage of rtc::MessageHandler in pc/remote_audio_source

Bug: webrtc:9702
Change-Id: Ibef43b8c1b61afe4cf4e79a7c6549af6d5bff93f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272546
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37859}
This commit is contained in:
Danil Chapovalov
2022-08-22 10:22:40 +02:00
committed by WebRTC LUCI CQ
parent cca4832042
commit c6c346da61
3 changed files with 22 additions and 39 deletions

View File

@ -1854,14 +1854,13 @@ rtc_library("remote_audio_source") {
"../api:media_stream_interface", "../api:media_stream_interface",
"../api:scoped_refptr", "../api:scoped_refptr",
"../api:sequence_checker", "../api:sequence_checker",
"../api/task_queue",
"../media:rtc_media_base", "../media:rtc_media_base",
"../rtc_base", "../rtc_base",
"../rtc_base:checks", "../rtc_base:checks",
"../rtc_base:location",
"../rtc_base:logging", "../rtc_base:logging",
"../rtc_base:safe_conversions", "../rtc_base:safe_conversions",
"../rtc_base:stringutils", "../rtc_base:stringutils",
"../rtc_base:threading",
"../rtc_base/synchronization:mutex", "../rtc_base/synchronization:mutex",
] ]
absl_deps = [ absl_deps = [

View File

@ -14,15 +14,15 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "api/sequence_checker.h" #include "api/sequence_checker.h"
#include "api/task_queue/task_queue_base.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/location.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/strings/string_format.h" #include "rtc_base/strings/string_format.h"
#include "rtc_base/thread.h"
namespace webrtc { namespace webrtc {
@ -51,9 +51,9 @@ class RemoteAudioSource::AudioDataProxy : public AudioSinkInterface {
}; };
RemoteAudioSource::RemoteAudioSource( RemoteAudioSource::RemoteAudioSource(
rtc::Thread* worker_thread, TaskQueueBase* worker_thread,
OnAudioChannelGoneAction on_audio_channel_gone_action) OnAudioChannelGoneAction on_audio_channel_gone_action)
: main_thread_(rtc::Thread::Current()), : main_thread_(TaskQueueBase::Current()),
worker_thread_(worker_thread), worker_thread_(worker_thread),
on_audio_channel_gone_action_(on_audio_channel_gone_action), on_audio_channel_gone_action_(on_audio_channel_gone_action),
state_(MediaSourceInterface::kInitializing) { state_(MediaSourceInterface::kInitializing) {
@ -163,24 +163,18 @@ void RemoteAudioSource::OnAudioChannelGone() {
if (on_audio_channel_gone_action_ != OnAudioChannelGoneAction::kEnd) { if (on_audio_channel_gone_action_ != OnAudioChannelGoneAction::kEnd) {
return; return;
} }
// Called when the audio channel is deleted. It may be the worker thread // Called when the audio channel is deleted. It may be the worker thread or
// in libjingle or may be a different worker thread. // may be a different task queue.
// This object needs to live long enough for the cleanup logic in OnMessage to // This object needs to live long enough for the cleanup logic in the posted
// run, so take a reference to it as the data. Sometimes the message may not // task to run, so take a reference to it. Sometimes the task may not be
// be processed (because the thread was destroyed shortly after this call), // processed (because the task queue was destroyed shortly after this call),
// but that is fine because the thread destructor will take care of destroying // but that is fine because the task queue destructor will take care of
// the message data which will release the reference on RemoteAudioSource. // destroying task which will release the reference on RemoteAudioSource.
main_thread_->Post(RTC_FROM_HERE, this, 0, rtc::scoped_refptr<RemoteAudioSource> thiz(this);
new rtc::ScopedRefMessageData<RemoteAudioSource>(this)); main_thread_->PostTask([thiz = std::move(thiz)] {
} thiz->sinks_.clear();
thiz->SetState(MediaSourceInterface::kEnded);
void RemoteAudioSource::OnMessage(rtc::Message* msg) { });
RTC_DCHECK_RUN_ON(main_thread_);
sinks_.clear();
SetState(MediaSourceInterface::kEnded);
// Will possibly delete this RemoteAudioSource since it is reference counted
// in the message.
delete msg->pdata;
} }
} // namespace webrtc } // namespace webrtc

View File

@ -20,24 +20,16 @@
#include "api/call/audio_sink.h" #include "api/call/audio_sink.h"
#include "api/media_stream_interface.h" #include "api/media_stream_interface.h"
#include "api/notifier.h" #include "api/notifier.h"
#include "api/task_queue/task_queue_base.h"
#include "media/base/media_channel.h" #include "media/base/media_channel.h"
#include "rtc_base/message_handler.h"
#include "rtc_base/synchronization/mutex.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread.h"
#include "rtc_base/thread_message.h"
namespace rtc {
struct Message;
class Thread;
} // namespace rtc
namespace webrtc { namespace webrtc {
// This class implements the audio source used by the remote audio track. // This class implements the audio source used by the remote audio track.
// This class works by configuring itself as a sink with the underlying media // This class works by configuring itself as a sink with the underlying media
// engine, then when receiving data will fan out to all added sinks. // engine, then when receiving data will fan out to all added sinks.
class RemoteAudioSource : public Notifier<AudioSourceInterface>, class RemoteAudioSource : public Notifier<AudioSourceInterface> {
rtc::MessageHandler {
public: public:
// In Unified Plan, receivers map to m= sections and their tracks and sources // In Unified Plan, receivers map to m= sections and their tracks and sources
// survive SSRCs being reconfigured. The life cycle of the remote audio source // survive SSRCs being reconfigured. The life cycle of the remote audio source
@ -52,7 +44,7 @@ class RemoteAudioSource : public Notifier<AudioSourceInterface>,
}; };
explicit RemoteAudioSource( explicit RemoteAudioSource(
rtc::Thread* worker_thread, TaskQueueBase* worker_thread,
OnAudioChannelGoneAction on_audio_channel_gone_action); OnAudioChannelGoneAction on_audio_channel_gone_action);
// Register and unregister remote audio source with the underlying media // Register and unregister remote audio source with the underlying media
@ -85,10 +77,8 @@ class RemoteAudioSource : public Notifier<AudioSourceInterface>,
void OnData(const AudioSinkInterface::Data& audio); void OnData(const AudioSinkInterface::Data& audio);
void OnAudioChannelGone(); void OnAudioChannelGone();
void OnMessage(rtc::Message* msg) override; TaskQueueBase* const main_thread_;
TaskQueueBase* const worker_thread_;
rtc::Thread* const main_thread_;
rtc::Thread* const worker_thread_;
const OnAudioChannelGoneAction on_audio_channel_gone_action_; const OnAudioChannelGoneAction on_audio_channel_gone_action_;
std::list<AudioObserver*> audio_observers_; std::list<AudioObserver*> audio_observers_;
Mutex sink_lock_; Mutex sink_lock_;