OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 | 10 |
11 #include <limits> | 11 #include <limits> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
15 #include "webrtc/base/fakeclock.h" | |
danilchap
2017/01/10 13:08:15
fakeclock before logging for alphabetical order
sprang_webrtc
2017/01/10 13:26:12
Done.
| |
16 #include "webrtc/base/timeutils.h" | |
17 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h" | |
15 #include "webrtc/system_wrappers/include/metrics_default.h" | 18 #include "webrtc/system_wrappers/include/metrics_default.h" |
19 #include "webrtc/system_wrappers/include/sleep.h" | |
danilchap
2017/01/10 13:08:15
can remove this include
sprang_webrtc
2017/01/10 13:26:12
Done.
| |
16 #include "webrtc/test/encoder_settings.h" | 20 #include "webrtc/test/encoder_settings.h" |
17 #include "webrtc/test/fake_encoder.h" | 21 #include "webrtc/test/fake_encoder.h" |
18 #include "webrtc/test/frame_generator.h" | 22 #include "webrtc/test/frame_generator.h" |
23 #include "webrtc/test/gmock.h" | |
19 #include "webrtc/test/gtest.h" | 24 #include "webrtc/test/gtest.h" |
20 #include "webrtc/video/send_statistics_proxy.h" | 25 #include "webrtc/video/send_statistics_proxy.h" |
21 #include "webrtc/video/vie_encoder.h" | 26 #include "webrtc/video/vie_encoder.h" |
22 | 27 |
23 namespace { | 28 namespace { |
24 #if defined(WEBRTC_ANDROID) | 29 #if defined(WEBRTC_ANDROID) |
25 // TODO(kthelgason): Lower this limit when better testing | 30 // TODO(kthelgason): Lower this limit when better testing |
26 // on MediaCodec and fallback implementations are in place. | 31 // on MediaCodec and fallback implementations are in place. |
27 const int kMinPixelsPerFrame = 320 * 180; | 32 const int kMinPixelsPerFrame = 320 * 180; |
28 #else | 33 #else |
29 const int kMinPixelsPerFrame = 120 * 90; | 34 const int kMinPixelsPerFrame = 120 * 90; |
30 #endif | 35 #endif |
31 } | 36 } |
32 | 37 |
33 namespace webrtc { | 38 namespace webrtc { |
34 | 39 |
35 using DegredationPreference = VideoSendStream::DegradationPreference; | 40 using DegredationPreference = VideoSendStream::DegradationPreference; |
36 using ScaleReason = ScalingObserverInterface::ScaleReason; | 41 using ScaleReason = ScalingObserverInterface::ScaleReason; |
42 using ::testing::_; | |
43 using ::testing::Return; | |
37 | 44 |
38 namespace { | 45 namespace { |
39 const size_t kMaxPayloadLength = 1440; | 46 const size_t kMaxPayloadLength = 1440; |
40 const int kTargetBitrateBps = 100000; | 47 const int kTargetBitrateBps = 100000; |
41 | 48 |
42 class TestBuffer : public webrtc::I420Buffer { | 49 class TestBuffer : public webrtc::I420Buffer { |
43 public: | 50 public: |
44 TestBuffer(rtc::Event* event, int width, int height) | 51 TestBuffer(rtc::Event* event, int width, int height) |
45 : I420Buffer(width, height), event_(event) {} | 52 : I420Buffer(width, height), event_(event) {} |
46 | 53 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 video_send_config_.encoder_settings.payload_name = payload_name; | 162 video_send_config_.encoder_settings.payload_name = payload_name; |
156 | 163 |
157 VideoEncoderConfig video_encoder_config; | 164 VideoEncoderConfig video_encoder_config; |
158 video_encoder_config.number_of_streams = num_streams; | 165 video_encoder_config.number_of_streams = num_streams; |
159 video_encoder_config.max_bitrate_bps = 1000000; | 166 video_encoder_config.max_bitrate_bps = 1000000; |
160 video_encoder_config.video_stream_factory = | 167 video_encoder_config.video_stream_factory = |
161 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); | 168 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
162 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); | 169 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
163 } | 170 } |
164 | 171 |
165 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { | 172 VideoFrame CreateFrame(int64_t ntp_time_ms, |
173 rtc::Event* destruction_event) const { | |
166 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( | 174 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( |
167 destruction_event, codec_width_, codec_height_), | 175 destruction_event, codec_width_, codec_height_), |
168 99, 99, kVideoRotation_0); | 176 99, 99, kVideoRotation_0); |
169 frame.set_ntp_time_ms(ntp_ts); | 177 frame.set_ntp_time_ms(ntp_time_ms); |
170 return frame; | 178 return frame; |
171 } | 179 } |
172 | 180 |
173 VideoFrame CreateFrame(int64_t ntp_ts, int width, int height) const { | 181 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const { |
174 VideoFrame frame( | 182 VideoFrame frame( |
175 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, | 183 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, |
176 kVideoRotation_0); | 184 kVideoRotation_0); |
177 frame.set_ntp_time_ms(ntp_ts); | 185 frame.set_ntp_time_ms(ntp_time_ms); |
178 return frame; | 186 return frame; |
179 } | 187 } |
180 | 188 |
181 class TestEncoder : public test::FakeEncoder { | 189 class TestEncoder : public test::FakeEncoder { |
182 public: | 190 public: |
183 TestEncoder() | 191 TestEncoder() |
184 : FakeEncoder(Clock::GetRealTimeClock()), | 192 : FakeEncoder(Clock::GetRealTimeClock()), |
185 continue_encode_event_(false, false) {} | 193 continue_encode_event_(false, false) {} |
186 | 194 |
187 VideoCodec codec_config() { | 195 VideoCodec codec_config() { |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 | 979 |
972 vie_encoder_->Stop(); | 980 vie_encoder_->Stop(); |
973 | 981 |
974 stats_proxy_.reset(); | 982 stats_proxy_.reset(); |
975 EXPECT_EQ(1, | 983 EXPECT_EQ(1, |
976 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); | 984 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); |
977 EXPECT_EQ( | 985 EXPECT_EQ( |
978 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); | 986 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); |
979 } | 987 } |
980 | 988 |
989 TEST_F(ViEEncoderTest, CallsBitrateObserver) { | |
990 class MockBitrateObserver : public VideoBitrateAllocationObserver { | |
991 public: | |
992 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&)); | |
993 } bitrate_observer; | |
994 vie_encoder_->SetBitrateObserver(&bitrate_observer); | |
995 | |
996 const int kDefaultFps = 30; | |
997 const BitrateAllocation expected_bitrate = | |
998 DefaultVideoBitrateAllocator(fake_encoder_.codec_config()) | |
999 .GetAllocation(kTargetBitrateBps, kDefaultFps); | |
1000 | |
1001 rtc::ScopedFakeClock fake_clock; | |
1002 | |
1003 // First called on bitrate updated, then again on first frame. | |
1004 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | |
1005 .Times(2); | |
1006 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); | |
1007 | |
1008 const int64_t kStartTimeMs = 1; | |
1009 video_source_.IncomingCapturedFrame( | |
1010 CreateFrame(kStartTimeMs, codec_width_, codec_height_)); | |
1011 sink_.WaitForEncodedFrame(kStartTimeMs); | |
1012 | |
1013 // Not called on second frame. | |
1014 fake_clock.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec); | |
1015 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | |
1016 .Times(0); | |
1017 video_source_.IncomingCapturedFrame( | |
1018 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); | |
1019 sink_.WaitForEncodedFrame(kStartTimeMs + 1); | |
1020 | |
1021 // Called after a process interval. | |
1022 const int64_t kProcessIntervalMs = | |
1023 vcm::VCMProcessTimer::kDefaultProcessIntervalMs; | |
1024 fake_clock.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * | |
1025 kProcessIntervalMs); | |
1026 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) | |
1027 .Times(1); | |
1028 video_source_.IncomingCapturedFrame(CreateFrame( | |
1029 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); | |
1030 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); | |
1031 | |
1032 vie_encoder_->Stop(); | |
1033 } | |
1034 | |
981 } // namespace webrtc | 1035 } // namespace webrtc |
OLD | NEW |