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

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: 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') | webrtc/test/direct_transport.h » ('J')
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/scoped_ptr.h" 18 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/base/thread_annotations.h" 19 #include "webrtc/base/thread_annotations.h"
20 #include "webrtc/call.h" 20 #include "webrtc/call.h"
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
22 #include "webrtc/system_wrappers/include/event_wrapper.h" 22 #include "webrtc/system_wrappers/include/event_wrapper.h"
mflodman 2015/12/10 08:11:34 Remove.
pbos-webrtc 2015/12/10 11:44:55 Done.
23 #include "webrtc/system_wrappers/include/trace.h" 23 #include "webrtc/system_wrappers/include/trace.h"
24 #include "webrtc/test/call_test.h" 24 #include "webrtc/test/call_test.h"
25 #include "webrtc/test/direct_transport.h" 25 #include "webrtc/test/direct_transport.h"
26 #include "webrtc/test/encoder_settings.h" 26 #include "webrtc/test/encoder_settings.h"
27 #include "webrtc/test/fake_decoder.h" 27 #include "webrtc/test/fake_decoder.h"
28 #include "webrtc/test/fake_encoder.h" 28 #include "webrtc/test/fake_encoder.h"
29 #include "webrtc/test/mock_voice_engine.h" 29 #include "webrtc/test/mock_voice_engine.h"
30 #include "webrtc/test/frame_generator_capturer.h" 30 #include "webrtc/test/frame_generator_capturer.h"
31 31
32 namespace webrtc { 32 namespace webrtc {
(...skipping 17 matching lines...) Expand all
50 50
51 ~TraceObserver() { 51 ~TraceObserver() {
52 Trace::SetTraceCallback(nullptr); 52 Trace::SetTraceCallback(nullptr);
53 Trace::ReturnTrace(); 53 Trace::ReturnTrace();
54 } 54 }
55 55
56 void PushExpectedLogLine(const std::string& expected_log_line) { 56 void PushExpectedLogLine(const std::string& expected_log_line) {
57 callback_.PushExpectedLogLine(expected_log_line); 57 callback_.PushExpectedLogLine(expected_log_line);
58 } 58 }
59 59
60 EventTypeWrapper Wait() { return callback_.Wait(); } 60 bool Wait() { return callback_.Wait(); }
61 61
62 private: 62 private:
63 class Callback : public TraceCallback { 63 class Callback : public TraceCallback {
64 public: 64 public:
65 Callback() : done_(EventWrapper::Create()) {} 65 Callback() : done_(false, false) {}
66 66
67 void Print(TraceLevel level, const char* message, int length) override { 67 void Print(TraceLevel level, const char* message, int length) override {
68 rtc::CritScope lock(&crit_sect_); 68 rtc::CritScope lock(&crit_sect_);
69 std::string msg(message); 69 std::string msg(message);
70 if (msg.find("BitrateEstimator") != std::string::npos) { 70 if (msg.find("BitrateEstimator") != std::string::npos) {
71 received_log_lines_.push_back(msg); 71 received_log_lines_.push_back(msg);
72 } 72 }
73 int num_popped = 0; 73 int num_popped = 0;
74 while (!received_log_lines_.empty() && !expected_log_lines_.empty()) { 74 while (!received_log_lines_.empty() && !expected_log_lines_.empty()) {
75 std::string a = received_log_lines_.front(); 75 std::string a = received_log_lines_.front();
76 std::string b = expected_log_lines_.front(); 76 std::string b = expected_log_lines_.front();
77 received_log_lines_.pop_front(); 77 received_log_lines_.pop_front();
78 expected_log_lines_.pop_front(); 78 expected_log_lines_.pop_front();
79 num_popped++; 79 num_popped++;
80 EXPECT_TRUE(a.find(b) != std::string::npos); 80 EXPECT_TRUE(a.find(b) != std::string::npos);
81 } 81 }
82 if (expected_log_lines_.size() <= 0) { 82 if (expected_log_lines_.size() <= 0) {
83 if (num_popped > 0) { 83 if (num_popped > 0) {
84 done_->Set(); 84 done_.Set();
85 } 85 }
86 return; 86 return;
87 } 87 }
88 } 88 }
89 89
90 EventTypeWrapper Wait() { 90 bool Wait() { return done_.Wait(test::CallTest::kDefaultTimeoutMs); }
91 return done_->Wait(test::CallTest::kDefaultTimeoutMs);
92 }
93 91
94 void PushExpectedLogLine(const std::string& expected_log_line) { 92 void PushExpectedLogLine(const std::string& expected_log_line) {
95 rtc::CritScope lock(&crit_sect_); 93 rtc::CritScope lock(&crit_sect_);
96 expected_log_lines_.push_back(expected_log_line); 94 expected_log_lines_.push_back(expected_log_line);
97 } 95 }
98 96
99 private: 97 private:
100 typedef std::list<std::string> Strings; 98 typedef std::list<std::string> Strings;
101 rtc::CriticalSection crit_sect_; 99 rtc::CriticalSection crit_sect_;
102 Strings received_log_lines_ GUARDED_BY(crit_sect_); 100 Strings received_log_lines_ GUARDED_BY(crit_sect_);
103 Strings expected_log_lines_ GUARDED_BY(crit_sect_); 101 Strings expected_log_lines_ GUARDED_BY(crit_sect_);
104 rtc::scoped_ptr<EventWrapper> done_; 102 rtc::Event done_;
105 }; 103 };
106 104
107 Callback callback_; 105 Callback callback_;
108 }; 106 };
109 } // namespace 107 } // namespace
110 108
111 static const int kTOFExtensionId = 4; 109 static const int kTOFExtensionId = 4;
112 static const int kASTExtensionId = 5; 110 static const int kASTExtensionId = 5;
113 111
114 class BitrateEstimatorTest : public test::CallTest { 112 class BitrateEstimatorTest : public test::CallTest {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 "RemoteBitrateEstimatorAbsSendTime: Instantiating."; 271 "RemoteBitrateEstimatorAbsSendTime: Instantiating.";
274 static const char* kSingleStreamLog = 272 static const char* kSingleStreamLog =
275 "RemoteBitrateEstimatorSingleStream: Instantiating."; 273 "RemoteBitrateEstimatorSingleStream: Instantiating.";
276 274
277 TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) { 275 TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) {
278 send_config_.rtp.extensions.push_back( 276 send_config_.rtp.extensions.push_back(
279 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 277 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
280 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 278 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
281 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 279 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
282 streams_.push_back(new Stream(this, false)); 280 streams_.push_back(new Stream(this, false));
283 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 281 EXPECT_TRUE(receiver_trace_.Wait());
284 } 282 }
285 283
286 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForAudio) { 284 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForAudio) {
287 send_config_.rtp.extensions.push_back( 285 send_config_.rtp.extensions.push_back(
288 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 286 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
289 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 287 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
290 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 288 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
291 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 289 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE.");
292 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 290 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog);
293 streams_.push_back(new Stream(this, true)); 291 streams_.push_back(new Stream(this, true));
294 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 292 EXPECT_TRUE(receiver_trace_.Wait());
295 } 293 }
296 294
297 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) { 295 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) {
298 send_config_.rtp.extensions.push_back( 296 send_config_.rtp.extensions.push_back(
299 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 297 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
300 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 298 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
301 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 299 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
302 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 300 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE.");
303 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 301 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog);
304 streams_.push_back(new Stream(this, false)); 302 streams_.push_back(new Stream(this, false));
305 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 303 EXPECT_TRUE(receiver_trace_.Wait());
306 } 304 }
307 305
308 TEST_F(BitrateEstimatorTest, SwitchesToASTForAudio) { 306 TEST_F(BitrateEstimatorTest, SwitchesToASTForAudio) {
309 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 307 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
310 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 308 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
311 streams_.push_back(new Stream(this, true)); 309 streams_.push_back(new Stream(this, true));
312 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 310 EXPECT_TRUE(receiver_trace_.Wait());
313 311
314 send_config_.rtp.extensions.push_back( 312 send_config_.rtp.extensions.push_back(
315 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 313 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
316 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 314 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE.");
317 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 315 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog);
318 streams_.push_back(new Stream(this, true)); 316 streams_.push_back(new Stream(this, true));
319 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 317 EXPECT_TRUE(receiver_trace_.Wait());
320 } 318 }
321 319
322 TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) { 320 TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) {
323 send_config_.rtp.extensions.push_back( 321 send_config_.rtp.extensions.push_back(
324 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 322 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
325 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 323 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
326 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 324 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
327 streams_.push_back(new Stream(this, false)); 325 streams_.push_back(new Stream(this, false));
328 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 326 EXPECT_TRUE(receiver_trace_.Wait());
329 327
330 send_config_.rtp.extensions[0] = 328 send_config_.rtp.extensions[0] =
331 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId); 329 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId);
332 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 330 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE.");
333 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 331 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog);
334 streams_.push_back(new Stream(this, false)); 332 streams_.push_back(new Stream(this, false));
335 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 333 EXPECT_TRUE(receiver_trace_.Wait());
336 } 334 }
337 335
338 TEST_F(BitrateEstimatorTest, SwitchesToASTThenBackToTOFForVideo) { 336 TEST_F(BitrateEstimatorTest, SwitchesToASTThenBackToTOFForVideo) {
339 send_config_.rtp.extensions.push_back( 337 send_config_.rtp.extensions.push_back(
340 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 338 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
341 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 339 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
342 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 340 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
343 streams_.push_back(new Stream(this, false)); 341 streams_.push_back(new Stream(this, false));
344 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 342 EXPECT_TRUE(receiver_trace_.Wait());
345 343
346 send_config_.rtp.extensions[0] = 344 send_config_.rtp.extensions[0] =
347 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId); 345 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId);
348 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 346 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE.");
349 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 347 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog);
350 streams_.push_back(new Stream(this, false)); 348 streams_.push_back(new Stream(this, false));
351 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 349 EXPECT_TRUE(receiver_trace_.Wait());
352 350
353 send_config_.rtp.extensions[0] = 351 send_config_.rtp.extensions[0] =
354 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId); 352 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId);
355 receiver_trace_.PushExpectedLogLine( 353 receiver_trace_.PushExpectedLogLine(
356 "WrappingBitrateEstimator: Switching to transmission time offset RBE."); 354 "WrappingBitrateEstimator: Switching to transmission time offset RBE.");
357 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 355 receiver_trace_.PushExpectedLogLine(kSingleStreamLog);
358 streams_.push_back(new Stream(this, false)); 356 streams_.push_back(new Stream(this, false));
359 streams_[0]->StopSending(); 357 streams_[0]->StopSending();
360 streams_[1]->StopSending(); 358 streams_[1]->StopSending();
361 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 359 EXPECT_TRUE(receiver_trace_.Wait());
362 } 360 }
363 } // namespace webrtc 361 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/call/call_perf_tests.cc » ('j') | webrtc/test/direct_transport.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698