diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:35:49 +0000 |
commit | d8bbc7858622b6d9c278469aab701ca0b609cddf (patch) | |
tree | eff41dc61d9f714852212739e6b3738b82a2af87 /third_party/libwebrtc/audio | |
parent | Releasing progress-linux version 125.0.3-1~progress7.99u1. (diff) | |
download | firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.tar.xz firefox-d8bbc7858622b6d9c278469aab701ca0b609cddf.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/audio')
13 files changed, 80 insertions, 63 deletions
diff --git a/third_party/libwebrtc/audio/BUILD.gn b/third_party/libwebrtc/audio/BUILD.gn index 09562b9131..7ece107407 100644 --- a/third_party/libwebrtc/audio/BUILD.gn +++ b/third_party/libwebrtc/audio/BUILD.gn @@ -97,7 +97,6 @@ rtc_library("audio") { "../rtc_base:refcount", "../rtc_base:rtc_event", "../rtc_base:rtc_numerics", - "../rtc_base:rtc_task_queue", "../rtc_base:safe_conversions", "../rtc_base:safe_minmax", "../rtc_base:stringutils", @@ -175,7 +174,8 @@ if (rtc_include_tests) { "../api/audio_codecs/opus:audio_decoder_opus", "../api/audio_codecs/opus:audio_encoder_opus", "../api/crypto:frame_decryptor_interface", - "../api/rtc_event_log", + "../api/environment", + "../api/environment:environment_factory", "../api/task_queue:default_task_queue_factory", "../api/task_queue/test:mock_task_queue_base", "../api/units:time_delta", @@ -223,7 +223,10 @@ if (rtc_include_tests) { "utility:utility_tests", "//testing/gtest", ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/types:optional", + ] } rtc_library("channel_receive_unittest") { @@ -247,6 +250,9 @@ if (rtc_include_tests) { "../test:test_support", "../test/time_controller", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] } } diff --git a/third_party/libwebrtc/audio/audio_receive_stream.cc b/third_party/libwebrtc/audio/audio_receive_stream.cc index c49b83f95f..32a8e1c172 100644 --- a/third_party/libwebrtc/audio/audio_receive_stream.cc +++ b/third_party/libwebrtc/audio/audio_receive_stream.cc @@ -186,6 +186,7 @@ void AudioReceiveStreamImpl::Start() { if (playing_) { return; } + RTC_LOG(LS_INFO) << "AudioReceiveStreamImpl::Start: " << remote_ssrc(); channel_receive_->StartPlayout(); playing_ = true; audio_state()->AddReceivingStream(this); @@ -196,6 +197,7 @@ void AudioReceiveStreamImpl::Stop() { if (!playing_) { return; } + RTC_LOG(LS_INFO) << "AudioReceiveStreamImpl::Stop: " << remote_ssrc(); channel_receive_->StopPlayout(); playing_ = false; audio_state()->RemoveReceivingStream(this); diff --git a/third_party/libwebrtc/audio/audio_send_stream.cc b/third_party/libwebrtc/audio/audio_send_stream.cc index e7ebb2bf4e..8dc78b18fa 100644 --- a/third_party/libwebrtc/audio/audio_send_stream.cc +++ b/third_party/libwebrtc/audio/audio_send_stream.cc @@ -355,6 +355,7 @@ void AudioSendStream::Start() { if (sending_) { return; } + RTC_LOG(LS_INFO) << "AudioSendStream::Start: " << config_.rtp.ssrc; if (!config_.has_dscp && config_.min_bitrate_bps != -1 && config_.max_bitrate_bps != -1 && (allocate_audio_without_feedback_ || TransportSeqNumId(config_) != 0)) { @@ -376,7 +377,7 @@ void AudioSendStream::Stop() { if (!sending_) { return; } - + RTC_LOG(LS_INFO) << "AudioSendStream::Stop: " << config_.rtp.ssrc; RemoveBitrateObserver(); channel_send_->StopSend(); sending_ = false; diff --git a/third_party/libwebrtc/audio/audio_send_stream.h b/third_party/libwebrtc/audio/audio_send_stream.h index 62ccd524cb..09fd712d40 100644 --- a/third_party/libwebrtc/audio/audio_send_stream.h +++ b/third_party/libwebrtc/audio/audio_send_stream.h @@ -28,7 +28,6 @@ #include "rtc_base/experiments/struct_parameters_parser.h" #include "rtc_base/race_checker.h" #include "rtc_base/synchronization/mutex.h" -#include "rtc_base/task_queue.h" namespace webrtc { class RtcEventLog; diff --git a/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.h b/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.h index 37ff75c2e9..d572ffe8d1 100644 --- a/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.h +++ b/third_party/libwebrtc/audio/channel_receive_frame_transformer_delegate.h @@ -16,8 +16,8 @@ #include "api/frame_transformer_interface.h" #include "api/sequence_checker.h" +#include "api/task_queue/task_queue_base.h" #include "rtc_base/system/no_unique_address.h" -#include "rtc_base/task_queue.h" #include "rtc_base/thread.h" namespace webrtc { diff --git a/third_party/libwebrtc/audio/channel_send.cc b/third_party/libwebrtc/audio/channel_send.cc index 3c59be52b4..ae264a4c77 100644 --- a/third_party/libwebrtc/audio/channel_send.cc +++ b/third_party/libwebrtc/audio/channel_send.cc @@ -39,7 +39,7 @@ #include "rtc_base/rate_limiter.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/synchronization/mutex.h" -#include "rtc_base/task_queue.h" +#include "rtc_base/system/no_unique_address.h" #include "rtc_base/time_utils.h" #include "rtc_base/trace_event.h" #include "system_wrappers/include/clock.h" @@ -196,7 +196,7 @@ class ChannelSend : public ChannelSendInterface, rtc::ArrayView<const uint8_t> payload, int64_t absolute_capture_timestamp_ms, rtc::ArrayView<const uint32_t> csrcs) - RTC_RUN_ON(encoder_queue_); + RTC_RUN_ON(encoder_queue_checker_); void OnReceivedRtt(int64_t rtt_ms); @@ -207,7 +207,7 @@ class ChannelSend : public ChannelSendInterface, // specific threads we know about. The goal is to eventually split up // voe::Channel into parts with single-threaded semantics, and thereby reduce // the need for locks. - SequenceChecker worker_thread_checker_; + RTC_NO_UNIQUE_ADDRESS SequenceChecker worker_thread_checker_; // Methods accessed from audio and video threads are checked for sequential- // only access. We don't necessarily own and control these threads, so thread // checkers cannot be used. E.g. Chromium may transfer "ownership" from one @@ -231,9 +231,9 @@ class ChannelSend : public ChannelSendInterface, absl::optional<int64_t> last_capture_timestamp_ms_ RTC_GUARDED_BY(audio_thread_race_checker_); - RmsLevel rms_level_ RTC_GUARDED_BY(encoder_queue_); + RmsLevel rms_level_ RTC_GUARDED_BY(encoder_queue_checker_); bool input_mute_ RTC_GUARDED_BY(volume_settings_mutex_) = false; - bool previous_frame_muted_ RTC_GUARDED_BY(encoder_queue_) = false; + bool previous_frame_muted_ RTC_GUARDED_BY(encoder_queue_checker_) = false; const std::unique_ptr<RtcpCounterObserver> rtcp_counter_observer_; @@ -242,7 +242,7 @@ class ChannelSend : public ChannelSendInterface, const std::unique_ptr<RtpPacketSenderProxy> rtp_packet_pacer_proxy_; const std::unique_ptr<RateLimiter> retransmission_rate_limiter_; - SequenceChecker construction_thread_; + RTC_NO_UNIQUE_ADDRESS SequenceChecker construction_thread_; std::atomic<bool> include_audio_level_indication_ = false; std::atomic<bool> encoder_queue_is_active_ = false; @@ -250,7 +250,7 @@ class ChannelSend : public ChannelSendInterface, // E2EE Audio Frame Encryption rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor_ - RTC_GUARDED_BY(encoder_queue_); + RTC_GUARDED_BY(encoder_queue_checker_); // E2EE Frame Encryption Options const webrtc::CryptoOptions crypto_options_; @@ -258,15 +258,14 @@ class ChannelSend : public ChannelSendInterface, // receives callbacks with the transformed frames; delegates calls to // ChannelSend::SendRtpAudio to send the transformed audio. rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> - frame_transformer_delegate_ RTC_GUARDED_BY(encoder_queue_); + frame_transformer_delegate_ RTC_GUARDED_BY(encoder_queue_checker_); mutable Mutex rtcp_counter_mutex_; RtcpPacketTypeCounter rtcp_packet_type_counter_ RTC_GUARDED_BY(rtcp_counter_mutex_); - // Defined last to ensure that there are no running tasks when the other - // members are destroyed. - rtc::TaskQueue encoder_queue_; + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue_; + RTC_NO_UNIQUE_ADDRESS SequenceChecker encoder_queue_checker_; SdpAudioFormat encoder_format_; }; @@ -299,7 +298,7 @@ class RtpPacketSenderProxy : public RtpPacketSender { } private: - SequenceChecker thread_checker_; + RTC_NO_UNIQUE_ADDRESS SequenceChecker thread_checker_; Mutex mutex_; RtpPacketSender* rtp_packet_pacer_ RTC_GUARDED_BY(&mutex_); }; @@ -310,7 +309,7 @@ int32_t ChannelSend::SendData(AudioFrameType frameType, const uint8_t* payloadData, size_t payloadSize, int64_t absolute_capture_timestamp_ms) { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); rtc::ArrayView<const uint8_t> payload(payloadData, payloadSize); if (frame_transformer_delegate_) { // Asynchronously transform the payload before sending it. After the payload @@ -438,6 +437,7 @@ ChannelSend::ChannelSend( encoder_queue_(task_queue_factory->CreateTaskQueue( "AudioEncoder", TaskQueueFactory::Priority::NORMAL)), + encoder_queue_checker_(encoder_queue_.get()), encoder_format_("x-unknown", 0, 0) { audio_coding_ = AudioCodingModule::Create(); @@ -490,6 +490,10 @@ ChannelSend::~ChannelSend() { StopSend(); int error = audio_coding_->RegisterTransportCallback(NULL); RTC_DCHECK_EQ(0, error); + + // Delete the encoder task queue first to ensure that there are no running + // tasks when the other members are destroyed. + encoder_queue_ = nullptr; } void ChannelSend::StartSend() { @@ -519,8 +523,8 @@ void ChannelSend::StopSend() { // Wait until all pending encode tasks are executed and clear any remaining // buffers in the encoder. rtc::Event flush; - encoder_queue_.PostTask([this, &flush]() { - RTC_DCHECK_RUN_ON(&encoder_queue_); + encoder_queue_->PostTask([this, &flush]() { + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); CallEncoder([](AudioEncoder* encoder) { encoder->Reset(); }); flush.Set(); }); @@ -794,9 +798,9 @@ void ChannelSend::ProcessAndEncodeAudio( // Profile time between when the audio frame is added to the task queue and // when the task is actually executed. audio_frame->UpdateProfileTimeStamp(); - encoder_queue_.PostTask( + encoder_queue_->PostTask( [this, audio_frame = std::move(audio_frame)]() mutable { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); if (!encoder_queue_is_active_.load()) { return; } @@ -858,8 +862,8 @@ int64_t ChannelSend::GetRTT() const { void ChannelSend::SetFrameEncryptor( rtc::scoped_refptr<FrameEncryptorInterface> frame_encryptor) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); - encoder_queue_.PostTask([this, frame_encryptor]() mutable { - RTC_DCHECK_RUN_ON(&encoder_queue_); + encoder_queue_->PostTask([this, frame_encryptor]() mutable { + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); frame_encryptor_ = std::move(frame_encryptor); }); } @@ -870,9 +874,9 @@ void ChannelSend::SetEncoderToPacketizerFrameTransformer( if (!frame_transformer) return; - encoder_queue_.PostTask( + encoder_queue_->PostTask( [this, frame_transformer = std::move(frame_transformer)]() mutable { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); InitFrameTransformerDelegate(std::move(frame_transformer)); }); } @@ -885,7 +889,7 @@ void ChannelSend::OnReceivedRtt(int64_t rtt_ms) { void ChannelSend::InitFrameTransformerDelegate( rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); RTC_DCHECK(frame_transformer); RTC_DCHECK(!frame_transformer_delegate_); @@ -897,7 +901,7 @@ void ChannelSend::InitFrameTransformerDelegate( rtc::ArrayView<const uint8_t> payload, int64_t absolute_capture_timestamp_ms, rtc::ArrayView<const uint32_t> csrcs) { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); return SendRtpAudio( frameType, payloadType, rtp_timestamp_with_offset - rtp_rtcp_->StartTimestamp(), payload, @@ -906,7 +910,7 @@ void ChannelSend::InitFrameTransformerDelegate( frame_transformer_delegate_ = rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( std::move(send_audio_callback), std::move(frame_transformer), - &encoder_queue_); + encoder_queue_.get()); frame_transformer_delegate_->Init(); } diff --git a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.cc b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.cc index 2eea0d2387..ac32410aed 100644 --- a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.cc +++ b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.cc @@ -114,7 +114,7 @@ class TransformableOutgoingAudioFrame ChannelSendFrameTransformerDelegate::ChannelSendFrameTransformerDelegate( SendFrameCallback send_frame_callback, rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, - rtc::TaskQueue* encoder_queue) + TaskQueueBase* encoder_queue) : send_frame_callback_(send_frame_callback), frame_transformer_(std::move(frame_transformer)), encoder_queue_(encoder_queue) {} diff --git a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.h b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.h index 97fc14f737..30e63ff98b 100644 --- a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.h +++ b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate.h @@ -16,10 +16,10 @@ #include "api/frame_transformer_interface.h" #include "api/sequence_checker.h" +#include "api/task_queue/task_queue_base.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "rtc_base/buffer.h" #include "rtc_base/synchronization/mutex.h" -#include "rtc_base/task_queue.h" namespace webrtc { @@ -40,7 +40,7 @@ class ChannelSendFrameTransformerDelegate : public TransformedFrameCallback { ChannelSendFrameTransformerDelegate( SendFrameCallback send_frame_callback, rtc::scoped_refptr<FrameTransformerInterface> frame_transformer, - rtc::TaskQueue* encoder_queue); + TaskQueueBase* encoder_queue); // Registers `this` as callback for `frame_transformer_`, to get the // transformed frames. @@ -79,7 +79,7 @@ class ChannelSendFrameTransformerDelegate : public TransformedFrameCallback { mutable Mutex send_lock_; SendFrameCallback send_frame_callback_ RTC_GUARDED_BY(send_lock_); rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_; - rtc::TaskQueue* encoder_queue_ RTC_GUARDED_BY(send_lock_); + TaskQueueBase* const encoder_queue_; bool short_circuit_ RTC_GUARDED_BY(send_lock_) = false; }; diff --git a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc index 4dcd15cd95..483a2cce78 100644 --- a/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc +++ b/third_party/libwebrtc/audio/channel_send_frame_transformer_delegate_unittest.cc @@ -78,7 +78,7 @@ std::unique_ptr<TransformableAudioFrameInterface> CreateFrame() { MockChannelSend mock_channel; rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( - mock_channel.callback(), mock_frame_transformer, &channel_queue); + mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); std::unique_ptr<TransformableFrameInterface> frame; ON_CALL(*mock_frame_transformer, Transform) @@ -131,7 +131,7 @@ TEST(ChannelSendFrameTransformerDelegateTest, MockChannelSend mock_channel; rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( - mock_channel.callback(), mock_frame_transformer, &channel_queue); + mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); rtc::scoped_refptr<TransformedFrameCallback> callback; EXPECT_CALL(*mock_frame_transformer, RegisterTransformedFrameCallback) .WillOnce(SaveArg<0>(&callback)); @@ -160,7 +160,7 @@ TEST(ChannelSendFrameTransformerDelegateTest, MockChannelSend mock_channel; rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( - mock_channel.callback(), mock_frame_transformer, &channel_queue); + mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); rtc::scoped_refptr<TransformedFrameCallback> callback; EXPECT_CALL(*mock_frame_transformer, RegisterTransformedFrameCallback) .WillOnce(SaveArg<0>(&callback)); @@ -192,7 +192,7 @@ TEST(ChannelSendFrameTransformerDelegateTest, MockChannelSend mock_channel; rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( - mock_channel.callback(), mock_frame_transformer, &channel_queue); + mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); delegate->Reset(); EXPECT_CALL(mock_channel, SendFrame).Times(0); @@ -207,7 +207,7 @@ TEST(ChannelSendFrameTransformerDelegateTest, ShortCircuitingSkipsTransform) { MockChannelSend mock_channel; rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = rtc::make_ref_counted<ChannelSendFrameTransformerDelegate>( - mock_channel.callback(), mock_frame_transformer, &channel_queue); + mock_channel.callback(), mock_frame_transformer, channel_queue.Get()); delegate->StartShortCircuiting(); diff --git a/third_party/libwebrtc/audio/channel_send_unittest.cc b/third_party/libwebrtc/audio/channel_send_unittest.cc index 58d7c93c1e..c86dcefadc 100644 --- a/third_party/libwebrtc/audio/channel_send_unittest.cc +++ b/third_party/libwebrtc/audio/channel_send_unittest.cc @@ -14,7 +14,8 @@ #include "api/audio/audio_frame.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" -#include "api/rtc_event_log/rtc_event_log.h" +#include "api/environment/environment.h" +#include "api/environment/environment_factory.h" #include "api/scoped_refptr.h" #include "api/units/time_delta.h" #include "api/units/timestamp.h" @@ -53,18 +54,17 @@ class ChannelSendTest : public ::testing::Test { protected: ChannelSendTest() : time_controller_(Timestamp::Seconds(1)), + env_(CreateEnvironment(&field_trials_, + time_controller_.GetClock(), + time_controller_.CreateTaskQueueFactory())), transport_controller_( - time_controller_.GetClock(), - RtpTransportConfig{ - .bitrate_config = GetBitrateConfig(), - .event_log = &event_log_, - .task_queue_factory = time_controller_.GetTaskQueueFactory(), - .trials = &field_trials_, - }) { + RtpTransportConfig{.env = env_, + .bitrate_config = GetBitrateConfig()}) { channel_ = voe::CreateChannelSend( time_controller_.GetClock(), time_controller_.GetTaskQueueFactory(), - &transport_, nullptr, &event_log_, nullptr, crypto_options_, false, - kRtcpIntervalMs, kSsrc, nullptr, &transport_controller_, field_trials_); + &transport_, nullptr, &env_.event_log(), nullptr, crypto_options_, + false, kRtcpIntervalMs, kSsrc, nullptr, &transport_controller_, + env_.field_trials()); encoder_factory_ = CreateBuiltinAudioEncoderFactory(); SdpAudioFormat opus = SdpAudioFormat("opus", kRtpRateHz, 2); std::unique_ptr<AudioEncoder> encoder = @@ -94,7 +94,7 @@ class ChannelSendTest : public ::testing::Test { GlobalSimulatedTimeController time_controller_; webrtc::test::ScopedKeyValueConfig field_trials_; - RtcEventLogNull event_log_; + Environment env_; NiceMock<MockTransport> transport_; CryptoOptions crypto_options_; RtpTransportControllerSend transport_controller_; diff --git a/third_party/libwebrtc/audio/voip/BUILD.gn b/third_party/libwebrtc/audio/voip/BUILD.gn index e807e2276b..75f20a6ed2 100644 --- a/third_party/libwebrtc/audio/voip/BUILD.gn +++ b/third_party/libwebrtc/audio/voip/BUILD.gn @@ -94,7 +94,6 @@ rtc_library("audio_egress") { "../../modules/rtp_rtcp", "../../modules/rtp_rtcp:rtp_rtcp_format", "../../rtc_base:logging", - "../../rtc_base:rtc_task_queue", "../../rtc_base:timeutils", "../../rtc_base/synchronization:mutex", "../../rtc_base/system:no_unique_address", diff --git a/third_party/libwebrtc/audio/voip/audio_egress.cc b/third_party/libwebrtc/audio/voip/audio_egress.cc index 95a1a3351e..09396cd28d 100644 --- a/third_party/libwebrtc/audio/voip/audio_egress.cc +++ b/third_party/libwebrtc/audio/voip/audio_egress.cc @@ -13,6 +13,7 @@ #include <utility> #include <vector> +#include "api/sequence_checker.h" #include "rtc_base/logging.h" namespace webrtc { @@ -25,12 +26,17 @@ AudioEgress::AudioEgress(RtpRtcpInterface* rtp_rtcp, audio_coding_(AudioCodingModule::Create()), encoder_queue_(task_queue_factory->CreateTaskQueue( "AudioEncoder", - TaskQueueFactory::Priority::NORMAL)) { + TaskQueueFactory::Priority::NORMAL)), + encoder_queue_checker_(encoder_queue_.get()) { audio_coding_->RegisterTransportCallback(this); } AudioEgress::~AudioEgress() { audio_coding_->RegisterTransportCallback(nullptr); + + // Delete first to ensure that there are no running tasks when the other + // members are destroyed. + encoder_queue_ = nullptr; } bool AudioEgress::IsSending() const { @@ -73,9 +79,9 @@ void AudioEgress::SendAudioData(std::unique_ptr<AudioFrame> audio_frame) { RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0); RTC_DCHECK_LE(audio_frame->num_channels_, 8); - encoder_queue_.PostTask( + encoder_queue_->PostTask( [this, audio_frame = std::move(audio_frame)]() mutable { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); if (!rtp_rtcp_->SendingMedia()) { return; } @@ -112,7 +118,7 @@ int32_t AudioEgress::SendData(AudioFrameType frame_type, uint32_t timestamp, const uint8_t* payload_data, size_t payload_size) { - RTC_DCHECK_RUN_ON(&encoder_queue_); + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); rtc::ArrayView<const uint8_t> payload(payload_data, payload_size); @@ -175,8 +181,8 @@ bool AudioEgress::SendTelephoneEvent(int dtmf_event, int duration_ms) { } void AudioEgress::SetMute(bool mute) { - encoder_queue_.PostTask([this, mute] { - RTC_DCHECK_RUN_ON(&encoder_queue_); + encoder_queue_->PostTask([this, mute] { + RTC_DCHECK_RUN_ON(&encoder_queue_checker_); encoder_context_.mute_ = mute; }); } diff --git a/third_party/libwebrtc/audio/voip/audio_egress.h b/third_party/libwebrtc/audio/voip/audio_egress.h index 989e5bda59..6d1489db34 100644 --- a/third_party/libwebrtc/audio/voip/audio_egress.h +++ b/third_party/libwebrtc/audio/voip/audio_egress.h @@ -16,6 +16,7 @@ #include "api/audio_codecs/audio_format.h" #include "api/sequence_checker.h" +#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_factory.h" #include "audio/audio_level.h" #include "audio/utility/audio_frame_operations.h" @@ -25,7 +26,7 @@ #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" #include "modules/rtp_rtcp/source/rtp_sender_audio.h" #include "rtc_base/synchronization/mutex.h" -#include "rtc_base/task_queue.h" +#include "rtc_base/system/no_unique_address.h" #include "rtc_base/time_utils.h" namespace webrtc { @@ -146,11 +147,10 @@ class AudioEgress : public AudioSender, public AudioPacketizationCallback { bool previously_muted_ = false; }; - EncoderContext encoder_context_ RTC_GUARDED_BY(encoder_queue_); + EncoderContext encoder_context_ RTC_GUARDED_BY(encoder_queue_checker_); - // Defined last to ensure that there are no running tasks when the other - // members are destroyed. - rtc::TaskQueue encoder_queue_; + std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue_; + RTC_NO_UNIQUE_ADDRESS SequenceChecker encoder_queue_checker_; }; } // namespace webrtc |