webrtc/call/adaptation/resource_unittest.cc
Henrik Boström 29444c6524 [Adaptation] Multi-processor support for injected Resources.
Because a single Resource only has a single ResourceListener, injected
Resources only gets wired up to the stream's ResourceAdaptationProcessor
that was last to call SetResourceListener. This could potentially lead
to the relevant stream not adapting based on the injected resource
because it got wired up to the wrong stream's processor.

This CL fixes this issue by introducing BroadcastResourceListener. By
listening to 1 resource (the injected one), it can spawn N "adapter"
resources that mirror's the injected resource's usage signal, allowing
all ResourceAdaptationProcessor's to react to the signal.

This is wired up in Call, and tests are updated to verify the signal
gets through.

Bug: chromium:1101263, webrtc:11720
Change-Id: I8a37284cb9a68f08ca1bdb1ee050b7144c451297
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178386
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31612}
2020-07-02 10:28:11 +00:00

55 lines
1.8 KiB
C++

/*
* Copyright 2020 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.
*/
#include "api/adaptation/resource.h"
#include <memory>
#include "api/scoped_refptr.h"
#include "call/adaptation/test/fake_resource.h"
#include "call/adaptation/test/mock_resource_listener.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
using ::testing::_;
using ::testing::StrictMock;
class ResourceTest : public ::testing::Test {
public:
ResourceTest() : fake_resource_(FakeResource::Create("FakeResource")) {}
protected:
rtc::scoped_refptr<FakeResource> fake_resource_;
};
TEST_F(ResourceTest, RegisteringListenerReceivesCallbacks) {
StrictMock<MockResourceListener> resource_listener;
fake_resource_->SetResourceListener(&resource_listener);
EXPECT_CALL(resource_listener, OnResourceUsageStateMeasured(_, _))
.Times(1)
.WillOnce([](rtc::scoped_refptr<Resource> resource,
ResourceUsageState usage_state) {
EXPECT_EQ(ResourceUsageState::kOveruse, usage_state);
});
fake_resource_->SetUsageState(ResourceUsageState::kOveruse);
fake_resource_->SetResourceListener(nullptr);
}
TEST_F(ResourceTest, UnregisteringListenerStopsCallbacks) {
StrictMock<MockResourceListener> resource_listener;
fake_resource_->SetResourceListener(&resource_listener);
fake_resource_->SetResourceListener(nullptr);
EXPECT_CALL(resource_listener, OnResourceUsageStateMeasured(_, _)).Times(0);
fake_resource_->SetUsageState(ResourceUsageState::kOveruse);
}
} // namespace webrtc