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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/video/vie_encoder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/video/vie_encoder_unittest.cc
diff --git a/webrtc/video/vie_encoder_unittest.cc b/webrtc/video/vie_encoder_unittest.cc
index 7dd59212e0e84fac3955ba169b6b25d95d161c6c..003fd2f420bf81ac25204175ada9fd36fd0af477 100644
--- a/webrtc/video/vie_encoder_unittest.cc
+++ b/webrtc/video/vie_encoder_unittest.cc
@@ -12,14 +12,20 @@
#include <utility>
#include "webrtc/base/logging.h"
+#include "webrtc/modules/video_coding/utility/default_video_bitrate_allocator.h"
#include "webrtc/system_wrappers/include/metrics_default.h"
+#include "webrtc/system_wrappers/include/sleep.h"
#include "webrtc/test/encoder_settings.h"
#include "webrtc/test/fake_encoder.h"
#include "webrtc/test/frame_generator.h"
+#include "webrtc/test/gmock.h"
#include "webrtc/test/gtest.h"
#include "webrtc/video/send_statistics_proxy.h"
#include "webrtc/video/vie_encoder.h"
+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.
+using ::testing::Return;
+
namespace {
#if defined(WEBRTC_ANDROID)
// TODO(kthelgason): Lower this limit when better testing
@@ -978,4 +984,46 @@ TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) {
1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
}
+TEST_F(ViEEncoderTest, CallsBitrateObserver) {
+ class MockBitrateObserver : public VideoBitrateAllocationObserver {
+ public:
+ MOCK_METHOD1(OnBitrateAllocationUpdated, void(const BitrateAllocation&));
+ } bitrate_observer;
+ vie_encoder_->SetBitrateObserver(&bitrate_observer);
+
+ const BitrateAllocation expected_bitrate =
+ DefaultVideoBitrateAllocator(fake_encoder_.codec_config())
+ .GetAllocation(kTargetBitrateBps, 30);
+
+ // First called on bitrate updated, then again on first frame.
+ EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
+ .Times(2);
+ vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
+
+ const int64_t kStartTsNtp = 1;
+ video_source_.IncomingCapturedFrame(
+ CreateFrame(kStartTsNtp, codec_width_, codec_height_));
+ sink_.WaitForEncodedFrame(kStartTsNtp);
+
+ // Not called on second frame.
+ EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
+ .Times(0);
+ video_source_.IncomingCapturedFrame(
+ CreateFrame(kStartTsNtp + 90, codec_width_, codec_height_));
+ sink_.WaitForEncodedFrame(kStartTsNtp + 90);
+
+ // Called after a process interval.
+ const int64_t kProcessIntervalMs =
+ vcm::VCMProcessTimer::kDefaultProcessIntervalMs;
+ // TODO(sprang): ViEEncoder should die and/or get injectable clock.
+ 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
+ EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
+ .Times(1);
+ video_source_.IncomingCapturedFrame(CreateFrame(
+ 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
+ sink_.WaitForEncodedFrame(kStartTsNtp + kProcessIntervalMs * 90);
+
+ vie_encoder_->Stop();
+}
+
} // namespace webrtc
« 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