| OLD | NEW |
| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" | 14 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 15 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" | 15 #include "webrtc/modules/video_coding/codecs/vp8/include/vp8_common_types.h" |
| 16 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" | 16 #include "webrtc/modules/video_coding/codecs/vp8/temporal_layers.h" |
| 17 #include "webrtc/modules/video_coding/include/mock/mock_vcm_callbacks.h" | 17 #include "webrtc/modules/video_coding/include/mock/mock_vcm_callbacks.h" |
| 18 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" | 18 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" |
| 19 #include "webrtc/modules/video_coding/include/video_coding.h" | 19 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 20 #include "webrtc/modules/video_coding/test/test_util.h" | 20 #include "webrtc/modules/video_coding/test/test_util.h" |
| 21 #include "webrtc/modules/video_coding/video_coding_impl.h" | 21 #include "webrtc/modules/video_coding/video_coding_impl.h" |
| 22 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | |
| 23 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | |
| 24 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
| 25 #include "webrtc/test/frame_generator.h" | 23 #include "webrtc/test/frame_generator.h" |
| 26 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
| 27 #include "webrtc/test/testsupport/fileutils.h" | 25 #include "webrtc/test/testsupport/fileutils.h" |
| 28 | 26 |
| 29 using ::testing::_; | 27 using ::testing::_; |
| 30 using ::testing::AllOf; | 28 using ::testing::AllOf; |
| 31 using ::testing::ElementsAre; | 29 using ::testing::ElementsAre; |
| 32 using ::testing::ElementsAreArray; | 30 using ::testing::ElementsAreArray; |
| 33 using ::testing::Field; | 31 using ::testing::Field; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 189 |
| 192 SimulatedClock clock_; | 190 SimulatedClock clock_; |
| 193 EncodedImageCallbackImpl encoded_frame_callback_; | 191 EncodedImageCallbackImpl encoded_frame_callback_; |
| 194 // Used by subclassing tests, need to outlive sender_. | 192 // Used by subclassing tests, need to outlive sender_. |
| 195 std::unique_ptr<VideoEncoder> encoder_; | 193 std::unique_ptr<VideoEncoder> encoder_; |
| 196 std::unique_ptr<VideoSender> sender_; | 194 std::unique_ptr<VideoSender> sender_; |
| 197 std::unique_ptr<FrameGenerator> generator_; | 195 std::unique_ptr<FrameGenerator> generator_; |
| 198 }; | 196 }; |
| 199 | 197 |
| 200 class TestVideoSenderWithMockEncoder : public TestVideoSender { | 198 class TestVideoSenderWithMockEncoder : public TestVideoSender { |
| 201 public: | |
| 202 TestVideoSenderWithMockEncoder() {} | |
| 203 ~TestVideoSenderWithMockEncoder() override {} | |
| 204 | |
| 205 protected: | 199 protected: |
| 206 void SetUp() override { | 200 void SetUp() override { |
| 207 TestVideoSender::SetUp(); | 201 TestVideoSender::SetUp(); |
| 208 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, false); | 202 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, false); |
| 209 VideoCodingModule::Codec(kVideoCodecVP8, &settings_); | 203 VideoCodingModule::Codec(kVideoCodecVP8, &settings_); |
| 210 settings_.numberOfSimulcastStreams = kNumberOfStreams; | 204 settings_.numberOfSimulcastStreams = kNumberOfStreams; |
| 211 ConfigureStream(kDefaultWidth / 4, kDefaultHeight / 4, 100, | 205 ConfigureStream(kDefaultWidth / 4, kDefaultHeight / 4, 100, |
| 212 &settings_.simulcastStream[0]); | 206 &settings_.simulcastStream[0]); |
| 213 ConfigureStream(kDefaultWidth / 2, kDefaultHeight / 2, 500, | 207 ConfigureStream(kDefaultWidth / 2, kDefaultHeight / 2, 500, |
| 214 &settings_.simulcastStream[1]); | 208 &settings_.simulcastStream[1]); |
| 215 ConfigureStream(kDefaultWidth, kDefaultHeight, 1200, | 209 ConfigureStream(kDefaultWidth, kDefaultHeight, 1200, |
| 216 &settings_.simulcastStream[2]); | 210 &settings_.simulcastStream[2]); |
| 217 settings_.plType = kUnusedPayloadType; // Use the mocked encoder. | 211 settings_.plType = kUnusedPayloadType; // Use the mocked encoder. |
| 218 generator_.reset( | 212 generator_.reset( |
| 219 new EmptyFrameGenerator(settings_.width, settings_.height)); | 213 new EmptyFrameGenerator(settings_.width, settings_.height)); |
| 220 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); | 214 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); |
| 221 rate_allocator_.reset(new DefaultVideoBitrateAllocator(settings_)); | |
| 222 } | 215 } |
| 223 | 216 |
| 224 void TearDown() override { sender_.reset(); } | 217 void TearDown() override { sender_.reset(); } |
| 225 | 218 |
| 226 void ExpectIntraRequest(int stream) { | 219 void ExpectIntraRequest(int stream) { |
| 227 ExpectEncodeWithFrameTypes(stream, false); | 220 ExpectEncodeWithFrameTypes(stream, false); |
| 228 } | 221 } |
| 229 | 222 |
| 230 void ExpectInitialKeyFrames() { | 223 void ExpectInitialKeyFrames() { |
| 231 ExpectEncodeWithFrameTypes(-1, true); | 224 ExpectEncodeWithFrameTypes(-1, true); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 261 assert(stream); | 254 assert(stream); |
| 262 stream->width = width; | 255 stream->width = width; |
| 263 stream->height = height; | 256 stream->height = height; |
| 264 stream->maxBitrate = max_bitrate; | 257 stream->maxBitrate = max_bitrate; |
| 265 stream->numberOfTemporalLayers = kNumberOfLayers; | 258 stream->numberOfTemporalLayers = kNumberOfLayers; |
| 266 stream->qpMax = 45; | 259 stream->qpMax = 45; |
| 267 } | 260 } |
| 268 | 261 |
| 269 VideoCodec settings_; | 262 VideoCodec settings_; |
| 270 NiceMock<MockVideoEncoder> encoder_; | 263 NiceMock<MockVideoEncoder> encoder_; |
| 271 std::unique_ptr<DefaultVideoBitrateAllocator> rate_allocator_; | |
| 272 }; | 264 }; |
| 273 | 265 |
| 274 TEST_F(TestVideoSenderWithMockEncoder, TestIntraRequests) { | 266 TEST_F(TestVideoSenderWithMockEncoder, TestIntraRequests) { |
| 275 // Initial request should be all keyframes. | 267 // Initial request should be all keyframes. |
| 276 ExpectInitialKeyFrames(); | 268 ExpectInitialKeyFrames(); |
| 277 AddFrame(); | 269 AddFrame(); |
| 278 EXPECT_EQ(0, sender_->IntraFrameRequest(0)); | 270 EXPECT_EQ(0, sender_->IntraFrameRequest(0)); |
| 279 ExpectIntraRequest(0); | 271 ExpectIntraRequest(0); |
| 280 AddFrame(); | 272 AddFrame(); |
| 281 ExpectIntraRequest(-1); | 273 ExpectIntraRequest(-1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 292 AddFrame(); | 284 AddFrame(); |
| 293 ExpectIntraRequest(-1); | 285 ExpectIntraRequest(-1); |
| 294 AddFrame(); | 286 AddFrame(); |
| 295 | 287 |
| 296 EXPECT_EQ(-1, sender_->IntraFrameRequest(3)); | 288 EXPECT_EQ(-1, sender_->IntraFrameRequest(3)); |
| 297 ExpectIntraRequest(-1); | 289 ExpectIntraRequest(-1); |
| 298 AddFrame(); | 290 AddFrame(); |
| 299 } | 291 } |
| 300 | 292 |
| 301 TEST_F(TestVideoSenderWithMockEncoder, TestSetRate) { | 293 TEST_F(TestVideoSenderWithMockEncoder, TestSetRate) { |
| 302 const uint32_t new_bitrate_kbps = settings_.startBitrate + 300; | 294 const uint32_t new_bitrate = settings_.startBitrate + 300; |
| 303 BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( | 295 EXPECT_CALL(encoder_, SetRates(new_bitrate, _)).Times(1).WillOnce(Return(0)); |
| 304 new_bitrate_kbps * 1000, settings_.maxFramerate); | 296 sender_->SetChannelParameters(new_bitrate * 1000, 0, 200); |
| 305 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, _)) | |
| 306 .Times(1) | |
| 307 .WillOnce(Return(0)); | |
| 308 sender_->SetChannelParameters(new_bitrate_kbps * 1000, 0, 200, | |
| 309 rate_allocator_.get()); | |
| 310 AddFrame(); | 297 AddFrame(); |
| 311 | 298 |
| 312 // Expect no call to encoder_.SetRates if the new bitrate is zero. | 299 // Expect no call to encoder_.SetRates if the new bitrate is zero. |
| 313 EXPECT_CALL(encoder_, SetRateAllocation(_, _)).Times(0); | 300 EXPECT_CALL(encoder_, SetRates(new_bitrate, _)).Times(0); |
| 314 sender_->SetChannelParameters(0, 0, 200, rate_allocator_.get()); | 301 sender_->SetChannelParameters(0, 0, 200); |
| 315 AddFrame(); | 302 AddFrame(); |
| 316 } | 303 } |
| 317 | 304 |
| 318 TEST_F(TestVideoSenderWithMockEncoder, TestIntraRequestsInternalCapture) { | 305 TEST_F(TestVideoSenderWithMockEncoder, TestIntraRequestsInternalCapture) { |
| 319 // De-register current external encoder. | 306 // De-register current external encoder. |
| 320 sender_->RegisterExternalEncoder(nullptr, kUnusedPayloadType, false); | 307 sender_->RegisterExternalEncoder(nullptr, kUnusedPayloadType, false); |
| 321 // Register encoder with internal capture. | 308 // Register encoder with internal capture. |
| 322 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, true); | 309 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, true); |
| 323 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); | 310 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); |
| 324 // Initial request should be all keyframes. | 311 // Initial request should be all keyframes. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 335 } | 322 } |
| 336 | 323 |
| 337 TEST_F(TestVideoSenderWithMockEncoder, TestEncoderParametersForInternalSource) { | 324 TEST_F(TestVideoSenderWithMockEncoder, TestEncoderParametersForInternalSource) { |
| 338 // De-register current external encoder. | 325 // De-register current external encoder. |
| 339 sender_->RegisterExternalEncoder(nullptr, kUnusedPayloadType, false); | 326 sender_->RegisterExternalEncoder(nullptr, kUnusedPayloadType, false); |
| 340 // Register encoder with internal capture. | 327 // Register encoder with internal capture. |
| 341 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, true); | 328 sender_->RegisterExternalEncoder(&encoder_, kUnusedPayloadType, true); |
| 342 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); | 329 EXPECT_EQ(0, sender_->RegisterSendCodec(&settings_, 1, 1200)); |
| 343 // Update encoder bitrate parameters. We expect that to immediately call | 330 // Update encoder bitrate parameters. We expect that to immediately call |
| 344 // SetRates on the encoder without waiting for AddFrame processing. | 331 // SetRates on the encoder without waiting for AddFrame processing. |
| 345 const uint32_t new_bitrate_kbps = settings_.startBitrate + 300; | 332 const uint32_t new_bitrate = settings_.startBitrate + 300; |
| 346 BitrateAllocation new_rate_allocation = rate_allocator_->GetAllocation( | 333 EXPECT_CALL(encoder_, SetRates(new_bitrate, _)).Times(1).WillOnce(Return(0)); |
| 347 new_bitrate_kbps * 1000, settings_.maxFramerate); | 334 sender_->SetChannelParameters(new_bitrate * 1000, 0, 200); |
| 348 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, _)) | |
| 349 .Times(1) | |
| 350 .WillOnce(Return(0)); | |
| 351 sender_->SetChannelParameters(new_bitrate_kbps * 1000, 0, 200, | |
| 352 rate_allocator_.get()); | |
| 353 } | 335 } |
| 354 | 336 |
| 355 TEST_F(TestVideoSenderWithMockEncoder, EncoderFramerateUpdatedViaProcess) { | 337 TEST_F(TestVideoSenderWithMockEncoder, EncoderFramerateUpdatedViaProcess) { |
| 356 sender_->SetChannelParameters(settings_.startBitrate * 1000, 0, 200, | 338 sender_->SetChannelParameters(settings_.startBitrate * 1000, 0, 200); |
| 357 rate_allocator_.get()); | |
| 358 const int64_t kRateStatsWindowMs = 2000; | 339 const int64_t kRateStatsWindowMs = 2000; |
| 359 const uint32_t kInputFps = 20; | 340 const uint32_t kInputFps = 20; |
| 360 int64_t start_time = clock_.TimeInMilliseconds(); | 341 int64_t start_time = clock_.TimeInMilliseconds(); |
| 361 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) { | 342 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) { |
| 362 AddFrame(); | 343 AddFrame(); |
| 363 clock_.AdvanceTimeMilliseconds(1000 / kInputFps); | 344 clock_.AdvanceTimeMilliseconds(1000 / kInputFps); |
| 364 } | 345 } |
| 365 EXPECT_CALL(encoder_, SetRateAllocation(_, kInputFps)) | 346 EXPECT_CALL(encoder_, SetRates(_, kInputFps)).Times(1).WillOnce(Return(0)); |
| 366 .Times(1) | |
| 367 .WillOnce(Return(0)); | |
| 368 sender_->Process(); | 347 sender_->Process(); |
| 369 AddFrame(); | 348 AddFrame(); |
| 370 } | 349 } |
| 371 | 350 |
| 372 TEST_F(TestVideoSenderWithMockEncoder, | 351 TEST_F(TestVideoSenderWithMockEncoder, |
| 373 NoRedundantSetChannelParameterOrSetRatesCalls) { | 352 NoRedundantSetChannelParameterOrSetRatesCalls) { |
| 374 const uint8_t kLossRate = 4; | 353 const uint8_t kLossRate = 4; |
| 375 const uint8_t kRtt = 200; | 354 const uint8_t kRtt = 200; |
| 376 const int64_t kRateStatsWindowMs = 2000; | 355 const int64_t kRateStatsWindowMs = 2000; |
| 377 const uint32_t kInputFps = 20; | 356 const uint32_t kInputFps = 20; |
| 378 int64_t start_time = clock_.TimeInMilliseconds(); | 357 int64_t start_time = clock_.TimeInMilliseconds(); |
| 379 // Expect initial call to SetChannelParameters. Rates are initialized through | 358 // Expect initial call to SetChannelParameters. Rates are initialized through |
| 380 // InitEncode and expects no additional call before the framerate (or bitrate) | 359 // InitEncode and expects no additional call before the framerate (or bitrate) |
| 381 // updates. | 360 // updates. |
| 382 EXPECT_CALL(encoder_, SetChannelParameters(kLossRate, kRtt)) | 361 EXPECT_CALL(encoder_, SetChannelParameters(kLossRate, kRtt)) |
| 383 .Times(1) | 362 .Times(1) |
| 384 .WillOnce(Return(0)); | 363 .WillOnce(Return(0)); |
| 385 sender_->SetChannelParameters(settings_.startBitrate * 1000, kLossRate, kRtt, | 364 sender_->SetChannelParameters(settings_.startBitrate * 1000, kLossRate, kRtt); |
| 386 rate_allocator_.get()); | |
| 387 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) { | 365 while (clock_.TimeInMilliseconds() < start_time + kRateStatsWindowMs) { |
| 388 AddFrame(); | 366 AddFrame(); |
| 389 clock_.AdvanceTimeMilliseconds(1000 / kInputFps); | 367 clock_.AdvanceTimeMilliseconds(1000 / kInputFps); |
| 390 } | 368 } |
| 391 // After process, input framerate should be updated but not ChannelParameters | 369 // After process, input framerate should be updated but not ChannelParameters |
| 392 // as they are the same as before. | 370 // as they are the same as before. |
| 393 EXPECT_CALL(encoder_, SetRateAllocation(_, kInputFps)) | 371 EXPECT_CALL(encoder_, SetRates(_, kInputFps)).Times(1).WillOnce(Return(0)); |
| 394 .Times(1) | |
| 395 .WillOnce(Return(0)); | |
| 396 sender_->Process(); | 372 sender_->Process(); |
| 397 AddFrame(); | 373 AddFrame(); |
| 398 // Call to SetChannelParameters with changed bitrate should call encoder | 374 // Call to SetChannelParameters with changed bitrate should call encoder |
| 399 // SetRates but not encoder SetChannelParameters (that are unchanged). | 375 // SetRates but not encoder SetChannelParameters (that are unchanged). |
| 400 uint32_t new_bitrate_bps = 2 * settings_.startBitrate * 1000; | 376 EXPECT_CALL(encoder_, SetRates(2 * settings_.startBitrate, kInputFps)) |
| 401 BitrateAllocation new_rate_allocation = | |
| 402 rate_allocator_->GetAllocation(new_bitrate_bps, kInputFps); | |
| 403 EXPECT_CALL(encoder_, SetRateAllocation(new_rate_allocation, kInputFps)) | |
| 404 .Times(1) | 377 .Times(1) |
| 405 .WillOnce(Return(0)); | 378 .WillOnce(Return(0)); |
| 406 sender_->SetChannelParameters(new_bitrate_bps, kLossRate, kRtt, | 379 sender_->SetChannelParameters(2 * settings_.startBitrate * 1000, kLossRate, |
| 407 rate_allocator_.get()); | 380 kRtt); |
| 408 AddFrame(); | 381 AddFrame(); |
| 409 } | 382 } |
| 410 | 383 |
| 411 class TestVideoSenderWithVp8 : public TestVideoSender { | 384 class TestVideoSenderWithVp8 : public TestVideoSender { |
| 412 public: | 385 public: |
| 413 TestVideoSenderWithVp8() | 386 TestVideoSenderWithVp8() |
| 414 : codec_bitrate_kbps_(300), available_bitrate_kbps_(1000) {} | 387 : codec_bitrate_kbps_(300), available_bitrate_kbps_(1000) {} |
| 415 | 388 |
| 416 void SetUp() override { | 389 void SetUp() override { |
| 417 TestVideoSender::SetUp(); | 390 TestVideoSender::SetUp(); |
| 418 | 391 |
| 419 const char* input_video = "foreman_cif"; | 392 const char* input_video = "foreman_cif"; |
| 420 const int width = 352; | 393 const int width = 352; |
| 421 const int height = 288; | 394 const int height = 288; |
| 422 generator_.reset(FrameGenerator::CreateFromYuvFile( | 395 generator_.reset(FrameGenerator::CreateFromYuvFile( |
| 423 std::vector<std::string>(1, test::ResourcePath(input_video, "yuv")), | 396 std::vector<std::string>(1, test::ResourcePath(input_video, "yuv")), |
| 424 width, height, 1)); | 397 width, height, 1)); |
| 425 | 398 |
| 426 codec_ = MakeVp8VideoCodec(width, height, 3); | 399 codec_ = MakeVp8VideoCodec(width, height, 3); |
| 427 codec_.minBitrate = 10; | 400 codec_.minBitrate = 10; |
| 428 codec_.startBitrate = codec_bitrate_kbps_; | 401 codec_.startBitrate = codec_bitrate_kbps_; |
| 429 codec_.maxBitrate = codec_bitrate_kbps_; | 402 codec_.maxBitrate = codec_bitrate_kbps_; |
| 430 | |
| 431 TemporalLayersFactory* tl_factory = new TemporalLayersFactory(); | |
| 432 rate_allocator_.reset(new SimulcastRateAllocator( | |
| 433 codec_, std::unique_ptr<TemporalLayersFactory>(tl_factory))); | |
| 434 codec_.codecSpecific.VP8.tl_factory = tl_factory; | |
| 435 | |
| 436 encoder_.reset(VP8Encoder::Create()); | 403 encoder_.reset(VP8Encoder::Create()); |
| 437 sender_->RegisterExternalEncoder(encoder_.get(), codec_.plType, false); | 404 sender_->RegisterExternalEncoder(encoder_.get(), codec_.plType, false); |
| 438 EXPECT_EQ(0, sender_->RegisterSendCodec(&codec_, 1, 1200)); | 405 EXPECT_EQ(0, sender_->RegisterSendCodec(&codec_, 1, 1200)); |
| 439 } | 406 } |
| 440 | 407 |
| 441 static VideoCodec MakeVp8VideoCodec(int width, | 408 static VideoCodec MakeVp8VideoCodec(int width, |
| 442 int height, | 409 int height, |
| 443 int temporal_layers) { | 410 int temporal_layers) { |
| 444 VideoCodec codec; | 411 VideoCodec codec; |
| 445 VideoCodingModule::Codec(kVideoCodecVP8, &codec); | 412 VideoCodingModule::Codec(kVideoCodecVP8, &codec); |
| 446 codec.width = width; | 413 codec.width = width; |
| 447 codec.height = height; | 414 codec.height = height; |
| 448 codec.VP8()->numberOfTemporalLayers = temporal_layers; | 415 codec.VP8()->numberOfTemporalLayers = temporal_layers; |
| 449 return codec; | 416 return codec; |
| 450 } | 417 } |
| 451 | 418 |
| 452 void InsertFrames(float framerate, float seconds) { | 419 void InsertFrames(float framerate, float seconds) { |
| 453 for (int i = 0; i < seconds * framerate; ++i) { | 420 for (int i = 0; i < seconds * framerate; ++i) { |
| 454 clock_.AdvanceTimeMilliseconds(1000.0f / framerate); | 421 clock_.AdvanceTimeMilliseconds(1000.0f / framerate); |
| 455 AddFrame(); | 422 AddFrame(); |
| 456 // SetChannelParameters needs to be called frequently to propagate | 423 // SetChannelParameters needs to be called frequently to propagate |
| 457 // framerate from the media optimization into the encoder. | 424 // framerate from the media optimization into the encoder. |
| 458 // Note: SetChannelParameters fails if less than 2 frames are in the | 425 // Note: SetChannelParameters fails if less than 2 frames are in the |
| 459 // buffer since it will fail to calculate the framerate. | 426 // buffer since it will fail to calculate the framerate. |
| 460 if (i != 0) { | 427 if (i != 0) { |
| 461 EXPECT_EQ(VCM_OK, | 428 EXPECT_EQ(VCM_OK, sender_->SetChannelParameters( |
| 462 sender_->SetChannelParameters(available_bitrate_kbps_ * 1000, | 429 available_bitrate_kbps_ * 1000, 0, 200)); |
| 463 0, 200, rate_allocator_.get())); | |
| 464 } | 430 } |
| 465 } | 431 } |
| 466 } | 432 } |
| 467 | 433 |
| 468 Vp8StreamInfo SimulateWithFramerate(float framerate) { | 434 Vp8StreamInfo SimulateWithFramerate(float framerate) { |
| 469 const float short_simulation_interval = 5.0; | 435 const float short_simulation_interval = 5.0; |
| 470 const float long_simulation_interval = 10.0; | 436 const float long_simulation_interval = 10.0; |
| 471 // It appears that this 5 seconds simulation is needed to allow | 437 // It appears that this 5 seconds simulation is needed to allow |
| 472 // bitrate and framerate to stabilize. | 438 // bitrate and framerate to stabilize. |
| 473 InsertFrames(framerate, short_simulation_interval); | 439 InsertFrames(framerate, short_simulation_interval); |
| 474 encoded_frame_callback_.Reset(); | 440 encoded_frame_callback_.Reset(); |
| 475 | 441 |
| 476 InsertFrames(framerate, long_simulation_interval); | 442 InsertFrames(framerate, long_simulation_interval); |
| 477 return encoded_frame_callback_.CalculateVp8StreamInfo(); | 443 return encoded_frame_callback_.CalculateVp8StreamInfo(); |
| 478 } | 444 } |
| 479 | 445 |
| 480 protected: | 446 protected: |
| 481 VideoCodec codec_; | 447 VideoCodec codec_; |
| 482 int codec_bitrate_kbps_; | 448 int codec_bitrate_kbps_; |
| 483 int available_bitrate_kbps_; | 449 int available_bitrate_kbps_; |
| 484 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; | |
| 485 }; | 450 }; |
| 486 | 451 |
| 487 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 452 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 488 #define MAYBE_FixedTemporalLayersStrategy DISABLED_FixedTemporalLayersStrategy | 453 #define MAYBE_FixedTemporalLayersStrategy DISABLED_FixedTemporalLayersStrategy |
| 489 #else | 454 #else |
| 490 #define MAYBE_FixedTemporalLayersStrategy FixedTemporalLayersStrategy | 455 #define MAYBE_FixedTemporalLayersStrategy FixedTemporalLayersStrategy |
| 491 #endif | 456 #endif |
| 492 TEST_F(TestVideoSenderWithVp8, MAYBE_FixedTemporalLayersStrategy) { | 457 TEST_F(TestVideoSenderWithVp8, MAYBE_FixedTemporalLayersStrategy) { |
| 493 const int low_b = codec_bitrate_kbps_ * kVp8LayerRateAlloction[2][0]; | 458 const int low_b = codec_bitrate_kbps_ * kVp8LayerRateAlloction[2][0]; |
| 494 const int mid_b = codec_bitrate_kbps_ * kVp8LayerRateAlloction[2][1]; | 459 const int mid_b = codec_bitrate_kbps_ * kVp8LayerRateAlloction[2][1]; |
| 495 const int high_b = codec_bitrate_kbps_ * kVp8LayerRateAlloction[2][2]; | 460 const int high_b = codec_bitrate_kbps_ * kVp8LayerRateAlloction[2][2]; |
| 496 { | 461 { |
| 497 Vp8StreamInfo expected = {{7.5, 15.0, 30.0}, {low_b, mid_b, high_b}}; | 462 Vp8StreamInfo expected = {{7.5, 15.0, 30.0}, {low_b, mid_b, high_b}}; |
| 498 EXPECT_THAT(SimulateWithFramerate(30.0), MatchesVp8StreamInfo(expected)); | 463 EXPECT_THAT(SimulateWithFramerate(30.0), MatchesVp8StreamInfo(expected)); |
| 499 } | 464 } |
| 500 { | 465 { |
| 501 Vp8StreamInfo expected = {{3.75, 7.5, 15.0}, {low_b, mid_b, high_b}}; | 466 Vp8StreamInfo expected = {{3.75, 7.5, 15.0}, {low_b, mid_b, high_b}}; |
| 502 EXPECT_THAT(SimulateWithFramerate(15.0), MatchesVp8StreamInfo(expected)); | 467 EXPECT_THAT(SimulateWithFramerate(15.0), MatchesVp8StreamInfo(expected)); |
| 503 } | 468 } |
| 504 } | 469 } |
| 505 | 470 |
| 506 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 471 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 507 #define MAYBE_RealTimeTemporalLayersStrategy \ | 472 #define MAYBE_RealTimeTemporalLayersStrategy \ |
| 508 DISABLED_RealTimeTemporalLayersStrategy | 473 DISABLED_RealTimeTemporalLayersStrategy |
| 509 #else | 474 #else |
| 510 #define MAYBE_RealTimeTemporalLayersStrategy RealTimeTemporalLayersStrategy | 475 #define MAYBE_RealTimeTemporalLayersStrategy RealTimeTemporalLayersStrategy |
| 511 #endif | 476 #endif |
| 512 TEST_F(TestVideoSenderWithVp8, MAYBE_RealTimeTemporalLayersStrategy) { | 477 TEST_F(TestVideoSenderWithVp8, MAYBE_RealTimeTemporalLayersStrategy) { |
| 513 VideoCodec codec = MakeVp8VideoCodec(352, 288, 3); | 478 VideoCodec codec = MakeVp8VideoCodec(352, 288, 3); |
| 479 RealTimeTemporalLayersFactory realtime_tl_factory; |
| 480 codec.VP8()->tl_factory = &realtime_tl_factory; |
| 514 codec.minBitrate = 10; | 481 codec.minBitrate = 10; |
| 515 codec.startBitrate = codec_bitrate_kbps_; | 482 codec.startBitrate = codec_bitrate_kbps_; |
| 516 codec.maxBitrate = codec_bitrate_kbps_; | 483 codec.maxBitrate = codec_bitrate_kbps_; |
| 517 | |
| 518 TemporalLayersFactory* tl_factory = new RealTimeTemporalLayersFactory(); | |
| 519 rate_allocator_.reset(new SimulcastRateAllocator( | |
| 520 codec, std::unique_ptr<TemporalLayersFactory>(tl_factory))); | |
| 521 codec.VP8()->tl_factory = tl_factory; | |
| 522 | |
| 523 EXPECT_EQ(0, sender_->RegisterSendCodec(&codec, 1, 1200)); | 484 EXPECT_EQ(0, sender_->RegisterSendCodec(&codec, 1, 1200)); |
| 524 | 485 |
| 525 const int low_b = codec_bitrate_kbps_ * 0.4; | 486 const int low_b = codec_bitrate_kbps_ * 0.4; |
| 526 const int mid_b = codec_bitrate_kbps_ * 0.6; | 487 const int mid_b = codec_bitrate_kbps_ * 0.6; |
| 527 const int high_b = codec_bitrate_kbps_; | 488 const int high_b = codec_bitrate_kbps_; |
| 528 | 489 |
| 529 { | 490 { |
| 530 Vp8StreamInfo expected = {{7.5, 15.0, 30.0}, {low_b, mid_b, high_b}}; | 491 Vp8StreamInfo expected = {{7.5, 15.0, 30.0}, {low_b, mid_b, high_b}}; |
| 531 EXPECT_THAT(SimulateWithFramerate(30.0), MatchesVp8StreamInfo(expected)); | 492 EXPECT_THAT(SimulateWithFramerate(30.0), MatchesVp8StreamInfo(expected)); |
| 532 } | 493 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 544 } | 505 } |
| 545 { | 506 { |
| 546 // TODO(andresp): Find out why this fails with framerate = 7.5 | 507 // TODO(andresp): Find out why this fails with framerate = 7.5 |
| 547 Vp8StreamInfo expected = {{7.0, 7.0, 7.0}, {high_b, high_b, high_b}}; | 508 Vp8StreamInfo expected = {{7.0, 7.0, 7.0}, {high_b, high_b, high_b}}; |
| 548 EXPECT_THAT(SimulateWithFramerate(7.0), MatchesVp8StreamInfo(expected)); | 509 EXPECT_THAT(SimulateWithFramerate(7.0), MatchesVp8StreamInfo(expected)); |
| 549 } | 510 } |
| 550 } | 511 } |
| 551 } // namespace | 512 } // namespace |
| 552 } // namespace vcm | 513 } // namespace vcm |
| 553 } // namespace webrtc | 514 } // namespace webrtc |
| OLD | NEW |