* This replaces the video stream methods for forcing adaptation with a mock resource that triggers overuse. * Resources can now be injected to the Module using the AddResource function. * Resources now have tests for adding and removing callbacks. * Quality/EncoderUse% resources are tracked in the Resource list of the adaptation module. * The adaptation module ties all resources to a reason to keep stats working as expected. BUG=webrtc:11377 Change-Id: I1f5902f7416dc41b4915c0072e6f0da2bb3bb2b7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168948 Commit-Queue: Evan Shrubsole <eshr@google.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30610}
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
/*
|
|
* Copyright 2019 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 "call/adaptation/resource.h"
|
|
|
|
#include "absl/algorithm/container.h"
|
|
#include "rtc_base/checks.h"
|
|
|
|
namespace webrtc {
|
|
|
|
ResourceListener::~ResourceListener() {}
|
|
|
|
Resource::Resource() : usage_state_(ResourceUsageState::kStable) {}
|
|
|
|
Resource::~Resource() {
|
|
RTC_DCHECK(listeners_.empty());
|
|
}
|
|
|
|
void Resource::RegisterListener(ResourceListener* listener) {
|
|
RTC_DCHECK(listener);
|
|
RTC_DCHECK(absl::c_find(listeners_, listener) == listeners_.end())
|
|
<< "ResourceListener was added twice.";
|
|
listeners_.push_back(listener);
|
|
}
|
|
|
|
void Resource::UnregisterListener(ResourceListener* listener) {
|
|
RTC_DCHECK(listener);
|
|
auto it = absl::c_find(listeners_, listener);
|
|
if (it != listeners_.end())
|
|
listeners_.erase(it);
|
|
}
|
|
|
|
ResourceUsageState Resource::usage_state() const {
|
|
return usage_state_;
|
|
}
|
|
|
|
ResourceListenerResponse Resource::OnResourceUsageStateMeasured(
|
|
ResourceUsageState usage_state) {
|
|
ResourceListenerResponse response = ResourceListenerResponse::kNothing;
|
|
usage_state_ = usage_state;
|
|
for (auto* listener : listeners_) {
|
|
ResourceListenerResponse listener_response =
|
|
listener->OnResourceUsageStateMeasured(*this);
|
|
if (listener_response != ResourceListenerResponse::kNothing)
|
|
response = listener_response;
|
|
}
|
|
return response;
|
|
}
|
|
|
|
} // namespace webrtc
|