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

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

Issue 2616393003: Periodically update channel parameters and send TargetBitrate message. (Closed)
Patch Set: Rebase 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/api/video/i420_buffer.h" 14 #include "webrtc/api/video/i420_buffer.h"
15 #include "webrtc/base/logging.h" 15 #include "webrtc/base/logging.h"
16 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h"
16 #include "webrtc/system_wrappers/include/metrics_default.h" 17 #include "webrtc/system_wrappers/include/metrics_default.h"
18 #include "webrtc/system_wrappers/include/sleep.h"
17 #include "webrtc/test/encoder_settings.h" 19 #include "webrtc/test/encoder_settings.h"
18 #include "webrtc/test/fake_encoder.h" 20 #include "webrtc/test/fake_encoder.h"
19 #include "webrtc/test/frame_generator.h" 21 #include "webrtc/test/frame_generator.h"
22 #include "webrtc/test/gmock.h"
20 #include "webrtc/test/gtest.h" 23 #include "webrtc/test/gtest.h"
21 #include "webrtc/video/send_statistics_proxy.h" 24 #include "webrtc/video/send_statistics_proxy.h"
22 #include "webrtc/video/vie_encoder.h" 25 #include "webrtc/video/vie_encoder.h"
23 26
24 namespace { 27 namespace {
25 #if defined(WEBRTC_ANDROID) 28 #if defined(WEBRTC_ANDROID)
26 // TODO(kthelgason): Lower this limit when better testing 29 // TODO(kthelgason): Lower this limit when better testing
27 // on MediaCodec and fallback implementations are in place. 30 // on MediaCodec and fallback implementations are in place.
28 const int kMinPixelsPerFrame = 320 * 180; 31 const int kMinPixelsPerFrame = 320 * 180;
29 #else 32 #else
30 const int kMinPixelsPerFrame = 120 * 90; 33 const int kMinPixelsPerFrame = 120 * 90;
31 #endif 34 #endif
32 } 35 }
33 36
34 namespace webrtc { 37 namespace webrtc {
35 38
36 using DegredationPreference = VideoSendStream::DegradationPreference; 39 using DegredationPreference = VideoSendStream::DegradationPreference;
37 using ScaleReason = ScalingObserverInterface::ScaleReason; 40 using ScaleReason = ScalingObserverInterface::ScaleReason;
41 using ::testing::_;
42 using ::testing::Return;
38 43
39 namespace { 44 namespace {
40 const size_t kMaxPayloadLength = 1440; 45 const size_t kMaxPayloadLength = 1440;
41 const int kTargetBitrateBps = 100000; 46 const int kTargetBitrateBps = 100000;
42 47
43 class TestBuffer : public webrtc::I420Buffer { 48 class TestBuffer : public webrtc::I420Buffer {
44 public: 49 public:
45 TestBuffer(rtc::Event* event, int width, int height) 50 TestBuffer(rtc::Event* event, int width, int height)
46 : I420Buffer(width, height), event_(event) {} 51 : I420Buffer(width, height), event_(event) {}
47 52
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 video_send_config_.encoder_settings.payload_name = payload_name; 161 video_send_config_.encoder_settings.payload_name = payload_name;
157 162
158 VideoEncoderConfig video_encoder_config; 163 VideoEncoderConfig video_encoder_config;
159 video_encoder_config.number_of_streams = num_streams; 164 video_encoder_config.number_of_streams = num_streams;
160 video_encoder_config.max_bitrate_bps = 1000000; 165 video_encoder_config.max_bitrate_bps = 1000000;
161 video_encoder_config.video_stream_factory = 166 video_encoder_config.video_stream_factory =
162 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); 167 new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers);
163 ConfigureEncoder(std::move(video_encoder_config), nack_enabled); 168 ConfigureEncoder(std::move(video_encoder_config), nack_enabled);
164 } 169 }
165 170
166 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 {
167 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>( 173 VideoFrame frame(new rtc::RefCountedObject<TestBuffer>(
168 destruction_event, codec_width_, codec_height_), 174 destruction_event, codec_width_, codec_height_),
169 99, 99, kVideoRotation_0); 175 99, 99, kVideoRotation_0);
170 frame.set_ntp_time_ms(ntp_ts); 176 frame.set_ntp_time_ms(ntp_time_ms);
171 return frame; 177 return frame;
172 } 178 }
173 179
174 VideoFrame CreateFrame(int64_t ntp_ts, int width, int height) const { 180 VideoFrame CreateFrame(int64_t ntp_time_ms, int width, int height) const {
175 VideoFrame frame( 181 VideoFrame frame(
176 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99, 182 new rtc::RefCountedObject<TestBuffer>(nullptr, width, height), 99, 99,
177 kVideoRotation_0); 183 kVideoRotation_0);
178 frame.set_ntp_time_ms(ntp_ts); 184 frame.set_ntp_time_ms(ntp_time_ms);
179 return frame; 185 return frame;
180 } 186 }
181 187
182 class TestEncoder : public test::FakeEncoder { 188 class TestEncoder : public test::FakeEncoder {
183 public: 189 public:
184 TestEncoder() 190 TestEncoder()
185 : FakeEncoder(Clock::GetRealTimeClock()), 191 : FakeEncoder(Clock::GetRealTimeClock()),
186 continue_encode_event_(false, false) {} 192 continue_encode_event_(false, false) {}
187 193
188 VideoCodec codec_config() { 194 VideoCodec codec_config() {
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 978
973 vie_encoder_->Stop(); 979 vie_encoder_->Stop();
974 980
975 stats_proxy_.reset(); 981 stats_proxy_.reset();
976 EXPECT_EQ(1, 982 EXPECT_EQ(1,
977 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); 983 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
978 EXPECT_EQ( 984 EXPECT_EQ(
979 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); 985 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
980 } 986 }
981 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 // First called on bitrate updated, then again on first frame.
1001 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1002 .Times(2);
1003 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1004
1005 const int64_t kStartTimeMs = 1;
1006 video_source_.IncomingCapturedFrame(
1007 CreateFrame(kStartTimeMs, codec_width_, codec_height_));
1008 sink_.WaitForEncodedFrame(kStartTimeMs);
1009
1010 // Not called on second frame.
1011 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1012 .Times(0);
1013 video_source_.IncomingCapturedFrame(
1014 CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_));
1015 sink_.WaitForEncodedFrame(kStartTimeMs + 1);
1016
1017 // Called after a process interval.
1018 const int64_t kProcessIntervalMs =
1019 vcm::VCMProcessTimer::kDefaultProcessIntervalMs;
1020 // TODO(sprang): ViEEncoder should die and/or get injectable clock.
1021 // Sleep for one processing interval plus one frame to avoid flakiness.
1022 SleepMs(kProcessIntervalMs + 1000 / kDefaultFps);
1023 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1024 .Times(1);
1025 video_source_.IncomingCapturedFrame(CreateFrame(
1026 kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_));
1027 sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs);
1028
1029 vie_encoder_->Stop();
1030 }
1031
982 } // namespace webrtc 1032 } // 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