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

Side by Side Diff: webrtc/video/video_send_stream_tests.cc

Issue 2434073003: Extract bitrate allocation of spatial/temporal layers out of codec impl. (Closed)
Patch Set: VideoCodecImpl fix Created 4 years, 1 month 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) 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 <algorithm> // max 10 #include <algorithm> // max
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 last_initialized_frame_height_(0) {} 1429 last_initialized_frame_height_(0) {}
1430 1430
1431 void WaitForResolution(int width, int height) { 1431 void WaitForResolution(int width, int height) {
1432 { 1432 {
1433 rtc::CritScope lock(&crit_); 1433 rtc::CritScope lock(&crit_);
1434 if (last_initialized_frame_width_ == width && 1434 if (last_initialized_frame_width_ == width &&
1435 last_initialized_frame_height_ == height) { 1435 last_initialized_frame_height_ == height) {
1436 return; 1436 return;
1437 } 1437 }
1438 } 1438 }
1439 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); 1439 EXPECT_TRUE(
1440 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
1440 { 1441 {
1441 rtc::CritScope lock(&crit_); 1442 rtc::CritScope lock(&crit_);
1442 EXPECT_EQ(width, last_initialized_frame_width_); 1443 EXPECT_EQ(width, last_initialized_frame_width_);
1443 EXPECT_EQ(height, last_initialized_frame_height_); 1444 EXPECT_EQ(height, last_initialized_frame_height_);
1444 } 1445 }
1445 } 1446 }
1446 1447
1447 private: 1448 private:
1448 int32_t InitEncode(const VideoCodec* config, 1449 int32_t InitEncode(const VideoCodec* config,
1449 int32_t number_of_cores, 1450 int32_t number_of_cores,
1450 size_t max_payload_size) override { 1451 size_t max_payload_size) override {
1451 rtc::CritScope lock(&crit_); 1452 rtc::CritScope lock(&crit_);
1452 last_initialized_frame_width_ = config->width; 1453 last_initialized_frame_width_ = config->width;
1453 last_initialized_frame_height_ = config->height; 1454 last_initialized_frame_height_ = config->height;
1454 ++number_of_initializations_; 1455 ++number_of_initializations_;
1455 // First time InitEncode is called, the frame size is unknown. 1456 init_encode_called_.Set();
1456 if (number_of_initializations_ > 1)
1457 init_encode_called_.Set();
1458 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); 1457 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1459 } 1458 }
1460 1459
1461 int32_t Encode(const VideoFrame& input_image, 1460 int32_t Encode(const VideoFrame& input_image,
1462 const CodecSpecificInfo* codec_specific_info, 1461 const CodecSpecificInfo* codec_specific_info,
1463 const std::vector<FrameType>* frame_types) override { 1462 const std::vector<FrameType>* frame_types) override {
1464 ADD_FAILURE() 1463 ADD_FAILURE()
1465 << "Unexpected Encode call since the send stream is not started"; 1464 << "Unexpected Encode call since the send stream is not started";
1466 return 0; 1465 return 0;
1467 } 1466 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 bitrate_kbps_(0) {} 1576 bitrate_kbps_(0) {}
1578 int32_t InitEncode(const VideoCodec* config, 1577 int32_t InitEncode(const VideoCodec* config,
1579 int32_t number_of_cores, 1578 int32_t number_of_cores,
1580 size_t max_payload_size) override { 1579 size_t max_payload_size) override {
1581 rtc::CritScope lock(&crit_); 1580 rtc::CritScope lock(&crit_);
1582 bitrate_kbps_ = config->startBitrate; 1581 bitrate_kbps_ = config->startBitrate;
1583 encoder_init_.Set(); 1582 encoder_init_.Set();
1584 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); 1583 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1585 } 1584 }
1586 1585
1587 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override { 1586 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
1587 uint32_t framerate) override {
1588 rtc::CritScope lock(&crit_); 1588 rtc::CritScope lock(&crit_);
1589 bitrate_kbps_ = new_target_bitrate; 1589 bitrate_kbps_ = bitrate.get_sum_kbps();
1590 bitrate_changed_.Set(); 1590 bitrate_changed_.Set();
1591 return FakeEncoder::SetRates(new_target_bitrate, framerate); 1591 return FakeEncoder::SetRateAllocation(bitrate, framerate);
1592 } 1592 }
1593 1593
1594 int GetBitrateKbps() const { 1594 int GetBitrateKbps() const {
1595 rtc::CritScope lock(&crit_); 1595 rtc::CritScope lock(&crit_);
1596 return bitrate_kbps_; 1596 return bitrate_kbps_;
1597 } 1597 }
1598 1598
1599 bool WaitForEncoderInit() { 1599 bool WaitForEncoderInit() {
1600 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); 1600 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs);
1601 } 1601 }
(...skipping 13 matching lines...) Expand all
1615 test::NullTransport transport; 1615 test::NullTransport transport;
1616 CreateSendConfig(1, 0, &transport); 1616 CreateSendConfig(1, 0, &transport);
1617 1617
1618 StartStopBitrateObserver encoder; 1618 StartStopBitrateObserver encoder;
1619 video_send_config_.encoder_settings.encoder = &encoder; 1619 video_send_config_.encoder_settings.encoder = &encoder;
1620 video_send_config_.encoder_settings.internal_source = true; 1620 video_send_config_.encoder_settings.internal_source = true;
1621 1621
1622 CreateVideoStreams(); 1622 CreateVideoStreams();
1623 1623
1624 EXPECT_TRUE(encoder.WaitForEncoderInit()); 1624 EXPECT_TRUE(encoder.WaitForEncoderInit());
1625 EXPECT_GT(encoder.GetBitrateKbps(), 0); 1625 EXPECT_TRUE(encoder.WaitBitrateChanged());
1626 EXPECT_EQ(0, encoder.GetBitrateKbps());
1627
1626 video_send_stream_->Start(); 1628 video_send_stream_->Start();
1627 EXPECT_TRUE(encoder.WaitBitrateChanged()); 1629 EXPECT_TRUE(encoder.WaitBitrateChanged());
1628 EXPECT_GT(encoder.GetBitrateKbps(), 0); 1630 EXPECT_GT(encoder.GetBitrateKbps(), 0);
1631
1629 video_send_stream_->Stop(); 1632 video_send_stream_->Stop();
1630 EXPECT_TRUE(encoder.WaitBitrateChanged()); 1633 EXPECT_TRUE(encoder.WaitBitrateChanged());
1631 EXPECT_EQ(0, encoder.GetBitrateKbps()); 1634 EXPECT_EQ(0, encoder.GetBitrateKbps());
1635
1632 video_send_stream_->Start(); 1636 video_send_stream_->Start();
1633 EXPECT_TRUE(encoder.WaitBitrateChanged()); 1637 EXPECT_TRUE(encoder.WaitBitrateChanged());
1634 EXPECT_GT(encoder.GetBitrateKbps(), 0); 1638 EXPECT_GT(encoder.GetBitrateKbps(), 0);
1635 1639
1636 DestroyStreams(); 1640 DestroyStreams();
1637 } 1641 }
1638 1642
1639 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { 1643 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) {
1640 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { 1644 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> {
1641 public: 1645 public:
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2036 // VideoCodec. 2040 // VideoCodec.
2037 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, 2041 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
2038 config.VP8().numberOfTemporalLayers); 2042 config.VP8().numberOfTemporalLayers);
2039 2043
2040 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { 2044 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) {
2041 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, 2045 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
2042 config.simulcastStream[i].numberOfTemporalLayers); 2046 config.simulcastStream[i].numberOfTemporalLayers);
2043 } 2047 }
2044 2048
2045 // Set expected temporal layers as they should have been set when 2049 // Set expected temporal layers as they should have been set when
2046 // reconfiguring the encoder and not match the set config. 2050 // reconfiguring the encoder and not match the set config. Also copy the
2051 // TemporalLayersFactory pointer that has been injected by ViEEncoder.
2047 VideoCodecVP8 encoder_settings = encoder_settings_; 2052 VideoCodecVP8 encoder_settings = encoder_settings_;
2048 encoder_settings.numberOfTemporalLayers = 2053 encoder_settings.numberOfTemporalLayers =
2049 kVideoCodecConfigObserverNumberOfTemporalLayers; 2054 kVideoCodecConfigObserverNumberOfTemporalLayers;
2055 encoder_settings.tl_factory = config.VP8().tl_factory;
2050 EXPECT_EQ( 2056 EXPECT_EQ(
2051 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_))); 2057 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_)));
2052 } 2058 }
2053 2059
2054 template <> 2060 template <>
2055 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> 2061 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings>
2056 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { 2062 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const {
2057 return new rtc::RefCountedObject< 2063 return new rtc::RefCountedObject<
2058 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); 2064 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_);
2059 } 2065 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 // has currently configured but in the span of the set max and min 2267 // has currently configured but in the span of the set max and min
2262 // bitrate. 2268 // bitrate.
2263 } 2269 }
2264 ++num_initializations_; 2270 ++num_initializations_;
2265 init_encode_event_.Set(); 2271 init_encode_event_.Set();
2266 2272
2267 return FakeEncoder::InitEncode(codecSettings, numberOfCores, 2273 return FakeEncoder::InitEncode(codecSettings, numberOfCores,
2268 maxPayloadSize); 2274 maxPayloadSize);
2269 } 2275 }
2270 2276
2271 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { 2277 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
2278 uint32_t frameRate) override {
2272 { 2279 {
2273 rtc::CritScope lock(&crit_); 2280 rtc::CritScope lock(&crit_);
2274 if (target_bitrate_ == newBitRate) { 2281 if (target_bitrate_ == bitrate.get_sum_kbps()) {
2275 return FakeEncoder::SetRates(newBitRate, frameRate); 2282 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
2276 } 2283 }
2277 target_bitrate_ = newBitRate; 2284 target_bitrate_ = bitrate.get_sum_kbps();
2278 } 2285 }
2279 bitrate_changed_event_.Set(); 2286 bitrate_changed_event_.Set();
2280 return FakeEncoder::SetRates(newBitRate, frameRate); 2287 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
2281 } 2288 }
2282 2289
2283 void WaitForSetRates(uint32_t expected_bitrate) { 2290 void WaitForSetRates(uint32_t expected_bitrate) {
2284 EXPECT_TRUE( 2291 EXPECT_TRUE(
2285 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) 2292 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs))
2286 << "Timed out while waiting encoder rate to be set."; 2293 << "Timed out while waiting encoder rate to be set.";
2287 rtc::CritScope lock(&crit_); 2294 rtc::CritScope lock(&crit_);
2288 EXPECT_EQ(expected_bitrate, target_bitrate_); 2295 EXPECT_EQ(expected_bitrate, target_bitrate_);
2289 } 2296 }
2290 2297
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
2945 RequestSourceRotateIfVideoOrientationExtensionNotSupported) { 2952 RequestSourceRotateIfVideoOrientationExtensionNotSupported) {
2946 TestRequestSourceRotateVideo(false); 2953 TestRequestSourceRotateVideo(false);
2947 } 2954 }
2948 2955
2949 TEST_F(VideoSendStreamTest, 2956 TEST_F(VideoSendStreamTest,
2950 DoNotRequestsRotationIfVideoOrientationExtensionSupported) { 2957 DoNotRequestsRotationIfVideoOrientationExtensionSupported) {
2951 TestRequestSourceRotateVideo(true); 2958 TestRequestSourceRotateVideo(true);
2952 } 2959 }
2953 2960
2954 } // namespace webrtc 2961 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698