Added measure of encode time. Added encode time to the ViE CpuOveruseMeasure api.

R=mflodman@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5178 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
asapersson@webrtc.org 2013-11-26 11:12:33 +00:00
parent bd51d9324e
commit c7ff8f990a
8 changed files with 57 additions and 15 deletions

View File

@ -122,8 +122,9 @@ class WEBRTC_DLLEXPORT ViEBase {
// Gets the last cpu overuse measure.
// TODO(asapersson): Remove default implementation.
virtual int CpuOveruseMeasure(int channel,
int* capture_jitter_ms) { return -1; }
virtual int CpuOveruseMeasures(int channel,
int* capture_jitter_ms,
int* avg_encode_time_ms) { return -1; }
// Specifies the VoiceEngine and VideoEngine channel pair to use for
// audio/video synchronization.

View File

@ -47,6 +47,8 @@ const int kMaxRampUpDelayMs = 120 * 1000;
// Expontential back-off factor, to prevent annoying up-down behaviour.
const double kRampUpBackoffFactor = 2.0;
// The initial average encode time (set to a fairly small value).
const float kInitialAvgEncodeTimeMs = 5.0f;
} // namespace
Statistics::Statistics() :
@ -117,7 +119,7 @@ OveruseFrameDetector::OveruseFrameDetector(Clock* clock,
in_quick_rampup_(false),
current_rampup_delay_ms_(kStandardRampUpDelayMs),
num_pixels_(0),
last_capture_jitter_ms_(-1) {}
avg_encode_time_ms_(kInitialAvgEncodeTimeMs) {}
OveruseFrameDetector::~OveruseFrameDetector() {
}
@ -145,9 +147,21 @@ void OveruseFrameDetector::FrameCaptured(int width, int height) {
last_capture_time_ = time;
}
int OveruseFrameDetector::last_capture_jitter_ms() {
void OveruseFrameDetector::FrameEncoded(int encode_time_ms) {
CriticalSectionScoped cs(crit_.get());
return last_capture_jitter_ms_;
const float kWeight = 0.1f;
avg_encode_time_ms_ = kWeight * encode_time_ms +
(1.0f - kWeight) * avg_encode_time_ms_;
}
int OveruseFrameDetector::last_capture_jitter_ms() const {
CriticalSectionScoped cs(crit_.get());
return static_cast<int>(capture_deltas_.StdDev() + 0.5);
}
int OveruseFrameDetector::avg_encode_time_ms() const {
CriticalSectionScoped cs(crit_.get());
return static_cast<int>(avg_encode_time_ms_ + 0.5);
}
int32_t OveruseFrameDetector::TimeUntilNextProcess() {
@ -214,7 +228,6 @@ int32_t OveruseFrameDetector::Process() {
overuse_stddev_ms_,
normaluse_stddev_ms_);
last_capture_jitter_ms_ = static_cast<int>(capture_deltas_.StdDev());
return 0;
}

View File

@ -71,7 +71,13 @@ class OveruseFrameDetector : public Module {
// Called for each captured frame.
void FrameCaptured(int width, int height);
int last_capture_jitter_ms();
void FrameEncoded(int encode_time_ms);
int last_capture_jitter_ms() const;
// Running average of reported encode time (FrameEncoded()).
// Only used for stats.
int avg_encode_time_ms() const;
// Implements Module.
virtual int32_t TimeUntilNextProcess() OVERRIDE;
@ -107,7 +113,7 @@ class OveruseFrameDetector : public Module {
// Number of pixels of last captured frame.
int num_pixels_;
int last_capture_jitter_ms_;
float avg_encode_time_ms_;
DISALLOW_COPY_AND_ASSIGN(OveruseFrameDetector);
};

View File

@ -96,9 +96,17 @@ TEST_F(OveruseFrameDetectorTest, ConstantOveruseGivesNoNormalUsage) {
}
TEST_F(OveruseFrameDetectorTest, LastCaptureJitter) {
EXPECT_EQ(-1, overuse_detector_->last_capture_jitter_ms());
EXPECT_EQ(0, overuse_detector_->last_capture_jitter_ms());
TriggerOveruse();
EXPECT_GT(overuse_detector_->last_capture_jitter_ms(), 0);
}
TEST_F(OveruseFrameDetectorTest, EncodedFrame) {
const int kInitialAvgEncodeTimeInMs = 5;
EXPECT_EQ(kInitialAvgEncodeTimeInMs, overuse_detector_->avg_encode_time_ms());
for (int i = 0; i < 30; i++)
overuse_detector_->FrameEncoded(2);
EXPECT_EQ(2, overuse_detector_->avg_encode_time_ms());
}
} // namespace webrtc

View File

@ -117,7 +117,9 @@ int ViEBaseImpl::RegisterCpuOveruseObserver(int video_channel,
return 0;
}
int ViEBaseImpl::CpuOveruseMeasure(int video_channel, int* capture_jitter_ms) {
int ViEBaseImpl::CpuOveruseMeasures(int video_channel,
int* capture_jitter_ms,
int* avg_encode_time_ms) {
ViEChannelManagerScoped cs(*(shared_data_.channel_manager()));
ViEChannel* vie_channel = cs.Channel(video_channel);
if (!vie_channel) {
@ -138,7 +140,7 @@ int ViEBaseImpl::CpuOveruseMeasure(int video_channel, int* capture_jitter_ms) {
if (provider) {
ViECapturer* capturer = is.Capture(provider->Id());
if (capturer) {
*capture_jitter_ms = capturer->CpuOveruseMeasure();
capturer->CpuOveruseMeasures(capture_jitter_ms, avg_encode_time_ms);
return 0;
}
}

View File

@ -33,7 +33,9 @@ class ViEBaseImpl
virtual int SetVoiceEngine(VoiceEngine* voice_engine);
virtual int RegisterCpuOveruseObserver(int channel,
CpuOveruseObserver* observer);
virtual int CpuOveruseMeasure(int channel, int* capture_jitter_ms);
virtual int CpuOveruseMeasures(int channel,
int* capture_jitter_ms,
int* avg_encode_time_ms);
virtual int CreateChannel(int& video_channel); // NOLINT
virtual int CreateChannel(int& video_channel, // NOLINT
int original_channel);

View File

@ -266,8 +266,10 @@ void ViECapturer::RegisterCpuOveruseObserver(CpuOveruseObserver* observer) {
overuse_detector_->SetObserver(observer);
}
int ViECapturer::CpuOveruseMeasure() {
return overuse_detector_->last_capture_jitter_ms();
void ViECapturer::CpuOveruseMeasures(int* capture_jitter_ms,
int* avg_encode_time_ms) const {
*capture_jitter_ms = overuse_detector_->last_capture_jitter_ms();
*avg_encode_time_ms = overuse_detector_->avg_encode_time_ms();
}
int32_t ViECapturer::SetCaptureDelay(int32_t delay_ms) {
@ -530,8 +532,10 @@ bool ViECapturer::ViECaptureThreadFunction(void* obj) {
bool ViECapturer::ViECaptureProcess() {
if (capture_event_.Wait(kThreadWaitTimeMs) == kEventSignaled) {
int64_t encode_start_time = -1;
deliver_cs_->Enter();
if (SwapCapturedAndDeliverFrameIfAvailable()) {
encode_start_time = Clock::GetRealTimeClock()->TimeInMilliseconds();
DeliverI420Frame(&deliver_frame_);
}
deliver_cs_->Leave();
@ -542,6 +546,11 @@ bool ViECapturer::ViECaptureProcess() {
reported_brightness_level_ = current_brightness_level_;
}
}
// Update the overuse detector with the duration.
if (encode_start_time != -1) {
overuse_detector_->FrameEncoded(
Clock::GetRealTimeClock()->TimeInMilliseconds() - encode_start_time);
}
}
// We're done!
return true;

View File

@ -104,7 +104,8 @@ class ViECapturer
void RegisterCpuOveruseObserver(CpuOveruseObserver* observer);
int CpuOveruseMeasure();
void CpuOveruseMeasures(int* capture_jitter_ms,
int* avg_encode_time_ms) const;
protected:
ViECapturer(int capture_id,