Adds mock bitrate allocator.

This is used to allow mocking in tests in later CLs.

Bug: None
Change-Id: Id610471efb4a86c903530585dd4ee2fa1d1ea5bc
Reviewed-on: https://webrtc-review.googlesource.com/70880
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22941}
This commit is contained in:
Sebastian Jansson 2018-04-19 08:27:19 +02:00 committed by Commit Bot
parent 497bdaf1d5
commit 832678079d
3 changed files with 54 additions and 5 deletions

View File

@ -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

View File

@ -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.

View File

@ -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 <string>
#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_