Reland 8631 "Speculative revert of 8631 "Remove lock from Bitrat..."
> Speculative revert of 8631 "Remove lock from Bitrate() and FrameRate() in Video..." > > We ran into the alignment problem on Mac 10.9 debug again. This is the only CL I see in the range that adds an rtc::CriticalSection, so I'm trying out reverting it before attempting another roll. > > > Remove lock from Bitrate() and FrameRate() in VideoSender. > > These methods are called on the VideoSender's construction thread, which is the same thread as modifies the value of _encoder. It's therefore safe to not require a lock to access _encoder on this thread. > > > > I'm making access to the rate variables from VCMGenericEncoder, thread safe, by using a lock that's not associated with the encoder. There should be little to no contention there. While modifying VCMGenericEncoder, I noticed that a couple of member variables weren't needed, so I removed them. > > > > The reason for this change is that getStats is currently contending with the encoder when Bitrate() is called. On my machine, this means that getStats can take about 25-30ms instead of ~1ms. > > > > Also adding some documentation for other methods and a suggestion for how we could avoid contention between the encoder and the network thread. > > > > BUG=2822 > > R=mflodman@webrtc.org > > > > Review URL: https://webrtc-codereview.appspot.com/43479004 > > TBR=tommi@webrtc.org > > Review URL: https://webrtc-codereview.appspot.com/45529004 TBR=tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/46519004 Cr-Commit-Position: refs/heads/master@{#8645} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8645 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -60,11 +60,9 @@ VCMGenericEncoder::VCMGenericEncoder(VideoEncoder* encoder,
|
||||
bool internalSource)
|
||||
: encoder_(encoder),
|
||||
rate_observer_(rate_observer),
|
||||
_codecType(kVideoCodecUnknown),
|
||||
_VCMencodedFrameCallback(NULL),
|
||||
_bitRate(0),
|
||||
_frameRate(0),
|
||||
_internalSource(internalSource) {
|
||||
bit_rate_(0),
|
||||
frame_rate_(0),
|
||||
internal_source_(internalSource) {
|
||||
}
|
||||
|
||||
VCMGenericEncoder::~VCMGenericEncoder()
|
||||
@ -73,9 +71,12 @@ VCMGenericEncoder::~VCMGenericEncoder()
|
||||
|
||||
int32_t VCMGenericEncoder::Release()
|
||||
{
|
||||
_bitRate = 0;
|
||||
_frameRate = 0;
|
||||
_VCMencodedFrameCallback = NULL;
|
||||
{
|
||||
rtc::CritScope lock(&rates_lock_);
|
||||
bit_rate_ = 0;
|
||||
frame_rate_ = 0;
|
||||
}
|
||||
|
||||
return encoder_->Release();
|
||||
}
|
||||
|
||||
@ -84,9 +85,12 @@ VCMGenericEncoder::InitEncode(const VideoCodec* settings,
|
||||
int32_t numberOfCores,
|
||||
size_t maxPayloadSize)
|
||||
{
|
||||
_bitRate = settings->startBitrate * 1000;
|
||||
_frameRate = settings->maxFramerate;
|
||||
_codecType = settings->codecType;
|
||||
{
|
||||
rtc::CritScope lock(&rates_lock_);
|
||||
bit_rate_ = settings->startBitrate * 1000;
|
||||
frame_rate_ = settings->maxFramerate;
|
||||
}
|
||||
|
||||
if (encoder_->InitEncode(settings, numberOfCores, maxPayloadSize) != 0) {
|
||||
LOG(LS_ERROR) << "Failed to initialize the encoder associated with "
|
||||
"payload name: " << settings->plName;
|
||||
@ -120,8 +124,13 @@ VCMGenericEncoder::SetRates(uint32_t newBitRate, uint32_t frameRate)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
_bitRate = newBitRate;
|
||||
_frameRate = frameRate;
|
||||
|
||||
{
|
||||
rtc::CritScope lock(&rates_lock_);
|
||||
bit_rate_ = newBitRate;
|
||||
frame_rate_ = frameRate;
|
||||
}
|
||||
|
||||
if (rate_observer_ != nullptr)
|
||||
rate_observer_->OnSetRates(newBitRate, frameRate);
|
||||
return VCM_OK;
|
||||
@ -140,12 +149,14 @@ VCMGenericEncoder::CodecConfigParameters(uint8_t* buffer, int32_t size)
|
||||
|
||||
uint32_t VCMGenericEncoder::BitRate() const
|
||||
{
|
||||
return _bitRate;
|
||||
rtc::CritScope lock(&rates_lock_);
|
||||
return bit_rate_;
|
||||
}
|
||||
|
||||
uint32_t VCMGenericEncoder::FrameRate() const
|
||||
{
|
||||
return _frameRate;
|
||||
rtc::CritScope lock(&rates_lock_);
|
||||
return frame_rate_;
|
||||
}
|
||||
|
||||
int32_t
|
||||
@ -166,15 +177,14 @@ int32_t VCMGenericEncoder::RequestFrame(
|
||||
int32_t
|
||||
VCMGenericEncoder::RegisterEncodeCallback(VCMEncodedFrameCallback* VCMencodedFrameCallback)
|
||||
{
|
||||
_VCMencodedFrameCallback = VCMencodedFrameCallback;
|
||||
_VCMencodedFrameCallback->SetInternalSource(_internalSource);
|
||||
return encoder_->RegisterEncodeCompleteCallback(_VCMencodedFrameCallback);
|
||||
VCMencodedFrameCallback->SetInternalSource(internal_source_);
|
||||
return encoder_->RegisterEncodeCompleteCallback(VCMencodedFrameCallback);
|
||||
}
|
||||
|
||||
bool
|
||||
VCMGenericEncoder::InternalSource() const
|
||||
{
|
||||
return _internalSource;
|
||||
return internal_source_;
|
||||
}
|
||||
|
||||
/***************************
|
||||
|
||||
Reference in New Issue
Block a user