| 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 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 std::vector<VideoReceiveStream::Config>* receive_configs, | 1719 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1720 VideoEncoderConfig* encoder_config) override { | 1720 VideoEncoderConfig* encoder_config) override { |
| 1721 send_config->encoder_settings.encoder = this; | 1721 send_config->encoder_settings.encoder = this; |
| 1722 send_config->encoder_settings.payload_name = codec_name_; | 1722 send_config->encoder_settings.payload_name = codec_name_; |
| 1723 | 1723 |
| 1724 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { | 1724 for (size_t i = 0; i < encoder_config->streams.size(); ++i) { |
| 1725 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( | 1725 encoder_config->streams[i].temporal_layer_thresholds_bps.resize( |
| 1726 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); | 1726 kVideoCodecConfigObserverNumberOfTemporalLayers - 1); |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 encoder_config->encoder_specific_settings = &encoder_settings_; | 1729 encoder_config->encoder_specific_settings = GetEncoderSpecificSettings(); |
| 1730 encoder_config_ = encoder_config->Copy(); | 1730 encoder_config_ = encoder_config->Copy(); |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 void OnVideoStreamsCreated( | 1733 void OnVideoStreamsCreated( |
| 1734 VideoSendStream* send_stream, | 1734 VideoSendStream* send_stream, |
| 1735 const std::vector<VideoReceiveStream*>& receive_streams) override { | 1735 const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 1736 stream_ = send_stream; | 1736 stream_ = send_stream; |
| 1737 } | 1737 } |
| 1738 | 1738 |
| 1739 int32_t InitEncode(const VideoCodec* config, | 1739 int32_t InitEncode(const VideoCodec* config, |
| 1740 int32_t number_of_cores, | 1740 int32_t number_of_cores, |
| 1741 size_t max_payload_size) override { | 1741 size_t max_payload_size) override { |
| 1742 EXPECT_EQ(video_codec_type_, config->codecType); | 1742 EXPECT_EQ(video_codec_type_, config->codecType); |
| 1743 VerifyCodecSpecifics(*config); | 1743 VerifyCodecSpecifics(*config); |
| 1744 ++num_initializations_; | 1744 ++num_initializations_; |
| 1745 init_encode_event_.Set(); | 1745 init_encode_event_.Set(); |
| 1746 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); | 1746 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 1747 } | 1747 } |
| 1748 | 1748 |
| 1749 void VerifyCodecSpecifics(const VideoCodec& config) const; | 1749 void VerifyCodecSpecifics(const VideoCodec& config) const; |
| 1750 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1751 GetEncoderSpecificSettings() const; |
| 1750 | 1752 |
| 1751 void PerformTest() override { | 1753 void PerformTest() override { |
| 1752 EXPECT_TRUE( | 1754 EXPECT_TRUE( |
| 1753 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1755 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
| 1754 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; | 1756 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
| 1755 | 1757 |
| 1756 encoder_settings_.frameDroppingOn = true; | 1758 encoder_settings_.frameDroppingOn = true; |
| 1759 encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings(); |
| 1757 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); | 1760 stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
| 1758 ASSERT_TRUE( | 1761 ASSERT_TRUE( |
| 1759 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); | 1762 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
| 1760 EXPECT_EQ(2u, num_initializations_) | 1763 EXPECT_EQ(2u, num_initializations_) |
| 1761 << "ReconfigureVideoEncoder did not reinitialize the encoder with " | 1764 << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
| 1762 "new encoder settings."; | 1765 "new encoder settings."; |
| 1763 } | 1766 } |
| 1764 | 1767 |
| 1765 int32_t Encode(const VideoFrame& input_image, | 1768 int32_t Encode(const VideoFrame& input_image, |
| 1766 const CodecSpecificInfo* codec_specific_info, | 1769 const CodecSpecificInfo* codec_specific_info, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1777 VideoSendStream* stream_; | 1780 VideoSendStream* stream_; |
| 1778 VideoEncoderConfig encoder_config_; | 1781 VideoEncoderConfig encoder_config_; |
| 1779 }; | 1782 }; |
| 1780 | 1783 |
| 1781 template <> | 1784 template <> |
| 1782 void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( | 1785 void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( |
| 1783 const VideoCodec& config) const { | 1786 const VideoCodec& config) const { |
| 1784 EXPECT_EQ(0, memcmp(&config.codecSpecific.H264, &encoder_settings_, | 1787 EXPECT_EQ(0, memcmp(&config.codecSpecific.H264, &encoder_settings_, |
| 1785 sizeof(encoder_settings_))); | 1788 sizeof(encoder_settings_))); |
| 1786 } | 1789 } |
| 1790 |
| 1791 template <> |
| 1792 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1793 VideoCodecConfigObserver<VideoCodecH264>::GetEncoderSpecificSettings() const { |
| 1794 return new rtc::RefCountedObject< |
| 1795 VideoEncoderConfig::H264EncoderSpecificSettings>(encoder_settings_); |
| 1796 } |
| 1797 |
| 1787 template <> | 1798 template <> |
| 1788 void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( | 1799 void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( |
| 1789 const VideoCodec& config) const { | 1800 const VideoCodec& config) const { |
| 1790 // Check that the number of temporal layers has propagated properly to | 1801 // Check that the number of temporal layers has propagated properly to |
| 1791 // VideoCodec. | 1802 // VideoCodec. |
| 1792 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1803 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1793 config.codecSpecific.VP8.numberOfTemporalLayers); | 1804 config.codecSpecific.VP8.numberOfTemporalLayers); |
| 1794 | 1805 |
| 1795 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 1806 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
| 1796 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1807 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1797 config.simulcastStream[i].numberOfTemporalLayers); | 1808 config.simulcastStream[i].numberOfTemporalLayers); |
| 1798 } | 1809 } |
| 1799 | 1810 |
| 1800 // Set expected temporal layers as they should have been set when | 1811 // Set expected temporal layers as they should have been set when |
| 1801 // reconfiguring the encoder and not match the set config. | 1812 // reconfiguring the encoder and not match the set config. |
| 1802 VideoCodecVP8 encoder_settings = encoder_settings_; | 1813 VideoCodecVP8 encoder_settings = encoder_settings_; |
| 1803 encoder_settings.numberOfTemporalLayers = | 1814 encoder_settings.numberOfTemporalLayers = |
| 1804 kVideoCodecConfigObserverNumberOfTemporalLayers; | 1815 kVideoCodecConfigObserverNumberOfTemporalLayers; |
| 1805 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP8, &encoder_settings, | 1816 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP8, &encoder_settings, |
| 1806 sizeof(encoder_settings_))); | 1817 sizeof(encoder_settings_))); |
| 1807 } | 1818 } |
| 1819 |
| 1820 template <> |
| 1821 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1822 VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { |
| 1823 return new rtc::RefCountedObject< |
| 1824 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); |
| 1825 } |
| 1826 |
| 1808 template <> | 1827 template <> |
| 1809 void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( | 1828 void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( |
| 1810 const VideoCodec& config) const { | 1829 const VideoCodec& config) const { |
| 1811 // Check that the number of temporal layers has propagated properly to | 1830 // Check that the number of temporal layers has propagated properly to |
| 1812 // VideoCodec. | 1831 // VideoCodec. |
| 1813 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1832 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1814 config.codecSpecific.VP9.numberOfTemporalLayers); | 1833 config.codecSpecific.VP9.numberOfTemporalLayers); |
| 1815 | 1834 |
| 1816 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { | 1835 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
| 1817 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, | 1836 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 1818 config.simulcastStream[i].numberOfTemporalLayers); | 1837 config.simulcastStream[i].numberOfTemporalLayers); |
| 1819 } | 1838 } |
| 1820 | 1839 |
| 1821 // Set expected temporal layers as they should have been set when | 1840 // Set expected temporal layers as they should have been set when |
| 1822 // reconfiguring the encoder and not match the set config. | 1841 // reconfiguring the encoder and not match the set config. |
| 1823 VideoCodecVP9 encoder_settings = encoder_settings_; | 1842 VideoCodecVP9 encoder_settings = encoder_settings_; |
| 1824 encoder_settings.numberOfTemporalLayers = | 1843 encoder_settings.numberOfTemporalLayers = |
| 1825 kVideoCodecConfigObserverNumberOfTemporalLayers; | 1844 kVideoCodecConfigObserverNumberOfTemporalLayers; |
| 1826 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP9, &encoder_settings, | 1845 EXPECT_EQ(0, memcmp(&config.codecSpecific.VP9, &encoder_settings, |
| 1827 sizeof(encoder_settings_))); | 1846 sizeof(encoder_settings_))); |
| 1828 } | 1847 } |
| 1829 | 1848 |
| 1849 template <> |
| 1850 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 1851 VideoCodecConfigObserver<VideoCodecVP9>::GetEncoderSpecificSettings() const { |
| 1852 return new rtc::RefCountedObject< |
| 1853 VideoEncoderConfig::Vp9EncoderSpecificSettings>(encoder_settings_); |
| 1854 } |
| 1855 |
| 1830 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { | 1856 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { |
| 1831 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); | 1857 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); |
| 1832 RunBaseTest(&test); | 1858 RunBaseTest(&test); |
| 1833 } | 1859 } |
| 1834 | 1860 |
| 1835 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { | 1861 TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { |
| 1836 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); | 1862 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); |
| 1837 RunBaseTest(&test); | 1863 RunBaseTest(&test); |
| 1838 } | 1864 } |
| 1839 | 1865 |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 | 2209 |
| 2184 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; | 2210 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; |
| 2185 | 2211 |
| 2186 private: | 2212 private: |
| 2187 const int kVp9PayloadType = 105; | 2213 const int kVp9PayloadType = 105; |
| 2188 | 2214 |
| 2189 void ModifyVideoConfigs( | 2215 void ModifyVideoConfigs( |
| 2190 VideoSendStream::Config* send_config, | 2216 VideoSendStream::Config* send_config, |
| 2191 std::vector<VideoReceiveStream::Config>* receive_configs, | 2217 std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2192 VideoEncoderConfig* encoder_config) override { | 2218 VideoEncoderConfig* encoder_config) override { |
| 2193 encoder_config->encoder_specific_settings = &vp9_settings_; | |
| 2194 send_config->encoder_settings.encoder = vp9_encoder_.get(); | 2219 send_config->encoder_settings.encoder = vp9_encoder_.get(); |
| 2195 send_config->encoder_settings.payload_name = "VP9"; | 2220 send_config->encoder_settings.payload_name = "VP9"; |
| 2196 send_config->encoder_settings.payload_type = kVp9PayloadType; | 2221 send_config->encoder_settings.payload_type = kVp9PayloadType; |
| 2197 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); | 2222 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); |
| 2223 encoder_config->encoder_specific_settings = new rtc::RefCountedObject< |
| 2224 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings_); |
| 2198 EXPECT_EQ(1u, encoder_config->streams.size()); | 2225 EXPECT_EQ(1u, encoder_config->streams.size()); |
| 2199 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( | 2226 encoder_config->streams[0].temporal_layer_thresholds_bps.resize( |
| 2200 vp9_settings_.numberOfTemporalLayers - 1); | 2227 vp9_settings_.numberOfTemporalLayers - 1); |
| 2201 encoder_config_ = encoder_config->Copy(); | 2228 encoder_config_ = encoder_config->Copy(); |
| 2202 } | 2229 } |
| 2203 | 2230 |
| 2204 void PerformTest() override { | 2231 void PerformTest() override { |
| 2205 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " | 2232 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " |
| 2206 << frames_sent_; | 2233 << frames_sent_; |
| 2207 } | 2234 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 observation_complete_.Set(); | 2597 observation_complete_.Set(); |
| 2571 } | 2598 } |
| 2572 } | 2599 } |
| 2573 } test; | 2600 } test; |
| 2574 | 2601 |
| 2575 RunBaseTest(&test); | 2602 RunBaseTest(&test); |
| 2576 } | 2603 } |
| 2577 #endif // !defined(RTC_DISABLE_VP9) | 2604 #endif // !defined(RTC_DISABLE_VP9) |
| 2578 | 2605 |
| 2579 } // namespace webrtc | 2606 } // namespace webrtc |
| OLD | NEW |