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 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1471 last_initialized_frame_height_(0) {} | 1471 last_initialized_frame_height_(0) {} |
1472 | 1472 |
1473 void WaitForResolution(int width, int height) { | 1473 void WaitForResolution(int width, int height) { |
1474 { | 1474 { |
1475 rtc::CritScope lock(&crit_); | 1475 rtc::CritScope lock(&crit_); |
1476 if (last_initialized_frame_width_ == width && | 1476 if (last_initialized_frame_width_ == width && |
1477 last_initialized_frame_height_ == height) { | 1477 last_initialized_frame_height_ == height) { |
1478 return; | 1478 return; |
1479 } | 1479 } |
1480 } | 1480 } |
1481 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); | 1481 EXPECT_TRUE( |
| 1482 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
1482 { | 1483 { |
1483 rtc::CritScope lock(&crit_); | 1484 rtc::CritScope lock(&crit_); |
1484 EXPECT_EQ(width, last_initialized_frame_width_); | 1485 EXPECT_EQ(width, last_initialized_frame_width_); |
1485 EXPECT_EQ(height, last_initialized_frame_height_); | 1486 EXPECT_EQ(height, last_initialized_frame_height_); |
1486 } | 1487 } |
1487 } | 1488 } |
1488 | 1489 |
1489 private: | 1490 private: |
1490 int32_t InitEncode(const VideoCodec* config, | 1491 int32_t InitEncode(const VideoCodec* config, |
1491 int32_t number_of_cores, | 1492 int32_t number_of_cores, |
1492 size_t max_payload_size) override { | 1493 size_t max_payload_size) override { |
1493 rtc::CritScope lock(&crit_); | 1494 rtc::CritScope lock(&crit_); |
1494 last_initialized_frame_width_ = config->width; | 1495 last_initialized_frame_width_ = config->width; |
1495 last_initialized_frame_height_ = config->height; | 1496 last_initialized_frame_height_ = config->height; |
1496 ++number_of_initializations_; | 1497 ++number_of_initializations_; |
1497 // First time InitEncode is called, the frame size is unknown. | 1498 init_encode_called_.Set(); |
1498 if (number_of_initializations_ > 1) | |
1499 init_encode_called_.Set(); | |
1500 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1499 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
1501 } | 1500 } |
1502 | 1501 |
1503 int32_t Encode(const VideoFrame& input_image, | 1502 int32_t Encode(const VideoFrame& input_image, |
1504 const CodecSpecificInfo* codec_specific_info, | 1503 const CodecSpecificInfo* codec_specific_info, |
1505 const std::vector<FrameType>* frame_types) override { | 1504 const std::vector<FrameType>* frame_types) override { |
1506 ADD_FAILURE() | 1505 ADD_FAILURE() |
1507 << "Unexpected Encode call since the send stream is not started"; | 1506 << "Unexpected Encode call since the send stream is not started"; |
1508 return 0; | 1507 return 0; |
1509 } | 1508 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 bitrate_kbps_(0) {} | 1618 bitrate_kbps_(0) {} |
1620 int32_t InitEncode(const VideoCodec* config, | 1619 int32_t InitEncode(const VideoCodec* config, |
1621 int32_t number_of_cores, | 1620 int32_t number_of_cores, |
1622 size_t max_payload_size) override { | 1621 size_t max_payload_size) override { |
1623 rtc::CritScope lock(&crit_); | 1622 rtc::CritScope lock(&crit_); |
1624 bitrate_kbps_ = config->startBitrate; | 1623 bitrate_kbps_ = config->startBitrate; |
1625 encoder_init_.Set(); | 1624 encoder_init_.Set(); |
1626 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1625 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
1627 } | 1626 } |
1628 | 1627 |
1629 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override { | 1628 int32_t SetRateAllocation(const BitrateAllocation& bitrate, |
| 1629 uint32_t framerate) override { |
1630 rtc::CritScope lock(&crit_); | 1630 rtc::CritScope lock(&crit_); |
1631 bitrate_kbps_ = new_target_bitrate; | 1631 bitrate_kbps_ = bitrate.get_sum_kbps(); |
1632 bitrate_changed_.Set(); | 1632 bitrate_changed_.Set(); |
1633 return FakeEncoder::SetRates(new_target_bitrate, framerate); | 1633 return FakeEncoder::SetRateAllocation(bitrate, framerate); |
1634 } | 1634 } |
1635 | 1635 |
1636 int GetBitrateKbps() const { | 1636 int GetBitrateKbps() const { |
1637 rtc::CritScope lock(&crit_); | 1637 rtc::CritScope lock(&crit_); |
1638 return bitrate_kbps_; | 1638 return bitrate_kbps_; |
1639 } | 1639 } |
1640 | 1640 |
1641 bool WaitForEncoderInit() { | 1641 bool WaitForEncoderInit() { |
1642 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); | 1642 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); |
1643 } | 1643 } |
(...skipping 13 matching lines...) Expand all Loading... |
1657 test::NullTransport transport; | 1657 test::NullTransport transport; |
1658 CreateSendConfig(1, 0, &transport); | 1658 CreateSendConfig(1, 0, &transport); |
1659 | 1659 |
1660 StartStopBitrateObserver encoder; | 1660 StartStopBitrateObserver encoder; |
1661 video_send_config_.encoder_settings.encoder = &encoder; | 1661 video_send_config_.encoder_settings.encoder = &encoder; |
1662 video_send_config_.encoder_settings.internal_source = true; | 1662 video_send_config_.encoder_settings.internal_source = true; |
1663 | 1663 |
1664 CreateVideoStreams(); | 1664 CreateVideoStreams(); |
1665 | 1665 |
1666 EXPECT_TRUE(encoder.WaitForEncoderInit()); | 1666 EXPECT_TRUE(encoder.WaitForEncoderInit()); |
1667 EXPECT_GT(encoder.GetBitrateKbps(), 0); | 1667 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
| 1668 EXPECT_EQ(0, encoder.GetBitrateKbps()); |
| 1669 |
1668 video_send_stream_->Start(); | 1670 video_send_stream_->Start(); |
1669 EXPECT_TRUE(encoder.WaitBitrateChanged()); | 1671 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
1670 EXPECT_GT(encoder.GetBitrateKbps(), 0); | 1672 EXPECT_GT(encoder.GetBitrateKbps(), 0); |
| 1673 |
1671 video_send_stream_->Stop(); | 1674 video_send_stream_->Stop(); |
1672 EXPECT_TRUE(encoder.WaitBitrateChanged()); | 1675 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
1673 EXPECT_EQ(0, encoder.GetBitrateKbps()); | 1676 EXPECT_EQ(0, encoder.GetBitrateKbps()); |
| 1677 |
1674 video_send_stream_->Start(); | 1678 video_send_stream_->Start(); |
1675 EXPECT_TRUE(encoder.WaitBitrateChanged()); | 1679 EXPECT_TRUE(encoder.WaitBitrateChanged()); |
1676 EXPECT_GT(encoder.GetBitrateKbps(), 0); | 1680 EXPECT_GT(encoder.GetBitrateKbps(), 0); |
1677 | 1681 |
1678 DestroyStreams(); | 1682 DestroyStreams(); |
1679 } | 1683 } |
1680 | 1684 |
1681 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { | 1685 TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { |
1682 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { | 1686 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { |
1683 public: | 1687 public: |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 // VideoCodec. | 2082 // VideoCodec. |
2079 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 2083 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
2080 config.VP8().numberOfTemporalLayers); | 2084 config.VP8().numberOfTemporalLayers); |
2081 | 2085 |
2082 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 2086 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
2083 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 2087 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
2084 config.simulcastStream[i].numberOfTemporalLayers); | 2088 config.simulcastStream[i].numberOfTemporalLayers); |
2085 } | 2089 } |
2086 | 2090 |
2087 // Set expected temporal layers as they should have been set when | 2091 // Set expected temporal layers as they should have been set when |
2088 // reconfiguring the encoder and not match the set config. | 2092 // reconfiguring the encoder and not match the set config. Also copy the |
| 2093 // TemporalLayersFactory pointer that has been injected by ViEEncoder. |
2089 VideoCodecVP8 encoder_settings = encoder_settings_; | 2094 VideoCodecVP8 encoder_settings = encoder_settings_; |
2090 encoder_settings.numberOfTemporalLayers = | 2095 encoder_settings.numberOfTemporalLayers = |
2091 kVideoCodecConfigObserverNumberOfTemporalLayers; | 2096 kVideoCodecConfigObserverNumberOfTemporalLayers; |
| 2097 encoder_settings.tl_factory = config.VP8().tl_factory; |
2092 EXPECT_EQ( | 2098 EXPECT_EQ( |
2093 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_))); | 2099 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_))); |
2094 } | 2100 } |
2095 | 2101 |
2096 template <> | 2102 template <> |
2097 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> | 2103 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
2098 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { | 2104 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { |
2099 return new rtc::RefCountedObject< | 2105 return new rtc::RefCountedObject< |
2100 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); | 2106 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); |
2101 } | 2107 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 // has currently configured but in the span of the set max and min | 2309 // has currently configured but in the span of the set max and min |
2304 // bitrate. | 2310 // bitrate. |
2305 } | 2311 } |
2306 ++num_initializations_; | 2312 ++num_initializations_; |
2307 init_encode_event_.Set(); | 2313 init_encode_event_.Set(); |
2308 | 2314 |
2309 return FakeEncoder::InitEncode(codecSettings, numberOfCores, | 2315 return FakeEncoder::InitEncode(codecSettings, numberOfCores, |
2310 maxPayloadSize); | 2316 maxPayloadSize); |
2311 } | 2317 } |
2312 | 2318 |
2313 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { | 2319 int32_t SetRateAllocation(const BitrateAllocation& bitrate, |
| 2320 uint32_t frameRate) override { |
2314 { | 2321 { |
2315 rtc::CritScope lock(&crit_); | 2322 rtc::CritScope lock(&crit_); |
2316 if (target_bitrate_ == newBitRate) { | 2323 if (target_bitrate_ == bitrate.get_sum_kbps()) { |
2317 return FakeEncoder::SetRates(newBitRate, frameRate); | 2324 return FakeEncoder::SetRateAllocation(bitrate, frameRate); |
2318 } | 2325 } |
2319 target_bitrate_ = newBitRate; | 2326 target_bitrate_ = bitrate.get_sum_kbps(); |
2320 } | 2327 } |
2321 bitrate_changed_event_.Set(); | 2328 bitrate_changed_event_.Set(); |
2322 return FakeEncoder::SetRates(newBitRate, frameRate); | 2329 return FakeEncoder::SetRateAllocation(bitrate, frameRate); |
2323 } | 2330 } |
2324 | 2331 |
2325 void WaitForSetRates(uint32_t expected_bitrate) { | 2332 void WaitForSetRates(uint32_t expected_bitrate) { |
2326 EXPECT_TRUE( | 2333 EXPECT_TRUE( |
2327 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) | 2334 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) |
2328 << "Timed out while waiting encoder rate to be set."; | 2335 << "Timed out while waiting encoder rate to be set."; |
2329 rtc::CritScope lock(&crit_); | 2336 rtc::CritScope lock(&crit_); |
2330 EXPECT_EQ(expected_bitrate, target_bitrate_); | 2337 EXPECT_EQ(expected_bitrate, target_bitrate_); |
2331 } | 2338 } |
2332 | 2339 |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2987 RequestSourceRotateIfVideoOrientationExtensionNotSupported) { | 2994 RequestSourceRotateIfVideoOrientationExtensionNotSupported) { |
2988 TestRequestSourceRotateVideo(false); | 2995 TestRequestSourceRotateVideo(false); |
2989 } | 2996 } |
2990 | 2997 |
2991 TEST_F(VideoSendStreamTest, | 2998 TEST_F(VideoSendStreamTest, |
2992 DoNotRequestsRotationIfVideoOrientationExtensionSupported) { | 2999 DoNotRequestsRotationIfVideoOrientationExtensionSupported) { |
2993 TestRequestSourceRotateVideo(true); | 3000 TestRequestSourceRotateVideo(true); |
2994 } | 3001 } |
2995 | 3002 |
2996 } // namespace webrtc | 3003 } // namespace webrtc |
OLD | NEW |