Use rtc::CriticalSection in webrtc/video/.

Removes heap allocation from CriticalSection creation.

BUG=
R=stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/50839004

Cr-Commit-Position: refs/heads/master@{#9126}
This commit is contained in:
Peter Boström 2015-05-01 13:00:41 +02:00
parent cac1b38135
commit f2f828374c
21 changed files with 154 additions and 180 deletions

View File

@ -18,22 +18,19 @@ namespace webrtc {
namespace test {
DirectTransport::DirectTransport()
: lock_(CriticalSectionWrapper::CreateCriticalSection()),
packet_event_(EventWrapper::Create()),
thread_(ThreadWrapper::CreateThread(
NetworkProcess, this, "NetworkProcess")),
: packet_event_(EventWrapper::Create()),
thread_(
ThreadWrapper::CreateThread(NetworkProcess, this, "NetworkProcess")),
clock_(Clock::GetRealTimeClock()),
shutting_down_(false),
fake_network_(FakeNetworkPipe::Config()) {
EXPECT_TRUE(thread_->Start());
}
DirectTransport::DirectTransport(
const FakeNetworkPipe::Config& config)
: lock_(CriticalSectionWrapper::CreateCriticalSection()),
packet_event_(EventWrapper::Create()),
thread_(ThreadWrapper::CreateThread(
NetworkProcess, this, "NetworkProcess")),
DirectTransport::DirectTransport(const FakeNetworkPipe::Config& config)
: packet_event_(EventWrapper::Create()),
thread_(
ThreadWrapper::CreateThread(NetworkProcess, this, "NetworkProcess")),
clock_(Clock::GetRealTimeClock()),
shutting_down_(false),
fake_network_(config) {
@ -48,7 +45,7 @@ void DirectTransport::SetConfig(const FakeNetworkPipe::Config& config) {
void DirectTransport::StopSending() {
{
CriticalSectionScoped crit_(lock_.get());
rtc::CritScope crit(&lock_);
shutting_down_ = true;
}
@ -90,7 +87,7 @@ bool DirectTransport::SendPackets() {
return true;
}
}
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
return shutting_down_ ? false : true;
}
} // namespace test

View File

@ -14,8 +14,8 @@
#include <deque>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
#include "webrtc/test/fake_network_pipe.h"
@ -46,7 +46,7 @@ class DirectTransport : public newapi::Transport {
static bool NetworkProcess(void* transport);
bool SendPackets();
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
rtc::CriticalSection lock_;
rtc::scoped_ptr<EventWrapper> packet_event_;
rtc::scoped_ptr<ThreadWrapper> thread_;
Clock* const clock_;

View File

@ -15,7 +15,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/modules/media_file/source/media_file_utility.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/file_wrapper.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
@ -31,7 +30,6 @@ FakeAudioDevice::FakeAudioDevice(Clock* clock, const std::string& filename)
last_playout_ms_(-1),
clock_(clock),
tick_(EventTimerWrapper::Create()),
lock_(CriticalSectionWrapper::CreateCriticalSection()),
file_utility_(new ModuleFileUtility(0)),
input_stream_(FileWrapper::Create()) {
memset(captured_audio_, 0, sizeof(captured_audio_));
@ -49,7 +47,7 @@ FakeAudioDevice::~FakeAudioDevice() {
}
int32_t FakeAudioDevice::Init() {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
if (file_utility_->InitPCMReading(*input_stream_.get()) != 0)
return -1;
@ -68,13 +66,13 @@ int32_t FakeAudioDevice::Init() {
}
int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
audio_callback_ = callback;
return 0;
}
bool FakeAudioDevice::Playing() const {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
return capturing_;
}
@ -84,7 +82,7 @@ int32_t FakeAudioDevice::PlayoutDelay(uint16_t* delay_ms) const {
}
bool FakeAudioDevice::Recording() const {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
return capturing_;
}
@ -95,7 +93,7 @@ bool FakeAudioDevice::Run(void* obj) {
void FakeAudioDevice::CaptureAudio() {
{
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
if (capturing_) {
int bytes_read = file_utility_->ReadPCMData(
*input_stream_.get(), captured_audio_, kBufferSizeBytes);
@ -138,12 +136,12 @@ void FakeAudioDevice::CaptureAudio() {
}
void FakeAudioDevice::Start() {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
capturing_ = true;
}
void FakeAudioDevice::Stop() {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
capturing_ = false;
}
} // namespace test

View File

@ -12,6 +12,7 @@
#include <string>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_device/include/fake_audio_device.h"
#include "webrtc/typedefs.h"
@ -19,7 +20,6 @@
namespace webrtc {
class Clock;
class CriticalSectionWrapper;
class EventTimerWrapper;
class FileWrapper;
class ModuleFileUtility;
@ -58,7 +58,7 @@ class FakeAudioDevice : public FakeAudioDeviceModule {
Clock* clock_;
rtc::scoped_ptr<EventTimerWrapper> tick_;
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
mutable rtc::CriticalSection lock_;
rtc::scoped_ptr<ThreadWrapper> thread_;
rtc::scoped_ptr<ModuleFileUtility> file_utility_;
rtc::scoped_ptr<FileWrapper> input_stream_;

View File

@ -16,7 +16,6 @@
#include <algorithm>
#include "webrtc/call.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/tick_util.h"
namespace webrtc {
@ -71,10 +70,8 @@ class NetworkPacket {
int64_t arrival_time_;
};
FakeNetworkPipe::FakeNetworkPipe(
const FakeNetworkPipe::Config& config)
: lock_(CriticalSectionWrapper::CreateCriticalSection()),
packet_receiver_(NULL),
FakeNetworkPipe::FakeNetworkPipe(const FakeNetworkPipe::Config& config)
: packet_receiver_(NULL),
config_(config),
dropped_packets_(0),
sent_packets_(0),
@ -98,7 +95,7 @@ void FakeNetworkPipe::SetReceiver(PacketReceiver* receiver) {
}
void FakeNetworkPipe::SetConfig(const FakeNetworkPipe::Config& config) {
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
config_ = config; // Shallow copy of the struct.
}
@ -107,7 +104,7 @@ void FakeNetworkPipe::SendPacket(const uint8_t* data, size_t data_length) {
// packets.
if (packet_receiver_ == NULL)
return;
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
if (config_.queue_length_packets > 0 &&
capacity_link_.size() >= config_.queue_length_packets) {
// Too many packet on the link, drop this one.
@ -135,7 +132,7 @@ void FakeNetworkPipe::SendPacket(const uint8_t* data, size_t data_length) {
}
float FakeNetworkPipe::PercentageLoss() {
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
if (sent_packets_ == 0)
return 0;
@ -144,7 +141,7 @@ float FakeNetworkPipe::PercentageLoss() {
}
int FakeNetworkPipe::AverageDelay() {
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
if (sent_packets_ == 0)
return 0;
@ -155,7 +152,7 @@ void FakeNetworkPipe::Process() {
int64_t time_now = TickTime::MillisecondTimestamp();
std::queue<NetworkPacket*> packets_to_deliver;
{
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
// Check the capacity link first.
while (capacity_link_.size() > 0 &&
time_now >= capacity_link_.front()->arrival_time()) {
@ -209,7 +206,7 @@ void FakeNetworkPipe::Process() {
}
int64_t FakeNetworkPipe::TimeUntilNextProcess() const {
CriticalSectionScoped crit(lock_.get());
rtc::CritScope crit(&lock_);
const int64_t kDefaultProcessIntervalMs = 30;
if (capacity_link_.size() == 0 || delay_link_.size() == 0)
return kDefaultProcessIntervalMs;

View File

@ -14,6 +14,7 @@
#include <queue>
#include "webrtc/base/constructormagic.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/typedefs.h"
@ -75,7 +76,7 @@ class FakeNetworkPipe {
size_t sent_packets() { return sent_packets_; }
private:
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
mutable rtc::CriticalSection lock_;
PacketReceiver* packet_receiver_;
std::queue<NetworkPacket*> capacity_link_;
std::queue<NetworkPacket*> delay_link_;

View File

@ -10,9 +10,9 @@
#include "webrtc/test/frame_generator_capturer.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/test/frame_generator.h"
#include "webrtc/system_wrappers/interface/clock.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/event_wrapper.h"
#include "webrtc/system_wrappers/interface/sleep.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
@ -66,7 +66,6 @@ FrameGeneratorCapturer::FrameGeneratorCapturer(Clock* clock,
clock_(clock),
sending_(false),
tick_(EventTimerWrapper::Create()),
lock_(CriticalSectionWrapper::CreateCriticalSection()),
frame_generator_(frame_generator),
target_fps_(target_fps),
first_frame_capture_time_(-1) {
@ -109,7 +108,7 @@ bool FrameGeneratorCapturer::Run(void* obj) {
void FrameGeneratorCapturer::InsertFrame() {
{
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
if (sending_) {
I420VideoFrame* frame = frame_generator_->NextFrame();
frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds());
@ -123,12 +122,12 @@ void FrameGeneratorCapturer::InsertFrame() {
}
void FrameGeneratorCapturer::Start() {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
sending_ = true;
}
void FrameGeneratorCapturer::Stop() {
CriticalSectionScoped cs(lock_.get());
rtc::CritScope cs(&lock_);
sending_ = false;
}
} // test

View File

@ -12,6 +12,7 @@
#include <string>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/test/video_capturer.h"
#include "webrtc/typedefs.h"
@ -61,7 +62,7 @@ class FrameGeneratorCapturer : public VideoCapturer {
bool sending_;
rtc::scoped_ptr<EventTimerWrapper> tick_;
rtc::scoped_ptr<CriticalSectionWrapper> lock_;
rtc::CriticalSection lock_;
rtc::scoped_ptr<ThreadWrapper> thread_;
rtc::scoped_ptr<FrameGenerator> frame_generator_;

View File

@ -15,6 +15,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
#include "webrtc/test/direct_transport.h"
#include "webrtc/typedefs.h"
@ -52,16 +53,15 @@ class RtpRtcpObserver {
protected:
RtpRtcpObserver(unsigned int event_timeout_ms,
const FakeNetworkPipe::Config& configuration)
: crit_(CriticalSectionWrapper::CreateCriticalSection()),
observation_complete_(EventWrapper::Create()),
const FakeNetworkPipe::Config& configuration)
: observation_complete_(EventWrapper::Create()),
parser_(RtpHeaderParser::Create()),
send_transport_(crit_.get(),
send_transport_(&crit_,
this,
&RtpRtcpObserver::OnSendRtp,
&RtpRtcpObserver::OnSendRtcp,
configuration),
receive_transport_(crit_.get(),
receive_transport_(&crit_,
this,
&RtpRtcpObserver::OnReceiveRtp,
&RtpRtcpObserver::OnReceiveRtcp,
@ -69,15 +69,14 @@ class RtpRtcpObserver {
timeout_ms_(event_timeout_ms) {}
explicit RtpRtcpObserver(unsigned int event_timeout_ms)
: crit_(CriticalSectionWrapper::CreateCriticalSection()),
observation_complete_(EventWrapper::Create()),
: observation_complete_(EventWrapper::Create()),
parser_(RtpHeaderParser::Create()),
send_transport_(crit_.get(),
send_transport_(&crit_,
this,
&RtpRtcpObserver::OnSendRtp,
&RtpRtcpObserver::OnSendRtcp,
FakeNetworkPipe::Config()),
receive_transport_(crit_.get(),
receive_transport_(&crit_,
this,
&RtpRtcpObserver::OnReceiveRtp,
&RtpRtcpObserver::OnReceiveRtcp,
@ -115,7 +114,7 @@ class RtpRtcpObserver {
typedef Action (RtpRtcpObserver::*PacketTransportAction)(const uint8_t*,
size_t);
PacketTransport(CriticalSectionWrapper* lock,
PacketTransport(rtc::CriticalSection* lock,
RtpRtcpObserver* observer,
PacketTransportAction on_rtp,
PacketTransportAction on_rtcp,
@ -131,7 +130,7 @@ class RtpRtcpObserver {
EXPECT_FALSE(RtpHeaderParser::IsRtcp(packet, length));
Action action;
{
CriticalSectionScoped lock(crit_);
rtc::CritScope lock(crit_);
action = (observer_->*on_rtp_)(packet, length);
}
switch (action) {
@ -148,7 +147,7 @@ class RtpRtcpObserver {
EXPECT_TRUE(RtpHeaderParser::IsRtcp(packet, length));
Action action;
{
CriticalSectionScoped lock(crit_);
rtc::CritScope lock(crit_);
action = (observer_->*on_rtcp_)(packet, length);
}
switch (action) {
@ -162,14 +161,14 @@ class RtpRtcpObserver {
}
// Pointer to shared lock instance protecting on_rtp_/on_rtcp_ calls.
CriticalSectionWrapper* const crit_;
rtc::CriticalSection* const crit_;
RtpRtcpObserver* const observer_;
const PacketTransportAction on_rtp_, on_rtcp_;
};
protected:
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
const rtc::scoped_ptr<EventWrapper> observation_complete_;
const rtc::scoped_ptr<RtpHeaderParser> parser_;

View File

@ -64,12 +64,10 @@ class TraceObserver {
private:
class Callback : public TraceCallback {
public:
Callback()
: crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
done_(EventWrapper::Create()) {}
Callback() : done_(EventWrapper::Create()) {}
void Print(TraceLevel level, const char* message, int length) override {
CriticalSectionScoped lock(crit_sect_.get());
rtc::CritScope lock(&crit_sect_);
std::string msg(message);
if (msg.find("BitrateEstimator") != std::string::npos) {
received_log_lines_.push_back(msg);
@ -96,13 +94,13 @@ class TraceObserver {
}
void PushExpectedLogLine(const std::string& expected_log_line) {
CriticalSectionScoped lock(crit_sect_.get());
rtc::CritScope lock(&crit_sect_);
expected_log_lines_.push_back(expected_log_line);
}
private:
typedef std::list<std::string> Strings;
const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
rtc::CriticalSection crit_sect_;
Strings received_log_lines_ GUARDED_BY(crit_sect_);
Strings expected_log_lines_ GUARDED_BY(crit_sect_);
rtc::scoped_ptr<EventWrapper> done_;

View File

@ -69,25 +69,24 @@ namespace internal {
class CpuOveruseObserverProxy : public webrtc::CpuOveruseObserver {
public:
explicit CpuOveruseObserverProxy(LoadObserver* overuse_callback)
: crit_(CriticalSectionWrapper::CreateCriticalSection()),
overuse_callback_(overuse_callback) {
: overuse_callback_(overuse_callback) {
DCHECK(overuse_callback != nullptr);
}
virtual ~CpuOveruseObserverProxy() {}
void OveruseDetected() override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
overuse_callback_->OnLoadUpdate(LoadObserver::kOveruse);
}
void NormalUsage() override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
overuse_callback_->OnLoadUpdate(LoadObserver::kUnderuse);
}
private:
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
LoadObserver* overuse_callback_ GUARDED_BY(crit_);
};
@ -133,7 +132,7 @@ class Call : public webrtc::Call, public PacketReceiver {
// Needs to be held while write-locking |receive_crit_| or |send_crit_|. This
// ensures that we have a consistent network state signalled to all senders
// and receivers.
rtc::scoped_ptr<CriticalSectionWrapper> network_enabled_crit_;
rtc::CriticalSection network_enabled_crit_;
bool network_enabled_ GUARDED_BY(network_enabled_crit_);
rtc::scoped_ptr<RWLockWrapper> receive_crit_;
@ -178,7 +177,6 @@ namespace internal {
Call::Call(webrtc::VideoEngine* video_engine, const Call::Config& config)
: config_(config),
network_enabled_crit_(CriticalSectionWrapper::CreateCriticalSection()),
network_enabled_(true),
receive_crit_(RWLockWrapper::CreateRWLock()),
send_crit_(RWLockWrapper::CreateRWLock()),
@ -293,7 +291,7 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream(
// This needs to be taken before send_crit_ as both locks need to be held
// while changing network state.
CriticalSectionScoped lock(network_enabled_crit_.get());
rtc::CritScope lock(&network_enabled_crit_);
WriteLockScoped write_lock(*send_crit_);
for (uint32_t ssrc : config.rtp.ssrcs) {
DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
@ -349,7 +347,7 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
// This needs to be taken before receive_crit_ as both locks need to be held
// while changing network state.
CriticalSectionScoped lock(network_enabled_crit_.get());
rtc::CritScope lock(&network_enabled_crit_);
WriteLockScoped write_lock(*receive_crit_);
DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
video_receive_ssrcs_.end());
@ -439,7 +437,7 @@ void Call::SetBitrateConfig(
void Call::SignalNetworkState(NetworkState state) {
// Take crit for entire function, it needs to be held while updating streams
// to guarantee a consistent state across streams.
CriticalSectionScoped lock(network_enabled_crit_.get());
rtc::CritScope lock(&network_enabled_crit_);
network_enabled_ = state == kNetworkUp;
{
ReadLockScoped write_lock(*send_crit_);

View File

@ -59,8 +59,7 @@ class CallPerfTest : public test::CallTest {
class SyncRtcpObserver : public test::RtpRtcpObserver {
public:
explicit SyncRtcpObserver(const FakeNetworkPipe::Config& config)
: test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs, config),
crit_(CriticalSectionWrapper::CreateCriticalSection()) {}
: test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs, config) {}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
RTCPUtility::RTCPParserV2 parser(packet, length, true);
@ -82,7 +81,7 @@ class SyncRtcpObserver : public test::RtpRtcpObserver {
}
int64_t RtpTimestampToNtp(uint32_t timestamp) const {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
int64_t timestamp_in_ms = -1;
if (ntp_rtp_pairs_.size() == 2) {
// TODO(stefan): We can't EXPECT_TRUE on this call due to a bug in the
@ -96,7 +95,7 @@ class SyncRtcpObserver : public test::RtpRtcpObserver {
private:
void StoreNtpRtpPair(RtcpMeasurement ntp_rtp_pair) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
for (RtcpList::iterator it = ntp_rtp_pairs_.begin();
it != ntp_rtp_pairs_.end();
++it) {
@ -114,7 +113,7 @@ class SyncRtcpObserver : public test::RtpRtcpObserver {
ntp_rtp_pairs_.push_front(ntp_rtp_pair);
}
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
mutable rtc::CriticalSection crit_;
RtcpList ntp_rtp_pairs_ GUARDED_BY(crit_);
};

View File

@ -504,7 +504,7 @@ TEST_F(EndToEndTest, CanReceiveFec) {
void RenderFrame(const I420VideoFrame& video_frame,
int time_to_render_ms) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
// Rendering frame with timestamp of packet that was dropped -> FEC
// protection worked.
if (protected_timestamps_.count(video_frame.timestamp()) != 0)
@ -712,7 +712,7 @@ void EndToEndTest::DecodesRetransmittedFrame(bool use_rtx, bool use_red) {
}
void FrameCallback(I420VideoFrame* frame) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (frame->timestamp() == retransmitted_timestamp_) {
EXPECT_TRUE(frame_retransmitted_);
observation_complete_->Set();
@ -935,7 +935,7 @@ void EndToEndTest::ReceivesPliAndRecovers(int rtp_history_ms) {
void RenderFrame(const I420VideoFrame& video_frame,
int time_to_render_ms) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (received_pli_ &&
video_frame.timestamp() > highest_dropped_timestamp_) {
observation_complete_->Set();
@ -1877,7 +1877,7 @@ TEST_F(EndToEndTest, ReportsSetEncoderRates) {
// Make sure not to trigger on any default zero bitrates.
if (new_target_bitrate == 0)
return 0;
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
bitrate_kbps_ = new_target_bitrate;
observation_complete_->Set();
return 0;
@ -1890,7 +1890,7 @@ TEST_F(EndToEndTest, ReportsSetEncoderRates) {
for (unsigned int i = 0; i < kDefaultTimeoutMs; ++i) {
VideoSendStream::Stats stats = send_stream_->GetStats();
{
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if ((stats.target_media_bitrate_bps + 500) / 1000 ==
static_cast<int>(bitrate_kbps_)) {
return;
@ -2297,7 +2297,6 @@ void EndToEndTest::TestRtpStatePreservation(bool use_rtx) {
public:
explicit RtpSequenceObserver(bool use_rtx)
: test::RtpRtcpObserver(kDefaultTimeoutMs),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
ssrcs_to_observe_(kNumSsrcs) {
for (size_t i = 0; i < kNumSsrcs; ++i) {
configured_ssrcs_[kSendSsrcs[i]] = true;
@ -2307,7 +2306,7 @@ void EndToEndTest::TestRtpStatePreservation(bool use_rtx) {
}
void ResetExpectedSsrcs(size_t num_expected_ssrcs) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
ssrc_observed_.clear();
ssrcs_to_observe_ = num_expected_ssrcs;
}
@ -2362,7 +2361,7 @@ void EndToEndTest::TestRtpStatePreservation(bool use_rtx) {
last_observed_timestamp_[ssrc] = timestamp;
}
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
// Wait for media packets on all ssrcs.
if (!ssrc_observed_[ssrc] && !only_padding) {
ssrc_observed_[ssrc] = true;
@ -2377,7 +2376,7 @@ void EndToEndTest::TestRtpStatePreservation(bool use_rtx) {
std::map<uint32_t, uint32_t> last_observed_timestamp_;
std::map<uint32_t, bool> configured_ssrcs_;
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
size_t ssrcs_to_observe_ GUARDED_BY(crit_);
std::map<uint32_t, bool> ssrc_observed_ GUARDED_BY(crit_);
} observer(use_rtx);
@ -2489,7 +2488,6 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
NetworkStateTest()
: EndToEndTest(kDefaultTimeoutMs),
FakeEncoder(Clock::GetRealTimeClock()),
test_crit_(CriticalSectionWrapper::CreateCriticalSection()),
encoded_frames_(EventWrapper::Create()),
packet_event_(EventWrapper::Create()),
sender_state_(Call::kNetworkUp),
@ -2499,14 +2497,14 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
down_frames_(0) {}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
++sender_rtp_;
packet_event_->Set();
return SEND_PACKET;
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
++sender_rtcp_;
packet_event_->Set();
return SEND_PACKET;
@ -2518,7 +2516,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
}
Action OnReceiveRtcp(const uint8_t* packet, size_t length) override {
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
++receiver_rtcp_;
packet_event_->Set();
return SEND_PACKET;
@ -2544,7 +2542,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
// Sender-side network down.
sender_call_->SignalNetworkState(Call::kNetworkDown);
{
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
// After network goes down we shouldn't be encoding more frames.
sender_state_ = Call::kNetworkDown;
}
@ -2557,7 +2555,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
// Network back up again for both.
{
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
// It's OK to encode frames again, as we're about to bring up the
// network.
sender_state_ = Call::kNetworkUp;
@ -2571,7 +2569,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
const CodecSpecificInfo* codec_specific_info,
const std::vector<VideoFrameType>* frame_types) override {
{
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
if (sender_state_ == Call::kNetworkDown) {
++down_frames_;
EXPECT_LE(down_frames_, 1)
@ -2593,7 +2591,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
int initial_sender_rtcp;
int initial_receiver_rtcp;
{
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
initial_sender_rtp = sender_rtp_;
initial_sender_rtcp = sender_rtcp_;
initial_receiver_rtcp = receiver_rtcp_;
@ -2603,7 +2601,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
while(!sender_done || !receiver_done) {
packet_event_->Wait(kSilenceTimeoutMs);
int64_t time_now_ms = clock_->TimeInMilliseconds();
CriticalSectionScoped lock(test_crit_.get());
rtc::CritScope lock(&test_crit_);
if (sender_down) {
ASSERT_LE(sender_rtp_ - initial_sender_rtp, kNumAcceptedDowntimeRtp)
<< "RTP sent during sender-side downtime.";
@ -2633,7 +2631,7 @@ TEST_F(EndToEndTest, RespectsNetworkState) {
}
}
const rtc::scoped_ptr<CriticalSectionWrapper> test_crit_;
rtc::CriticalSection test_crit_;
const rtc::scoped_ptr<EventWrapper> encoded_frames_;
const rtc::scoped_ptr<EventWrapper> packet_event_;
Call* sender_call_;

View File

@ -81,10 +81,8 @@ class VideoAnalyzer : public PacketReceiver,
dropped_frames_(0),
last_render_time_(0),
rtp_timestamp_delta_(0),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
avg_psnr_threshold_(avg_psnr_threshold),
avg_ssim_threshold_(avg_ssim_threshold),
comparison_lock_(CriticalSectionWrapper::CreateCriticalSection()),
comparison_available_event_(EventWrapper::Create()),
done_(EventWrapper::Create()) {
// Create thread pool for CPU-expensive PSNR/SSIM calculations.
@ -129,7 +127,7 @@ class VideoAnalyzer : public PacketReceiver,
RTPHeader header;
parser->Parse(packet, length, &header);
{
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
recv_times_[header.timestamp - rtp_timestamp_delta_] =
Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
}
@ -142,7 +140,7 @@ class VideoAnalyzer : public PacketReceiver,
copy.set_timestamp(copy.ntp_time_ms() * 90);
{
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (first_send_frame_.IsZeroSize() && rtp_timestamp_delta_ == 0)
first_send_frame_ = copy;
@ -158,7 +156,7 @@ class VideoAnalyzer : public PacketReceiver,
parser->Parse(packet, length, &header);
{
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (rtp_timestamp_delta_ == 0) {
rtp_timestamp_delta_ =
header.timestamp - first_send_frame_.timestamp();
@ -181,7 +179,7 @@ class VideoAnalyzer : public PacketReceiver,
Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_;
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
while (frames_.front().timestamp() < send_timestamp) {
AddFrameComparison(frames_.front(), last_rendered_frame_, true,
@ -213,7 +211,7 @@ class VideoAnalyzer : public PacketReceiver,
kEventSignaled) {
int frames_processed;
{
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
frames_processed = frames_processed_;
}
if (last_frames_processed == -1) {
@ -266,7 +264,7 @@ class VideoAnalyzer : public PacketReceiver,
int64_t recv_time_ms = recv_times_[reference.timestamp()];
recv_times_.erase(reference.timestamp());
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
comparisons_.push_back(FrameComparison(reference,
render,
dropped,
@ -312,7 +310,7 @@ class VideoAnalyzer : public PacketReceiver,
}
bool PopComparison(FrameComparison* comparison) {
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
// If AllFramesRecorded() is true, it means we have already popped
// frames_to_process_ frames from comparisons_, so there is no more work
// for this thread to be done. frames_processed_ might still be lower if
@ -330,13 +328,13 @@ class VideoAnalyzer : public PacketReceiver,
// Increment counter for number of frames received for comparison.
void FrameRecorded() {
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
++frames_recorded_;
}
// Returns true if all frames to be compared have been taken from the queue.
bool AllFramesRecorded() {
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
assert(frames_recorded_ <= frames_to_process_);
return frames_recorded_ == frames_to_process_;
}
@ -344,14 +342,14 @@ class VideoAnalyzer : public PacketReceiver,
// Increase count of number of frames processed. Returns true if this was the
// last frame to be processed.
bool FrameProcessed() {
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
++frames_processed_;
assert(frames_processed_ <= frames_to_process_);
return frames_processed_ == frames_to_process_;
}
void PrintResults() {
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
PrintResult("psnr", psnr_, " dB");
PrintResult("ssim", ssim_, "");
PrintResult("sender_time", sender_time_, " ms");
@ -369,7 +367,7 @@ class VideoAnalyzer : public PacketReceiver,
double psnr = I420PSNR(&comparison.reference, &comparison.render);
double ssim = I420SSIM(&comparison.reference, &comparison.render);
CriticalSectionScoped crit(comparison_lock_.get());
rtc::CritScope crit(&comparison_lock_);
psnr_.AddSample(psnr);
ssim_.AddSample(ssim);
if (comparison.dropped) {
@ -412,7 +410,7 @@ class VideoAnalyzer : public PacketReceiver,
int64_t last_render_time_;
uint32_t rtp_timestamp_delta_;
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
std::deque<I420VideoFrame> frames_ GUARDED_BY(crit_);
I420VideoFrame last_rendered_frame_ GUARDED_BY(crit_);
std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_);
@ -421,7 +419,7 @@ class VideoAnalyzer : public PacketReceiver,
const double avg_psnr_threshold_;
const double avg_ssim_threshold_;
const rtc::scoped_ptr<CriticalSectionWrapper> comparison_lock_;
rtc::CriticalSection comparison_lock_;
std::vector<ThreadWrapper*> comparison_thread_pool_;
const rtc::scoped_ptr<EventWrapper> comparison_available_event_;
std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);

View File

@ -46,7 +46,6 @@ StreamObserver::StreamObserver(const SsrcMap& rtx_media_ssrcs,
receive_stats_(ReceiveStatistics::Create(clock)),
payload_registry_(
new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(false))),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
expected_bitrate_bps_(0),
start_bitrate_bps_(0),
rtx_media_ssrcs_(rtx_media_ssrcs),
@ -83,18 +82,18 @@ StreamObserver::StreamObserver(const SsrcMap& rtx_media_ssrcs,
void StreamObserver::set_expected_bitrate_bps(
unsigned int expected_bitrate_bps) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
expected_bitrate_bps_ = expected_bitrate_bps;
}
void StreamObserver::set_start_bitrate_bps(unsigned int start_bitrate_bps) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
start_bitrate_bps_ = start_bitrate_bps;
}
void StreamObserver::OnReceiveBitrateChanged(
const std::vector<unsigned int>& ssrcs, unsigned int bitrate) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
DCHECK_GT(expected_bitrate_bps_, 0u);
if (start_bitrate_bps_ != 0) {
// For tests with an explicitly set start bitrate, verify the first
@ -117,7 +116,7 @@ void StreamObserver::OnReceiveBitrateChanged(
}
bool StreamObserver::SendRtp(const uint8_t* packet, size_t length) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
RTPHeader header;
EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header));
receive_stats_->IncomingPacket(header, length, false);
@ -197,7 +196,6 @@ LowRateStreamObserver::LowRateStreamObserver(
rtp_parser_(RtpHeaderParser::Create()),
feedback_transport_(feedback_transport),
receive_stats_(ReceiveStatistics::Create(clock)),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
send_stream_(nullptr),
test_state_(kFirstRampup),
state_start_ms_(clock_->TimeInMilliseconds()),
@ -228,21 +226,21 @@ LowRateStreamObserver::LowRateStreamObserver(
}
void LowRateStreamObserver::SetSendStream(VideoSendStream* send_stream) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
send_stream_ = send_stream;
}
void LowRateStreamObserver::OnReceiveBitrateChanged(
const std::vector<unsigned int>& ssrcs,
unsigned int bitrate) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
rtp_rtcp_->SetREMBData(bitrate, ssrcs);
rtp_rtcp_->Process();
last_remb_bps_ = bitrate;
}
bool LowRateStreamObserver::SendRtp(const uint8_t* data, size_t length) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
sent_bytes_ += length;
int64_t now_ms = clock_->TimeInMilliseconds();
if (now_ms > interval_start_ms_ + 1000) { // Let at least 1 second pass.
@ -265,7 +263,7 @@ bool LowRateStreamObserver::SendRtp(const uint8_t* data, size_t length) {
PacketReceiver::DeliveryStatus LowRateStreamObserver::DeliverPacket(
MediaType media_type, const uint8_t* packet, size_t length) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
RTPHeader header;
EXPECT_TRUE(rtp_parser_->Parse(packet, length, &header));
receive_stats_->IncomingPacket(header, length, false);
@ -298,7 +296,7 @@ std::string LowRateStreamObserver::GetModifierString() {
void LowRateStreamObserver::EvolveTestState(unsigned int bitrate_bps) {
int64_t now = clock_->TimeInMilliseconds();
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
DCHECK(send_stream_ != nullptr);
switch (test_state_) {
case kFirstRampup: {

View File

@ -29,7 +29,6 @@ static const int kAbsSendTimeExtensionId = 7;
static const unsigned int kSingleStreamTargetBps = 1000000;
class Clock;
class CriticalSectionWrapper;
class ReceiveStatistics;
class RtpHeaderParser;
class RTPPayloadRegistry;
@ -73,7 +72,7 @@ class StreamObserver : public newapi::Transport, public RemoteBitrateObserver {
const rtc::scoped_ptr<RTPPayloadRegistry> payload_registry_;
rtc::scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
unsigned int expected_bitrate_bps_ GUARDED_BY(crit_);
unsigned int start_bitrate_bps_ GUARDED_BY(crit_);
SsrcMap rtx_media_ssrcs_ GUARDED_BY(crit_);
@ -134,7 +133,7 @@ class LowRateStreamObserver : public test::DirectTransport,
const rtc::scoped_ptr<ReceiveStatistics> receive_stats_;
rtc::scoped_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
VideoSendStream* send_stream_ GUARDED_BY(crit_);
FakeNetworkPipe::Config forward_transport_config_ GUARDED_BY(crit_);
TestStates test_state_ GUARDED_BY(crit_);

View File

@ -18,7 +18,6 @@ namespace webrtc {
ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t ssrc, Clock* clock)
: clock_(clock),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
// 1000ms window, scale 1000 for ms to s.
decode_fps_estimator_(1000, 1000),
renders_fps_estimator_(1000, 1000) {
@ -32,7 +31,7 @@ ReceiveStatisticsProxy::~ReceiveStatisticsProxy() {
void ReceiveStatisticsProxy::UpdateHistograms() const {
int fraction_lost;
{
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
fraction_lost = report_block_stats_.FractionLostInPercent();
}
if (fraction_lost != -1) {
@ -42,14 +41,14 @@ void ReceiveStatisticsProxy::UpdateHistograms() const {
}
VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
return stats_;
}
void ReceiveStatisticsProxy::IncomingRate(const int video_channel,
const unsigned int framerate,
const unsigned int bitrate_bps) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.network_frame_rate = framerate;
stats_.total_bitrate_bps = bitrate_bps;
}
@ -61,7 +60,7 @@ void ReceiveStatisticsProxy::DecoderTiming(int decode_ms,
int jitter_buffer_ms,
int min_playout_delay_ms,
int render_delay_ms) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.decode_ms = decode_ms;
stats_.max_decode_ms = max_decode_ms;
stats_.current_delay_ms = current_delay_ms;
@ -74,7 +73,7 @@ void ReceiveStatisticsProxy::DecoderTiming(int decode_ms,
void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
uint32_t ssrc,
const RtcpPacketTypeCounter& packet_counter) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (stats_.ssrc != ssrc)
return;
stats_.rtcp_packet_type_counts = packet_counter;
@ -83,7 +82,7 @@ void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated(
void ReceiveStatisticsProxy::StatisticsUpdated(
const webrtc::RtcpStatistics& statistics,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
// TODO(pbos): Handle both local and remote ssrcs here and DCHECK that we
// receive stats from one of them.
if (stats_.ssrc != ssrc)
@ -93,7 +92,7 @@ void ReceiveStatisticsProxy::StatisticsUpdated(
}
void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
// TODO(pbos): Handle both local and remote ssrcs here and DCHECK that we
// receive stats from one of them.
if (stats_.ssrc != ssrc)
@ -104,7 +103,7 @@ void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
void ReceiveStatisticsProxy::DataCountersUpdated(
const webrtc::StreamDataCounters& counters,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (stats_.ssrc != ssrc)
return;
stats_.rtp_stats = counters;
@ -113,7 +112,7 @@ void ReceiveStatisticsProxy::DataCountersUpdated(
void ReceiveStatisticsProxy::OnDecodedFrame() {
uint64_t now = clock_->TimeInMilliseconds();
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
decode_fps_estimator_.Update(1, now);
stats_.decode_frame_rate = decode_fps_estimator_.Rate(now);
}
@ -121,7 +120,7 @@ void ReceiveStatisticsProxy::OnDecodedFrame() {
void ReceiveStatisticsProxy::OnRenderedFrame() {
uint64_t now = clock_->TimeInMilliseconds();
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
renders_fps_estimator_.Update(1, now);
stats_.render_frame_rate = renders_fps_estimator_.Rate(now);
}
@ -132,12 +131,12 @@ void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate,
void ReceiveStatisticsProxy::OnFrameCountsUpdated(
const FrameCounts& frame_counts) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.frame_counts = frame_counts;
}
void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.discarded_packets = discarded_packets;
}

View File

@ -13,6 +13,7 @@
#include <string>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/thread_annotations.h"
#include "webrtc/common_types.h"
#include "webrtc/frame_callback.h"
@ -27,7 +28,6 @@
namespace webrtc {
class Clock;
class CriticalSectionWrapper;
class ViECodec;
class ViEDecoderObserver;
@ -82,7 +82,7 @@ class ReceiveStatisticsProxy : public ViEDecoderObserver,
void UpdateHistograms() const;
Clock* const clock_;
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
mutable rtc::CriticalSection crit_;
VideoReceiveStream::Stats stats_ GUARDED_BY(crit_);
RateStatistics decode_fps_estimator_ GUARDED_BY(crit_);
RateStatistics renders_fps_estimator_ GUARDED_BY(crit_);

View File

@ -24,8 +24,7 @@ const int SendStatisticsProxy::kStatsTimeoutMs = 5000;
SendStatisticsProxy::SendStatisticsProxy(Clock* clock,
const VideoSendStream::Config& config)
: clock_(clock),
config_(config),
crit_(CriticalSectionWrapper::CreateCriticalSection()) {
config_(config) {
}
SendStatisticsProxy::~SendStatisticsProxy() {}
@ -33,25 +32,25 @@ SendStatisticsProxy::~SendStatisticsProxy() {}
void SendStatisticsProxy::OutgoingRate(const int video_channel,
const unsigned int framerate,
const unsigned int bitrate) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.encode_frame_rate = framerate;
stats_.media_bitrate_bps = bitrate;
}
void SendStatisticsProxy::CpuOveruseMetricsUpdated(
const CpuOveruseMetrics& metrics) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.avg_encode_time_ms = metrics.avg_encode_time_ms;
stats_.encode_usage_percent = metrics.encode_usage_percent;
}
void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.suspended = is_suspended;
}
VideoSendStream::Stats SendStatisticsProxy::GetStats() {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
PurgeOldStats();
stats_.input_frame_rate =
static_cast<int>(input_frame_rate_tracker_.units_second());
@ -92,7 +91,7 @@ VideoSendStream::StreamStats* SendStatisticsProxy::GetStatsEntry(
}
void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
stats_.target_media_bitrate_bps = bitrate_bps;
}
@ -108,7 +107,7 @@ void SendStatisticsProxy::OnSendEncodedImage(
}
uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx];
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (stats == nullptr)
return;
@ -119,14 +118,14 @@ void SendStatisticsProxy::OnSendEncodedImage(
}
void SendStatisticsProxy::OnIncomingFrame() {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
input_frame_rate_tracker_.Update(1);
}
void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
uint32_t ssrc,
const RtcpPacketTypeCounter& packet_counter) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (stats == nullptr)
return;
@ -136,7 +135,7 @@ void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (stats == nullptr)
return;
@ -150,7 +149,7 @@ void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {
void SendStatisticsProxy::DataCountersUpdated(
const StreamDataCounters& counters,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
DCHECK(stats != nullptr) << "DataCountersUpdated reported for unknown ssrc: "
<< ssrc;
@ -161,7 +160,7 @@ void SendStatisticsProxy::DataCountersUpdated(
void SendStatisticsProxy::Notify(const BitrateStatistics& total_stats,
const BitrateStatistics& retransmit_stats,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (stats == nullptr)
return;
@ -172,7 +171,7 @@ void SendStatisticsProxy::Notify(const BitrateStatistics& total_stats,
void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (stats == nullptr)
return;
@ -183,7 +182,7 @@ void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts,
void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms,
int max_delay_ms,
uint32_t ssrc) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc);
if (stats == nullptr)
return;

View File

@ -13,6 +13,7 @@
#include <string>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/ratetracker.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/thread_annotations.h"
@ -27,8 +28,6 @@
namespace webrtc {
class CriticalSectionWrapper;
class SendStatisticsProxy : public CpuOveruseMetricsObserver,
public RtcpStatisticsCallback,
public RtcpPacketTypeCounterObserver,
@ -100,7 +99,7 @@ class SendStatisticsProxy : public CpuOveruseMetricsObserver,
Clock* const clock_;
const VideoSendStream::Config config_;
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
mutable rtc::CriticalSection crit_;
VideoSendStream::Stats stats_ GUARDED_BY(crit_);
rtc::RateTracker input_frame_rate_tracker_ GUARDED_BY(crit_);
std::map<uint32_t, StatsUpdateTimes> update_times_ GUARDED_BY(crit_);

View File

@ -665,7 +665,6 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
: SendTest(kDefaultTimeoutMs),
transport_adapter_(&transport_),
clock_(Clock::GetRealTimeClock()),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
test_state_(kBeforeSuspend),
rtp_count_(0),
last_sequence_number_(0),
@ -679,13 +678,13 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
// Receive statistics reporting having lost 0% of the packets.
// This is needed for the send-side bitrate controller to work properly.
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
SendRtcpFeedback(0); // REMB is only sent if value is > 0.
return SEND_PACKET;
}
Action OnSendRtp(const uint8_t* packet, size_t length) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
++rtp_count_;
RTPHeader header;
EXPECT_TRUE(parser_->Parse(packet, length, &header));
@ -720,7 +719,7 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
// This method implements the I420FrameCallback.
void FrameCallback(I420VideoFrame* video_frame) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
if (test_state_ == kDuringSuspend &&
++suspended_frame_count_ > kSuspendTimeFrames) {
VideoSendStream::Stats stats = stream_->GetStats();
@ -731,12 +730,12 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
}
void set_low_remb_bps(int value) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
low_remb_bps_ = value;
}
void set_high_remb_bps(int value) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
high_remb_bps_ = value;
}
@ -800,7 +799,7 @@ TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
Clock* const clock_;
VideoSendStream* stream_;
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
TestState test_state_ GUARDED_BY(crit_);
int rtp_count_ GUARDED_BY(crit_);
int last_sequence_number_ GUARDED_BY(crit_);
@ -819,7 +818,6 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
: SendTest(kDefaultTimeoutMs),
clock_(Clock::GetRealTimeClock()),
transport_adapter_(ReceiveTransport()),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
last_packet_time_ms_(-1),
capturer_(nullptr) {
transport_adapter_.Enable();
@ -827,14 +825,14 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
private:
Action OnSendRtp(const uint8_t* packet, size_t length) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
last_packet_time_ms_ = clock_->TimeInMilliseconds();
capturer_->Stop();
return SEND_PACKET;
}
Action OnSendRtcp(const uint8_t* packet, size_t length) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
const int kVideoMutedThresholdMs = 10000;
if (last_packet_time_ms_ > 0 &&
clock_->TimeInMilliseconds() - last_packet_time_ms_ >
@ -865,7 +863,7 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
virtual void OnFrameGeneratorCapturerCreated(
test::FrameGeneratorCapturer* frame_generator_capturer) {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
capturer_ = frame_generator_capturer;
}
@ -876,7 +874,7 @@ TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
Clock* const clock_;
internal::TransportAdapter transport_adapter_;
const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
int64_t last_packet_time_ms_ GUARDED_BY(crit_);
test::FrameGeneratorCapturer* capturer_ GUARDED_BY(crit_);
} test;
@ -1178,24 +1176,23 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
public:
EncoderStateObserver()
: SendTest(kDefaultTimeoutMs),
crit_(CriticalSectionWrapper::CreateCriticalSection()),
initialized_(false),
callback_registered_(false),
num_releases_(0),
released_(false) {}
bool IsReleased() {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
return released_;
}
bool IsReadyForEncode() {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
return initialized_ && callback_registered_;
}
size_t num_releases() {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
return num_releases_;
}
@ -1203,7 +1200,7 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
int32_t InitEncode(const VideoCodec* codecSettings,
int32_t numberOfCores,
size_t maxPayloadSize) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
EXPECT_FALSE(initialized_);
initialized_ = true;
released_ = false;
@ -1221,14 +1218,14 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
int32_t RegisterEncodeCompleteCallback(
EncodedImageCallback* callback) override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
EXPECT_TRUE(initialized_);
callback_registered_ = true;
return 0;
}
int32_t Release() override {
CriticalSectionScoped lock(crit_.get());
rtc::CritScope lock(&crit_);
EXPECT_TRUE(IsReadyForEncode());
EXPECT_FALSE(released_);
initialized_ = false;
@ -1280,7 +1277,7 @@ TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
<< "Timed out while waiting for Encode.";
}
rtc::scoped_ptr<CriticalSectionWrapper> crit_;
rtc::CriticalSection crit_;
VideoSendStream* stream_;
bool initialized_ GUARDED_BY(crit_);
bool callback_registered_ GUARDED_BY(crit_);