2019-12-10 14:14:09 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef CALL_ADAPTATION_RESOURCE_H_
|
|
|
|
|
#define CALL_ADAPTATION_RESOURCE_H_
|
|
|
|
|
|
2020-02-25 16:26:01 +01:00
|
|
|
#include <string>
|
2020-02-06 12:49:57 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "absl/types/optional.h"
|
2019-12-10 14:14:09 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
class Resource;
|
|
|
|
|
|
2019-12-10 14:14:09 +01:00
|
|
|
enum class ResourceUsageState {
|
|
|
|
|
// Action is needed to minimze the load on this resource.
|
|
|
|
|
kOveruse,
|
|
|
|
|
// No action needed for this resource, increasing the load on this resource
|
|
|
|
|
// is not allowed.
|
|
|
|
|
kStable,
|
|
|
|
|
// Increasing the load on this resource is allowed.
|
|
|
|
|
kUnderuse,
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
enum class ResourceListenerResponse {
|
|
|
|
|
kNothing,
|
|
|
|
|
// This response is only applicable to QualityScaler-based resources.
|
|
|
|
|
// It tells the QualityScaler to increase its QP measurement frequency.
|
|
|
|
|
//
|
|
|
|
|
// This is modelled after AdaptationObserverInterface::AdaptDown()'s return
|
|
|
|
|
// value. The method comment says "Returns false if a downgrade was requested
|
|
|
|
|
// but the request did not result in a new limiting resolution or fps."
|
|
|
|
|
// However the actual implementation seems to be: Return false if
|
|
|
|
|
// !has_input_video_ or if we use balanced degradation preference and we DID
|
|
|
|
|
// adapt frame rate but the difference between input frame rate and balanced
|
|
|
|
|
// settings' min fps is less than the balanced settings' min fps diff - in all
|
|
|
|
|
// other cases, return true whether or not adaptation happened.
|
|
|
|
|
//
|
|
|
|
|
// For QualityScaler-based resources, kQualityScalerShouldIncreaseFrequency
|
|
|
|
|
// maps to "return false" and kNothing maps to "return true".
|
|
|
|
|
//
|
|
|
|
|
// TODO(https://crbug.com/webrtc/11222): Remove this enum. Resource
|
|
|
|
|
// measurements and adaptation decisions need to be separated in order to
|
|
|
|
|
// support injectable adaptation modules, multi-stream aware adaptation and
|
|
|
|
|
// decision-making logic based on multiple resources.
|
|
|
|
|
kQualityScalerShouldIncreaseFrequency,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ResourceListener {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~ResourceListener();
|
|
|
|
|
|
|
|
|
|
// Informs the listener of a new measurement of resource usage. This means
|
|
|
|
|
// that |resource.usage_state()| is now up-to-date.
|
|
|
|
|
//
|
|
|
|
|
// The listener may influence the resource that signaled the measurement
|
|
|
|
|
// according to the returned ResourceListenerResponse enum.
|
|
|
|
|
virtual ResourceListenerResponse OnResourceUsageStateMeasured(
|
|
|
|
|
const Resource& resource) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-10 14:14:09 +01:00
|
|
|
// A Resource is something which can be measured as "overused", "stable" or
|
2020-02-06 12:49:57 +01:00
|
|
|
// "underused". When the resource usage changes, listeners of the resource are
|
|
|
|
|
// informed.
|
2019-12-10 14:14:09 +01:00
|
|
|
//
|
2020-02-06 12:49:57 +01:00
|
|
|
// Implementations of this interface are responsible for performing resource
|
|
|
|
|
// usage measurements and invoking OnResourceUsageStateMeasured().
|
2019-12-10 14:14:09 +01:00
|
|
|
class Resource {
|
|
|
|
|
public:
|
2020-02-06 12:49:57 +01:00
|
|
|
// By default, usage_state() is kStable until a measurement is made.
|
|
|
|
|
Resource();
|
2019-12-10 14:14:09 +01:00
|
|
|
virtual ~Resource();
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
void RegisterListener(ResourceListener* listener);
|
2020-02-25 16:26:01 +01:00
|
|
|
void UnregisterListener(ResourceListener* listener);
|
2020-02-06 12:49:57 +01:00
|
|
|
|
|
|
|
|
ResourceUsageState usage_state() const;
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-02-25 16:26:01 +01:00
|
|
|
virtual std::string name() const = 0;
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
protected:
|
|
|
|
|
// Updates the usage state and informs all registered listeners.
|
|
|
|
|
// Returns the result of the last listener's OnResourceUsageStateMeasured()
|
|
|
|
|
// call that was not kNothing, else kNothing.
|
|
|
|
|
ResourceListenerResponse OnResourceUsageStateMeasured(
|
|
|
|
|
ResourceUsageState usage_state);
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
private:
|
|
|
|
|
ResourceUsageState usage_state_;
|
|
|
|
|
std::vector<ResourceListener*> listeners_;
|
2019-12-10 14:14:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // CALL_ADAPTATION_RESOURCE_H_
|