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 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 std::vector<VideoReceiveStream::Config>* receive_configs, | 1480 std::vector<VideoReceiveStream::Config>* receive_configs, |
1481 VideoEncoderConfig* encoder_config) override { | 1481 VideoEncoderConfig* encoder_config) override { |
1482 send_config->encoder_settings.encoder = this; | 1482 send_config->encoder_settings.encoder = this; |
1483 send_config->encoder_settings.payload_name = codec_name_; | 1483 send_config->encoder_settings.payload_name = codec_name_; |
1484 | 1484 |
1485 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { | 1485 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { |
1486 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( | 1486 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( |
1487 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); | 1487 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); |
1488 } | 1488 } |
1489 | 1489 |
1490 encoder_config->encoder_specific_settings = &encoder_settings_; | 1490 encoder_config->encoder_specific_settings = GetEncoderSpecificSettings(); |
1491 encoder_config_ = *encoder_config; | 1491 encoder_config_ = *encoder_config; |
1492 } | 1492 } |
1493 | 1493 |
1494 void OnVideoStreamsCreated( | 1494 void OnVideoStreamsCreated( |
1495 VideoSendStream* send_stream, | 1495 VideoSendStream* send_stream, |
1496 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1496 const std::vector<VideoReceiveStream*>& receive_streams) override { |
1497 stream_ = send_stream; | 1497 stream_ = send_stream; |
1498 } | 1498 } |
1499 | 1499 |
1500 int32_t InitEncode(const VideoCodec* config, | 1500 int32_t InitEncode(const VideoCodec* config, |
1501 int32_t number_of_cores, | 1501 int32_t number_of_cores, |
1502 size_t max_payload_size) override { | 1502 size_t max_payload_size) override { |
1503 EXPECT_EQ(video_codec_type_, config->codecType); | 1503 EXPECT_EQ(video_codec_type_, config->codecType); |
1504 VerifyCodecSpecifics(*config); | 1504 VerifyCodecSpecifics(*config); |
1505 ++num_initializations_; | 1505 ++num_initializations_; |
1506 init_encode_event_.Set(); | 1506 init_encode_event_.Set(); |
1507 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1507 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
1508 } | 1508 } |
1509 | 1509 |
1510 void VerifyCodecSpecifics(const VideoCodec& config) const; | 1510 void VerifyCodecSpecifics(const VideoCodec& config) const; |
| 1511 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1512 GetEncoderSpecificSettings() const; |
1511 | 1513 |
1512 void PerformTest() override { | 1514 void PerformTest() override { |
1513 EXPECT_TRUE( | 1515 EXPECT_TRUE( |
1514 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1516 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
1515 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; | 1517 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
1516 | 1518 |
1517 encoder_settings_.frameDroppingOn = true; | 1519 encoder_settings_.frameDroppingOn = true; |
| 1520 encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings(); |
1518 stream_->ReconfigureVideoEncoder(encoder_config_); | 1521 stream_->ReconfigureVideoEncoder(encoder_config_); |
1519 ASSERT_TRUE( | 1522 ASSERT_TRUE( |
1520 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1523 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
1521 EXPECT_EQ(2u, num_initializations_) | 1524 EXPECT_EQ(2u, num_initializations_) |
1522 << "ReconfigureVideoEncoder did not reinitialize the encoder with " | 1525 << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
1523 "new encoder settings."; | 1526 "new encoder settings."; |
1524 } | 1527 } |
1525 | 1528 |
1526 int32_t Encode(const VideoFrame& input_image, | 1529 int32_t Encode(const VideoFrame& input_image, |
1527 const CodecSpecificInfo* codec_specific_info, | 1530 const CodecSpecificInfo* codec_specific_info, |
(...skipping 11 matching lines...) Expand all Loading... |
1539 VideoEncoderConfig encoder_config_; | 1542 VideoEncoderConfig encoder_config_; |
1540 }; | 1543 }; |
1541 | 1544 |
1542 template <> | 1545 template <> |
1543 void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( | 1546 void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( |
1544 const VideoCodec& config) const { | 1547 const VideoCodec& config) const { |
1545 EXPECT_EQ(0, memcmp(&config.codecSpecific.H264, &encoder_settings_, | 1548 EXPECT_EQ(0, memcmp(&config.codecSpecific.H264, &encoder_settings_, |
1546 sizeof(encoder_settings_))); | 1549 sizeof(encoder_settings_))); |
1547 } | 1550 } |
1548 template <> | 1551 template <> |
| 1552 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1553 VideoCodecConfigObserver<VideoCodecH264>::GetEncoderSpecificSettings() const { |
| 1554 return new rtc::RefCountedObject< |
| 1555 VideoEncoderConfig::H264EncoderSpecificSettings>(encoder_settings_); |
| 1556 } |
| 1557 |
| 1558 template <> |
1549 void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( | 1559 void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( |
1550 const VideoCodec& config) const { | 1560 const VideoCodec& config) const { |
1551 // Check that the number of temporal layers has propagated properly to | 1561 // Check that the number of temporal layers has propagated properly to |
1552 // VideoCodec. | 1562 // VideoCodec. |
1553 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1563 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
1554 config.codecSpecific.VP8.numberOfTemporalLayers); | 1564 config.codecSpecific.VP8.numberOfTemporalLayers); |
1555 | 1565 |
1556 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 1566 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
1557 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1567 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
1558 config.simulcastStream[i].numberOfTemporalLayers); | 1568 config.simulcastStream[i].numberOfTemporalLayers); |
1559 } | 1569 } |
1560 | 1570 |
1561 // Set expected temporal layers as they should have been set when | 1571 // Set expected temporal layers as they should have been set when |
1562 // reconfiguring the encoder and not match the set config. | 1572 // reconfiguring the encoder and not match the set config. |
1563 VideoCodecVP8 encoder_settings = encoder_settings_; | 1573 VideoCodecVP8 encoder_settings = encoder_settings_; |
1564 encoder_settings.numberOfTemporalLayers = | 1574 encoder_settings.numberOfTemporalLayers = |
1565 kVideoCodecConfigObserverNumberOfTemporalLayers; | 1575 kVideoCodecConfigObserverNumberOfTemporalLayers; |
1566 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP8, &encoder_settings, | 1576 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP8, &encoder_settings, |
1567 sizeof(encoder_settings_))); | 1577 sizeof(encoder_settings_))); |
1568 } | 1578 } |
1569 template <> | 1579 template <> |
| 1580 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1581 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { |
| 1582 return new rtc::RefCountedObject< |
| 1583 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); |
| 1584 } |
| 1585 |
| 1586 template <> |
1570 void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( | 1587 void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( |
1571 const VideoCodec& config) const { | 1588 const VideoCodec& config) const { |
1572 // Check that the number of temporal layers has propagated properly to | 1589 // Check that the number of temporal layers has propagated properly to |
1573 // VideoCodec. | 1590 // VideoCodec. |
1574 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1591 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
1575 config.codecSpecific.VP9.numberOfTemporalLayers); | 1592 config.codecSpecific.VP9.numberOfTemporalLayers); |
1576 | 1593 |
1577 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 1594 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
1578 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1595 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
1579 config.simulcastStream[i].numberOfTemporalLayers); | 1596 config.simulcastStream[i].numberOfTemporalLayers); |
1580 } | 1597 } |
1581 | 1598 |
1582 // Set expected temporal layers as they should have been set when | 1599 // Set expected temporal layers as they should have been set when |
1583 // reconfiguring the encoder and not match the set config. | 1600 // reconfiguring the encoder and not match the set config. |
1584 VideoCodecVP9 encoder_settings = encoder_settings_; | 1601 VideoCodecVP9 encoder_settings = encoder_settings_; |
1585 encoder_settings.numberOfTemporalLayers = | 1602 encoder_settings.numberOfTemporalLayers = |
1586 kVideoCodecConfigObserverNumberOfTemporalLayers; | 1603 kVideoCodecConfigObserverNumberOfTemporalLayers; |
1587 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP9, &encoder_settings, | 1604 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP9, &encoder_settings, |
1588 sizeof(encoder_settings_))); | 1605 sizeof(encoder_settings_))); |
1589 } | 1606 } |
| 1607 template <> |
| 1608 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1609 VideoCodecConfigObserver<VideoCodecVP9>::GetEncoderSpecificSettings() const { |
| 1610 return new rtc::RefCountedObject< |
| 1611 VideoEncoderConfig::Vp9EncoderSpecificSettings>(encoder_settings_); |
| 1612 } |
1590 | 1613 |
1591 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { | 1614 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { |
1592 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); | 1615 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); |
1593 RunBaseTest(&test); | 1616 RunBaseTest(&test); |
1594 } | 1617 } |
1595 | 1618 |
1596 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { | 1619 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { |
1597 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); | 1620 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); |
1598 RunBaseTest(&test); | 1621 RunBaseTest(&test); |
1599 } | 1622 } |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1909 | 1932 |
1910 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; | 1933 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; |
1911 | 1934 |
1912 private: | 1935 private: |
1913 const int kVp9PayloadType = 105; | 1936 const int kVp9PayloadType = 105; |
1914 | 1937 |
1915 void ModifyVideoConfigs( | 1938 void ModifyVideoConfigs( |
1916 VideoSendStream::Config* send_config, | 1939 VideoSendStream::Config* send_config, |
1917 std::vector<VideoReceiveStream::Config>* receive_configs, | 1940 std::vector<VideoReceiveStream::Config>* receive_configs, |
1918 VideoEncoderConfig* encoder_config) override { | 1941 VideoEncoderConfig* encoder_config) override { |
1919 encoder_config->encoder_specific_settings = &vp9_settings_; | |
1920 send_config->encoder_settings.encoder = vp9_encoder_.get(); | 1942 send_config->encoder_settings.encoder = vp9_encoder_.get(); |
1921 send_config->encoder_settings.payload_name = "VP9"; | 1943 send_config->encoder_settings.payload_name = "VP9"; |
1922 send_config->encoder_settings.payload_type = kVp9PayloadType; | 1944 send_config->encoder_settings.payload_type = kVp9PayloadType; |
1923 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); | 1945 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); |
| 1946 encoder_config->encoder_specific_settings = new rtc::RefCountedObject< |
| 1947 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings_); |
1924 EXPECT_EQ(1u, encoder_config->streams.size()); | 1948 EXPECT_EQ(1u, encoder_config->streams.size()); |
1925 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( | 1949 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( |
1926 vp9_settings_.numberOfTemporalLayers - 1); | 1950 vp9_settings_.numberOfTemporalLayers - 1); |
1927 encoder_config_ = *encoder_config; | 1951 encoder_config_ = *encoder_config; |
1928 } | 1952 } |
1929 | 1953 |
1930 void PerformTest() override { | 1954 void PerformTest() override { |
1931 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " | 1955 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " |
1932 << frames_sent_; | 1956 << frames_sent_; |
1933 } | 1957 } |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 observation_complete_.Set(); | 2320 observation_complete_.Set(); |
2297 } | 2321 } |
2298 } | 2322 } |
2299 } test; | 2323 } test; |
2300 | 2324 |
2301 RunBaseTest(&test); | 2325 RunBaseTest(&test); |
2302 } | 2326 } |
2303 #endif // !defined(RTC_DISABLE_VP9) | 2327 #endif // !defined(RTC_DISABLE_VP9) |
2304 | 2328 |
2305 } // namespace webrtc | 2329 } // namespace webrtc |
OLD | NEW |