Skip to content

Commit

Permalink
Start consolidating management/querying of stats on the Call thread.
Browse files Browse the repository at this point in the history
Call is instantiated on what we traditionally call the 'worker thread'
in PeerConnection terms. Call statistics are however gathered, processed
and reported in a number of different ways, which results in a lot of
locking, which is also unpredictable due to the those actions themselves
contending with other parts of the system.

Designating the worker thread as the general owner of the stats, helps
us keeps things regular and avoids loading unrelated task queues/threads
with reporting things like histograms or locking up due to a call to
GetStats().

This is a reland of remaining changes from https://webrtc-review.googlesource.com/c/src/+/172847:
This applies the changes from the above CL to the forked files and
switches call.cc over to using the forked implementation.

Bug: webrtc:11489
Change-Id: I93ad560500806ddd0e6df1448b1bcf5a1aae7583
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174000
Reviewed-by: Mirko Bonadei <[email protected]>
Reviewed-by: Magnus Flodman <[email protected]>
Reviewed-by: Danil Chapovalov <[email protected]>
Commit-Queue: Tommi <[email protected]>
Cr-Commit-Position: refs/heads/master@{#31186}
  • Loading branch information
Tommi authored and Commit Bot committed May 8, 2020
1 parent 04e1bab commit 553c869
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 99 deletions.
25 changes: 15 additions & 10 deletions call/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#include "video/call_stats.h"
#include "video/send_delay_stats.h"
#include "video/stats_counter.h"
#include "video/video_receive_stream.h"
#include "video/video_receive_stream2.h"
#include "video/video_send_stream.h"

namespace webrtc {
Expand Down Expand Up @@ -279,7 +279,7 @@ class Call final : public webrtc::Call,
// creates them.
std::set<AudioReceiveStream*> audio_receive_streams_
RTC_GUARDED_BY(receive_crit_);
std::set<VideoReceiveStream*> video_receive_streams_
std::set<VideoReceiveStream2*> video_receive_streams_
RTC_GUARDED_BY(receive_crit_);

std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
Expand Down Expand Up @@ -837,10 +837,15 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(

RegisterRateObserver();

VideoReceiveStream* receive_stream = new VideoReceiveStream(
task_queue_factory_, &video_receiver_controller_, num_cpu_cores_,
TaskQueueBase* current = TaskQueueBase::Current();
if (!current)
current = rtc::ThreadManager::Instance()->CurrentThread();
RTC_CHECK(current);
VideoReceiveStream2* receive_stream = new VideoReceiveStream2(
task_queue_factory_, current, &video_receiver_controller_, num_cpu_cores_,
transport_send_ptr_->packet_router(), std::move(configuration),
module_process_thread_.get(), call_stats_.get(), clock_);
module_process_thread_.get(), call_stats_.get(), clock_,
new VCMTiming(clock_));

const webrtc::VideoReceiveStream::Config& config = receive_stream->config();
{
Expand Down Expand Up @@ -870,8 +875,8 @@ void Call::DestroyVideoReceiveStream(
TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream");
RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
RTC_DCHECK(receive_stream != nullptr);
VideoReceiveStream* receive_stream_impl =
static_cast<VideoReceiveStream*>(receive_stream);
VideoReceiveStream2* receive_stream_impl =
static_cast<VideoReceiveStream2*>(receive_stream);
const VideoReceiveStream::Config& config = receive_stream_impl->config();
{
WriteLockScoped write_lock(*receive_crit_);
Expand Down Expand Up @@ -1007,7 +1012,7 @@ void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
UpdateAggregateNetworkState();
{
ReadLockScoped read_lock(*receive_crit_);
for (VideoReceiveStream* video_receive_stream : video_receive_streams_) {
for (VideoReceiveStream2* video_receive_stream : video_receive_streams_) {
video_receive_stream->SignalNetworkState(video_network_state_);
}
}
Expand Down Expand Up @@ -1150,7 +1155,7 @@ void Call::ConfigureSync(const std::string& sync_group) {
if (sync_audio_stream)
sync_stream_mapping_[sync_group] = sync_audio_stream;
size_t num_synced_streams = 0;
for (VideoReceiveStream* video_stream : video_receive_streams_) {
for (VideoReceiveStream2* video_stream : video_receive_streams_) {
if (video_stream->config().sync_group != sync_group)
continue;
++num_synced_streams;
Expand Down Expand Up @@ -1187,7 +1192,7 @@ PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type,
bool rtcp_delivered = false;
if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
ReadLockScoped read_lock(*receive_crit_);
for (VideoReceiveStream* stream : video_receive_streams_) {
for (VideoReceiveStream2* stream : video_receive_streams_) {
if (stream->DeliverRtcp(packet, length))
rtcp_delivered = true;
}
Expand Down
2 changes: 2 additions & 0 deletions call/call_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "test/gtest.h"
#include "test/mock_audio_decoder_factory.h"
#include "test/mock_transport.h"
#include "test/run_loop.h"

namespace {

Expand All @@ -56,6 +57,7 @@ struct CallHelper {
webrtc::Call* operator->() { return call_.get(); }

private:
webrtc::test::RunLoop loop_;
webrtc::RtcEventLogNull event_log_;
webrtc::FieldTrialBasedConfig field_trials_;
std::unique_ptr<webrtc::TaskQueueFactory> task_queue_factory_;
Expand Down
2 changes: 2 additions & 0 deletions modules/video_coding/generic_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ VCMReceiveCallback* VCMDecodedFrameCallback::UserReceiveCallback() {
}

int32_t VCMDecodedFrameCallback::Decoded(VideoFrame& decodedImage) {
// This function may be called on the decode TaskQueue, but may also be called
// on an OS provided queue such as on iOS (see e.g. b/153465112).
return Decoded(decodedImage, -1);
}

Expand Down
3 changes: 3 additions & 0 deletions test/call_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "test/fake_vp8_encoder.h"
#include "test/frame_generator_capturer.h"
#include "test/rtp_rtcp_observer.h"
#include "test/run_loop.h"

namespace webrtc {
namespace test {
Expand Down Expand Up @@ -176,6 +177,8 @@ class CallTest : public ::testing::Test {
FlexfecReceiveStream::Config* GetFlexFecConfig();
TaskQueueBase* task_queue() { return task_queue_.get(); }

test::RunLoop loop_;

Clock* const clock_;
const FieldTrialBasedConfig field_trials_;

Expand Down
Loading

0 comments on commit 553c869

Please sign in to comment.