| 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 1695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 std::vector<VideoReceiveStream::Config>* receive_configs, | 1706 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1707 VideoEncoderConfig* encoder_config) override { | 1707 VideoEncoderConfig* encoder_config) override { |
| 1708 send_config->encoder_settings.encoder = this; | 1708 send_config->encoder_settings.encoder = this; |
| 1709 send_config->encoder_settings.payload_name = codec_name_; | 1709 send_config->encoder_settings.payload_name = codec_name_; |
| 1710 | 1710 |
| 1711 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { | 1711 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { |
| 1712 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( | 1712 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( |
| 1713 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); | 1713 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); |
| 1714 } | 1714 } |
| 1715 | 1715 |
| 1716 encoder_config->encoder_specific_settings = &encoder_settings_; | 1716 encoder_config->encoder_specific_settings = GetEncoderSpecificSettings(); |
| 1717 encoder_config_ = *encoder_config; | 1717 encoder_config_ = *encoder_config; |
| 1718 } | 1718 } |
| 1719 | 1719 |
| 1720 void OnVideoStreamsCreated( | 1720 void OnVideoStreamsCreated( |
| 1721 VideoSendStream* send_stream, | 1721 VideoSendStream* send_stream, |
| 1722 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1722 const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 1723 stream_ = send_stream; | 1723 stream_ = send_stream; |
| 1724 } | 1724 } |
| 1725 | 1725 |
| 1726 int32_t InitEncode(const VideoCodec* config, | 1726 int32_t InitEncode(const VideoCodec* config, |
| 1727 int32_t number_of_cores, | 1727 int32_t number_of_cores, |
| 1728 size_t max_payload_size) override { | 1728 size_t max_payload_size) override { |
| 1729 EXPECT_EQ(video_codec_type_, config->codecType); | 1729 EXPECT_EQ(video_codec_type_, config->codecType); |
| 1730 VerifyCodecSpecifics(*config); | 1730 VerifyCodecSpecifics(*config); |
| 1731 ++num_initializations_; | 1731 ++num_initializations_; |
| 1732 init_encode_event_.Set(); | 1732 init_encode_event_.Set(); |
| 1733 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1733 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 1734 } | 1734 } |
| 1735 | 1735 |
| 1736 void VerifyCodecSpecifics(const VideoCodec& config) const; | 1736 void VerifyCodecSpecifics(const VideoCodec& config) const; |
| 1737 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1738 GetEncoderSpecificSettings() const; |
| 1737 | 1739 |
| 1738 void PerformTest() override { | 1740 void PerformTest() override { |
| 1739 EXPECT_TRUE( | 1741 EXPECT_TRUE( |
| 1740 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1742 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
| 1741 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; | 1743 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
| 1742 | 1744 |
| 1743 encoder_settings_.frameDroppingOn = true; | 1745 encoder_settings_.frameDroppingOn = true; |
| 1746 encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings(); |
| 1744 stream_->ReconfigureVideoEncoder(encoder_config_); | 1747 stream_->ReconfigureVideoEncoder(encoder_config_); |
| 1745 ASSERT_TRUE( | 1748 ASSERT_TRUE( |
| 1746 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1749 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
| 1747 EXPECT_EQ(2u, num_initializations_) | 1750 EXPECT_EQ(2u, num_initializations_) |
| 1748 << "ReconfigureVideoEncoder did not reinitialize the encoder with " | 1751 << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
| 1749 "new encoder settings."; | 1752 "new encoder settings."; |
| 1750 } | 1753 } |
| 1751 | 1754 |
| 1752 int32_t Encode(const VideoFrame& input_image, | 1755 int32_t Encode(const VideoFrame& input_image, |
| 1753 const CodecSpecificInfo* codec_specific_info, | 1756 const CodecSpecificInfo* codec_specific_info, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1765 VideoEncoderConfig encoder_config_; | 1768 VideoEncoderConfig encoder_config_; |
| 1766 }; | 1769 }; |
| 1767 | 1770 |
| 1768 template <> | 1771 template <> |
| 1769 void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( | 1772 void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( |
| 1770 const VideoCodec& config) const { | 1773 const VideoCodec& config) const { |
| 1771 EXPECT_EQ(0, memcmp(&config.codecSpecific.H264, &encoder_settings_, | 1774 EXPECT_EQ(0, memcmp(&config.codecSpecific.H264, &encoder_settings_, |
| 1772 sizeof(encoder_settings_))); | 1775 sizeof(encoder_settings_))); |
| 1773 } | 1776 } |
| 1774 template <> | 1777 template <> |
| 1778 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1779 VideoCodecConfigObserver<VideoCodecH264>::GetEncoderSpecificSettings() const { |
| 1780 return new rtc::RefCountedObject< |
| 1781 VideoEncoderConfig::H264EncoderSpecificSettings>(encoder_settings_); |
| 1782 } |
| 1783 |
| 1784 template <> |
| 1775 void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( | 1785 void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( |
| 1776 const VideoCodec& config) const { | 1786 const VideoCodec& config) const { |
| 1777 // Check that the number of temporal layers has propagated properly to | 1787 // Check that the number of temporal layers has propagated properly to |
| 1778 // VideoCodec. | 1788 // VideoCodec. |
| 1779 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1789 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1780 config.codecSpecific.VP8.numberOfTemporalLayers); | 1790 config.codecSpecific.VP8.numberOfTemporalLayers); |
| 1781 | 1791 |
| 1782 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 1792 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
| 1783 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1793 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1784 config.simulcastStream[i].numberOfTemporalLayers); | 1794 config.simulcastStream[i].numberOfTemporalLayers); |
| 1785 } | 1795 } |
| 1786 | 1796 |
| 1787 // Set expected temporal layers as they should have been set when | 1797 // Set expected temporal layers as they should have been set when |
| 1788 // reconfiguring the encoder and not match the set config. | 1798 // reconfiguring the encoder and not match the set config. |
| 1789 VideoCodecVP8 encoder_settings = encoder_settings_; | 1799 VideoCodecVP8 encoder_settings = encoder_settings_; |
| 1790 encoder_settings.numberOfTemporalLayers = | 1800 encoder_settings.numberOfTemporalLayers = |
| 1791 kVideoCodecConfigObserverNumberOfTemporalLayers; | 1801 kVideoCodecConfigObserverNumberOfTemporalLayers; |
| 1792 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP8, &encoder_settings, | 1802 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP8, &encoder_settings, |
| 1793 sizeof(encoder_settings_))); | 1803 sizeof(encoder_settings_))); |
| 1794 } | 1804 } |
| 1795 template <> | 1805 template <> |
| 1806 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1807 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { |
| 1808 return new rtc::RefCountedObject< |
| 1809 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); |
| 1810 } |
| 1811 |
| 1812 template <> |
| 1796 void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( | 1813 void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( |
| 1797 const VideoCodec& config) const { | 1814 const VideoCodec& config) const { |
| 1798 // Check that the number of temporal layers has propagated properly to | 1815 // Check that the number of temporal layers has propagated properly to |
| 1799 // VideoCodec. | 1816 // VideoCodec. |
| 1800 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1817 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1801 config.codecSpecific.VP9.numberOfTemporalLayers); | 1818 config.codecSpecific.VP9.numberOfTemporalLayers); |
| 1802 | 1819 |
| 1803 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 1820 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
| 1804 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1821 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1805 config.simulcastStream[i].numberOfTemporalLayers); | 1822 config.simulcastStream[i].numberOfTemporalLayers); |
| 1806 } | 1823 } |
| 1807 | 1824 |
| 1808 // Set expected temporal layers as they should have been set when | 1825 // Set expected temporal layers as they should have been set when |
| 1809 // reconfiguring the encoder and not match the set config. | 1826 // reconfiguring the encoder and not match the set config. |
| 1810 VideoCodecVP9 encoder_settings = encoder_settings_; | 1827 VideoCodecVP9 encoder_settings = encoder_settings_; |
| 1811 encoder_settings.numberOfTemporalLayers = | 1828 encoder_settings.numberOfTemporalLayers = |
| 1812 kVideoCodecConfigObserverNumberOfTemporalLayers; | 1829 kVideoCodecConfigObserverNumberOfTemporalLayers; |
| 1813 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP9, &encoder_settings, | 1830 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP9, &encoder_settings, |
| 1814 sizeof(encoder_settings_))); | 1831 sizeof(encoder_settings_))); |
| 1815 } | 1832 } |
| 1833 template <> |
| 1834 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1835 VideoCodecConfigObserver<VideoCodecVP9>::GetEncoderSpecificSettings() const { |
| 1836 return new rtc::RefCountedObject< |
| 1837 VideoEncoderConfig::Vp9EncoderSpecificSettings>(encoder_settings_); |
| 1838 } |
| 1816 | 1839 |
| 1817 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { | 1840 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { |
| 1818 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); | 1841 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); |
| 1819 RunBaseTest(&test); | 1842 RunBaseTest(&test); |
| 1820 } | 1843 } |
| 1821 | 1844 |
| 1822 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { | 1845 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { |
| 1823 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); | 1846 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); |
| 1824 RunBaseTest(&test); | 1847 RunBaseTest(&test); |
| 1825 } | 1848 } |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2138 | 2161 |
| 2139 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; | 2162 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; |
| 2140 | 2163 |
| 2141 private: | 2164 private: |
| 2142 const int kVp9PayloadType = 105; | 2165 const int kVp9PayloadType = 105; |
| 2143 | 2166 |
| 2144 void ModifyVideoConfigs( | 2167 void ModifyVideoConfigs( |
| 2145 VideoSendStream::Config* send_config, | 2168 VideoSendStream::Config* send_config, |
| 2146 std::vector<VideoReceiveStream::Config>* receive_configs, | 2169 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2147 VideoEncoderConfig* encoder_config) override { | 2170 VideoEncoderConfig* encoder_config) override { |
| 2148 encoder_config->encoder_specific_settings = &vp9_settings_; | |
| 2149 send_config->encoder_settings.encoder = vp9_encoder_.get(); | 2171 send_config->encoder_settings.encoder = vp9_encoder_.get(); |
| 2150 send_config->encoder_settings.payload_name = "VP9"; | 2172 send_config->encoder_settings.payload_name = "VP9"; |
| 2151 send_config->encoder_settings.payload_type = kVp9PayloadType; | 2173 send_config->encoder_settings.payload_type = kVp9PayloadType; |
| 2152 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); | 2174 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); |
| 2175 encoder_config->encoder_specific_settings = new rtc::RefCountedObject< |
| 2176 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings_); |
| 2153 EXPECT_EQ(1u, encoder_config->streams.size()); | 2177 EXPECT_EQ(1u, encoder_config->streams.size()); |
| 2154 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( | 2178 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( |
| 2155 vp9_settings_.numberOfTemporalLayers - 1); | 2179 vp9_settings_.numberOfTemporalLayers - 1); |
| 2156 encoder_config_ = *encoder_config; | 2180 encoder_config_ = *encoder_config; |
| 2157 } | 2181 } |
| 2158 | 2182 |
| 2159 void PerformTest() override { | 2183 void PerformTest() override { |
| 2160 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " | 2184 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " |
| 2161 << frames_sent_; | 2185 << frames_sent_; |
| 2162 } | 2186 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 observation_complete_.Set(); | 2549 observation_complete_.Set(); |
| 2526 } | 2550 } |
| 2527 } | 2551 } |
| 2528 } test; | 2552 } test; |
| 2529 | 2553 |
| 2530 RunBaseTest(&test); | 2554 RunBaseTest(&test); |
| 2531 } | 2555 } |
| 2532 #endif // !defined(RTC_DISABLE_VP9) | 2556 #endif // !defined(RTC_DISABLE_VP9) |
| 2533 | 2557 |
| 2534 } // namespace webrtc | 2558 } // namespace webrtc |
| OLD | NEW |