Migrate video/adaptation and video/end_to_end_tests to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: I6c2d0c7e3e8fac85cf4d19223c4ef3d144598fda
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178812
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31651}
This commit is contained in:
Markus Handell 2020-07-07 14:23:18 +02:00 committed by Commit Bot
parent 101750ac5b
commit 9bbff07b20
16 changed files with 137 additions and 126 deletions

View File

@ -641,6 +641,7 @@ if (rtc_include_tests) {
"../rtc_base:rtc_task_queue",
"../rtc_base:task_queue_for_test",
"../rtc_base/experiments:alr_experiment",
"../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker",
"../rtc_base/task_utils:to_queued_task",
"../system_wrappers",

View File

@ -48,6 +48,7 @@ rtc_library("video_adaptation") {
"../../rtc_base/experiments:field_trial_parser",
"../../rtc_base/experiments:quality_rampup_experiment",
"../../rtc_base/experiments:quality_scaler_settings",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/synchronization:sequence_checker",
"../../rtc_base/task_utils:repeating_task",
"../../rtc_base/task_utils:to_queued_task",

View File

@ -37,14 +37,14 @@ void VideoStreamEncoderResource::RegisterEncoderTaskQueue(
void VideoStreamEncoderResource::RegisterAdaptationTaskQueue(
TaskQueueBase* resource_adaptation_queue) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_DCHECK(!resource_adaptation_queue_);
RTC_DCHECK(resource_adaptation_queue);
resource_adaptation_queue_ = resource_adaptation_queue;
}
void VideoStreamEncoderResource::UnregisterAdaptationTaskQueue() {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_DCHECK(resource_adaptation_queue_);
RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
resource_adaptation_queue_ = nullptr;
@ -76,7 +76,7 @@ TaskQueueBase* VideoStreamEncoderResource::encoder_queue() const {
}
TaskQueueBase* VideoStreamEncoderResource::resource_adaptation_queue() const {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
RTC_DCHECK(resource_adaptation_queue_);
RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
return resource_adaptation_queue_;

View File

@ -19,7 +19,7 @@
#include "api/task_queue/task_queue_base.h"
#include "call/adaptation/adaptation_constraint.h"
#include "call/adaptation/adaptation_listener.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h"
namespace webrtc {
@ -60,14 +60,14 @@ class VideoStreamEncoderResource : public Resource {
TaskQueueBase* resource_adaptation_queue() const;
template <typename Closure>
void MaybePostTaskToResourceAdaptationQueue(Closure&& closure) {
rtc::CritScope crit(&lock_);
MutexLock lock(&lock_);
if (!resource_adaptation_queue_)
return;
resource_adaptation_queue_->PostTask(ToQueuedTask(closure));
}
private:
rtc::CriticalSection lock_;
mutable Mutex lock_;
const std::string name_;
// Treated as const after initialization.
TaskQueueBase* encoder_queue_;

View File

@ -354,7 +354,7 @@ void VideoStreamEncoderResourceManager::StopManagedResources() {
void VideoStreamEncoderResourceManager::MapResourceToReason(
rtc::scoped_refptr<Resource> resource,
VideoAdaptationReason reason) {
rtc::CritScope crit(&resource_lock_);
MutexLock lock(&resource_lock_);
RTC_DCHECK(resource);
RTC_DCHECK(absl::c_find_if(resources_,
[resource](const ResourceAndReason& r) {
@ -366,7 +366,7 @@ void VideoStreamEncoderResourceManager::MapResourceToReason(
std::vector<rtc::scoped_refptr<Resource>>
VideoStreamEncoderResourceManager::MappedResources() const {
rtc::CritScope crit(&resource_lock_);
MutexLock lock(&resource_lock_);
std::vector<rtc::scoped_refptr<Resource>> resources;
for (auto const& resource_and_reason : resources_) {
resources.push_back(resource_and_reason.resource);
@ -386,7 +386,7 @@ VideoStreamEncoderResourceManager::AdaptationListeners() const {
rtc::scoped_refptr<QualityScalerResource>
VideoStreamEncoderResourceManager::quality_scaler_resource_for_testing() {
rtc::CritScope crit(&resource_lock_);
MutexLock lock(&resource_lock_);
return quality_scaler_resource_;
}
@ -559,7 +559,7 @@ void VideoStreamEncoderResourceManager::ConfigureQualityScaler(
VideoAdaptationReason VideoStreamEncoderResourceManager::GetReasonFromResource(
rtc::scoped_refptr<Resource> resource) const {
rtc::CritScope crit(&resource_lock_);
MutexLock lock(&resource_lock_);
const auto& registered_resource =
absl::c_find_if(resources_, [&resource](const ResourceAndReason& r) {
return r.resource == resource;

View File

@ -35,10 +35,10 @@
#include "call/adaptation/resource_adaptation_processor_interface.h"
#include "call/adaptation/video_stream_adapter.h"
#include "call/adaptation/video_stream_input_state_provider.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/experiments/quality_scaler_settings.h"
#include "rtc_base/ref_count.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h"
#include "system_wrappers/include/clock.h"
#include "video/adaptation/encode_usage_resource.h"
@ -277,7 +277,7 @@ class VideoStreamEncoderResourceManager
const rtc::scoped_refptr<Resource> resource;
const VideoAdaptationReason reason;
};
rtc::CriticalSection resource_lock_;
mutable Mutex resource_lock_;
std::vector<ResourceAndReason> resources_ RTC_GUARDED_BY(&resource_lock_);
};

View File

@ -18,6 +18,7 @@
#include "call/simulated_network.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
#include "rtc_base/rate_limiter.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/task_utils/to_queued_task.h"
#include "system_wrappers/include/sleep.h"
@ -353,7 +354,7 @@ TEST_F(BandwidthEndToEndTest, ReportsSetEncoderRates) {
// Make sure not to trigger on any default zero bitrates.
if (parameters.bitrate.get_sum_bps() == 0)
return;
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
bitrate_kbps_ = parameters.bitrate.get_sum_kbps();
observation_complete_.Set();
}
@ -375,7 +376,7 @@ TEST_F(BandwidthEndToEndTest, ReportsSetEncoderRates) {
for (int i = 0; i < kDefaultTimeoutMs; ++i) {
VideoSendStream::Stats stats = send_stream_->GetStats();
{
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
if ((stats.target_media_bitrate_bps + 500) / 1000 ==
static_cast<int>(bitrate_kbps_)) {
return;
@ -399,11 +400,11 @@ TEST_F(BandwidthEndToEndTest, ReportsSetEncoderRates) {
private:
TaskQueueBase* const task_queue_;
rtc::CriticalSection crit_;
Mutex mutex_;
VideoSendStream* send_stream_;
test::VideoEncoderProxyFactory encoder_factory_;
std::unique_ptr<VideoBitrateAllocatorFactory> bitrate_allocator_factory_;
uint32_t bitrate_kbps_ RTC_GUARDED_BY(crit_);
uint32_t bitrate_kbps_ RTC_GUARDED_BY(mutex_);
} test(task_queue());
RunBaseTest(&test);

View File

@ -31,8 +31,8 @@
#include "call/video_send_stream.h"
#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
#include "modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "system_wrappers/include/clock.h"
#include "test/call_test.h"
@ -83,7 +83,7 @@ class RtcpXrObserver : public test::EndToEndTest {
private:
// Receive stream should send RR packets (and RRTR packets if enabled).
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
@ -100,7 +100,7 @@ class RtcpXrObserver : public test::EndToEndTest {
}
// Send stream should send SR packets (and DLRR packets if enabled).
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
@ -198,16 +198,16 @@ class RtcpXrObserver : public test::EndToEndTest {
static const int kNumRtcpReportPacketsToObserve = 5;
rtc::CriticalSection crit_;
Mutex mutex_;
const bool enable_rrtr_;
const bool expect_target_bitrate_;
const bool enable_zero_target_bitrate_;
const VideoEncoderConfig::ContentType content_type_;
int sent_rtcp_sr_;
int sent_rtcp_rr_ RTC_GUARDED_BY(&crit_);
int sent_rtcp_rrtr_ RTC_GUARDED_BY(&crit_);
bool sent_rtcp_target_bitrate_ RTC_GUARDED_BY(&crit_);
bool sent_zero_rtcp_target_bitrate_ RTC_GUARDED_BY(&crit_);
int sent_rtcp_rr_ RTC_GUARDED_BY(&mutex_);
int sent_rtcp_rrtr_ RTC_GUARDED_BY(&mutex_);
bool sent_rtcp_target_bitrate_ RTC_GUARDED_BY(&mutex_);
bool sent_zero_rtcp_target_bitrate_ RTC_GUARDED_BY(&mutex_);
int sent_rtcp_dlrr_;
BuiltInNetworkBehaviorConfig forward_transport_config_;
SimulatedNetwork* send_simulated_network_;

View File

@ -20,6 +20,7 @@
#include "modules/rtp_rtcp/source/byte_io.h"
#include "modules/rtp_rtcp/source/rtp_packet.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/call_test.h"
#include "test/field_trial.h"
#include "test/gmock.h"
@ -59,7 +60,7 @@ TEST_F(FecEndToEndTest, ReceivesUlpfec) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -98,7 +99,7 @@ TEST_F(FecEndToEndTest, ReceivesUlpfec) {
}
void OnFrame(const VideoFrame& video_frame) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
// Rendering frame with timestamp of packet that was dropped -> FEC
// protection worked.
auto it = dropped_timestamps_.find(video_frame.timestamp());
@ -137,15 +138,15 @@ TEST_F(FecEndToEndTest, ReceivesUlpfec) {
<< "Timed out waiting for dropped frames to be rendered.";
}
rtc::CriticalSection crit_;
Mutex mutex_;
std::unique_ptr<VideoEncoder> encoder_;
test::FunctionVideoEncoderFactory encoder_factory_;
InternalDecoderFactory decoder_factory_;
std::set<uint32_t> dropped_sequence_numbers_ RTC_GUARDED_BY(crit_);
std::set<uint32_t> dropped_sequence_numbers_ RTC_GUARDED_BY(mutex_);
// Several packets can have the same timestamp.
std::multiset<uint32_t> dropped_timestamps_ RTC_GUARDED_BY(crit_);
std::multiset<uint32_t> dropped_timestamps_ RTC_GUARDED_BY(mutex_);
Random random_;
int num_packets_sent_ RTC_GUARDED_BY(crit_);
int num_packets_sent_ RTC_GUARDED_BY(mutex_);
} test;
RunBaseTest(&test);
@ -169,7 +170,7 @@ class FlexfecRenderObserver : public test::EndToEndTest,
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -247,7 +248,7 @@ class FlexfecRenderObserver : public test::EndToEndTest,
EXPECT_EQ(1U, report_blocks.size());
EXPECT_EQ(test::CallTest::kFlexfecSendSsrc,
report_blocks[0].source_ssrc());
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
received_flexfec_rtcp_ = true;
}
}
@ -273,7 +274,7 @@ class FlexfecRenderObserver : public test::EndToEndTest,
void OnFrame(const VideoFrame& video_frame) override {
EXPECT_EQ(kVideoRotation_90, video_frame.rotation());
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
// Rendering frame with timestamp of packet that was dropped -> FEC
// protection worked.
auto it = dropped_timestamps_.find(video_frame.timestamp());
@ -321,13 +322,13 @@ class FlexfecRenderObserver : public test::EndToEndTest,
<< "Timed out waiting for dropped frames to be rendered.";
}
rtc::CriticalSection crit_;
std::set<uint32_t> dropped_sequence_numbers_ RTC_GUARDED_BY(crit_);
Mutex mutex_;
std::set<uint32_t> dropped_sequence_numbers_ RTC_GUARDED_BY(mutex_);
// Several packets can have the same timestamp.
std::multiset<uint32_t> dropped_timestamps_ RTC_GUARDED_BY(crit_);
std::multiset<uint32_t> dropped_timestamps_ RTC_GUARDED_BY(mutex_);
const bool enable_nack_;
const bool expect_flexfec_rtcp_;
bool received_flexfec_rtcp_ RTC_GUARDED_BY(crit_);
bool received_flexfec_rtcp_ RTC_GUARDED_BY(mutex_);
Random random_;
int num_packets_sent_;
};
@ -360,7 +361,7 @@ TEST_F(FecEndToEndTest, ReceivedUlpfecPacketsNotNacked) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock_(&crit_);
MutexLock lock_(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -424,7 +425,7 @@ TEST_F(FecEndToEndTest, ReceivedUlpfecPacketsNotNacked) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock_(&crit_);
MutexLock lock_(&mutex_);
if (state_ == kVerifyUlpfecPacketNotInNackList) {
test::RtcpPacketParser rtcp_parser;
rtcp_parser.Parse(packet, length);
@ -503,8 +504,8 @@ TEST_F(FecEndToEndTest, ReceivedUlpfecPacketsNotNacked) {
kVerifyUlpfecPacketNotInNackList,
} state_;
rtc::CriticalSection crit_;
uint16_t ulpfec_sequence_number_ RTC_GUARDED_BY(&crit_);
Mutex mutex_;
uint16_t ulpfec_sequence_number_ RTC_GUARDED_BY(&mutex_);
bool has_last_sequence_number_;
uint16_t last_sequence_number_;
test::FunctionVideoEncoderFactory encoder_factory_;

View File

@ -11,6 +11,7 @@
#include "absl/types/optional.h"
#include "api/test/video/function_video_encoder_factory.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "rtc_base/synchronization/mutex.h"
#include "system_wrappers/include/metrics.h"
#include "test/call_test.h"
#include "test/gtest.h"
@ -59,7 +60,7 @@ void HistogramTest::VerifyHistogramStats(bool use_rtx,
if (video_frame.ntp_time_ms() > 0 &&
Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() >=
video_frame.ntp_time_ms()) {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
++num_frames_received_;
}
}
@ -82,7 +83,7 @@ void HistogramTest::VerifyHistogramStats(bool use_rtx,
bool MinNumberOfFramesReceived() const {
const int kMinRequiredHistogramSamples = 200;
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
return num_frames_received_ > kMinRequiredHistogramSamples;
}
@ -131,13 +132,13 @@ void HistogramTest::VerifyHistogramStats(bool use_rtx,
EXPECT_TRUE(Wait()) << "Timed out waiting for min frames to be received.";
}
rtc::CriticalSection crit_;
mutable Mutex mutex_;
const bool use_rtx_;
const bool use_fec_;
const bool screenshare_;
test::FunctionVideoEncoderFactory encoder_factory_;
absl::optional<int64_t> start_runtime_ms_;
int num_frames_received_ RTC_GUARDED_BY(&crit_);
int num_frames_received_ RTC_GUARDED_BY(&mutex_);
} test(use_rtx, use_fec, screenshare);
metrics::Reset();

View File

@ -19,6 +19,7 @@
#include "modules/video_coding/codecs/h264/include/h264.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "modules/video_coding/codecs/vp9/include/vp9.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "test/call_test.h"
#include "test/gmock.h"
@ -65,7 +66,7 @@ class FrameObserver : public test::RtpRtcpObserver,
FrameObserver() : test::RtpRtcpObserver(test::CallTest::kDefaultTimeoutMs) {}
void Reset(uint8_t expected_payload_type) {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
num_sent_frames_ = 0;
num_rendered_frames_ = 0;
expected_payload_type_ = expected_payload_type;
@ -74,7 +75,7 @@ class FrameObserver : public test::RtpRtcpObserver,
private:
// Sends kFramesToObserve.
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -103,7 +104,7 @@ class FrameObserver : public test::RtpRtcpObserver,
// Verifies that all sent frames are decoded and rendered.
void OnFrame(const VideoFrame& rendered_frame) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
EXPECT_THAT(sent_timestamps_, Contains(rendered_frame.timestamp()));
// Remove old timestamps too, only the newest decoded frame is rendered.
@ -116,12 +117,12 @@ class FrameObserver : public test::RtpRtcpObserver,
}
}
rtc::CriticalSection crit_;
Mutex mutex_;
absl::optional<uint32_t> last_timestamp_; // Only accessed from pacer thread.
absl::optional<uint8_t> expected_payload_type_ RTC_GUARDED_BY(crit_);
int num_sent_frames_ RTC_GUARDED_BY(crit_) = 0;
int num_rendered_frames_ RTC_GUARDED_BY(crit_) = 0;
std::vector<uint32_t> sent_timestamps_ RTC_GUARDED_BY(crit_);
absl::optional<uint8_t> expected_payload_type_ RTC_GUARDED_BY(mutex_);
int num_sent_frames_ RTC_GUARDED_BY(mutex_) = 0;
int num_rendered_frames_ RTC_GUARDED_BY(mutex_) = 0;
std::vector<uint32_t> sent_timestamps_ RTC_GUARDED_BY(mutex_);
};
} // namespace

View File

@ -15,6 +15,7 @@
#include "call/fake_network_pipe.h"
#include "call/simulated_network.h"
#include "modules/rtp_rtcp/source/rtp_packet.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "system_wrappers/include/sleep.h"
#include "test/call_test.h"
@ -60,19 +61,19 @@ class NetworkStateEndToEndTest : public test::CallTest {
bool SendRtp(const uint8_t* packet,
size_t length,
const PacketOptions& options) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
need_rtp_ = false;
return true;
}
bool SendRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
need_rtcp_ = false;
return true;
}
bool need_rtp_;
bool need_rtcp_;
rtc::CriticalSection crit_;
Mutex mutex_;
};
void VerifyNewVideoSendStreamsRespectNetworkState(
MediaType network_to_bring_up,
@ -177,7 +178,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
down_frames_(0) {}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
if (rtp_packet.payload_size() == 0)
@ -188,7 +189,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
++sender_rtcp_;
packet_event_.Set();
return SEND_PACKET;
@ -200,7 +201,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
++receiver_rtcp_;
packet_event_.Set();
return SEND_PACKET;
@ -239,7 +240,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
// Sender-side network down.
sender_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkDown);
{
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
// After network goes down we shouldn't be encoding more frames.
sender_state_ = kNetworkDown;
}
@ -259,7 +260,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
// Network back up again for both.
{
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
// It's OK to encode frames again, as we're about to bring up the
// network.
sender_state_ = kNetworkUp;
@ -277,7 +278,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
int32_t Encode(const VideoFrame& input_image,
const std::vector<VideoFrameType>* frame_types) override {
{
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
if (sender_state_ == kNetworkDown) {
++down_frames_;
EXPECT_LE(down_frames_, 1)
@ -298,7 +299,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
int initial_sender_rtcp;
int initial_receiver_rtcp;
{
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
initial_sender_rtp = sender_rtp_;
initial_sender_rtcp = sender_rtcp_;
initial_receiver_rtcp = receiver_rtcp_;
@ -308,7 +309,7 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
while (!sender_done || !receiver_done) {
packet_event_.Wait(kSilenceTimeoutMs);
int64_t time_now_ms = clock_->TimeInMilliseconds();
rtc::CritScope lock(&test_crit_);
MutexLock lock(&test_mutex_);
if (sender_down) {
ASSERT_LE(sender_rtp_ - initial_sender_rtp - sender_padding_,
kNumAcceptedDowntimeRtp)
@ -340,18 +341,18 @@ TEST_F(NetworkStateEndToEndTest, RespectsNetworkState) {
}
TaskQueueBase* const task_queue_;
rtc::CriticalSection test_crit_;
Mutex test_mutex_;
rtc::Event encoded_frames_;
rtc::Event packet_event_;
Call* sender_call_;
Call* receiver_call_;
test::VideoEncoderProxyFactory encoder_factory_;
NetworkState sender_state_ RTC_GUARDED_BY(test_crit_);
int sender_rtp_ RTC_GUARDED_BY(test_crit_);
int sender_padding_ RTC_GUARDED_BY(test_crit_);
int sender_rtcp_ RTC_GUARDED_BY(test_crit_);
int receiver_rtcp_ RTC_GUARDED_BY(test_crit_);
int down_frames_ RTC_GUARDED_BY(test_crit_);
NetworkState sender_state_ RTC_GUARDED_BY(test_mutex_);
int sender_rtp_ RTC_GUARDED_BY(test_mutex_);
int sender_padding_ RTC_GUARDED_BY(test_mutex_);
int sender_rtcp_ RTC_GUARDED_BY(test_mutex_);
int receiver_rtcp_ RTC_GUARDED_BY(test_mutex_);
int down_frames_ RTC_GUARDED_BY(test_mutex_);
} test(task_queue());
RunBaseTest(&test);

View File

@ -19,6 +19,7 @@
#include "modules/rtp_rtcp/source/rtp_packet.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "rtc_base/event.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "test/call_test.h"
#include "test/field_trial.h"
@ -58,7 +59,7 @@ TEST_F(RetransmissionEndToEndTest, ReceivesAndRetransmitsNack) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -95,7 +96,7 @@ TEST_F(RetransmissionEndToEndTest, ReceivesAndRetransmitsNack) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
nacks_left_ -= parser.nack()->num_packets();
@ -116,12 +117,12 @@ TEST_F(RetransmissionEndToEndTest, ReceivesAndRetransmitsNack) {
"rendered.";
}
rtc::CriticalSection crit_;
Mutex mutex_;
std::set<uint16_t> dropped_packets_;
std::set<uint16_t> retransmitted_packets_;
uint64_t sent_rtp_packets_;
int packets_left_to_drop_;
int nacks_left_ RTC_GUARDED_BY(&crit_);
int nacks_left_ RTC_GUARDED_BY(&mutex_);
} test;
RunBaseTest(&test);
@ -290,7 +291,7 @@ void RetransmissionEndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -308,7 +309,7 @@ void RetransmissionEndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
if (!nack_enabled_)
@ -319,7 +320,7 @@ void RetransmissionEndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) {
}
void OnFrame(const VideoFrame& video_frame) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
if (received_pli_ &&
video_frame.timestamp() > highest_dropped_timestamp_) {
observation_complete_.Set();
@ -343,12 +344,12 @@ void RetransmissionEndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) {
"rendered afterwards.";
}
rtc::CriticalSection crit_;
Mutex mutex_;
int rtp_history_ms_;
bool nack_enabled_;
uint32_t highest_dropped_timestamp_ RTC_GUARDED_BY(&crit_);
int frames_to_drop_ RTC_GUARDED_BY(&crit_);
bool received_pli_ RTC_GUARDED_BY(&crit_);
uint32_t highest_dropped_timestamp_ RTC_GUARDED_BY(&mutex_);
int frames_to_drop_ RTC_GUARDED_BY(&mutex_);
bool received_pli_ RTC_GUARDED_BY(&mutex_);
} test(rtp_history_ms);
RunBaseTest(&test);
@ -382,7 +383,7 @@ void RetransmissionEndToEndTest::DecodesRetransmittedFrame(bool enable_rtx,
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -427,7 +428,7 @@ void RetransmissionEndToEndTest::DecodesRetransmittedFrame(bool enable_rtx,
void OnFrame(const VideoFrame& frame) override {
EXPECT_EQ(kVideoRotation_90, frame.rotation());
{
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
if (frame.timestamp() == retransmitted_timestamp_)
observation_complete_.Set();
rendered_timestamps_.push_back(frame.timestamp());
@ -502,7 +503,7 @@ void RetransmissionEndToEndTest::DecodesRetransmittedFrame(bool enable_rtx,
return kFakeVideoSendPayloadType;
}
rtc::CriticalSection crit_;
Mutex mutex_;
rtc::VideoSinkInterface<VideoFrame>* orig_renderer_ = nullptr;
const int payload_type_;
const uint32_t retransmission_ssrc_;
@ -510,8 +511,8 @@ void RetransmissionEndToEndTest::DecodesRetransmittedFrame(bool enable_rtx,
test::FunctionVideoEncoderFactory encoder_factory_;
const std::string payload_name_;
int marker_bits_observed_;
uint32_t retransmitted_timestamp_ RTC_GUARDED_BY(&crit_);
std::vector<uint32_t> rendered_timestamps_ RTC_GUARDED_BY(&crit_);
uint32_t retransmitted_timestamp_ RTC_GUARDED_BY(&mutex_);
std::vector<uint32_t> rendered_timestamps_ RTC_GUARDED_BY(&mutex_);
} test(enable_rtx, enable_red);
RunBaseTest(&test);

View File

@ -16,6 +16,7 @@
#include "modules/include/module_common_types_public.h"
#include "modules/rtp_rtcp/source/rtp_packet.h"
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "test/call_test.h"
#include "test/gtest.h"
@ -46,7 +47,7 @@ void RtpRtcpEndToEndTest::RespectsRtcpMode(RtcpMode rtcp_mode) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
if (++sent_rtp_ % 3 == 0)
return DROP_PACKET;
@ -54,7 +55,7 @@ void RtpRtcpEndToEndTest::RespectsRtcpMode(RtcpMode rtcp_mode) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
++sent_rtcp_;
test::RtcpPacketParser parser;
EXPECT_TRUE(parser.Parse(packet, length));
@ -105,11 +106,11 @@ void RtpRtcpEndToEndTest::RespectsRtcpMode(RtcpMode rtcp_mode) {
}
RtcpMode rtcp_mode_;
rtc::CriticalSection crit_;
Mutex mutex_;
// Must be protected since RTCP can be sent by both the process thread
// and the pacer thread.
int sent_rtp_ RTC_GUARDED_BY(&crit_);
int sent_rtcp_ RTC_GUARDED_BY(&crit_);
int sent_rtp_ RTC_GUARDED_BY(&mutex_);
int sent_rtcp_ RTC_GUARDED_BY(&mutex_);
} test(rtcp_mode);
RunBaseTest(&test);
@ -176,7 +177,7 @@ void RtpRtcpEndToEndTest::TestRtpStatePreservation(
}
void ResetExpectedSsrcs(size_t num_expected_ssrcs) {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
ssrc_observed_.clear();
ssrcs_to_observe_ = num_expected_ssrcs;
}
@ -185,7 +186,7 @@ void RtpRtcpEndToEndTest::TestRtpStatePreservation(
void ValidateTimestampGap(uint32_t ssrc,
uint32_t timestamp,
bool only_padding)
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
static const int32_t kMaxTimestampGap = kDefaultTimeoutMs * 90;
auto timestamp_it = last_observed_timestamp_.find(ssrc);
if (timestamp_it == last_observed_timestamp_.end()) {
@ -240,7 +241,7 @@ void RtpRtcpEndToEndTest::TestRtpStatePreservation(
}
if (!ssrc_is_rtx_[ssrc]) {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
ValidateTimestampGap(ssrc, timestamp, only_padding);
// Wait for media packets on all ssrcs.
@ -261,7 +262,7 @@ void RtpRtcpEndToEndTest::TestRtpStatePreservation(
uint32_t ssrc = rtcp_parser.sender_report()->sender_ssrc();
uint32_t rtcp_timestamp = rtcp_parser.sender_report()->rtp_timestamp();
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
ValidateTimestampGap(ssrc, rtcp_timestamp, false);
}
return SEND_PACKET;
@ -272,9 +273,9 @@ void RtpRtcpEndToEndTest::TestRtpStatePreservation(
std::map<uint32_t, uint32_t> last_observed_timestamp_;
std::map<uint32_t, bool> ssrc_is_rtx_;
rtc::CriticalSection crit_;
size_t ssrcs_to_observe_ RTC_GUARDED_BY(crit_);
std::map<uint32_t, bool> ssrc_observed_ RTC_GUARDED_BY(crit_);
Mutex mutex_;
size_t ssrcs_to_observe_ RTC_GUARDED_BY(mutex_);
std::map<uint32_t, bool> ssrc_observed_ RTC_GUARDED_BY(mutex_);
} observer(use_rtx);
std::unique_ptr<test::PacketTransport> send_transport;
@ -414,13 +415,13 @@ TEST_F(RtpRtcpEndToEndTest, DISABLED_TestFlexfecRtpStatePreservation) {
num_flexfec_packets_sent_(0) {}
void ResetPacketCount() {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
num_flexfec_packets_sent_ = 0;
}
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
@ -468,10 +469,10 @@ TEST_F(RtpRtcpEndToEndTest, DISABLED_TestFlexfecRtpStatePreservation) {
}
absl::optional<uint16_t> last_observed_sequence_number_
RTC_GUARDED_BY(crit_);
absl::optional<uint32_t> last_observed_timestamp_ RTC_GUARDED_BY(crit_);
size_t num_flexfec_packets_sent_ RTC_GUARDED_BY(crit_);
rtc::CriticalSection crit_;
RTC_GUARDED_BY(mutex_);
absl::optional<uint32_t> last_observed_timestamp_ RTC_GUARDED_BY(mutex_);
size_t num_flexfec_packets_sent_ RTC_GUARDED_BY(mutex_);
Mutex mutex_;
} observer;
static constexpr int kFrameMaxWidth = 320;

View File

@ -20,6 +20,7 @@
#include "modules/rtp_rtcp/source/rtp_utility.h"
#include "modules/video_coding/include/video_coding_defines.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue_for_test.h"
#include "system_wrappers/include/metrics.h"
#include "system_wrappers/include/sleep.h"
@ -479,7 +480,7 @@ TEST_F(StatsEndToEndTest, MAYBE_ContentTypeSwitches) {
if (video_frame.ntp_time_ms() > 0 &&
Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() >=
video_frame.ntp_time_ms()) {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
++num_frames_received_;
}
}
@ -493,7 +494,7 @@ TEST_F(StatsEndToEndTest, MAYBE_ContentTypeSwitches) {
bool MinNumberOfFramesReceived() const {
// Have some room for frames with wrong content type during switch.
const int kMinRequiredHistogramSamples = 200 + 50;
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
return num_frames_received_ > kMinRequiredHistogramSamples;
}
@ -502,13 +503,13 @@ TEST_F(StatsEndToEndTest, MAYBE_ContentTypeSwitches) {
EXPECT_TRUE(Wait()) << "Timed out waiting for enough packets.";
// Reset frame counter so next PerformTest() call will do something.
{
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
num_frames_received_ = 0;
}
}
rtc::CriticalSection crit_;
int num_frames_received_ RTC_GUARDED_BY(&crit_);
mutable Mutex mutex_;
int num_frames_received_ RTC_GUARDED_BY(&mutex_);
} test;
metrics::Reset();
@ -609,7 +610,7 @@ TEST_F(StatsEndToEndTest, VerifyNackStats) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
if (++sent_rtp_packets_ == kPacketNumberToDrop) {
std::unique_ptr<RtpHeaderParser> parser(
RtpHeaderParser::CreateForTest());
@ -623,7 +624,7 @@ TEST_F(StatsEndToEndTest, VerifyNackStats) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
test::RtcpPacketParser rtcp_parser;
rtcp_parser.Parse(packet, length);
const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids();
@ -633,7 +634,7 @@ TEST_F(StatsEndToEndTest, VerifyNackStats) {
return SEND_PACKET;
}
void VerifyStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(&crit_) {
void VerifyStats() RTC_EXCLUSIVE_LOCKS_REQUIRED(&mutex_) {
if (!dropped_rtp_packet_requested_)
return;
int send_stream_nack_packets = 0;
@ -684,7 +685,7 @@ TEST_F(StatsEndToEndTest, VerifyNackStats) {
}
bool Run() override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
VerifyStats();
return false;
}
@ -694,10 +695,10 @@ TEST_F(StatsEndToEndTest, VerifyNackStats) {
}
test::FakeVideoRenderer fake_renderer_;
rtc::CriticalSection crit_;
Mutex mutex_;
uint64_t sent_rtp_packets_;
uint16_t dropped_rtp_packet_ RTC_GUARDED_BY(&crit_);
bool dropped_rtp_packet_requested_ RTC_GUARDED_BY(&crit_);
uint16_t dropped_rtp_packet_ RTC_GUARDED_BY(&mutex_);
bool dropped_rtp_packet_requested_ RTC_GUARDED_BY(&mutex_);
std::vector<VideoReceiveStream*> receive_streams_;
VideoSendStream* send_stream_;
absl::optional<int64_t> start_runtime_ms_;

View File

@ -18,6 +18,7 @@
#include "modules/rtp_rtcp/source/byte_io.h"
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
#include "modules/rtp_rtcp/source/rtp_packet.h"
#include "rtc_base/synchronization/mutex.h"
#include "test/call_test.h"
#include "test/field_trial.h"
#include "test/gtest.h"
@ -65,7 +66,7 @@ TEST(TransportFeedbackMultiStreamTest, AssignsTransportSequenceNumbers) {
size_t length,
const PacketOptions& options) override {
{
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
if (IsDone())
return false;
@ -141,14 +142,14 @@ TEST(TransportFeedbackMultiStreamTest, AssignsTransportSequenceNumbers) {
{
// Can't be sure until this point that rtx_to_media_ssrcs_ etc have
// been initialized and are OK to read.
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
started_ = true;
}
return done_.Wait(kDefaultTimeoutMs);
}
private:
rtc::CriticalSection lock_;
Mutex lock_;
rtc::Event done_;
RtpHeaderExtensionMap extensions_;
SequenceNumberUnwrapper unwrapper_;
@ -366,7 +367,7 @@ TEST_F(TransportFeedbackEndToEndTest,
RtpPacket rtp_packet;
EXPECT_TRUE(rtp_packet.Parse(packet, length));
const bool only_padding = rtp_packet.payload_size() == 0;
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
// Padding is expected in congested state to probe for connectivity when
// packets has been dropped.
if (only_padding) {
@ -386,7 +387,7 @@ TEST_F(TransportFeedbackEndToEndTest,
}
Action OnReceiveRtcp(const uint8_t* data, size_t length) override {
rtc::CritScope lock(&crit_);
MutexLock lock(&mutex_);
// To fill up the congestion window we drop feedback on packets after 20
// packets have been sent. This means that any packets that has not yet
// received feedback after that will be considered as oustanding data and
@ -425,10 +426,10 @@ TEST_F(TransportFeedbackEndToEndTest,
private:
const size_t num_video_streams_;
const size_t num_audio_streams_;
rtc::CriticalSection crit_;
int media_sent_ RTC_GUARDED_BY(crit_);
int media_sent_before_ RTC_GUARDED_BY(crit_);
int padding_sent_ RTC_GUARDED_BY(crit_);
Mutex mutex_;
int media_sent_ RTC_GUARDED_BY(mutex_);
int media_sent_before_ RTC_GUARDED_BY(mutex_);
int padding_sent_ RTC_GUARDED_BY(mutex_);
} test(1, 0);
RunBaseTest(&test);
}