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

Side by Side Diff: webrtc/modules/video_coding/video_sender_unittest.cc

Issue 2531383002: Wire up BitrateAllocation to be sent as RTCP TargetBitrate (Closed)
Patch Set: Undo crit removal Created 4 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 | « webrtc/modules/video_coding/video_sender.cc ('k') | webrtc/video/end_to_end_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 10
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 const uint32_t new_bitrate_kbps = settings_.startBitrate + 300; 305 const uint32_t new_bitrate_kbps = settings_.startBitrate + 300;
306 306
307 // Initial frame rate is taken from config, as we have no data yet. 307 // Initial frame rate is taken from config, as we have no data yet.
308 BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( 308 BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation(
309 new_bitrate_kbps * 1000, settings_.maxFramerate); 309 new_bitrate_kbps * 1000, settings_.maxFramerate);
310 EXPECT_CALL(encoder_, 310 EXPECT_CALL(encoder_,
311 SetRateAllocation(new_rate_allocation, settings_.maxFramerate)) 311 SetRateAllocation(new_rate_allocation, settings_.maxFramerate))
312 .Times(1) 312 .Times(1)
313 .WillOnce(Return(0)); 313 .WillOnce(Return(0));
314 sender_->SetChannelParameters(new_bitrate_kbps * 1000, 0, 200, 314 sender_->SetChannelParameters(new_bitrate_kbps * 1000, 0, 200,
315 rate_allocator_.get()); 315 rate_allocator_.get(), nullptr);
316 AddFrame(); 316 AddFrame();
317 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 317 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
318 318
319 // Add enough frames so that input frame rate will be updated. 319 // Add enough frames so that input frame rate will be updated.
320 const int kFramesToSend = 320 const int kFramesToSend =
321 (VCMProcessTimer::kDefaultProcessIntervalMs / kFrameIntervalMs) + 1; 321 (VCMProcessTimer::kDefaultProcessIntervalMs / kFrameIntervalMs) + 1;
322 for (int i = 0; i < kFramesToSend; ++i) { 322 for (int i = 0; i < kFramesToSend; ++i) {
323 AddFrame(); 323 AddFrame();
324 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs); 324 clock_.AdvanceTimeMilliseconds(kFrameIntervalMs);
325 } 325 }
326 326
327 EXPECT_CALL(encoder_, 327 EXPECT_CALL(encoder_,
328 SetRateAllocation(new_rate_allocation, kActualFrameRate)) 328 SetRateAllocation(new_rate_allocation, kActualFrameRate))
329 .Times(1) 329 .Times(1)
330 .WillOnce(Return(0)); 330 .WillOnce(Return(0));
331 331
332 sender_->Process(); 332 sender_->Process();
333 AddFrame(); 333 AddFrame();
334 334
335 // Expect no call to encoder_.SetRates if the new bitrate is zero. 335 // Expect no call to encoder_.SetRates if the new bitrate is zero.
336 EXPECT_CALL(encoder_, SetRateAllocation(_, _)).Times(0); 336 EXPECT_CALL(encoder_, SetRateAllocation(_, _)).Times(0);
337 sender_->SetChannelParameters(0, 0, 200, rate_allocator_.get()); 337 sender_->SetChannelParameters(0, 0, 200, rate_allocator_.get(), nullptr);
338 AddFrame(); 338 AddFrame();
339 } 339 }
340 340
341 TEST_F(TestVideoSenderWithMockEncoder, TestIntraRequestsInternalCapture) { 341 TEST_F(TestVideoSenderWithMockEncoder, TestIntraRequestsInternalCapture) {
342 // De-register current external encoder. 342 // De-register current external encoder.
343 sender_->RegisterExternalEncoder(nullptr, kUnusedPayloadType, false); 343 sender_->RegisterExternalEncoder(nullptr, kUnusedPayloadType, false);
344 // Register encoder with internal capture. 344 // Register encoder with internal capture.
345 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, true); 345 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, true);
346 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); 346 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200));
347 // Initial request should be all keyframes. 347 // Initial request should be all keyframes.
(...skipping 17 matching lines...) Expand all
365 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); 365 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200));
366 // Update encoder bitrate parameters. We expect that to immediately call 366 // Update encoder bitrate parameters. We expect that to immediately call
367 // SetRates on the encoder without waiting for AddFrame processing. 367 // SetRates on the encoder without waiting for AddFrame processing.
368 const uint32_t new_bitrate_kbps = settings_.startBitrate + 300; 368 const uint32_t new_bitrate_kbps = settings_.startBitrate + 300;
369 BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( 369 BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation(
370 new_bitrate_kbps * 1000, settings_.maxFramerate); 370 new_bitrate_kbps * 1000, settings_.maxFramerate);
371 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, _)) 371 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, _))
372 .Times(1) 372 .Times(1)
373 .WillOnce(Return(0)); 373 .WillOnce(Return(0));
374 sender_->SetChannelParameters(new_bitrate_kbps * 1000, 0, 200, 374 sender_->SetChannelParameters(new_bitrate_kbps * 1000, 0, 200,
375 rate_allocator_.get()); 375 rate_allocator_.get(), nullptr);
376 } 376 }
377 377
378 TEST_F(TestVideoSenderWithMockEncoder, EncoderFramerateUpdatedViaProcess) { 378 TEST_F(TestVideoSenderWithMockEncoder, EncoderFramerateUpdatedViaProcess) {
379 sender_->SetChannelParameters(settings_.startBitrate * 1000, 0, 200, 379 sender_->SetChannelParameters(settings_.startBitrate * 1000, 0, 200,
380 rate_allocator_.get()); 380 rate_allocator_.get(), nullptr);
381 const int64_t kRateStatsWindowMs = 2000; 381 const int64_t kRateStatsWindowMs = 2000;
382 const uint32_t kInputFps = 20; 382 const uint32_t kInputFps = 20;
383 int64_t start_time = clock_.TimeInMilliseconds(); 383 int64_t start_time = clock_.TimeInMilliseconds();
384 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) { 384 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) {
385 AddFrame(); 385 AddFrame();
386 clock_.AdvanceTimeMilliseconds(1000 / kInputFps); 386 clock_.AdvanceTimeMilliseconds(1000 / kInputFps);
387 } 387 }
388 EXPECT_CALL(encoder_, SetRateAllocation(_, kInputFps)) 388 EXPECT_CALL(encoder_, SetRateAllocation(_, kInputFps))
389 .Times(1) 389 .Times(1)
390 .WillOnce(Return(0)); 390 .WillOnce(Return(0));
391 sender_->Process(); 391 sender_->Process();
392 AddFrame(); 392 AddFrame();
393 } 393 }
394 394
395 TEST_F(TestVideoSenderWithMockEncoder, 395 TEST_F(TestVideoSenderWithMockEncoder,
396 NoRedundantSetChannelParameterOrSetRatesCalls) { 396 NoRedundantSetChannelParameterOrSetRatesCalls) {
397 const uint8_t kLossRate = 4; 397 const uint8_t kLossRate = 4;
398 const uint8_t kRtt = 200; 398 const uint8_t kRtt = 200;
399 const int64_t kRateStatsWindowMs = 2000; 399 const int64_t kRateStatsWindowMs = 2000;
400 const uint32_t kInputFps = 20; 400 const uint32_t kInputFps = 20;
401 int64_t start_time = clock_.TimeInMilliseconds(); 401 int64_t start_time = clock_.TimeInMilliseconds();
402 // Expect initial call to SetChannelParameters. Rates are initialized through 402 // Expect initial call to SetChannelParameters. Rates are initialized through
403 // InitEncode and expects no additional call before the framerate (or bitrate) 403 // InitEncode and expects no additional call before the framerate (or bitrate)
404 // updates. 404 // updates.
405 EXPECT_CALL(encoder_, SetChannelParameters(kLossRate, kRtt)) 405 EXPECT_CALL(encoder_, SetChannelParameters(kLossRate, kRtt))
406 .Times(1) 406 .Times(1)
407 .WillOnce(Return(0)); 407 .WillOnce(Return(0));
408 sender_->SetChannelParameters(settings_.startBitrate * 1000, kLossRate, kRtt, 408 sender_->SetChannelParameters(settings_.startBitrate * 1000, kLossRate, kRtt,
409 rate_allocator_.get()); 409 rate_allocator_.get(), nullptr);
410 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) { 410 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) {
411 AddFrame(); 411 AddFrame();
412 clock_.AdvanceTimeMilliseconds(1000 / kInputFps); 412 clock_.AdvanceTimeMilliseconds(1000 / kInputFps);
413 } 413 }
414 // After process, input framerate should be updated but not ChannelParameters 414 // After process, input framerate should be updated but not ChannelParameters
415 // as they are the same as before. 415 // as they are the same as before.
416 EXPECT_CALL(encoder_, SetRateAllocation(_, kInputFps)) 416 EXPECT_CALL(encoder_, SetRateAllocation(_, kInputFps))
417 .Times(1) 417 .Times(1)
418 .WillOnce(Return(0)); 418 .WillOnce(Return(0));
419 sender_->Process(); 419 sender_->Process();
420 AddFrame(); 420 AddFrame();
421 // Call to SetChannelParameters with changed bitrate should call encoder 421 // Call to SetChannelParameters with changed bitrate should call encoder
422 // SetRates but not encoder SetChannelParameters (that are unchanged). 422 // SetRates but not encoder SetChannelParameters (that are unchanged).
423 uint32_t new_bitrate_bps = 2 * settings_.startBitrate * 1000; 423 uint32_t new_bitrate_bps = 2 * settings_.startBitrate * 1000;
424 BitrateAllocation new_rate_allocation = 424 BitrateAllocation new_rate_allocation =
425 rate_allocator_->GetAllocation(new_bitrate_bps, kInputFps); 425 rate_allocator_->GetAllocation(new_bitrate_bps, kInputFps);
426 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, kInputFps)) 426 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, kInputFps))
427 .Times(1) 427 .Times(1)
428 .WillOnce(Return(0)); 428 .WillOnce(Return(0));
429 sender_->SetChannelParameters(new_bitrate_bps, kLossRate, kRtt, 429 sender_->SetChannelParameters(new_bitrate_bps, kLossRate, kRtt,
430 rate_allocator_.get()); 430 rate_allocator_.get(), nullptr);
431 AddFrame(); 431 AddFrame();
432 } 432 }
433 433
434 class TestVideoSenderWithVp8 : public TestVideoSender { 434 class TestVideoSenderWithVp8 : public TestVideoSender {
435 public: 435 public:
436 TestVideoSenderWithVp8() 436 TestVideoSenderWithVp8()
437 : codec_bitrate_kbps_(300), available_bitrate_kbps_(1000) {} 437 : codec_bitrate_kbps_(300), available_bitrate_kbps_(1000) {}
438 438
439 void SetUp() override { 439 void SetUp() override {
440 TestVideoSender::SetUp(); 440 TestVideoSender::SetUp();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 void InsertFrames(float framerate, float seconds) { 475 void InsertFrames(float framerate, float seconds) {
476 for (int i = 0; i < seconds * framerate; ++i) { 476 for (int i = 0; i < seconds * framerate; ++i) {
477 clock_.AdvanceTimeMilliseconds(1000.0f / framerate); 477 clock_.AdvanceTimeMilliseconds(1000.0f / framerate);
478 AddFrame(); 478 AddFrame();
479 // SetChannelParameters needs to be called frequently to propagate 479 // SetChannelParameters needs to be called frequently to propagate
480 // framerate from the media optimization into the encoder. 480 // framerate from the media optimization into the encoder.
481 // Note: SetChannelParameters fails if less than 2 frames are in the 481 // Note: SetChannelParameters fails if less than 2 frames are in the
482 // buffer since it will fail to calculate the framerate. 482 // buffer since it will fail to calculate the framerate.
483 if (i != 0) { 483 if (i != 0) {
484 EXPECT_EQ(VCM_OK, 484 EXPECT_EQ(VCM_OK, sender_->SetChannelParameters(
485 sender_->SetChannelParameters(available_bitrate_kbps_ * 1000, 485 available_bitrate_kbps_ * 1000, 0, 200,
486 0, 200, rate_allocator_.get())); 486 rate_allocator_.get(), nullptr));
487 } 487 }
488 } 488 }
489 } 489 }
490 490
491 Vp8StreamInfo SimulateWithFramerate(float framerate) { 491 Vp8StreamInfo SimulateWithFramerate(float framerate) {
492 const float short_simulation_interval = 5.0; 492 const float short_simulation_interval = 5.0;
493 const float long_simulation_interval = 10.0; 493 const float long_simulation_interval = 10.0;
494 // It appears that this 5 seconds simulation is needed to allow 494 // It appears that this 5 seconds simulation is needed to allow
495 // bitrate and framerate to stabilize. 495 // bitrate and framerate to stabilize.
496 InsertFrames(framerate, short_simulation_interval); 496 InsertFrames(framerate, short_simulation_interval);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 567 }
568 { 568 {
569 // TODO(andresp): Find out why this fails with framerate = 7.5 569 // TODO(andresp): Find out why this fails with framerate = 7.5
570 Vp8StreamInfo expected = {{7.0, 7.0, 7.0}, {high_b, high_b, high_b}}; 570 Vp8StreamInfo expected = {{7.0, 7.0, 7.0}, {high_b, high_b, high_b}};
571 EXPECT_THAT(SimulateWithFramerate(7.0), MatchesVp8StreamInfo(expected)); 571 EXPECT_THAT(SimulateWithFramerate(7.0), MatchesVp8StreamInfo(expected));
572 } 572 }
573 } 573 }
574 } // namespace 574 } // namespace
575 } // namespace vcm 575 } // namespace vcm
576 } // namespace webrtc 576 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/video_sender.cc ('k') | webrtc/video/end_to_end_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698