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