Implemented AutoMuter in MediaOptimization

Also added a unittest. This is the first step towards creating an
AutoMuter function in WebRTC.

R=mflodman@webrtc.org, stefan@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@4857 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrik.lundin@webrtc.org
2013-09-26 12:05:15 +00:00
parent 04b61790d1
commit 544b17c6a9
4 changed files with 175 additions and 3 deletions

View File

@ -46,7 +46,11 @@ MediaOptimization::MediaOptimization(int32_t id, Clock* clock)
qm_resolution_(new VCMQmResolution()),
last_qm_update_time_(0),
last_change_time_(0),
num_layers_(0) {
num_layers_(0),
muting_enabled_(false),
video_muted_(false),
muter_threshold_bps_(0),
muter_window_bps_(0) {
memset(send_statistics_, 0, sizeof(send_statistics_));
memset(incoming_frame_times_, -1, sizeof(incoming_frame_times_));
}
@ -189,6 +193,8 @@ uint32_t MediaOptimization::SetTargetRates(uint32_t target_bitrate,
content_->ResetShortTermAvgData();
}
CheckAutoMuteConditions();
return target_bit_rate_;
}
@ -345,7 +351,9 @@ void MediaOptimization::EnableFrameDropper(bool enable) {
bool MediaOptimization::DropFrame() {
// Leak appropriate number of bytes.
frame_dropper_->Leak((uint32_t)(InputFrameRate() + 0.5f));
if (video_muted_) {
return true; // Drop all frames when muted.
}
return frame_dropper_->DropFrame();
}
@ -410,6 +418,19 @@ int32_t MediaOptimization::SelectQuality() {
return VCM_OK;
}
void MediaOptimization::EnableAutoMuting(int threshold_bps, int window_bps) {
assert(threshold_bps > 0 && window_bps >= 0);
muter_threshold_bps_ = threshold_bps;
muter_window_bps_ = window_bps;
muting_enabled_ = true;
video_muted_ = false;
}
void MediaOptimization::DisableAutoMuting() {
muting_enabled_ = false;
video_muted_ = false;
}
// Private methods below this line.
int MediaOptimization::UpdateProtectionCallback(
@ -584,5 +605,23 @@ void MediaOptimization::ProcessIncomingFrameRate(int64_t now) {
}
}
void MediaOptimization::CheckAutoMuteConditions() {
// Check conditions for AutoMute. |target_bit_rate_| is in bps.
if (muting_enabled_) {
if (!video_muted_) {
// Check if we just went below the threshold.
if (target_bit_rate_ < muter_threshold_bps_) {
video_muted_ = true;
}
} else {
// Video is already muted. Check if we just went over the threshold
// with a margin.
if (target_bit_rate_ > muter_threshold_bps_ + muter_window_bps_) {
video_muted_ = false;
}
}
}
}
} // namespace media_optimization
} // namespace webrtc