diff --git a/webrtc/call/call.cc b/webrtc/call/call.cc index e2b1e709ad..730233590f 100644 --- a/webrtc/call/call.cc +++ b/webrtc/call/call.cc @@ -23,6 +23,7 @@ #include "webrtc/base/basictypes.h" #include "webrtc/base/checks.h" #include "webrtc/base/constructormagic.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/base/optional.h" #include "webrtc/base/task_queue.h" @@ -355,11 +356,12 @@ Call::Call(const Call::Config& config) config_.bitrate_config.max_bitrate_bps); module_process_thread_->Start(); - module_process_thread_->RegisterModule(call_stats_.get()); - module_process_thread_->RegisterModule(congestion_controller_.get()); - pacer_thread_->RegisterModule(congestion_controller_->pacer()); + module_process_thread_->RegisterModule(call_stats_.get(), RTC_FROM_HERE); + module_process_thread_->RegisterModule(congestion_controller_.get(), + RTC_FROM_HERE); + pacer_thread_->RegisterModule(congestion_controller_->pacer(), RTC_FROM_HERE); pacer_thread_->RegisterModule( - congestion_controller_->GetRemoteBitrateEstimator(true)); + congestion_controller_->GetRemoteBitrateEstimator(true), RTC_FROM_HERE); pacer_thread_->Start(); } diff --git a/webrtc/call/flexfec_receive_stream_impl.cc b/webrtc/call/flexfec_receive_stream_impl.cc index 290b897cfe..fcfb3ef7ae 100644 --- a/webrtc/call/flexfec_receive_stream_impl.cc +++ b/webrtc/call/flexfec_receive_stream_impl.cc @@ -13,6 +13,7 @@ #include #include "webrtc/base/checks.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" @@ -140,7 +141,7 @@ FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl( rtp_rtcp_->SetSendingMediaStatus(false); rtp_rtcp_->SetRTCPStatus(config_.rtcp_mode); rtp_rtcp_->SetSSRC(config_.local_ssrc); - process_thread_->RegisterModule(rtp_rtcp_.get()); + process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE); } FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() { diff --git a/webrtc/modules/audio_device/BUILD.gn b/webrtc/modules/audio_device/BUILD.gn index ddf74c6e9a..2df1a66a38 100644 --- a/webrtc/modules/audio_device/BUILD.gn +++ b/webrtc/modules/audio_device/BUILD.gn @@ -330,6 +330,7 @@ if (rtc_include_tests) { deps = [ ":audio_device", "../..:webrtc_common", + "../../base:rtc_base_approved", "../../system_wrappers", "../../test:test_main", "../../test:test_support", diff --git a/webrtc/modules/audio_device/test/audio_device_test_api.cc b/webrtc/modules/audio_device/test/audio_device_test_api.cc index e36fc1d2cd..5bf01e6eae 100644 --- a/webrtc/modules/audio_device/test/audio_device_test_api.cc +++ b/webrtc/modules/audio_device/test/audio_device_test_api.cc @@ -14,15 +14,14 @@ #include -#include "webrtc/modules/audio_device/test/audio_device_test_defines.h" - -#include "webrtc/test/gtest.h" -#include "webrtc/test/testsupport/fileutils.h" - +#include "webrtc/base/location.h" #include "webrtc/modules/audio_device/audio_device_config.h" #include "webrtc/modules/audio_device/audio_device_impl.h" +#include "webrtc/modules/audio_device/test/audio_device_test_defines.h" #include "webrtc/modules/utility/include/process_thread.h" #include "webrtc/system_wrappers/include/sleep.h" +#include "webrtc/test/gtest.h" +#include "webrtc/test/testsupport/fileutils.h" // Helper functions #if defined(ANDROID) @@ -218,7 +217,7 @@ class AudioDeviceAPITest: public testing::Test { FAIL() << "Failed creating audio device object!"; } - process_thread_->RegisterModule(audio_device_); + process_thread_->RegisterModule(audio_device_, RTC_FROM_HERE); AudioDeviceModule::AudioLayer audio_layer = AudioDeviceModule::kPlatformDefaultAudio; diff --git a/webrtc/modules/utility/include/mock/mock_process_thread.h b/webrtc/modules/utility/include/mock/mock_process_thread.h index 6625a74b64..4d24033ff9 100644 --- a/webrtc/modules/utility/include/mock/mock_process_thread.h +++ b/webrtc/modules/utility/include/mock/mock_process_thread.h @@ -13,8 +13,8 @@ #include +#include "webrtc/base/location.h" #include "webrtc/modules/utility/include/process_thread.h" - #include "webrtc/test/gmock.h" namespace webrtc { @@ -29,7 +29,7 @@ class MockProcessThread : public ProcessThread { MOCK_METHOD0(Stop, void()); MOCK_METHOD1(WakeUp, void(Module* module)); MOCK_METHOD1(PostTask, void(rtc::QueuedTask* task)); - MOCK_METHOD1(RegisterModule, void(Module* module)); + MOCK_METHOD2(RegisterModule, void(Module* module, const rtc::Location&)); MOCK_METHOD1(DeRegisterModule, void(Module* module)); // MOCK_METHOD1 gets confused with mocking this method, so we work around it diff --git a/webrtc/modules/utility/include/process_thread.h b/webrtc/modules/utility/include/process_thread.h index 8524a5188e..2132ee453c 100644 --- a/webrtc/modules/utility/include/process_thread.h +++ b/webrtc/modules/utility/include/process_thread.h @@ -25,6 +25,10 @@ class QueuedTask; } #endif +namespace rtc { +class Location; +} + namespace webrtc { class Module; @@ -61,7 +65,7 @@ class ProcessThread { // Adds a module that will start to receive callbacks on the worker thread. // Can be called from any thread. - virtual void RegisterModule(Module* module) = 0; + virtual void RegisterModule(Module* module, const rtc::Location& from) = 0; // Removes a previously registered module. // Can be called from any thread. diff --git a/webrtc/modules/utility/source/process_thread_impl.cc b/webrtc/modules/utility/source/process_thread_impl.cc index 3332cd6dc6..6252931544 100644 --- a/webrtc/modules/utility/source/process_thread_impl.cc +++ b/webrtc/modules/utility/source/process_thread_impl.cc @@ -13,6 +13,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/task_queue.h" #include "webrtc/base/timeutils.h" +#include "webrtc/base/trace_event.h" #include "webrtc/modules/include/module.h" #include "webrtc/system_wrappers/include/logging.h" @@ -129,7 +130,8 @@ void ProcessThreadImpl::PostTask(std::unique_ptr task) { wake_up_->Set(); } -void ProcessThreadImpl::RegisterModule(Module* module) { +void ProcessThreadImpl::RegisterModule(Module* module, + const rtc::Location& from) { RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(module); @@ -150,7 +152,7 @@ void ProcessThreadImpl::RegisterModule(Module* module) { { rtc::CritScope lock(&lock_); - modules_.push_back(ModuleCallback(module)); + modules_.push_back(ModuleCallback(module, from)); } // Wake the thread calling ProcessThreadImpl::Process() to update the @@ -189,6 +191,7 @@ bool ProcessThreadImpl::Run(void* obj) { } bool ProcessThreadImpl::Process() { + TRACE_EVENT1("webrtc", "ProcessThreadImpl", "name", thread_name_); int64_t now = rtc::TimeMillis(); int64_t next_checkpoint = now + (1000 * 60); @@ -206,7 +209,12 @@ bool ProcessThreadImpl::Process() { if (m.next_callback <= now || m.next_callback == kCallProcessImmediately) { - m.module->Process(); + { + TRACE_EVENT2("webrtc", "ModuleProcess", "function", + m.location.function_name(), "file", + m.location.file_and_line()); + m.module->Process(); + } // Use a new 'now' reference to calculate when the next callback // should occur. We'll continue to use 'now' above for the baseline // of calculating how long we should wait, to reduce variance. diff --git a/webrtc/modules/utility/source/process_thread_impl.h b/webrtc/modules/utility/source/process_thread_impl.h index 510ab52daf..e07c3d7c8b 100644 --- a/webrtc/modules/utility/source/process_thread_impl.h +++ b/webrtc/modules/utility/source/process_thread_impl.h @@ -16,6 +16,7 @@ #include #include "webrtc/base/criticalsection.h" +#include "webrtc/base/location.h" #include "webrtc/base/platform_thread.h" #include "webrtc/base/thread_checker.h" #include "webrtc/modules/utility/include/process_thread.h" @@ -35,7 +36,7 @@ class ProcessThreadImpl : public ProcessThread { void WakeUp(Module* module) override; void PostTask(std::unique_ptr task) override; - void RegisterModule(Module* module) override; + void RegisterModule(Module* module, const rtc::Location& from) override; void DeRegisterModule(Module* module) override; protected: @@ -44,16 +45,18 @@ class ProcessThreadImpl : public ProcessThread { private: struct ModuleCallback { - ModuleCallback() : module(nullptr), next_callback(0) {} - ModuleCallback(const ModuleCallback& cb) - : module(cb.module), next_callback(cb.next_callback) {} - ModuleCallback(Module* module) : module(module), next_callback(0) {} + ModuleCallback() = delete; + ModuleCallback(ModuleCallback&& cb) = default; + ModuleCallback(const ModuleCallback& cb) = default; + ModuleCallback(Module* module, const rtc::Location& location) + : module(module), location(location) {} bool operator==(const ModuleCallback& cb) const { return cb.module == module; } Module* const module; - int64_t next_callback; // Absolute timestamp. + int64_t next_callback = 0; // Absolute timestamp. + const rtc::Location location; private: ModuleCallback& operator=(ModuleCallback&); diff --git a/webrtc/modules/utility/source/process_thread_impl_unittest.cc b/webrtc/modules/utility/source/process_thread_impl_unittest.cc index fae4c07884..8b0fb968f8 100644 --- a/webrtc/modules/utility/source/process_thread_impl_unittest.cc +++ b/webrtc/modules/utility/source/process_thread_impl_unittest.cc @@ -11,6 +11,7 @@ #include #include +#include "webrtc/base/location.h" #include "webrtc/base/task_queue.h" #include "webrtc/base/timeutils.h" #include "webrtc/modules/include/module.h" @@ -93,7 +94,7 @@ TEST(ProcessThreadImpl, ProcessCall) { .WillRepeatedly(Return()); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); - thread.RegisterModule(&module); + thread.RegisterModule(&module, RTC_FROM_HERE); EXPECT_EQ(kEventSignaled, event->Wait(kEventWaitTimeout)); EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); @@ -114,7 +115,7 @@ TEST(ProcessThreadImpl, ProcessCall2) { .WillOnce(DoAll(SetEvent(event.get()), Return())) .WillRepeatedly(Return()); - thread.RegisterModule(&module); + thread.RegisterModule(&module, RTC_FROM_HERE); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); thread.Start(); @@ -141,7 +142,7 @@ TEST(ProcessThreadImpl, Deregister) { Return())) .WillRepeatedly(DoAll(Increment(&process_count), Return())); - thread.RegisterModule(&module); + thread.RegisterModule(&module, RTC_FROM_HERE); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); thread.Start(); @@ -183,7 +184,7 @@ void ProcessCallAfterAFewMs(int64_t milliseconds) { .WillRepeatedly(Return()); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); - thread.RegisterModule(&module); + thread.RegisterModule(&module, RTC_FROM_HERE); // Add a buffer of 50ms due to slowness of some trybots // (e.g. win_drmemory_light) @@ -244,7 +245,7 @@ TEST(ProcessThreadImpl, DISABLED_Process50Times) { Return())); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); - thread.RegisterModule(&module); + thread.RegisterModule(&module, RTC_FROM_HERE); EXPECT_EQ(kEventTimeout, event->Wait(1000)); @@ -290,7 +291,7 @@ TEST(ProcessThreadImpl, WakeUp) { .WillRepeatedly(Return()); EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); - thread.RegisterModule(&module); + thread.RegisterModule(&module, RTC_FROM_HERE); EXPECT_EQ(kEventSignaled, started->Wait(kEventWaitTimeout)); thread.WakeUp(&module); diff --git a/webrtc/modules/video_coding/jitter_buffer_unittest.cc b/webrtc/modules/video_coding/jitter_buffer_unittest.cc index 99d4ee6919..2a52eb2865 100644 --- a/webrtc/modules/video_coding/jitter_buffer_unittest.cc +++ b/webrtc/modules/video_coding/jitter_buffer_unittest.cc @@ -14,6 +14,7 @@ #include #include +#include "webrtc/base/location.h" #include "webrtc/common_video/h264/h264_common.h" #include "webrtc/modules/video_coding/frame_buffer.h" #include "webrtc/modules/video_coding/jitter_buffer.h" @@ -199,7 +200,7 @@ class ProcessThreadMock : public ProcessThread { MOCK_METHOD0(Start, void()); MOCK_METHOD0(Stop, void()); MOCK_METHOD1(WakeUp, void(Module* module)); - MOCK_METHOD1(RegisterModule, void(Module* module)); + MOCK_METHOD2(RegisterModule, void(Module* module, const rtc::Location&)); MOCK_METHOD1(DeRegisterModule, void(Module* module)); void PostTask(std::unique_ptr task) /*override*/ {} }; diff --git a/webrtc/video/rtp_stream_receiver.cc b/webrtc/video/rtp_stream_receiver.cc index e964d10fd8..b8ef10d549 100644 --- a/webrtc/video/rtp_stream_receiver.cc +++ b/webrtc/video/rtp_stream_receiver.cc @@ -14,6 +14,7 @@ #include #include "webrtc/base/checks.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/common_types.h" #include "webrtc/config.h" @@ -184,12 +185,12 @@ RtpStreamReceiver::RtpStreamReceiver( // Stats callback for CNAME changes. rtp_rtcp_->RegisterRtcpStatisticsCallback(receive_stats_proxy); - process_thread_->RegisterModule(rtp_rtcp_.get()); + process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE); if (config_.rtp.nack.rtp_history_ms != 0) { nack_module_.reset( new NackModule(clock_, nack_sender, keyframe_request_sender)); - process_thread_->RegisterModule(nack_module_.get()); + process_thread_->RegisterModule(nack_module_.get(), RTC_FROM_HERE); } packet_buffer_ = video_coding::PacketBuffer::Create( diff --git a/webrtc/video/video_receive_stream.cc b/webrtc/video/video_receive_stream.cc index fbfdb2b67f..c0c5dca690 100644 --- a/webrtc/video/video_receive_stream.cc +++ b/webrtc/video/video_receive_stream.cc @@ -17,6 +17,7 @@ #include #include "webrtc/base/checks.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/base/optional.h" #include "webrtc/common_video/h264/profile_level_id.h" @@ -227,8 +228,8 @@ VideoReceiveStream::VideoReceiveStream( frame_buffer_.reset(new video_coding::FrameBuffer( clock_, jitter_estimator_.get(), timing_.get(), &stats_proxy_)); - process_thread_->RegisterModule(&video_receiver_); - process_thread_->RegisterModule(&rtp_stream_sync_); + process_thread_->RegisterModule(&video_receiver_, RTC_FROM_HERE); + process_thread_->RegisterModule(&rtp_stream_sync_, RTC_FROM_HERE); } VideoReceiveStream::~VideoReceiveStream() { diff --git a/webrtc/video/video_send_stream.cc b/webrtc/video/video_send_stream.cc index 3f2bba866e..bc7338e5ee 100644 --- a/webrtc/video/video_send_stream.cc +++ b/webrtc/video/video_send_stream.cc @@ -16,13 +16,14 @@ #include #include -#include "webrtc/common_types.h" -#include "webrtc/common_video/include/video_bitrate_allocator.h" #include "webrtc/base/checks.h" #include "webrtc/base/file.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/base/trace_event.h" #include "webrtc/base/weak_ptr.h" +#include "webrtc/common_types.h" +#include "webrtc/common_video/include/video_bitrate_allocator.h" #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" #include "webrtc/modules/congestion_controller/include/congestion_controller.h" #include "webrtc/modules/pacing/packet_router.h" @@ -883,7 +884,7 @@ void VideoSendStreamImpl::RegisterProcessThread( module_process_thread_ = module_process_thread; for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) - module_process_thread_->RegisterModule(rtp_rtcp); + module_process_thread_->RegisterModule(rtp_rtcp, RTC_FROM_HERE); } void VideoSendStreamImpl::DeRegisterProcessThread() { diff --git a/webrtc/video/vie_encoder.cc b/webrtc/video/vie_encoder.cc index 7880c4a275..c30752b6df 100644 --- a/webrtc/video/vie_encoder.cc +++ b/webrtc/video/vie_encoder.cc @@ -16,9 +16,10 @@ #include "webrtc/base/arraysize.h" #include "webrtc/base/checks.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" -#include "webrtc/base/trace_event.h" #include "webrtc/base/timeutils.h" +#include "webrtc/base/trace_event.h" #include "webrtc/common_video/include/video_bitrate_allocator.h" #include "webrtc/modules/pacing/paced_sender.h" #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" @@ -329,7 +330,7 @@ void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { RTC_DCHECK_RUN_ON(&thread_checker_); RTC_DCHECK(!module_process_thread_); module_process_thread_ = module_process_thread; - module_process_thread_->RegisterModule(&video_sender_); + module_process_thread_->RegisterModule(&video_sender_, RTC_FROM_HERE); module_process_thread_checker_.DetachFromThread(); } diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index 0573245aee..a9b9f3a92d 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -18,6 +18,7 @@ #include "webrtc/base/checks.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/format_macros.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/base/rate_limiter.h" #include "webrtc/base/thread_checker.h" @@ -1025,7 +1026,7 @@ int32_t Channel::Init() { // --- Add modules to process thread (for periodic schedulation) - _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get()); + _moduleProcessThreadPtr->RegisterModule(_rtpRtcpModule.get(), RTC_FROM_HERE); // --- ACM initialization diff --git a/webrtc/voice_engine/transmit_mixer.cc b/webrtc/voice_engine/transmit_mixer.cc index ae9f0f9034..eb5866c933 100644 --- a/webrtc/voice_engine/transmit_mixer.cc +++ b/webrtc/voice_engine/transmit_mixer.cc @@ -14,6 +14,7 @@ #include "webrtc/audio/utility/audio_frame_operations.h" #include "webrtc/base/format_macros.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/system_wrappers/include/event_wrapper.h" #include "webrtc/system_wrappers/include/trace.h" @@ -203,7 +204,7 @@ TransmitMixer::SetEngineInformation(ProcessThread& processThread, _channelManagerPtr = &channelManager; #if WEBRTC_VOICE_ENGINE_TYPING_DETECTION - _processThreadPtr->RegisterModule(&_monitorModule); + _processThreadPtr->RegisterModule(&_monitorModule, RTC_FROM_HERE); #endif return 0; } diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc index ecf5b94e7d..95a30d0799 100644 --- a/webrtc/voice_engine/voe_base_impl.cc +++ b/webrtc/voice_engine/voe_base_impl.cc @@ -12,6 +12,7 @@ #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" #include "webrtc/base/format_macros.h" +#include "webrtc/base/location.h" #include "webrtc/base/logging.h" #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h" #include "webrtc/modules/audio_coding/include/audio_coding_module.h" @@ -213,7 +214,8 @@ int VoEBaseImpl::Init( // Register the ADM to the process thread, which will drive the error // callback mechanism if (shared_->process_thread()) { - shared_->process_thread()->RegisterModule(shared_->audio_device()); + shared_->process_thread()->RegisterModule(shared_->audio_device(), + RTC_FROM_HERE); } bool available = false;