Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(847)

Unified Diff: webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc

Issue 1236793003: Add LoudestFilter in ConferenceTransport (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: avoiding C++11 map.erase signature Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..29dda630d7add6f8b5c8fa7dd87a55905d9ce4e5
--- /dev/null
+++ b/webrtc/voice_engine/test/auto_test/fakes/loudest_filter.cc
@@ -0,0 +1,82 @@
+/*
+ * 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()) {
+ if (rtc::TimeDiff(time_ms, it->second.last_time_ms) >
+ kStreamTimeOutMs) {
+ stream_levels_.erase(it++);
+ } else {
+ ++it;
+ }
+ }
+}
+
+unsigned int LoudestFilter::FindQuietestStream() {
+ int quietest_level = kInvalidAudioLevel;
+ unsigned int quietest_ssrc = 0;
+ for (auto stream : stream_levels_) {
+ // A smaller value if audio level corresponds to a louder sound.
+ if (quietest_level == kInvalidAudioLevel ||
+ stream.second.audio_level > quietest_level) {
+ quietest_level = stream.second.audio_level;
+ quietest_ssrc = stream.first;
+ }
+ }
+ return quietest_ssrc;
+}
+
+bool LoudestFilter::ForwardThisPacket(const webrtc::RTPHeader& rtp_header) {
+ uint32 time_now_ms = rtc::Time();
+ RemoveTimeoutStreams(time_now_ms);
+
+ int source_ssrc = rtp_header.ssrc;
+ int audio_level = rtp_header.extension.hasAudioLevel ?
+ rtp_header.extension.audioLevel : kInvalidAudioLevel;
+
+ 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);
+ // A smaller value if audio level corresponds to a louder sound.
+ if (audio_level < stream_levels_[quietest_ssrc].audio_level) {
+ stream_levels_.erase(quietest_ssrc);
+ stream_levels_[source_ssrc].Set(audio_level, time_now_ms);
+ return true;
+ }
+ return false;
+}
+
+} // namespace voetest
+
« no previous file with comments | « webrtc/voice_engine/test/auto_test/fakes/loudest_filter.h ('k') | webrtc/voice_engine/test/auto_test/voe_conference_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698