Chromium Code Reviews| Index: webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc |
| diff --git a/webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc b/webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1eb0b83801ab97f1408d04b5127c02f2fea737fd |
| --- /dev/null |
| +++ b/webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc |
| @@ -0,0 +1,76 @@ |
| +/* |
| + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include "webrtc/voice_engine/test/auto_test/fakes/loudest_filter.h" |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace voetest { |
| + |
| +void LoudestFilter::RemoveTimeoutStreams(uint32 time_ms) { |
| + auto it = stream_levels_.begin(); |
| + while (it != stream_levels_.end()) { |
|
hlundin-webrtc
2015/08/10 10:50:17
I suggest you make this a for loop instead
for (au
minyue-webrtc
2015/08/12 14:53:23
I do not think for (auto stream : stream_levels_)
|
| + if (rtc::TimeDiff(time_ms, it->second.last_time_ms_) > |
|
hlundin-webrtc
2015/08/10 10:50:17
Oh, is that why you kept using uint32_t for the ti
minyue-webrtc
2015/08/12 14:53:23
Acknowledged.
|
| + kStreamTimeOutMs) { |
| + stream_levels_.erase(it++); |
|
hlundin-webrtc
2015/08/10 10:50:17
I'm not sure it is valid after you called erase. "
minyue-webrtc
2015/08/12 14:53:23
I saw many examples of this on the net. It should
|
| + } else { |
| + ++it; |
| + } |
| + } |
| +} |
| + |
| +unsigned int LoudestFilter::FindQuietestStream() { |
| + int quietest_level = kInvalidAudioLevel; |
| + unsigned int quietest_ssrc = 0; |
| + for (auto stream : stream_levels_) { |
| + if (quietest_level == kInvalidAudioLevel || |
| + stream.second.audio_level_ > quietest_level) { |
|
hlundin-webrtc
2015/08/10 10:50:17
Comment about the fact that a quiet stream has a h
minyue-webrtc
2015/08/12 14:53:23
Done.
|
| + quietest_level = stream.second.audio_level_; |
| + quietest_ssrc = stream.first; |
| + } |
| + } |
| + return quietest_ssrc; |
| +} |
| + |
| +bool LoudestFilter::DecideForward(unsigned int source_ssrc, int audio_level) { |
| + uint32 time_now_ms = rtc::Time(); |
| + RemoveTimeoutStreams(time_now_ms); |
| + |
| + if (audio_level == kInvalidAudioLevel) { |
| + // Always forward streams with unknown audio level, and don't keep their |
| + // states. |
| + return true; |
| + } |
| + |
| + auto it = stream_levels_.find(source_ssrc); |
| + if (it != stream_levels_.end()) { |
| + // Stream has been forwarded. Update and continue to forward. |
| + it->second.audio_level_ = audio_level; |
| + it->second.last_time_ms_ = time_now_ms; |
| + return true; |
| + } |
| + |
| + if (stream_levels_.size() < kMaxMixSize) { |
| + stream_levels_[source_ssrc].Set(audio_level, time_now_ms); |
| + return true; |
| + } |
| + |
| + unsigned int quietest_ssrc = FindQuietestStream(); |
| + CHECK_NE(0u, quietest_ssrc); |
| + if (audio_level < stream_levels_[quietest_ssrc].audio_level_) { |
|
hlundin-webrtc
2015/08/10 10:50:17
Again, explain that "up is down, and down is up".
minyue-webrtc
2015/08/12 14:53:23
Done.
|
| + stream_levels_.erase(quietest_ssrc); |
| + stream_levels_[source_ssrc].Set(audio_level, time_now_ms); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +} // namespace voetest |
| + |