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

Cr-Commit-Position: refs/heads/master@{#8640}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8640 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tommi@webrtc.org
2015-03-07 09:26:16 +00:00
parent dc08a230da
commit 92696cd0c6
3 changed files with 52 additions and 80 deletions

View File

@ -16,7 +16,6 @@
#include <stdio.h>
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/scoped_ptr.h"
namespace webrtc {
@ -75,9 +74,9 @@ class VCMGenericEncoder
{
friend class VCMCodecDataBase;
public:
VCMGenericEncoder(VideoEncoder* encoder,
VideoEncoderRateObserver* rate_observer,
bool internalSource);
VCMGenericEncoder(VideoEncoder* encoder,
VideoEncoderRateObserver* rate_observer,
bool internalSource);
~VCMGenericEncoder();
/**
* Free encoder memory
@ -103,9 +102,6 @@ public:
* Set new target bitrate (bits/s) and framerate.
* Return Value: new bit rate if OK, otherwise <0s.
*/
// TODO(tommi): We could replace BitRate and FrameRate below with a GetRates
// method that matches SetRates. For fetching current rates, we'd then only
// grab the lock once instead of twice.
int32_t SetRates(uint32_t target_bitrate, uint32_t frameRate);
/**
* Set a new packet loss rate and a new round-trip time in milliseconds.
@ -136,10 +132,11 @@ public:
private:
VideoEncoder* const encoder_;
VideoEncoderRateObserver* const rate_observer_;
uint32_t bit_rate_;
uint32_t frame_rate_;
const bool internal_source_;
mutable rtc::CriticalSection rates_lock_;
VideoCodecType _codecType;
VCMEncodedFrameCallback* _VCMencodedFrameCallback;
uint32_t _bitRate;
uint32_t _frameRate;
bool _internalSource;
}; // end of VCMGenericEncoder class
} // namespace webrtc