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

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

Issue 2616393003: Periodically update channel parameters and send TargetBitrate message. (Closed)
Patch Set: Remove deprecated tests in VideoSender, add new one in ViEEncoder 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/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h"
15 #include "webrtc/system_wrappers/include/metrics_default.h" 16 #include "webrtc/system_wrappers/include/metrics_default.h"
17 #include "webrtc/system_wrappers/include/sleep.h"
16 #include "webrtc/test/encoder_settings.h" 18 #include "webrtc/test/encoder_settings.h"
17 #include "webrtc/test/fake_encoder.h" 19 #include "webrtc/test/fake_encoder.h"
18 #include "webrtc/test/frame_generator.h" 20 #include "webrtc/test/frame_generator.h"
21 #include "webrtc/test/gmock.h"
19 #include "webrtc/test/gtest.h" 22 #include "webrtc/test/gtest.h"
20 #include "webrtc/video/send_statistics_proxy.h" 23 #include "webrtc/video/send_statistics_proxy.h"
21 #include "webrtc/video/vie_encoder.h" 24 #include "webrtc/video/vie_encoder.h"
22 25
26 using ::testing::_;
danilchap 2017/01/10 10:32:33 put using inside (2nd) unnamed namespace (or at le
sprang_webrtc 2017/01/10 11:34:08 Done.
27 using ::testing::Return;
28
23 namespace { 29 namespace {
24 #if defined(WEBRTC_ANDROID) 30 #if defined(WEBRTC_ANDROID)
25 // TODO(kthelgason): Lower this limit when better testing 31 // TODO(kthelgason): Lower this limit when better testing
26 // on MediaCodec and fallback implementations are in place. 32 // on MediaCodec and fallback implementations are in place.
27 const int kMinPixelsPerFrame = 320 * 180; 33 const int kMinPixelsPerFrame = 320 * 180;
28 #else 34 #else
29 const int kMinPixelsPerFrame = 120 * 90; 35 const int kMinPixelsPerFrame = 120 * 90;
30 #endif 36 #endif
31 } 37 }
32 38
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 977
972 vie_encoder_->Stop(); 978 vie_encoder_->Stop();
973 979
974 stats_proxy_.reset(); 980 stats_proxy_.reset();
975 EXPECT_EQ(1, 981 EXPECT_EQ(1,
976 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent")); 982 metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
977 EXPECT_EQ( 983 EXPECT_EQ(
978 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50)); 984 1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
979 } 985 }
980 986
987 TEST_F(ViEEncoderTest, CallsBitrateObserver) {
988 class MockBitrateObserver : public VideoBitrateAllocationObserver {
989 public:
990 MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&));
991 } bitrate_observer;
992 vie_encoder_->SetBitrateObserver(&bitrate_observer);
993
994 const BitrateAllocation expected_bitrate =
995 DefaultVideoBitrateAllocator(fake_encoder_.codec_config())
996 .GetAllocation(kTargetBitrateBps, 30);
997
998 // First called on bitrate updated, then again on first frame.
999 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1000 .Times(2);
1001 vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
1002
1003 const int64_t kStartTsNtp = 1;
1004 video_source_.IncomingCapturedFrame(
1005 CreateFrame(kStartTsNtp, codec_width_, codec_height_));
1006 sink_.WaitForEncodedFrame(kStartTsNtp);
1007
1008 // Not called on second frame.
1009 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1010 .Times(0);
1011 video_source_.IncomingCapturedFrame(
1012 CreateFrame(kStartTsNtp + 90, codec_width_, codec_height_));
1013 sink_.WaitForEncodedFrame(kStartTsNtp + 90);
1014
1015 // Called after a process interval.
1016 const int64_t kProcessIntervalMs =
1017 vcm::VCMProcessTimer::kDefaultProcessIntervalMs;
1018 // TODO(sprang): ViEEncoder should die and/or get injectable clock.
1019 SleepMs(kProcessIntervalMs + 30);
danilchap 2017/01/10 10:32:33 Can Sleep be avoided using SetClockForTesting meth
sprang_webrtc 2017/01/10 11:34:08 Turns out it can, nice! 30 was just a margin to av
1020 EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
1021 .Times(1);
1022 video_source_.IncomingCapturedFrame(CreateFrame(
1023 kStartTsNtp + kProcessIntervalMs * 90, codec_width_, codec_height_));
danilchap 2017/01/10 10:32:33 though time (1st parameter to CreateFrame) is call
sprang_webrtc 2017/01/10 11:34:08 OK, that's confusing. I'll update the name of the
1024 sink_.WaitForEncodedFrame(kStartTsNtp + kProcessIntervalMs * 90);
1025
1026 vie_encoder_->Stop();
1027 }
1028
981 } // namespace webrtc 1029 } // 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