Add ability to include a larger time span (in addition to encode time) for measuring the processing time of a frame.
Controlled by setting enable_extended_processing_usage. Enabled by default. R=mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/13289004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7460 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
d1ba6d9cbf
commit
9aed002090
@ -49,6 +49,7 @@ struct CpuOveruseOptions {
|
||||
high_encode_usage_threshold_percent(90),
|
||||
low_encode_time_rsd_threshold(-1),
|
||||
high_encode_time_rsd_threshold(-1),
|
||||
enable_extended_processing_usage(true),
|
||||
frame_timeout_interval_ms(1500),
|
||||
min_frame_samples(120),
|
||||
min_process_count(3),
|
||||
@ -68,6 +69,10 @@ struct CpuOveruseOptions {
|
||||
int high_encode_time_rsd_threshold; // Additional threshold for triggering
|
||||
// overuse (used in addition to
|
||||
// threshold above if configured).
|
||||
bool enable_extended_processing_usage; // Include a larger time span (in
|
||||
// addition to encode time) for
|
||||
// measuring the processing time of a
|
||||
// frame.
|
||||
// General settings.
|
||||
int frame_timeout_interval_ms; // The maximum allowed interval between two
|
||||
// frames before resetting estimations.
|
||||
@ -90,6 +95,8 @@ struct CpuOveruseOptions {
|
||||
o.high_encode_usage_threshold_percent &&
|
||||
low_encode_time_rsd_threshold == o.low_encode_time_rsd_threshold &&
|
||||
high_encode_time_rsd_threshold == o.high_encode_time_rsd_threshold &&
|
||||
enable_extended_processing_usage ==
|
||||
o.enable_extended_processing_usage &&
|
||||
frame_timeout_interval_ms == o.frame_timeout_interval_ms &&
|
||||
min_frame_samples == o.min_frame_samples &&
|
||||
min_process_count == o.min_process_count &&
|
||||
|
@ -51,6 +51,7 @@ const float kMaxExp = 7.0f;
|
||||
|
||||
} // namespace
|
||||
|
||||
// TODO(asapersson): Remove this class. Not used.
|
||||
Statistics::Statistics() :
|
||||
sum_(0.0),
|
||||
count_(0),
|
||||
@ -121,7 +122,7 @@ class OveruseFrameDetector::EncodeTimeAvg {
|
||||
}
|
||||
~EncodeTimeAvg() {}
|
||||
|
||||
void AddEncodeSample(float encode_time_ms, int64_t diff_last_sample_ms) {
|
||||
void AddSample(float encode_time_ms, int64_t diff_last_sample_ms) {
|
||||
float exp = diff_last_sample_ms / kSampleDiffMs;
|
||||
exp = std::min(exp, kMaxExp);
|
||||
filtered_encode_time_ms_->Apply(exp, encode_time_ms);
|
||||
@ -137,20 +138,22 @@ class OveruseFrameDetector::EncodeTimeAvg {
|
||||
scoped_ptr<rtc::ExpFilter> filtered_encode_time_ms_;
|
||||
};
|
||||
|
||||
// Class for calculating the encode usage.
|
||||
class OveruseFrameDetector::EncodeUsage {
|
||||
// Class for calculating the processing usage on the send-side (the average
|
||||
// processing time of a frame divided by the average time difference between
|
||||
// captured frames).
|
||||
class OveruseFrameDetector::SendProcessingUsage {
|
||||
public:
|
||||
EncodeUsage()
|
||||
SendProcessingUsage()
|
||||
: kWeightFactorFrameDiff(0.998f),
|
||||
kWeightFactorEncodeTime(0.995f),
|
||||
kWeightFactorProcessing(0.995f),
|
||||
kInitialSampleDiffMs(40.0f),
|
||||
kMaxSampleDiffMs(45.0f),
|
||||
count_(0),
|
||||
filtered_encode_time_ms_(new rtc::ExpFilter(kWeightFactorEncodeTime)),
|
||||
filtered_processing_ms_(new rtc::ExpFilter(kWeightFactorProcessing)),
|
||||
filtered_frame_diff_ms_(new rtc::ExpFilter(kWeightFactorFrameDiff)) {
|
||||
Reset();
|
||||
}
|
||||
~EncodeUsage() {}
|
||||
~SendProcessingUsage() {}
|
||||
|
||||
void SetOptions(const CpuOveruseOptions& options) {
|
||||
options_ = options;
|
||||
@ -160,21 +163,21 @@ class OveruseFrameDetector::EncodeUsage {
|
||||
count_ = 0;
|
||||
filtered_frame_diff_ms_->Reset(kWeightFactorFrameDiff);
|
||||
filtered_frame_diff_ms_->Apply(1.0f, kInitialSampleDiffMs);
|
||||
filtered_encode_time_ms_->Reset(kWeightFactorEncodeTime);
|
||||
filtered_encode_time_ms_->Apply(1.0f, InitialEncodeTimeMs());
|
||||
filtered_processing_ms_->Reset(kWeightFactorProcessing);
|
||||
filtered_processing_ms_->Apply(1.0f, InitialProcessingMs());
|
||||
}
|
||||
|
||||
void AddSample(float sample_ms) {
|
||||
void AddCaptureSample(float sample_ms) {
|
||||
float exp = sample_ms / kSampleDiffMs;
|
||||
exp = std::min(exp, kMaxExp);
|
||||
filtered_frame_diff_ms_->Apply(exp, sample_ms);
|
||||
}
|
||||
|
||||
void AddEncodeSample(float encode_time_ms, int64_t diff_last_sample_ms) {
|
||||
void AddSample(float processing_ms, int64_t diff_last_sample_ms) {
|
||||
++count_;
|
||||
float exp = diff_last_sample_ms / kSampleDiffMs;
|
||||
exp = std::min(exp, kMaxExp);
|
||||
filtered_encode_time_ms_->Apply(exp, encode_time_ms);
|
||||
filtered_processing_ms_->Apply(exp, processing_ms);
|
||||
}
|
||||
|
||||
int Value() const {
|
||||
@ -184,7 +187,7 @@ class OveruseFrameDetector::EncodeUsage {
|
||||
float frame_diff_ms = std::max(filtered_frame_diff_ms_->filtered(), 1.0f);
|
||||
frame_diff_ms = std::min(frame_diff_ms, kMaxSampleDiffMs);
|
||||
float encode_usage_percent =
|
||||
100.0f * filtered_encode_time_ms_->filtered() / frame_diff_ms;
|
||||
100.0f * filtered_processing_ms_->filtered() / frame_diff_ms;
|
||||
return static_cast<int>(encode_usage_percent + 0.5);
|
||||
}
|
||||
|
||||
@ -195,24 +198,26 @@ class OveruseFrameDetector::EncodeUsage {
|
||||
options_.high_encode_usage_threshold_percent) / 2.0f;
|
||||
}
|
||||
|
||||
float InitialEncodeTimeMs() const {
|
||||
float InitialProcessingMs() const {
|
||||
return InitialUsageInPercent() * kInitialSampleDiffMs / 100;
|
||||
}
|
||||
|
||||
const float kWeightFactorFrameDiff;
|
||||
const float kWeightFactorEncodeTime;
|
||||
const float kWeightFactorProcessing;
|
||||
const float kInitialSampleDiffMs;
|
||||
const float kMaxSampleDiffMs;
|
||||
uint64_t count_;
|
||||
CpuOveruseOptions options_;
|
||||
scoped_ptr<rtc::ExpFilter> filtered_encode_time_ms_;
|
||||
scoped_ptr<rtc::ExpFilter> filtered_processing_ms_;
|
||||
scoped_ptr<rtc::ExpFilter> filtered_frame_diff_ms_;
|
||||
};
|
||||
|
||||
// Class for calculating the relative standard deviation of encode times.
|
||||
class OveruseFrameDetector::EncodeTimeRsd {
|
||||
// Class for calculating the relative standard deviation of the processing time
|
||||
// of frame on the send-side.
|
||||
// Currently only used for testing.
|
||||
class OveruseFrameDetector::SendProcessingRsd {
|
||||
public:
|
||||
EncodeTimeRsd(Clock* clock)
|
||||
SendProcessingRsd(Clock* clock)
|
||||
: kWeightFactor(0.6f),
|
||||
count_(0),
|
||||
filtered_rsd_(new rtc::ExpFilter(kWeightFactor)),
|
||||
@ -221,7 +226,7 @@ class OveruseFrameDetector::EncodeTimeRsd {
|
||||
last_process_time_ms_(clock->TimeInMilliseconds()) {
|
||||
Reset();
|
||||
}
|
||||
~EncodeTimeRsd() {}
|
||||
~SendProcessingRsd() {}
|
||||
|
||||
void SetOptions(const CpuOveruseOptions& options) {
|
||||
options_ = options;
|
||||
@ -236,10 +241,9 @@ class OveruseFrameDetector::EncodeTimeRsd {
|
||||
hist_sum_ = 0.0f;
|
||||
}
|
||||
|
||||
void AddEncodeSample(float encode_time_ms) {
|
||||
int bin = static_cast<int>(encode_time_ms + 0.5f);
|
||||
void AddSample(float processing_ms) {
|
||||
int bin = static_cast<int>(processing_ms + 0.5f);
|
||||
if (bin <= 0) {
|
||||
// The frame was probably not encoded, skip possible dropped frame.
|
||||
return;
|
||||
}
|
||||
++count_;
|
||||
@ -265,7 +269,7 @@ class OveruseFrameDetector::EncodeTimeRsd {
|
||||
last_process_time_ms_ = now;
|
||||
|
||||
// Calculate variance (using samples above the mean).
|
||||
// Checks for a larger encode time of some frames while there is a small
|
||||
// Checks for a larger processing time of some frames while there is a small
|
||||
// increase in the average time.
|
||||
int mean = hist_sum_ / hist_samples_;
|
||||
float variance = 0.0f;
|
||||
@ -305,15 +309,63 @@ class OveruseFrameDetector::EncodeTimeRsd {
|
||||
}
|
||||
|
||||
const float kWeightFactor;
|
||||
uint32_t count_; // Number of encode samples since last reset.
|
||||
uint32_t count_; // Number of samples since last reset.
|
||||
CpuOveruseOptions options_;
|
||||
scoped_ptr<rtc::ExpFilter> filtered_rsd_;
|
||||
int hist_samples_;
|
||||
float hist_sum_;
|
||||
std::map<int,int> hist_; // Histogram of encode time of frames.
|
||||
std::map<int, int> hist_; // Histogram of time spent on processing frames.
|
||||
int64_t last_process_time_ms_;
|
||||
};
|
||||
|
||||
// Class for calculating the processing time of frames.
|
||||
class OveruseFrameDetector::FrameQueue {
|
||||
public:
|
||||
FrameQueue() : last_processing_time_ms_(-1) {}
|
||||
~FrameQueue() {}
|
||||
|
||||
// Called when a frame is captured.
|
||||
// Starts the measuring of the processing time of the frame.
|
||||
void Start(int64_t capture_time, int64_t now) {
|
||||
const size_t kMaxSize = 90; // Allows for processing time of 1.5s at 60fps.
|
||||
if (frame_times_.size() > kMaxSize) {
|
||||
LOG(LS_WARNING) << "Max size reached, removed oldest frame.";
|
||||
frame_times_.erase(frame_times_.begin());
|
||||
}
|
||||
if (frame_times_.find(capture_time) != frame_times_.end()) {
|
||||
// Frame should not exist.
|
||||
assert(false);
|
||||
return;
|
||||
}
|
||||
frame_times_[capture_time] = now;
|
||||
}
|
||||
|
||||
// Called when the processing of a frame has finished.
|
||||
// Returns the processing time of the frame.
|
||||
int End(int64_t capture_time, int64_t now) {
|
||||
std::map<int64_t, int64_t>::iterator it = frame_times_.find(capture_time);
|
||||
if (it == frame_times_.end()) {
|
||||
return -1;
|
||||
}
|
||||
// Remove any old frames up to current.
|
||||
// Old frames have been skipped by the capture process thread.
|
||||
// TODO(asapersson): Consider measuring time from first frame in list.
|
||||
last_processing_time_ms_ = now - (*it).second;
|
||||
frame_times_.erase(frame_times_.begin(), ++it);
|
||||
return last_processing_time_ms_;
|
||||
}
|
||||
|
||||
void Reset() { frame_times_.clear(); }
|
||||
int NumFrames() const { return frame_times_.size(); }
|
||||
int last_processing_time_ms() const { return last_processing_time_ms_; }
|
||||
|
||||
private:
|
||||
// Captured frames mapped by the capture time.
|
||||
std::map<int64_t, int64_t> frame_times_;
|
||||
int last_processing_time_ms_;
|
||||
};
|
||||
|
||||
// TODO(asapersson): Remove this class. Not used.
|
||||
// Class for calculating the capture queue delay change.
|
||||
class OveruseFrameDetector::CaptureQueueDelay {
|
||||
public:
|
||||
@ -387,8 +439,10 @@ OveruseFrameDetector::OveruseFrameDetector(Clock* clock)
|
||||
num_pixels_(0),
|
||||
last_encode_sample_ms_(0),
|
||||
encode_time_(new EncodeTimeAvg()),
|
||||
encode_rsd_(new EncodeTimeRsd(clock)),
|
||||
encode_usage_(new EncodeUsage()),
|
||||
rsd_(new SendProcessingRsd(clock)),
|
||||
usage_(new SendProcessingUsage()),
|
||||
frame_queue_(new FrameQueue()),
|
||||
last_sample_time_ms_(0),
|
||||
capture_queue_delay_(new CaptureQueueDelay()) {
|
||||
}
|
||||
|
||||
@ -408,8 +462,8 @@ void OveruseFrameDetector::SetOptions(const CpuOveruseOptions& options) {
|
||||
}
|
||||
options_ = options;
|
||||
capture_deltas_.SetOptions(options);
|
||||
encode_usage_->SetOptions(options);
|
||||
encode_rsd_->SetOptions(options);
|
||||
usage_->SetOptions(options);
|
||||
rsd_->SetOptions(options);
|
||||
ResetAll(num_pixels_);
|
||||
}
|
||||
|
||||
@ -418,13 +472,23 @@ int OveruseFrameDetector::CaptureQueueDelayMsPerS() const {
|
||||
return capture_queue_delay_->delay_ms();
|
||||
}
|
||||
|
||||
int OveruseFrameDetector::LastProcessingTimeMs() const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
return frame_queue_->last_processing_time_ms();
|
||||
}
|
||||
|
||||
int OveruseFrameDetector::FramesInQueue() const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
return frame_queue_->NumFrames();
|
||||
}
|
||||
|
||||
void OveruseFrameDetector::GetCpuOveruseMetrics(
|
||||
CpuOveruseMetrics* metrics) const {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
metrics->capture_jitter_ms = static_cast<int>(capture_deltas_.StdDev() + 0.5);
|
||||
metrics->avg_encode_time_ms = encode_time_->Value();
|
||||
metrics->encode_rsd = encode_rsd_->Value();
|
||||
metrics->encode_usage_percent = encode_usage_->Value();
|
||||
metrics->encode_rsd = rsd_->Value();
|
||||
metrics->encode_usage_percent = usage_->Value();
|
||||
metrics->capture_queue_delay_ms_per_s = capture_queue_delay_->Value();
|
||||
}
|
||||
|
||||
@ -450,14 +514,17 @@ bool OveruseFrameDetector::FrameTimeoutDetected(int64_t now) const {
|
||||
void OveruseFrameDetector::ResetAll(int num_pixels) {
|
||||
num_pixels_ = num_pixels;
|
||||
capture_deltas_.Reset();
|
||||
encode_usage_->Reset();
|
||||
encode_rsd_->Reset();
|
||||
usage_->Reset();
|
||||
rsd_->Reset();
|
||||
frame_queue_->Reset();
|
||||
capture_queue_delay_->ClearFrames();
|
||||
last_capture_time_ = 0;
|
||||
num_process_times_ = 0;
|
||||
}
|
||||
|
||||
void OveruseFrameDetector::FrameCaptured(int width, int height) {
|
||||
void OveruseFrameDetector::FrameCaptured(int width,
|
||||
int height,
|
||||
int64_t capture_time_ms) {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
|
||||
int64_t now = clock_->TimeInMilliseconds();
|
||||
@ -467,11 +534,15 @@ void OveruseFrameDetector::FrameCaptured(int width, int height) {
|
||||
|
||||
if (last_capture_time_ != 0) {
|
||||
capture_deltas_.AddSample(now - last_capture_time_);
|
||||
encode_usage_->AddSample(now - last_capture_time_);
|
||||
usage_->AddCaptureSample(now - last_capture_time_);
|
||||
}
|
||||
last_capture_time_ = now;
|
||||
|
||||
capture_queue_delay_->FrameCaptured(now);
|
||||
|
||||
if (options_.enable_extended_processing_usage) {
|
||||
frame_queue_->Start(capture_time_ms, now);
|
||||
}
|
||||
}
|
||||
|
||||
void OveruseFrameDetector::FrameProcessingStarted() {
|
||||
@ -481,14 +552,38 @@ void OveruseFrameDetector::FrameProcessingStarted() {
|
||||
|
||||
void OveruseFrameDetector::FrameEncoded(int encode_time_ms) {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
int64_t time = clock_->TimeInMilliseconds();
|
||||
int64_t now = clock_->TimeInMilliseconds();
|
||||
if (last_encode_sample_ms_ != 0) {
|
||||
int64_t diff_ms = time - last_encode_sample_ms_;
|
||||
encode_time_->AddEncodeSample(encode_time_ms, diff_ms);
|
||||
encode_usage_->AddEncodeSample(encode_time_ms, diff_ms);
|
||||
encode_rsd_->AddEncodeSample(encode_time_ms);
|
||||
int64_t diff_ms = now - last_encode_sample_ms_;
|
||||
encode_time_->AddSample(encode_time_ms, diff_ms);
|
||||
}
|
||||
last_encode_sample_ms_ = time;
|
||||
last_encode_sample_ms_ = now;
|
||||
|
||||
if (!options_.enable_extended_processing_usage) {
|
||||
AddProcessingTime(encode_time_ms);
|
||||
}
|
||||
}
|
||||
|
||||
void OveruseFrameDetector::FrameSent(int64_t capture_time_ms) {
|
||||
CriticalSectionScoped cs(crit_.get());
|
||||
if (!options_.enable_extended_processing_usage) {
|
||||
return;
|
||||
}
|
||||
int delay_ms = frame_queue_->End(capture_time_ms,
|
||||
clock_->TimeInMilliseconds());
|
||||
if (delay_ms > 0) {
|
||||
AddProcessingTime(delay_ms);
|
||||
}
|
||||
}
|
||||
|
||||
void OveruseFrameDetector::AddProcessingTime(int elapsed_ms) {
|
||||
int64_t now = clock_->TimeInMilliseconds();
|
||||
if (last_sample_time_ms_ != 0) {
|
||||
int64_t diff_ms = now - last_sample_time_ms_;
|
||||
usage_->AddSample(elapsed_ms, diff_ms);
|
||||
rsd_->AddSample(elapsed_ms);
|
||||
}
|
||||
last_sample_time_ms_ = now;
|
||||
}
|
||||
|
||||
int32_t OveruseFrameDetector::Process() {
|
||||
@ -504,7 +599,7 @@ int32_t OveruseFrameDetector::Process() {
|
||||
next_process_time_ = now + kProcessIntervalMs;
|
||||
++num_process_times_;
|
||||
|
||||
encode_rsd_->Process(now);
|
||||
rsd_->Process(now);
|
||||
capture_queue_delay_->CalculateDelayChange(diff_ms);
|
||||
|
||||
if (num_process_times_ <= options_.min_process_count) {
|
||||
@ -548,8 +643,8 @@ int32_t OveruseFrameDetector::Process() {
|
||||
in_quick_rampup_ ? kQuickRampUpDelayMs : current_rampup_delay_ms_;
|
||||
LOG(LS_VERBOSE) << " Frame stats: capture avg: " << capture_deltas_.Mean()
|
||||
<< " capture stddev " << capture_deltas_.StdDev()
|
||||
<< " encode usage " << encode_usage_->Value()
|
||||
<< " encode rsd " << encode_rsd_->Value()
|
||||
<< " encode usage " << usage_->Value()
|
||||
<< " encode rsd " << rsd_->Value()
|
||||
<< " overuse detections " << num_overuse_detections_
|
||||
<< " rampup delay " << rampup_delay;
|
||||
return 0;
|
||||
@ -561,14 +656,13 @@ bool OveruseFrameDetector::IsOverusing() {
|
||||
overusing = capture_deltas_.StdDev() >=
|
||||
options_.high_capture_jitter_threshold_ms;
|
||||
} else if (options_.enable_encode_usage_method) {
|
||||
bool encode_usage_overuse =
|
||||
encode_usage_->Value() >= options_.high_encode_usage_threshold_percent;
|
||||
bool encode_rsd_overuse = false;
|
||||
bool usage_overuse =
|
||||
usage_->Value() >= options_.high_encode_usage_threshold_percent;
|
||||
bool rsd_overuse = false;
|
||||
if (options_.high_encode_time_rsd_threshold > 0) {
|
||||
encode_rsd_overuse =
|
||||
(encode_rsd_->Value() >= options_.high_encode_time_rsd_threshold);
|
||||
rsd_overuse = (rsd_->Value() >= options_.high_encode_time_rsd_threshold);
|
||||
}
|
||||
overusing = encode_usage_overuse || encode_rsd_overuse;
|
||||
overusing = usage_overuse || rsd_overuse;
|
||||
}
|
||||
|
||||
if (overusing) {
|
||||
@ -589,14 +683,13 @@ bool OveruseFrameDetector::IsUnderusing(int64_t time_now) {
|
||||
underusing = capture_deltas_.StdDev() <
|
||||
options_.low_capture_jitter_threshold_ms;
|
||||
} else if (options_.enable_encode_usage_method) {
|
||||
bool encode_usage_underuse =
|
||||
encode_usage_->Value() < options_.low_encode_usage_threshold_percent;
|
||||
bool encode_rsd_underuse = true;
|
||||
bool usage_underuse =
|
||||
usage_->Value() < options_.low_encode_usage_threshold_percent;
|
||||
bool rsd_underuse = true;
|
||||
if (options_.low_encode_time_rsd_threshold > 0) {
|
||||
encode_rsd_underuse =
|
||||
(encode_rsd_->Value() < options_.low_encode_time_rsd_threshold);
|
||||
rsd_underuse = (rsd_->Value() < options_.low_encode_time_rsd_threshold);
|
||||
}
|
||||
underusing = encode_usage_underuse && encode_rsd_underuse;
|
||||
underusing = usage_underuse && rsd_underuse;
|
||||
}
|
||||
return underusing;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class OveruseFrameDetector : public Module {
|
||||
void SetOptions(const CpuOveruseOptions& options);
|
||||
|
||||
// Called for each captured frame.
|
||||
void FrameCaptured(int width, int height);
|
||||
void FrameCaptured(int width, int height, int64_t capture_time_ms);
|
||||
|
||||
// Called when the processing of a captured frame is started.
|
||||
void FrameProcessingStarted();
|
||||
@ -69,14 +69,19 @@ class OveruseFrameDetector : public Module {
|
||||
// Called for each encoded frame.
|
||||
void FrameEncoded(int encode_time_ms);
|
||||
|
||||
// Called for each sent frame.
|
||||
void FrameSent(int64_t capture_time_ms);
|
||||
|
||||
// Accessors.
|
||||
|
||||
// Returns CpuOveruseMetrics where
|
||||
// capture_jitter_ms: The estimated jitter based on incoming captured frames.
|
||||
// avg_encode_time_ms: Running average of reported encode time
|
||||
// (FrameEncoded()). Only used for stats.
|
||||
// encode_usage_percent: The average encode time divided by the average time
|
||||
// difference between incoming captured frames.
|
||||
// TODO(asapersson): Rename metric.
|
||||
// encode_usage_percent: The average processing time of a frame on the
|
||||
// send-side divided by the average time difference
|
||||
// between incoming captured frames.
|
||||
// capture_queue_delay_ms_per_s: The current time delay between an incoming
|
||||
// captured frame (FrameCaptured()) until the
|
||||
// frame is being processed
|
||||
@ -87,7 +92,10 @@ class OveruseFrameDetector : public Module {
|
||||
// Only used for stats.
|
||||
void GetCpuOveruseMetrics(CpuOveruseMetrics* metrics) const;
|
||||
|
||||
// Only public for testing.
|
||||
int CaptureQueueDelayMsPerS() const;
|
||||
int LastProcessingTimeMs() const;
|
||||
int FramesInQueue() const;
|
||||
|
||||
// Implements Module.
|
||||
virtual int32_t TimeUntilNextProcess() OVERRIDE;
|
||||
@ -95,9 +103,12 @@ class OveruseFrameDetector : public Module {
|
||||
|
||||
private:
|
||||
class EncodeTimeAvg;
|
||||
class EncodeTimeRsd;
|
||||
class EncodeUsage;
|
||||
class SendProcessingRsd;
|
||||
class SendProcessingUsage;
|
||||
class CaptureQueueDelay;
|
||||
class FrameQueue;
|
||||
|
||||
void AddProcessingTime(int elapsed_ms);
|
||||
|
||||
bool IsOverusing();
|
||||
bool IsUnderusing(int64_t time_now);
|
||||
@ -135,8 +146,11 @@ class OveruseFrameDetector : public Module {
|
||||
|
||||
int64_t last_encode_sample_ms_;
|
||||
scoped_ptr<EncodeTimeAvg> encode_time_;
|
||||
scoped_ptr<EncodeTimeRsd> encode_rsd_;
|
||||
scoped_ptr<EncodeUsage> encode_usage_;
|
||||
|
||||
scoped_ptr<SendProcessingRsd> rsd_;
|
||||
scoped_ptr<SendProcessingUsage> usage_;
|
||||
scoped_ptr<FrameQueue> frame_queue_;
|
||||
int64_t last_sample_time_ms_;
|
||||
|
||||
scoped_ptr<CaptureQueueDelay> capture_queue_delay_;
|
||||
|
||||
|
@ -66,12 +66,12 @@ class OveruseFrameDetectorTest : public ::testing::Test {
|
||||
options_.high_capture_jitter_threshold_ms) / 2.0f) + 0.5;
|
||||
}
|
||||
|
||||
int InitialEncodeUsage() {
|
||||
int InitialUsage() {
|
||||
return ((options_.low_encode_usage_threshold_percent +
|
||||
options_.high_encode_usage_threshold_percent) / 2.0f) + 0.5;
|
||||
}
|
||||
|
||||
int InitialEncodeRsd() {
|
||||
int InitialRsd() {
|
||||
return std::max(
|
||||
((options_.low_encode_time_rsd_threshold +
|
||||
options_.high_encode_time_rsd_threshold) / 2.0f) + 0.5f, 0.0f);
|
||||
@ -81,17 +81,20 @@ class OveruseFrameDetectorTest : public ::testing::Test {
|
||||
size_t num_frames, int interval_ms, int width, int height) {
|
||||
while (num_frames-- > 0) {
|
||||
clock_->AdvanceTimeMilliseconds(interval_ms);
|
||||
overuse_detector_->FrameCaptured(width, height);
|
||||
overuse_detector_->FrameCaptured(width, height,
|
||||
clock_->TimeInMilliseconds());
|
||||
}
|
||||
}
|
||||
|
||||
void InsertAndEncodeFramesWithInterval(
|
||||
int num_frames, int interval_ms, int width, int height, int encode_ms) {
|
||||
void InsertAndSendFramesWithInterval(
|
||||
int num_frames, int interval_ms, int width, int height, int delay_ms) {
|
||||
while (num_frames-- > 0) {
|
||||
overuse_detector_->FrameCaptured(width, height);
|
||||
clock_->AdvanceTimeMilliseconds(encode_ms);
|
||||
overuse_detector_->FrameEncoded(encode_ms);
|
||||
clock_->AdvanceTimeMilliseconds(interval_ms - encode_ms);
|
||||
int64_t capture_time_ms = clock_->TimeInMilliseconds();
|
||||
overuse_detector_->FrameCaptured(width, height, capture_time_ms);
|
||||
clock_->AdvanceTimeMilliseconds(delay_ms);
|
||||
overuse_detector_->FrameEncoded(delay_ms);
|
||||
overuse_detector_->FrameSent(capture_time_ms);
|
||||
clock_->AdvanceTimeMilliseconds(interval_ms - delay_ms);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,39 +106,39 @@ class OveruseFrameDetectorTest : public ::testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerNormalUsage() {
|
||||
void TriggerUnderuse() {
|
||||
InsertFramesWithInterval(900, kFrameInterval33ms, kWidth, kHeight);
|
||||
overuse_detector_->Process();
|
||||
}
|
||||
|
||||
void TriggerOveruseWithEncodeUsage(int num_times) {
|
||||
const int kEncodeTimeMs = 32;
|
||||
void TriggerOveruseWithProcessingUsage(int num_times) {
|
||||
const int kDelayMs = 32;
|
||||
for (int i = 0; i < num_times; ++i) {
|
||||
InsertAndEncodeFramesWithInterval(
|
||||
1000, kFrameInterval33ms, kWidth, kHeight, kEncodeTimeMs);
|
||||
InsertAndSendFramesWithInterval(
|
||||
1000, kFrameInterval33ms, kWidth, kHeight, kDelayMs);
|
||||
overuse_detector_->Process();
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerOveruseWithEncodeRsd(int num_times) {
|
||||
const int kEncodeTimeMs1 = 10;
|
||||
const int kEncodeTimeMs2 = 25;
|
||||
void TriggerOveruseWithRsd(int num_times) {
|
||||
const int kDelayMs1 = 10;
|
||||
const int kDelayMs2 = 25;
|
||||
for (int i = 0; i < num_times; ++i) {
|
||||
InsertAndEncodeFramesWithInterval(
|
||||
200, kFrameInterval33ms, kWidth, kHeight, kEncodeTimeMs1);
|
||||
InsertAndEncodeFramesWithInterval(
|
||||
10, kFrameInterval33ms, kWidth, kHeight, kEncodeTimeMs2);
|
||||
InsertAndSendFramesWithInterval(
|
||||
200, kFrameInterval33ms, kWidth, kHeight, kDelayMs1);
|
||||
InsertAndSendFramesWithInterval(
|
||||
10, kFrameInterval33ms, kWidth, kHeight, kDelayMs2);
|
||||
overuse_detector_->Process();
|
||||
}
|
||||
}
|
||||
|
||||
void TriggerNormalUsageWithEncodeTime() {
|
||||
const int kEncodeTimeMs1 = 5;
|
||||
const int kEncodeTimeMs2 = 6;
|
||||
InsertAndEncodeFramesWithInterval(
|
||||
1300, kFrameInterval33ms, kWidth, kHeight, kEncodeTimeMs1);
|
||||
InsertAndEncodeFramesWithInterval(
|
||||
1, kFrameInterval33ms, kWidth, kHeight, kEncodeTimeMs2);
|
||||
void TriggerUnderuseWithProcessingUsage() {
|
||||
const int kDelayMs1 = 5;
|
||||
const int kDelayMs2 = 6;
|
||||
InsertAndSendFramesWithInterval(
|
||||
1300, kFrameInterval33ms, kWidth, kHeight, kDelayMs1);
|
||||
InsertAndSendFramesWithInterval(
|
||||
1, kFrameInterval33ms, kWidth, kHeight, kDelayMs2);
|
||||
overuse_detector_->Process();
|
||||
}
|
||||
|
||||
@ -151,13 +154,13 @@ class OveruseFrameDetectorTest : public ::testing::Test {
|
||||
return metrics.avg_encode_time_ms;
|
||||
}
|
||||
|
||||
int EncodeUsagePercent() {
|
||||
int UsagePercent() {
|
||||
CpuOveruseMetrics metrics;
|
||||
overuse_detector_->GetCpuOveruseMetrics(&metrics);
|
||||
return metrics.encode_usage_percent;
|
||||
}
|
||||
|
||||
int EncodeRsd() {
|
||||
int Rsd() {
|
||||
CpuOveruseMetrics metrics;
|
||||
overuse_detector_->GetCpuOveruseMetrics(&metrics);
|
||||
return metrics.encode_rsd;
|
||||
@ -184,7 +187,7 @@ TEST_F(OveruseFrameDetectorTest, OveruseAndRecover) {
|
||||
TriggerOveruse(options_.high_threshold_consecutive_count);
|
||||
// capture_jitter < low => underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
|
||||
TriggerNormalUsage();
|
||||
TriggerUnderuse();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) {
|
||||
@ -192,7 +195,7 @@ TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithNoObserver) {
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
|
||||
TriggerOveruse(options_.high_threshold_consecutive_count);
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
|
||||
TriggerNormalUsage();
|
||||
TriggerUnderuse();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithMethodDisabled) {
|
||||
@ -202,7 +205,7 @@ TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithMethodDisabled) {
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
|
||||
TriggerOveruse(options_.high_threshold_consecutive_count);
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
|
||||
TriggerNormalUsage();
|
||||
TriggerUnderuse();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) {
|
||||
@ -210,10 +213,10 @@ TEST_F(OveruseFrameDetectorTest, DoubleOveruseAndRecover) {
|
||||
TriggerOveruse(options_.high_threshold_consecutive_count);
|
||||
TriggerOveruse(options_.high_threshold_consecutive_count);
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
|
||||
TriggerNormalUsage();
|
||||
TriggerUnderuse();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerNormalUsageWithMinProcessCount) {
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerUnderuseWithMinProcessCount) {
|
||||
CpuOveruseObserverImpl overuse_observer_;
|
||||
overuse_detector_->SetObserver(&overuse_observer_);
|
||||
options_.min_process_count = 1;
|
||||
@ -305,22 +308,26 @@ TEST_F(OveruseFrameDetectorTest, MinFrameSamplesBeforeUpdatingCaptureJitter) {
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, NoCaptureQueueDelay) {
|
||||
EXPECT_EQ(overuse_detector_->CaptureQueueDelayMsPerS(), 0);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight, clock_->TimeInMilliseconds());
|
||||
overuse_detector_->FrameProcessingStarted();
|
||||
EXPECT_EQ(overuse_detector_->CaptureQueueDelayMsPerS(), 0);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, CaptureQueueDelay) {
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight, clock_->TimeInMilliseconds());
|
||||
clock_->AdvanceTimeMilliseconds(100);
|
||||
overuse_detector_->FrameProcessingStarted();
|
||||
EXPECT_EQ(overuse_detector_->CaptureQueueDelayMsPerS(), 100);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, CaptureQueueDelayMultipleFrames) {
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight, clock_->TimeInMilliseconds());
|
||||
clock_->AdvanceTimeMilliseconds(10);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight, clock_->TimeInMilliseconds());
|
||||
clock_->AdvanceTimeMilliseconds(20);
|
||||
|
||||
overuse_detector_->FrameProcessingStarted();
|
||||
@ -330,9 +337,11 @@ TEST_F(OveruseFrameDetectorTest, CaptureQueueDelayMultipleFrames) {
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, CaptureQueueDelayResetAtResolutionSwitch) {
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight, clock_->TimeInMilliseconds());
|
||||
clock_->AdvanceTimeMilliseconds(10);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight + 1);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight + 1, clock_->TimeInMilliseconds());
|
||||
clock_->AdvanceTimeMilliseconds(20);
|
||||
|
||||
overuse_detector_->FrameProcessingStarted();
|
||||
@ -340,7 +349,8 @@ TEST_F(OveruseFrameDetectorTest, CaptureQueueDelayResetAtResolutionSwitch) {
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, CaptureQueueDelayNoMatchingCapturedFrame) {
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight);
|
||||
overuse_detector_->FrameCaptured(
|
||||
kWidth, kHeight, clock_->TimeInMilliseconds());
|
||||
clock_->AdvanceTimeMilliseconds(100);
|
||||
overuse_detector_->FrameProcessingStarted();
|
||||
EXPECT_EQ(overuse_detector_->CaptureQueueDelayMsPerS(), 100);
|
||||
@ -349,6 +359,106 @@ TEST_F(OveruseFrameDetectorTest, CaptureQueueDelayNoMatchingCapturedFrame) {
|
||||
EXPECT_EQ(overuse_detector_->CaptureQueueDelayMsPerS(), 100);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_OneFrameDisabled) {
|
||||
options_.enable_extended_processing_usage = false;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kProcessingTimeMs = 100;
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
overuse_detector_->FrameSent(33);
|
||||
EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_OneFrame) {
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kProcessingTimeMs = 100;
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs());
|
||||
overuse_detector_->FrameSent(33);
|
||||
EXPECT_EQ(kProcessingTimeMs, overuse_detector_->LastProcessingTimeMs());
|
||||
EXPECT_EQ(0, overuse_detector_->FramesInQueue());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_TwoFrames) {
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kProcessingTimeMs1 = 100;
|
||||
const int kProcessingTimeMs2 = 50;
|
||||
const int kTimeBetweenFramesMs = 200;
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs1);
|
||||
overuse_detector_->FrameSent(33);
|
||||
EXPECT_EQ(kProcessingTimeMs1, overuse_detector_->LastProcessingTimeMs());
|
||||
clock_->AdvanceTimeMilliseconds(kTimeBetweenFramesMs);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 66);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs2);
|
||||
overuse_detector_->FrameSent(66);
|
||||
EXPECT_EQ(kProcessingTimeMs2, overuse_detector_->LastProcessingTimeMs());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_MaxQueueSize) {
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kMaxQueueSize = 91;
|
||||
for (int i = 0; i < kMaxQueueSize * 2; ++i) {
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, i);
|
||||
}
|
||||
EXPECT_EQ(kMaxQueueSize, overuse_detector_->FramesInQueue());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_NonProcessedFramesRemoved) {
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kProcessingTimeMs = 100;
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 35);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 66);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 99);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs());
|
||||
EXPECT_EQ(4, overuse_detector_->FramesInQueue());
|
||||
overuse_detector_->FrameSent(66);
|
||||
// Frame 33, 35 removed, 66 processed, 99 not processed.
|
||||
EXPECT_EQ(2 * kProcessingTimeMs, overuse_detector_->LastProcessingTimeMs());
|
||||
EXPECT_EQ(1, overuse_detector_->FramesInQueue());
|
||||
overuse_detector_->FrameSent(99);
|
||||
EXPECT_EQ(kProcessingTimeMs, overuse_detector_->LastProcessingTimeMs());
|
||||
EXPECT_EQ(0, overuse_detector_->FramesInQueue());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_ResetClearsFrames) {
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kProcessingTimeMs = 100;
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
|
||||
EXPECT_EQ(1, overuse_detector_->FramesInQueue());
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
// Verify reset (resolution changed).
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight + 1, 66);
|
||||
EXPECT_EQ(1, overuse_detector_->FramesInQueue());
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
overuse_detector_->FrameSent(66);
|
||||
EXPECT_EQ(kProcessingTimeMs, overuse_detector_->LastProcessingTimeMs());
|
||||
EXPECT_EQ(0, overuse_detector_->FramesInQueue());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, FrameDelay_NonMatchingSendFrameIgnored) {
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
const int kProcessingTimeMs = 100;
|
||||
overuse_detector_->FrameCaptured(kWidth, kHeight, 33);
|
||||
clock_->AdvanceTimeMilliseconds(kProcessingTimeMs);
|
||||
overuse_detector_->FrameSent(34);
|
||||
EXPECT_EQ(-1, overuse_detector_->LastProcessingTimeMs());
|
||||
overuse_detector_->FrameSent(33);
|
||||
EXPECT_EQ(kProcessingTimeMs, overuse_detector_->LastProcessingTimeMs());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, EncodedFrame) {
|
||||
const int kInitialAvgEncodeTimeInMs = 5;
|
||||
EXPECT_EQ(kInitialAvgEncodeTimeInMs, AvgEncodeTimeMs());
|
||||
@ -359,92 +469,136 @@ TEST_F(OveruseFrameDetectorTest, EncodedFrame) {
|
||||
EXPECT_EQ(2, AvgEncodeTimeMs());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, InitialEncodeUsage) {
|
||||
EXPECT_EQ(InitialEncodeUsage(), EncodeUsagePercent());
|
||||
TEST_F(OveruseFrameDetectorTest, InitialProcessingUsage) {
|
||||
EXPECT_EQ(InitialUsage(), UsagePercent());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, EncodedUsage) {
|
||||
const int kEncodeTimeMs = 5;
|
||||
InsertAndEncodeFramesWithInterval(
|
||||
1000, kFrameInterval33ms, kWidth, kHeight, kEncodeTimeMs);
|
||||
EXPECT_EQ(kEncodeTimeMs * 100 / kFrameInterval33ms, EncodeUsagePercent());
|
||||
TEST_F(OveruseFrameDetectorTest, ProcessingUsage) {
|
||||
const int kProcessingTimeMs = 5;
|
||||
InsertAndSendFramesWithInterval(
|
||||
1000, kFrameInterval33ms, kWidth, kHeight, kProcessingTimeMs);
|
||||
EXPECT_EQ(kProcessingTimeMs * 100 / kFrameInterval33ms, UsagePercent());
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, EncodeUsageResetAfterChangingThreshold) {
|
||||
EXPECT_EQ(InitialEncodeUsage(), EncodeUsagePercent());
|
||||
TEST_F(OveruseFrameDetectorTest, ProcessingUsageResetAfterChangingThreshold) {
|
||||
EXPECT_EQ(InitialUsage(), UsagePercent());
|
||||
options_.high_encode_usage_threshold_percent = 100;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
EXPECT_EQ(InitialEncodeUsage(), EncodeUsagePercent());
|
||||
EXPECT_EQ(InitialUsage(), UsagePercent());
|
||||
options_.low_encode_usage_threshold_percent = 20;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
EXPECT_EQ(InitialEncodeUsage(), EncodeUsagePercent());
|
||||
EXPECT_EQ(InitialUsage(), UsagePercent());
|
||||
}
|
||||
|
||||
// enable_encode_usage_method = true;
|
||||
// EncodeUsagePercent() > high_encode_usage_threshold_percent => overuse.
|
||||
// EncodeUsagePercent() < low_encode_usage_threshold_percent => underuse.
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithEncodeUsage) {
|
||||
// UsagePercent() > high_encode_usage_threshold_percent => overuse.
|
||||
// UsagePercent() < low_encode_usage_threshold_percent => underuse.
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithProcessingUsage) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.enable_extended_processing_usage = false;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// usage > high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
|
||||
TriggerOveruseWithEncodeUsage(options_.high_threshold_consecutive_count);
|
||||
TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithEncodeUsage) {
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithProcessingUsage) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.enable_extended_processing_usage = false;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// usage > high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
|
||||
TriggerOveruseWithEncodeUsage(options_.high_threshold_consecutive_count);
|
||||
TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
|
||||
// usage < low => underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
|
||||
TriggerNormalUsageWithEncodeTime();
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest,
|
||||
OveruseAndRecoverWithEncodeUsageMethodDisabled) {
|
||||
OveruseAndRecoverWithProcessingUsageMethodDisabled) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = false;
|
||||
options_.enable_extended_processing_usage = false;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// usage > high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
|
||||
TriggerOveruseWithEncodeUsage(options_.high_threshold_consecutive_count);
|
||||
TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
|
||||
// usage < low => underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
|
||||
TriggerNormalUsageWithEncodeTime();
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, EncodeRsdResetAfterChangingThreshold) {
|
||||
EXPECT_EQ(InitialEncodeRsd(), EncodeRsd());
|
||||
// enable_extended_processing_usage = true;
|
||||
// enable_encode_usage_method = true;
|
||||
// UsagePercent() > high_encode_usage_threshold_percent => overuse.
|
||||
// UsagePercent() < low_encode_usage_threshold_percent => underuse.
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithExtendedProcessingUsage) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// usage > high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
|
||||
TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithExtendedProcessingUsage) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// usage > high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
|
||||
TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
|
||||
// usage < low => underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest,
|
||||
OveruseAndRecoverWithExtendedProcessingUsageMethodDisabled) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = false;
|
||||
options_.enable_extended_processing_usage = true;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// usage > high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(0);
|
||||
TriggerOveruseWithProcessingUsage(options_.high_threshold_consecutive_count);
|
||||
// usage < low => underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, RsdResetAfterChangingThreshold) {
|
||||
EXPECT_EQ(InitialRsd(), Rsd());
|
||||
options_.high_encode_time_rsd_threshold = 100;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
EXPECT_EQ(InitialEncodeRsd(), EncodeRsd());
|
||||
EXPECT_EQ(InitialRsd(), Rsd());
|
||||
options_.low_encode_time_rsd_threshold = 20;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
EXPECT_EQ(InitialEncodeRsd(), EncodeRsd());
|
||||
EXPECT_EQ(InitialRsd(), Rsd());
|
||||
}
|
||||
|
||||
// enable_encode_usage_method = true;
|
||||
// low/high_encode_time_rsd_threshold >= 0
|
||||
// EncodeUsagePercent() > high_encode_usage_threshold_percent ||
|
||||
// EncodeRsd() > high_encode_time_rsd_threshold => overuse.
|
||||
// EncodeUsagePercent() < low_encode_usage_threshold_percent &&
|
||||
// EncodeRsd() < low_encode_time_rsd_threshold => underuse.
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithEncodeRsd) {
|
||||
// UsagePercent() > high_encode_usage_threshold_percent ||
|
||||
// Rsd() > high_encode_time_rsd_threshold => overuse.
|
||||
// UsagePercent() < low_encode_usage_threshold_percent &&
|
||||
// Rsd() < low_encode_time_rsd_threshold => underuse.
|
||||
TEST_F(OveruseFrameDetectorTest, TriggerOveruseWithRsd) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.high_encode_time_rsd_threshold = 80;
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// rsd > high, usage < high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
|
||||
TriggerOveruseWithEncodeRsd(options_.high_threshold_consecutive_count);
|
||||
EXPECT_LT(EncodeUsagePercent(), options_.high_encode_usage_threshold_percent);
|
||||
TriggerOveruseWithRsd(options_.high_threshold_consecutive_count);
|
||||
EXPECT_LT(UsagePercent(), options_.high_encode_usage_threshold_percent);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithEncodeRsd) {
|
||||
TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithRsd) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.low_encode_time_rsd_threshold = 25;
|
||||
@ -452,14 +606,14 @@ TEST_F(OveruseFrameDetectorTest, OveruseAndRecoverWithEncodeRsd) {
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// rsd > high, usage < high => overuse
|
||||
EXPECT_CALL(*(observer_.get()), OveruseDetected()).Times(1);
|
||||
TriggerOveruseWithEncodeRsd(options_.high_threshold_consecutive_count);
|
||||
EXPECT_LT(EncodeUsagePercent(), options_.high_encode_usage_threshold_percent);
|
||||
TriggerOveruseWithRsd(options_.high_threshold_consecutive_count);
|
||||
EXPECT_LT(UsagePercent(), options_.high_encode_usage_threshold_percent);
|
||||
// rsd < low, usage < low => underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(testing::AtLeast(1));
|
||||
TriggerNormalUsageWithEncodeTime();
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, NoUnderuseWithEncodeRsd_UsageGtLowThreshold) {
|
||||
TEST_F(OveruseFrameDetectorTest, NoUnderuseWithRsd_UsageGtLowThreshold) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.low_encode_usage_threshold_percent = 1;
|
||||
@ -468,12 +622,12 @@ TEST_F(OveruseFrameDetectorTest, NoUnderuseWithEncodeRsd_UsageGtLowThreshold) {
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// rsd < low, usage > low => no underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
|
||||
TriggerNormalUsageWithEncodeTime();
|
||||
EXPECT_LT(EncodeRsd(), options_.low_encode_time_rsd_threshold);
|
||||
EXPECT_GT(EncodeUsagePercent(), options_.low_encode_usage_threshold_percent);
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
EXPECT_LT(Rsd(), options_.low_encode_time_rsd_threshold);
|
||||
EXPECT_GT(UsagePercent(), options_.low_encode_usage_threshold_percent);
|
||||
}
|
||||
|
||||
TEST_F(OveruseFrameDetectorTest, NoUnderuseWithEncodeRsd_RsdGtLowThreshold) {
|
||||
TEST_F(OveruseFrameDetectorTest, NoUnderuseWithRsd_RsdGtLowThreshold) {
|
||||
options_.enable_capture_jitter_method = false;
|
||||
options_.enable_encode_usage_method = true;
|
||||
options_.low_encode_usage_threshold_percent = 20;
|
||||
@ -482,8 +636,8 @@ TEST_F(OveruseFrameDetectorTest, NoUnderuseWithEncodeRsd_RsdGtLowThreshold) {
|
||||
overuse_detector_->SetOptions(options_);
|
||||
// rsd > low, usage < low => no underuse
|
||||
EXPECT_CALL(*(observer_.get()), NormalUsage()).Times(0);
|
||||
TriggerNormalUsageWithEncodeTime();
|
||||
EXPECT_GT(EncodeRsd(), options_.low_encode_time_rsd_threshold);
|
||||
EXPECT_LT(EncodeUsagePercent(), options_.low_encode_usage_threshold_percent);
|
||||
TriggerUnderuseWithProcessingUsage();
|
||||
EXPECT_GT(Rsd(), options_.low_encode_time_rsd_threshold);
|
||||
EXPECT_LT(UsagePercent(), options_.low_encode_usage_threshold_percent);
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
@ -343,6 +343,10 @@ void ViECapturer::OnIncomingCapturedFrame(const int32_t capture_id,
|
||||
// the camera, and not when the camera actually captured the frame.
|
||||
video_frame.set_render_time_ms(video_frame.render_time_ms() - FrameDelay());
|
||||
|
||||
overuse_detector_->FrameCaptured(video_frame.width(),
|
||||
video_frame.height(),
|
||||
video_frame.render_time_ms());
|
||||
|
||||
TRACE_EVENT_ASYNC_BEGIN1("webrtc", "Video", video_frame.render_time_ms(),
|
||||
"render_time", video_frame.render_time_ms());
|
||||
|
||||
@ -354,8 +358,6 @@ void ViECapturer::OnIncomingCapturedFrame(const int32_t capture_id,
|
||||
captured_frame_->SwapFrame(&video_frame);
|
||||
}
|
||||
capture_event_.Set();
|
||||
overuse_detector_->FrameCaptured(captured_frame_->width(),
|
||||
captured_frame_->height());
|
||||
}
|
||||
|
||||
void ViECapturer::OnCaptureDelayChanged(const int32_t id,
|
||||
@ -450,11 +452,13 @@ bool ViECapturer::ViECaptureThreadFunction(void* obj) {
|
||||
}
|
||||
|
||||
bool ViECapturer::ViECaptureProcess() {
|
||||
int64_t capture_time = -1;
|
||||
if (capture_event_.Wait(kThreadWaitTimeMs) == kEventSignaled) {
|
||||
overuse_detector_->FrameProcessingStarted();
|
||||
int64_t encode_start_time = -1;
|
||||
deliver_cs_->Enter();
|
||||
if (SwapCapturedAndDeliverFrameIfAvailable()) {
|
||||
capture_time = deliver_frame_->render_time_ms();
|
||||
encode_start_time = Clock::GetRealTimeClock()->TimeInMilliseconds();
|
||||
DeliverI420Frame(deliver_frame_.get());
|
||||
if (deliver_frame_->native_handle() != NULL)
|
||||
@ -475,6 +479,9 @@ bool ViECapturer::ViECaptureProcess() {
|
||||
}
|
||||
}
|
||||
// We're done!
|
||||
if (capture_time != -1) {
|
||||
overuse_detector_->FrameSent(capture_time);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user