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