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

Side by Side Diff: webrtc/call/bitrate_estimator_tests.cc

Issue 1487893004: Replace EventWrapper in video/, test/ and call/. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: add some back, EventTimerWrapper is in use Created 5 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/call/call_perf_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include <functional> 10 #include <functional>
11 #include <list> 11 #include <list>
12 #include <string> 12 #include <string>
13 13
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #include "webrtc/audio_state.h" 16 #include "webrtc/audio_state.h"
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/event.h"
18 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
19 #include "webrtc/base/scoped_ptr.h" 20 #include "webrtc/base/scoped_ptr.h"
20 #include "webrtc/base/thread_annotations.h" 21 #include "webrtc/base/thread_annotations.h"
21 #include "webrtc/call.h" 22 #include "webrtc/call.h"
22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
23 #include "webrtc/system_wrappers/include/event_wrapper.h"
24 #include "webrtc/system_wrappers/include/trace.h" 24 #include "webrtc/system_wrappers/include/trace.h"
25 #include "webrtc/test/call_test.h" 25 #include "webrtc/test/call_test.h"
26 #include "webrtc/test/direct_transport.h" 26 #include "webrtc/test/direct_transport.h"
27 #include "webrtc/test/encoder_settings.h" 27 #include "webrtc/test/encoder_settings.h"
28 #include "webrtc/test/fake_decoder.h" 28 #include "webrtc/test/fake_decoder.h"
29 #include "webrtc/test/fake_encoder.h" 29 #include "webrtc/test/fake_encoder.h"
30 #include "webrtc/test/mock_voice_engine.h" 30 #include "webrtc/test/mock_voice_engine.h"
31 #include "webrtc/test/frame_generator_capturer.h" 31 #include "webrtc/test/frame_generator_capturer.h"
32 32
33 namespace webrtc { 33 namespace webrtc {
34 namespace { 34 namespace {
35 // Note: If you consider to re-use this class, think twice and instead consider 35 // Note: If you consider to re-use this class, think twice and instead consider
36 // writing tests that don't depend on the logging system. 36 // writing tests that don't depend on the logging system.
37 class LogObserver { 37 class LogObserver {
38 public: 38 public:
39 LogObserver() { rtc::LogMessage::AddLogToStream(&callback_, rtc::LS_INFO); } 39 LogObserver() { rtc::LogMessage::AddLogToStream(&callback_, rtc::LS_INFO); }
40 40
41 ~LogObserver() { rtc::LogMessage::RemoveLogToStream(&callback_); } 41 ~LogObserver() { rtc::LogMessage::RemoveLogToStream(&callback_); }
42 42
43 void PushExpectedLogLine(const std::string& expected_log_line) { 43 void PushExpectedLogLine(const std::string& expected_log_line) {
44 callback_.PushExpectedLogLine(expected_log_line); 44 callback_.PushExpectedLogLine(expected_log_line);
45 } 45 }
46 46
47 EventTypeWrapper Wait() { return callback_.Wait(); } 47 bool Wait() { return callback_.Wait(); }
48 48
49 private: 49 private:
50 class Callback : public rtc::LogSink { 50 class Callback : public rtc::LogSink {
51 public: 51 public:
52 Callback() : done_(EventWrapper::Create()) {} 52 Callback() : done_(false, false) {}
53 53
54 void OnLogMessage(const std::string& message) override { 54 void OnLogMessage(const std::string& message) override {
55 rtc::CritScope lock(&crit_sect_); 55 rtc::CritScope lock(&crit_sect_);
56 // Ignore log lines that are due to missing AST extensions, these are 56 // Ignore log lines that are due to missing AST extensions, these are
57 // logged when we switch back from AST to TOF until the wrapping bitrate 57 // logged when we switch back from AST to TOF until the wrapping bitrate
58 // estimator gives up on using AST. 58 // estimator gives up on using AST.
59 if (message.find("BitrateEstimator") != std::string::npos && 59 if (message.find("BitrateEstimator") != std::string::npos &&
60 message.find("packet is missing") == std::string::npos) { 60 message.find("packet is missing") == std::string::npos) {
61 received_log_lines_.push_back(message); 61 received_log_lines_.push_back(message);
62 } 62 }
63 63
64 int num_popped = 0; 64 int num_popped = 0;
65 while (!received_log_lines_.empty() && !expected_log_lines_.empty()) { 65 while (!received_log_lines_.empty() && !expected_log_lines_.empty()) {
66 std::string a = received_log_lines_.front(); 66 std::string a = received_log_lines_.front();
67 std::string b = expected_log_lines_.front(); 67 std::string b = expected_log_lines_.front();
68 received_log_lines_.pop_front(); 68 received_log_lines_.pop_front();
69 expected_log_lines_.pop_front(); 69 expected_log_lines_.pop_front();
70 num_popped++; 70 num_popped++;
71 EXPECT_TRUE(a.find(b) != std::string::npos) << a << " != " << b; 71 EXPECT_TRUE(a.find(b) != std::string::npos) << a << " != " << b;
72 } 72 }
73 if (expected_log_lines_.size() <= 0) { 73 if (expected_log_lines_.size() <= 0) {
74 if (num_popped > 0) { 74 if (num_popped > 0) {
75 done_->Set(); 75 done_.Set();
76 } 76 }
77 return; 77 return;
78 } 78 }
79 } 79 }
80 80
81 EventTypeWrapper Wait() { 81 bool Wait() { return done_.Wait(test::CallTest::kDefaultTimeoutMs); }
82 return done_->Wait(test::CallTest::kDefaultTimeoutMs);
83 }
84 82
85 void PushExpectedLogLine(const std::string& expected_log_line) { 83 void PushExpectedLogLine(const std::string& expected_log_line) {
86 rtc::CritScope lock(&crit_sect_); 84 rtc::CritScope lock(&crit_sect_);
87 expected_log_lines_.push_back(expected_log_line); 85 expected_log_lines_.push_back(expected_log_line);
88 } 86 }
89 87
90 private: 88 private:
91 typedef std::list<std::string> Strings; 89 typedef std::list<std::string> Strings;
92 rtc::CriticalSection crit_sect_; 90 rtc::CriticalSection crit_sect_;
93 Strings received_log_lines_ GUARDED_BY(crit_sect_); 91 Strings received_log_lines_ GUARDED_BY(crit_sect_);
94 Strings expected_log_lines_ GUARDED_BY(crit_sect_); 92 Strings expected_log_lines_ GUARDED_BY(crit_sect_);
95 rtc::scoped_ptr<EventWrapper> done_; 93 rtc::Event done_;
96 }; 94 };
97 95
98 Callback callback_; 96 Callback callback_;
99 }; 97 };
100 } // namespace 98 } // namespace
101 99
102 static const int kTOFExtensionId = 4; 100 static const int kTOFExtensionId = 4;
103 static const int kASTExtensionId = 5; 101 static const int kASTExtensionId = 5;
104 102
105 class BitrateEstimatorTest : public test::CallTest { 103 class BitrateEstimatorTest : public test::CallTest {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 "RemoteBitrateEstimatorAbsSendTime: Instantiating."; 262 "RemoteBitrateEstimatorAbsSendTime: Instantiating.";
265 static const char* kSingleStreamLog = 263 static const char* kSingleStreamLog =
266 "RemoteBitrateEstimatorSingleStream: Instantiating."; 264 "RemoteBitrateEstimatorSingleStream: Instantiating.";
267 265
268 TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) { 266 TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) {
269 send_config_.rtp.extensions.push_back( 267 send_config_.rtp.extensions.push_back(
270 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 268 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
271 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 269 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
272 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 270 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
273 streams_.push_back(new Stream(this, false)); 271 streams_.push_back(new Stream(this, false));
274 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 272 EXPECT_TRUE(receiver_log_.Wait());
275 } 273 }
276 274
277 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForAudio) { 275 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForAudio) {
278 send_config_.rtp.extensions.push_back( 276 send_config_.rtp.extensions.push_back(
279 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 277 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
280 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 278 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
281 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 279 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
282 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); 280 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
283 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); 281 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
284 streams_.push_back(new Stream(this, true)); 282 streams_.push_back(new Stream(this, true));
285 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 283 EXPECT_TRUE(receiver_log_.Wait());
286 } 284 }
287 285
288 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) { 286 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) {
289 send_config_.rtp.extensions.push_back( 287 send_config_.rtp.extensions.push_back(
290 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 288 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
291 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 289 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
292 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 290 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
293 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); 291 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
294 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); 292 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
295 streams_.push_back(new Stream(this, false)); 293 streams_.push_back(new Stream(this, false));
296 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 294 EXPECT_TRUE(receiver_log_.Wait());
297 } 295 }
298 296
299 TEST_F(BitrateEstimatorTest, SwitchesToASTForAudio) { 297 TEST_F(BitrateEstimatorTest, SwitchesToASTForAudio) {
300 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 298 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
301 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 299 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
302 streams_.push_back(new Stream(this, true)); 300 streams_.push_back(new Stream(this, true));
303 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 301 EXPECT_TRUE(receiver_log_.Wait());
304 302
305 send_config_.rtp.extensions.push_back( 303 send_config_.rtp.extensions.push_back(
306 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 304 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
307 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); 305 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
308 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); 306 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
309 streams_.push_back(new Stream(this, true)); 307 streams_.push_back(new Stream(this, true));
310 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 308 EXPECT_TRUE(receiver_log_.Wait());
311 } 309 }
312 310
313 TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) { 311 TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) {
314 send_config_.rtp.extensions.push_back( 312 send_config_.rtp.extensions.push_back(
315 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 313 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
316 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 314 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
317 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 315 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
318 streams_.push_back(new Stream(this, false)); 316 streams_.push_back(new Stream(this, false));
319 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 317 EXPECT_TRUE(receiver_log_.Wait());
320 318
321 send_config_.rtp.extensions[0] = 319 send_config_.rtp.extensions[0] =
322 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId); 320 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId);
323 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); 321 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
324 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); 322 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
325 streams_.push_back(new Stream(this, false)); 323 streams_.push_back(new Stream(this, false));
326 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 324 EXPECT_TRUE(receiver_log_.Wait());
327 } 325 }
328 326
329 TEST_F(BitrateEstimatorTest, SwitchesToASTThenBackToTOFForVideo) { 327 TEST_F(BitrateEstimatorTest, SwitchesToASTThenBackToTOFForVideo) {
330 send_config_.rtp.extensions.push_back( 328 send_config_.rtp.extensions.push_back(
331 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 329 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
332 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 330 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
333 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 331 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
334 streams_.push_back(new Stream(this, false)); 332 streams_.push_back(new Stream(this, false));
335 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 333 EXPECT_TRUE(receiver_log_.Wait());
336 334
337 send_config_.rtp.extensions[0] = 335 send_config_.rtp.extensions[0] =
338 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId); 336 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId);
339 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); 337 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
340 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); 338 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
341 streams_.push_back(new Stream(this, false)); 339 streams_.push_back(new Stream(this, false));
342 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 340 EXPECT_TRUE(receiver_log_.Wait());
343 341
344 send_config_.rtp.extensions[0] = 342 send_config_.rtp.extensions[0] =
345 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId); 343 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId);
346 receiver_log_.PushExpectedLogLine( 344 receiver_log_.PushExpectedLogLine(
347 "WrappingBitrateEstimator: Switching to transmission time offset RBE."); 345 "WrappingBitrateEstimator: Switching to transmission time offset RBE.");
348 receiver_log_.PushExpectedLogLine(kSingleStreamLog); 346 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
349 streams_.push_back(new Stream(this, false)); 347 streams_.push_back(new Stream(this, false));
350 streams_[0]->StopSending(); 348 streams_[0]->StopSending();
351 streams_[1]->StopSending(); 349 streams_[1]->StopSending();
352 EXPECT_EQ(kEventSignaled, receiver_log_.Wait()); 350 EXPECT_TRUE(receiver_log_.Wait());
353 } 351 }
354 } // namespace webrtc 352 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/call/call_perf_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698