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

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

Issue 2838233002: Add PeerConnectionInterface::UpdateCallBitrate with call tests. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 10
11 #include <list> 11 #include <list>
12 #include <map> 12 #include <map>
13 #include <memory> 13 #include <memory>
14 #include <utility>
14 15
16 #include "webrtc/base/ptr_util.h"
15 #include "webrtc/call/audio_state.h" 17 #include "webrtc/call/audio_state.h"
16 #include "webrtc/call/call.h" 18 #include "webrtc/call/call.h"
17 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
18 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" 20 #include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
21 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont roller.h"
19 #include "webrtc/test/gtest.h" 22 #include "webrtc/test/gtest.h"
20 #include "webrtc/test/mock_audio_decoder_factory.h" 23 #include "webrtc/test/mock_audio_decoder_factory.h"
21 #include "webrtc/test/mock_transport.h" 24 #include "webrtc/test/mock_transport.h"
22 #include "webrtc/test/mock_voice_engine.h" 25 #include "webrtc/test/mock_voice_engine.h"
23 26
24 namespace { 27 namespace {
25 28
26 struct CallHelper { 29 struct CallHelper {
27 explicit CallHelper( 30 explicit CallHelper(
28 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) 31 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 config.remote_ssrc = 5548; 301 config.remote_ssrc = 5548;
299 stream = call->CreateFlexfecReceiveStream(config); 302 stream = call->CreateFlexfecReceiveStream(config);
300 EXPECT_NE(stream, nullptr); 303 EXPECT_NE(stream, nullptr);
301 streams.push_back(stream); 304 streams.push_back(stream);
302 305
303 for (auto s : streams) { 306 for (auto s : streams) {
304 call->DestroyFlexfecReceiveStream(s); 307 call->DestroyFlexfecReceiveStream(s);
305 } 308 }
306 } 309 }
307 310
311 // TODO(zstein): This probably belongs in webrtc/modules/congestion_controller/
312 class MockSendSideCongestionController : public SendSideCongestionController {
313 public:
314 MockSendSideCongestionController(const Clock* clock,
315 Observer* observer,
316 RtcEventLog* event_log,
317 PacketRouter* packet_router)
318 : SendSideCongestionController(clock,
319 observer,
320 event_log,
321 packet_router) {}
322
323 MOCK_METHOD3(SetBweBitrates, void(int, int, int));
324 };
325
326 class FakeRtpTransportController : public RtpTransportControllerSendInterface {
327 public:
328 explicit FakeRtpTransportController(PacketRouter* r,
329 SendSideCongestionController* cc)
330 : packet_router_(r), send_side_cc_(cc) {}
331
332 PacketRouter* packet_router() override { return packet_router_; }
333
334 SendSideCongestionController* send_side_cc() override {
335 return send_side_cc_;
336 }
337
338 TransportFeedbackObserver* transport_feedback_observer() override {
339 return send_side_cc_;
340 }
341
342 RtpPacketSender* packet_sender() override { return nullptr; }
343
344 private:
345 PacketRouter* packet_router_;
346 SendSideCongestionController* send_side_cc_;
347 };
348
349 class CallBitrateTest : public testing::Test {
350 public:
351 void SetUp() {
352 Clock* clock = Clock::GetRealTimeClock(); // TODO(zstein): test clock?
353 mock_cc_ =
354 rtc::MakeUnique<testing::NiceMock<MockSendSideCongestionController>>(
355 clock, nullptr, &event_log_, &packet_router_);
356 }
357
358 void SetCall() {
Taylor_Brandstetter 2017/04/26 15:46:11 nit: "CreateCall"?
Zach Stein 2017/05/04 22:32:44 Done.
359 Call::Config config(&event_log_);
360 SetCall(config);
361 }
362
363 void SetCall(const Call::Config& config) {
364 std::unique_ptr<RtpTransportControllerSendInterface> fake_controller =
365 rtc::MakeUnique<FakeRtpTransportController>(&packet_router_,
366 mock_cc_.get());
367 call_.reset(Call::Create(config, std::move(fake_controller)));
368 }
369
370 std::unique_ptr<testing::NiceMock<MockSendSideCongestionController>> mock_cc_;
371 std::unique_ptr<Call> call_;
372
373 webrtc::RtcEventLogNullImpl event_log_;
374
375 private:
376 PacketRouter packet_router_; // TODO(zstein): fake?
377 };
378
379 using testing::_;
380
381 TEST_F(CallBitrateTest, MinMaskPreferred) {
382 SetCall();
383 Call::Config::BitrateConfigMask mask;
384 mask.min_bitrate_bps = rtc::Optional<int>(1234);
385
386 EXPECT_CALL(*mock_cc_, SetBweBitrates(*mask.min_bitrate_bps, _, _));
387 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok());
388 }
389
390 TEST_F(CallBitrateTest, StartMaskPreferred) {
391 SetCall();
392 Call::Config::BitrateConfigMask mask;
393 mask.start_bitrate_bps = rtc::Optional<int>(1234);
394
395 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, *mask.start_bitrate_bps, _));
396 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok());
397 }
Taylor_Brandstetter 2017/04/26 15:46:11 Could also test setting the same "start_bitrate_bp
Zach Stein 2017/05/04 22:32:44 Great idea, thanks.
398
399 TEST_F(CallBitrateTest, SmallerMaskMaxUsed) {
400 Call::Config config(&event_log_);
401 config.bitrate_config.max_bitrate_bps =
402 config.bitrate_config.start_bitrate_bps + 2000;
403 SetCall(config);
404
405 Call::Config::BitrateConfigMask mask;
406 mask.max_bitrate_bps =
407 rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 1000);
408
409 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, _, *mask.max_bitrate_bps));
410 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok());
411 }
412
413 TEST_F(CallBitrateTest, SmallerConfigMaxUsed) {
414 Call::Config config(&event_log_);
415 config.bitrate_config.max_bitrate_bps =
416 config.bitrate_config.start_bitrate_bps + 1000;
417 SetCall(config);
418
419 Call::Config::BitrateConfigMask mask;
420 mask.max_bitrate_bps =
421 rtc::Optional<int>(config.bitrate_config.start_bitrate_bps + 2000);
422
423 // Expect no calls because nothing changes
424 EXPECT_CALL(*mock_cc_, SetBweBitrates(_, _, _)).Times(0);
425 EXPECT_TRUE(call_->SetBitrateConfigMask(mask).ok());
426 }
427
428 TEST_F(CallBitrateTest, MaskStartLessThanConfigMinFails) {
Taylor_Brandstetter 2017/04/26 15:46:11 I'm not sure if it should work this way. Since the
Zach Stein 2017/05/04 22:32:43 What do you think about having PeerConnection::Set
Taylor Brandstetter 2017/05/05 08:04:32 That's a good idea. RTCError was actually meant to
Zach Stein 2017/05/09 00:41:26 I was thinking that inconsistency was "less bad" s
Taylor Brandstetter 2017/05/09 15:51:54 That sounds good to me. I think this is what's mos
429 Call::Config config(&event_log_);
430 config.bitrate_config.min_bitrate_bps = 2000;
431 SetCall(config);
432
433 Call::Config::BitrateConfigMask mask;
434 mask.start_bitrate_bps = rtc::Optional<int>(1000);
435
436 EXPECT_FALSE(call_->SetBitrateConfigMask(mask).ok());
437 }
438
439 TEST_F(CallBitrateTest, MaskMaxLessThanConfigStartFails) {
440 Call::Config config(&event_log_);
441 config.bitrate_config.start_bitrate_bps = 2000;
442 SetCall(config);
443
444 Call::Config::BitrateConfigMask mask;
445 mask.max_bitrate_bps = rtc::Optional<int>(1000);
446
447 EXPECT_FALSE(call_->SetBitrateConfigMask(mask).ok());
448 }
449
450 TEST_F(CallBitrateTest, MaskMaxLessThanConfigMinFails) {
451 Call::Config config(&event_log_);
452 config.bitrate_config.min_bitrate_bps = 2000;
453 SetCall(config);
454
455 Call::Config::BitrateConfigMask mask;
456 mask.max_bitrate_bps = rtc::Optional<int>(1000);
457
458 EXPECT_FALSE(call_->SetBitrateConfigMask(mask).ok());
459 }
460
461 // TODO(zstein): Delete or rename.
462 TEST_F(CallBitrateTest, TaylorCR) {
463 SetCall();
464
465 Call::Config::BitrateConfig config1;
466 config1.min_bitrate_bps = 0;
467 config1.start_bitrate_bps = 1000;
468 config1.max_bitrate_bps = -1;
469
470 Call::Config::BitrateConfig config2;
471 config2.min_bitrate_bps = 0;
472 config2.start_bitrate_bps = -1;
473 config2.max_bitrate_bps = -1;
474
475 EXPECT_CALL(*mock_cc_, SetBweBitrates(0, 1000, -1));
476 call_->SetBitrateConfig(config1);
477 call_->SetBitrateConfig(config2);
478 }
479
308 } // namespace webrtc 480 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698