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

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

Issue 1484503002: Use webrtc/base/logging.h in stefan@'s ownership. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: improved logging + ignore packet in abssendtime 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.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/logging.h"
18 #include "webrtc/base/scoped_ptr.h" 19 #include "webrtc/base/scoped_ptr.h"
19 #include "webrtc/base/thread_annotations.h" 20 #include "webrtc/base/thread_annotations.h"
20 #include "webrtc/call.h" 21 #include "webrtc/call.h"
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" 22 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
22 #include "webrtc/system_wrappers/include/event_wrapper.h" 23 #include "webrtc/system_wrappers/include/event_wrapper.h"
23 #include "webrtc/system_wrappers/include/trace.h" 24 #include "webrtc/system_wrappers/include/trace.h"
24 #include "webrtc/test/call_test.h" 25 #include "webrtc/test/call_test.h"
25 #include "webrtc/test/direct_transport.h" 26 #include "webrtc/test/direct_transport.h"
26 #include "webrtc/test/encoder_settings.h" 27 #include "webrtc/test/encoder_settings.h"
27 #include "webrtc/test/fake_decoder.h" 28 #include "webrtc/test/fake_decoder.h"
28 #include "webrtc/test/fake_encoder.h" 29 #include "webrtc/test/fake_encoder.h"
29 #include "webrtc/test/mock_voice_engine.h" 30 #include "webrtc/test/mock_voice_engine.h"
30 #include "webrtc/test/frame_generator_capturer.h" 31 #include "webrtc/test/frame_generator_capturer.h"
31 32
32 namespace webrtc { 33 namespace webrtc {
33 namespace { 34 namespace {
34 // 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
35 // writing tests that don't depend on the trace system. 36 // writing tests that don't depend on the logging system.
36 class TraceObserver { 37 class LogObserver {
37 public: 38 public:
38 TraceObserver() { 39 LogObserver() { rtc::LogMessage::AddLogToStream(&callback_, rtc::LS_INFO); }
39 Trace::set_level_filter(kTraceTerseInfo);
40 40
41 Trace::CreateTrace(); 41 ~LogObserver() { rtc::LogMessage::RemoveLogToStream(&callback_); }
42 Trace::SetTraceCallback(&callback_);
43
44 // Call webrtc trace to initialize the tracer that would otherwise trigger a
45 // data-race if left to be initialized by multiple threads (i.e. threads
46 // spawned by test::DirectTransport members in BitrateEstimatorTest).
47 WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1,
48 "Instantiate without data races.");
49 }
50
51 ~TraceObserver() {
52 Trace::SetTraceCallback(nullptr);
53 Trace::ReturnTrace();
54 }
55 42
56 void PushExpectedLogLine(const std::string& expected_log_line) { 43 void PushExpectedLogLine(const std::string& expected_log_line) {
57 callback_.PushExpectedLogLine(expected_log_line); 44 callback_.PushExpectedLogLine(expected_log_line);
58 } 45 }
59 46
60 EventTypeWrapper Wait() { return callback_.Wait(); } 47 EventTypeWrapper Wait() { return callback_.Wait(); }
61 48
62 private: 49 private:
63 class Callback : public TraceCallback { 50 class Callback : public rtc::LogSink {
64 public: 51 public:
65 Callback() : done_(EventWrapper::Create()) {} 52 Callback() : done_(EventWrapper::Create()) {}
66 53
67 void Print(TraceLevel level, const char* message, int length) override { 54 void OnLogMessage(const std::string& message) override {
68 rtc::CritScope lock(&crit_sect_); 55 rtc::CritScope lock(&crit_sect_);
69 std::string msg(message); 56 // Ignore log lines that are due to missing AST extensions, these are
70 if (msg.find("BitrateEstimator") != std::string::npos) { 57 // logged when we switch back from AST to TOF until the wrapping bitrate
71 received_log_lines_.push_back(msg); 58 // estimator gives up on using AST.
59 if (message.find("BitrateEstimator") != std::string::npos &&
60 message.find("packet is missing") == std::string::npos) {
61 received_log_lines_.push_back(message);
72 } 62 }
63
73 int num_popped = 0; 64 int num_popped = 0;
74 while (!received_log_lines_.empty() && !expected_log_lines_.empty()) { 65 while (!received_log_lines_.empty() && !expected_log_lines_.empty()) {
75 std::string a = received_log_lines_.front(); 66 std::string a = received_log_lines_.front();
76 std::string b = expected_log_lines_.front(); 67 std::string b = expected_log_lines_.front();
77 received_log_lines_.pop_front(); 68 received_log_lines_.pop_front();
78 expected_log_lines_.pop_front(); 69 expected_log_lines_.pop_front();
79 num_popped++; 70 num_popped++;
80 EXPECT_TRUE(a.find(b) != std::string::npos); 71 EXPECT_TRUE(a.find(b) != std::string::npos) << a << " != " << b;
81 } 72 }
82 if (expected_log_lines_.size() <= 0) { 73 if (expected_log_lines_.size() <= 0) {
83 if (num_popped > 0) { 74 if (num_popped > 0) {
84 done_->Set(); 75 done_->Set();
85 } 76 }
86 return; 77 return;
87 } 78 }
88 } 79 }
89 80
90 EventTypeWrapper Wait() { 81 EventTypeWrapper Wait() {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 bool is_sending_receiving_; 244 bool is_sending_receiving_;
254 VideoSendStream* send_stream_; 245 VideoSendStream* send_stream_;
255 AudioReceiveStream* audio_receive_stream_; 246 AudioReceiveStream* audio_receive_stream_;
256 VideoReceiveStream* video_receive_stream_; 247 VideoReceiveStream* video_receive_stream_;
257 rtc::scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_; 248 rtc::scoped_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_;
258 test::FakeEncoder fake_encoder_; 249 test::FakeEncoder fake_encoder_;
259 test::FakeDecoder fake_decoder_; 250 test::FakeDecoder fake_decoder_;
260 }; 251 };
261 252
262 testing::NiceMock<test::MockVoiceEngine> mock_voice_engine_; 253 testing::NiceMock<test::MockVoiceEngine> mock_voice_engine_;
263 TraceObserver receiver_trace_; 254 LogObserver receiver_log_;
264 rtc::scoped_ptr<test::DirectTransport> send_transport_; 255 rtc::scoped_ptr<test::DirectTransport> send_transport_;
265 rtc::scoped_ptr<test::DirectTransport> receive_transport_; 256 rtc::scoped_ptr<test::DirectTransport> receive_transport_;
266 rtc::scoped_ptr<Call> sender_call_; 257 rtc::scoped_ptr<Call> sender_call_;
267 rtc::scoped_ptr<Call> receiver_call_; 258 rtc::scoped_ptr<Call> receiver_call_;
268 VideoReceiveStream::Config receive_config_; 259 VideoReceiveStream::Config receive_config_;
269 std::vector<Stream*> streams_; 260 std::vector<Stream*> streams_;
270 }; 261 };
271 262
272 static const char* kAbsSendTimeLog = 263 static const char* kAbsSendTimeLog =
273 "RemoteBitrateEstimatorAbsSendTime: Instantiating."; 264 "RemoteBitrateEstimatorAbsSendTime: Instantiating.";
274 static const char* kSingleStreamLog = 265 static const char* kSingleStreamLog =
275 "RemoteBitrateEstimatorSingleStream: Instantiating."; 266 "RemoteBitrateEstimatorSingleStream: Instantiating.";
276 267
277 TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) { 268 TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) {
278 send_config_.rtp.extensions.push_back( 269 send_config_.rtp.extensions.push_back(
279 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 270 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
280 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 271 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
281 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 272 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
282 streams_.push_back(new Stream(this, false)); 273 streams_.push_back(new Stream(this, false));
283 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 274 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
284 } 275 }
285 276
286 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForAudio) { 277 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForAudio) {
287 send_config_.rtp.extensions.push_back( 278 send_config_.rtp.extensions.push_back(
288 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 279 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
289 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 280 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
290 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 281 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
291 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 282 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
292 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 283 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
293 streams_.push_back(new Stream(this, true)); 284 streams_.push_back(new Stream(this, true));
294 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 285 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
295 } 286 }
296 287
297 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) { 288 TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) {
298 send_config_.rtp.extensions.push_back( 289 send_config_.rtp.extensions.push_back(
299 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 290 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
300 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 291 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
301 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 292 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
302 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 293 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
303 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 294 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
304 streams_.push_back(new Stream(this, false)); 295 streams_.push_back(new Stream(this, false));
305 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 296 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
306 } 297 }
307 298
308 TEST_F(BitrateEstimatorTest, SwitchesToASTForAudio) { 299 TEST_F(BitrateEstimatorTest, SwitchesToASTForAudio) {
309 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 300 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
310 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 301 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
311 streams_.push_back(new Stream(this, true)); 302 streams_.push_back(new Stream(this, true));
312 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 303 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
313 304
314 send_config_.rtp.extensions.push_back( 305 send_config_.rtp.extensions.push_back(
315 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId)); 306 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId));
316 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 307 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
317 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 308 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
318 streams_.push_back(new Stream(this, true)); 309 streams_.push_back(new Stream(this, true));
319 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 310 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
320 } 311 }
321 312
322 TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) { 313 TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) {
323 send_config_.rtp.extensions.push_back( 314 send_config_.rtp.extensions.push_back(
324 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 315 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
325 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 316 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
326 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 317 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
327 streams_.push_back(new Stream(this, false)); 318 streams_.push_back(new Stream(this, false));
328 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 319 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
329 320
330 send_config_.rtp.extensions[0] = 321 send_config_.rtp.extensions[0] =
331 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId); 322 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId);
332 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 323 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
333 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 324 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
334 streams_.push_back(new Stream(this, false)); 325 streams_.push_back(new Stream(this, false));
335 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 326 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
336 } 327 }
337 328
338 TEST_F(BitrateEstimatorTest, SwitchesToASTThenBackToTOFForVideo) { 329 TEST_F(BitrateEstimatorTest, SwitchesToASTThenBackToTOFForVideo) {
339 send_config_.rtp.extensions.push_back( 330 send_config_.rtp.extensions.push_back(
340 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId)); 331 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId));
341 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 332 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
342 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 333 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
343 streams_.push_back(new Stream(this, false)); 334 streams_.push_back(new Stream(this, false));
344 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 335 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
345 336
346 send_config_.rtp.extensions[0] = 337 send_config_.rtp.extensions[0] =
347 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId); 338 RtpExtension(RtpExtension::kAbsSendTime, kASTExtensionId);
348 receiver_trace_.PushExpectedLogLine("Switching to absolute send time RBE."); 339 receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE.");
349 receiver_trace_.PushExpectedLogLine(kAbsSendTimeLog); 340 receiver_log_.PushExpectedLogLine(kAbsSendTimeLog);
350 streams_.push_back(new Stream(this, false)); 341 streams_.push_back(new Stream(this, false));
351 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 342 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
352 343
353 send_config_.rtp.extensions[0] = 344 send_config_.rtp.extensions[0] =
354 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId); 345 RtpExtension(RtpExtension::kTOffset, kTOFExtensionId);
355 receiver_trace_.PushExpectedLogLine( 346 receiver_log_.PushExpectedLogLine(
356 "WrappingBitrateEstimator: Switching to transmission time offset RBE."); 347 "WrappingBitrateEstimator: Switching to transmission time offset RBE.");
357 receiver_trace_.PushExpectedLogLine(kSingleStreamLog); 348 receiver_log_.PushExpectedLogLine(kSingleStreamLog);
358 streams_.push_back(new Stream(this, false)); 349 streams_.push_back(new Stream(this, false));
359 streams_[0]->StopSending(); 350 streams_[0]->StopSending();
360 streams_[1]->StopSending(); 351 streams_[1]->StopSending();
361 EXPECT_EQ(kEventSignaled, receiver_trace_.Wait()); 352 EXPECT_EQ(kEventSignaled, receiver_log_.Wait());
362 } 353 }
363 } // namespace webrtc 354 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/call/call.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698