diff --git a/call/BUILD.gn b/call/BUILD.gn index 3d6f32fb84..ffb38ee9e3 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -370,7 +370,17 @@ if (rtc_include_tests) { "../test:test_support", ] } + rtc_source_set("mock_bitrate_allocator") { + testonly = true + sources = [ + "test/mock_bitrate_allocator.h", + ] + deps = [ + ":bitrate_allocator", + "//test:test_support", + ] + } rtc_source_set("mock_call_interfaces") { testonly = true diff --git a/call/bitrate_allocator.h b/call/bitrate_allocator.h index 99f2018190..ac98210e2f 100644 --- a/call/bitrate_allocator.h +++ b/call/bitrate_allocator.h @@ -67,10 +67,22 @@ struct MediaStreamAllocationConfig { bool has_packet_feedback; }; +// Interface used for mocking +class BitrateAllocatorInterface { + public: + virtual void AddObserver(BitrateAllocatorObserver* observer, + MediaStreamAllocationConfig config) = 0; + virtual void RemoveObserver(BitrateAllocatorObserver* observer) = 0; + virtual int GetStartBitrate(BitrateAllocatorObserver* observer) = 0; + + protected: + virtual ~BitrateAllocatorInterface() = default; +}; + // Usage: this class will register multiple RtcpBitrateObserver's one at each // RTCP module. It will aggregate the results and run one bandwidth estimation // and push the result to the encoders via BitrateAllocatorObserver(s). -class BitrateAllocator { +class BitrateAllocator : public BitrateAllocatorInterface { public: // Used to get notified when send stream limits such as the minimum send // bitrate and max padding bitrate is changed. @@ -82,7 +94,7 @@ class BitrateAllocator { bool has_packet_feedback) = 0; protected: - virtual ~LimitObserver() {} + virtual ~LimitObserver() = default; }; explicit BitrateAllocator(LimitObserver* limit_observer); @@ -98,15 +110,15 @@ class BitrateAllocator { // |observer| updates bitrates if already in use. // |config| is the configuration to use for allocation. void AddObserver(BitrateAllocatorObserver* observer, - MediaStreamAllocationConfig config); + MediaStreamAllocationConfig config) override; // Removes a previously added observer, but will not trigger a new bitrate // allocation. - void RemoveObserver(BitrateAllocatorObserver* observer); + void RemoveObserver(BitrateAllocatorObserver* observer) override; // Returns initial bitrate allocated for |observer|. If |observer| is not in // the list of added observers, a best guess is returned. - int GetStartBitrate(BitrateAllocatorObserver* observer); + int GetStartBitrate(BitrateAllocatorObserver* observer) override; // Sets external allocation strategy. If strategy is not set default WebRTC // allocation mechanism will be used. The strategy may be changed during call. diff --git a/call/test/mock_bitrate_allocator.h b/call/test/mock_bitrate_allocator.h new file mode 100644 index 0000000000..714c02541f --- /dev/null +++ b/call/test/mock_bitrate_allocator.h @@ -0,0 +1,27 @@ +/* + * Copyright 2018 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#ifndef CALL_TEST_MOCK_BITRATE_ALLOCATOR_H_ +#define CALL_TEST_MOCK_BITRATE_ALLOCATOR_H_ + +#include + +#include "call/bitrate_allocator.h" +#include "test/gmock.h" + +namespace webrtc { +class MockBitrateAllocator : public BitrateAllocatorInterface { + public: + MOCK_METHOD2(AddObserver, + void(BitrateAllocatorObserver*, MediaStreamAllocationConfig)); + MOCK_METHOD1(RemoveObserver, void(BitrateAllocatorObserver*)); + MOCK_METHOD1(GetStartBitrate, int(BitrateAllocatorObserver*)); +}; +} // namespace webrtc +#endif // CALL_TEST_MOCK_BITRATE_ALLOCATOR_H_