Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: webrtc/video/vie_encoder_unittest.cc

Issue 2616393003: Periodically update channel parameters and send TargetBitrate message. (Closed)
Patch Set: Fixed includes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/fakeclock.h"
mflodman 2017/01/13 13:29:38 AFAICT fakeclock.h depends on messagequeue.h, whic
14 #include "webrtc/base/logging.h" 15 #include "webrtc/base/logging.h"
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"
16 #include "webrtc/test/encoder_settings.h" 19 #include "webrtc/test/encoder_settings.h"
17 #include "webrtc/test/fake_encoder.h" 20 #include "webrtc/test/fake_encoder.h"
18 #include "webrtc/test/frame_generator.h" 21 #include "webrtc/test/frame_generator.h"
22 #include "webrtc/test/gmock.h"
19 #include "webrtc/test/gtest.h" 23 #include "webrtc/test/gtest.h"
20 #include "webrtc/video/send_statistics_proxy.h" 24 #include "webrtc/video/send_statistics_proxy.h"
21 #include "webrtc/video/vie_encoder.h" 25 #include "webrtc/video/vie_encoder.h"
22 26
23 namespace { 27 namespace {
24 #if defined(WEBRTC_ANDROID) 28 #if defined(WEBRTC_ANDROID)
25 // TODO(kthelgason): Lower this limit when better testing 29 // TODO(kthelgason): Lower this limit when better testing
26 // on MediaCodec and fallback implementations are in place. 30 // on MediaCodec and fallback implementations are in place.
27 const int kMinPixelsPerFrame = 320 * 180; 31 const int kMinPixelsPerFrame = 320 * 180;
28 #else 32 #else
29 const int kMinPixelsPerFrame = 120 * 90; 33 const int kMinPixelsPerFrame = 120 * 90;
30 #endif 34 #endif
31 } 35 }
32 36
33 namespace webrtc { 37 namespace webrtc {
34 38
35 using DegredationPreference = VideoSendStream::DegradationPreference; 39 using DegredationPreference = VideoSendStream::DegradationPreference;
36 using ScaleReason = ScalingObserverInterface::ScaleReason; 40 using ScaleReason = ScalingObserverInterface::ScaleReason;
41 using ::testing::_;
42 using ::testing::Return;
37 43
38 namespace { 44 namespace {
39 const size_t kMaxPayloadLength = 1440; 45 const size_t kMaxPayloadLength = 1440;
40 const int kTargetBitrateBps = 100000; 46 const int kTargetBitrateBps = 100000;
41 47
42 class TestBuffer : public webrtc::I420Buffer { 48 class TestBuffer : public webrtc::I420Buffer {
43 public: 49 public:
44 TestBuffer(rtc::Event* event, int width, int height) 50 TestBuffer(rtc::Event* event, int width, int height)
45 : I420Buffer(width, height), event_(event) {} 51 : I420Buffer(width, height), event_(event) {}
46 52
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 video_send_config_.encoder_settings.payload_name = payload_name; 161 video_send_config_.encoder_settings.payload_name = payload_name;
156 162
157 VideoEncoderConfig video_encoder_config; 163 VideoEncoderConfig video_encoder_config;
158 video_encoder_config.number_of_streams = num_streams; 164 video_encoder_config.number_of_streams = num_streams;
159 video_encoder_config.max_bitrate_bps = 1000000; 165 video_encoder_config.max_bitrate_bps = 1000000;
160 video_encoder_config.video_stream_factory = 166 video_encoder_config.video_stream_factory =
161 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); 167 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers);
162 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); 168 ConfigureEncoder(std::move(video_encoder_config), nack_enabled);
163 } 169 }
164 170
165 VideoFrame CreateFrame(int64_t ntp_ts, rtc::Event* destruction_event) const { 171 VideoFrame CreateFrame(int64_t ntp_time_ms,
172 rtc::Event* destruction_event) const {
166 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( 173 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>(
167 destruction_event, codec_width_, codec_height_), 174 destruction_event, codec_width_, codec_height_),
168 99, 99, kVideoRotation_0); 175 99, 99, kVideoRotation_0);
169 frame.set_ntp_time_ms(ntp_ts); 176 frame.set_ntp_time_ms(ntp_time_ms);
170 return frame; 177 return frame;
171 } 178 }
172 179
173 VideoFrame CreateFrame(int64_t ntp_ts, int width, int height) const { 180 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const {
174 VideoFrame frame( 181 VideoFrame frame(
175 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, 182 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99,
176 kVideoRotation_0); 183 kVideoRotation_0);
177 frame.set_ntp_time_ms(ntp_ts); 184 frame.set_ntp_time_ms(ntp_time_ms);
178 return frame; 185 return frame;
179 } 186 }
180 187
181 class TestEncoder : public test::FakeEncoder { 188 class TestEncoder : public test::FakeEncoder {
182 public: 189 public:
183 TestEncoder() 190 TestEncoder()
184 : FakeEncoder(Clock::GetRealTimeClock()), 191 : FakeEncoder(Clock::GetRealTimeClock()),
185 continue_encode_event_(false, false) {} 192 continue_encode_event_(false, false) {}
186 193
187 VideoCodec codec_config() { 194 VideoCodec codec_config() {
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 978
972 vie_encoder_->Stop(); 979 vie_encoder_->Stop();
973 980
974 stats_proxy_.reset(); 981 stats_proxy_.reset();
975 EXPECT_EQ(1, 982 EXPECT_EQ(1,
976 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); 983 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
977 EXPECT_EQ( 984 EXPECT_EQ(
978 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); 985 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
979 } 986 }
980 987
988 TEST_F(ViEEncoderTest, CallsBitrateObserver) {
989 class MockBitrateObserver : public VideoBitrateAllocationObserver {
990 public:
991 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&));
992 } bitrate_observer;
993 vie_encoder_->SetBitrateObserver(&bitrate_observer);
994
995 const int kDefaultFps = 30;
996 const BitrateAllocation expected_bitrate =
997 DefaultVideoBitrateAllocator(fake_encoder_.codec_config())
998 .GetAllocation(kTargetBitrateBps, kDefaultFps);
999
1000 rtc::ScopedFakeClock fake_clock;
1001
1002 // First called on bitrate updated, then again on first frame.
1003 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1004 .Times(2);
1005 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1006
1007 const int64_t kStartTimeMs = 1;
1008 video_source_.IncomingCapturedFrame(
1009 CreateFrame(kStartTimeMs, codec_width_, codec_height_));
1010 sink_.WaitForEncodedFrame(kStartTimeMs);
1011
1012 // Not called on second frame.
1013 fake_clock.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec);
1014 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1015 .Times(0);
1016 video_source_.IncomingCapturedFrame(
1017 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_));
1018 sink_.WaitForEncodedFrame(kStartTimeMs + 1);
1019
1020 // Called after a process interval.
1021 const int64_t kProcessIntervalMs =
1022 vcm::VCMProcessTimer::kDefaultProcessIntervalMs;
1023 fake_clock.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec *
1024 kProcessIntervalMs);
1025 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1026 .Times(1);
1027 video_source_.IncomingCapturedFrame(CreateFrame(
1028 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_));
1029 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs);
1030
1031 vie_encoder_->Stop();
1032 }
1033
981 } // namespace webrtc 1034 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698