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"
|
2020-04-17 13:48:21 +02:00
|
|
|
#include "call/adaptation/video_source_restrictions.h"
|
|
|
|
|
#include "call/adaptation/video_stream_input_state.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,
|
2020-04-20 12:04:12 +02:00
|
|
|
// Increasing the load on this resource is desired, if possible.
|
2019-12-10 14:14:09 +01:00
|
|
|
kUnderuse,
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
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.
|
2020-04-28 12:24:33 +02:00
|
|
|
virtual void OnResourceUsageStateMeasured(const Resource& resource) = 0;
|
2020-02-06 12:49:57 +01:00
|
|
|
};
|
|
|
|
|
|
2019-12-10 14:14:09 +01:00
|
|
|
class Resource {
|
|
|
|
|
public:
|
2020-04-20 12:04:12 +02:00
|
|
|
// By default, usage_state() is null until a measurement is made.
|
2020-02-06 12:49:57 +01:00
|
|
|
Resource();
|
2019-12-10 14:14:09 +01:00
|
|
|
virtual ~Resource();
|
|
|
|
|
|
2020-04-20 12:04:12 +02:00
|
|
|
void SetResourceListener(ResourceListener* listener);
|
|
|
|
|
|
|
|
|
|
absl::optional<ResourceUsageState> usage_state() const;
|
|
|
|
|
void ClearUsageState();
|
2020-02-06 12:49:57 +01:00
|
|
|
|
2020-04-17 13:48:21 +02:00
|
|
|
// This method allows the Resource to reject a proposed adaptation in the "up"
|
|
|
|
|
// direction if it predicts this would cause overuse of this resource. The
|
|
|
|
|
// default implementation unconditionally returns true (= allowed).
|
|
|
|
|
virtual bool IsAdaptationUpAllowed(
|
|
|
|
|
const VideoStreamInputState& input_state,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_before,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_after,
|
|
|
|
|
const Resource& reason_resource) const;
|
2020-04-28 12:24:33 +02:00
|
|
|
virtual void OnAdaptationApplied(
|
|
|
|
|
const VideoStreamInputState& input_state,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_before,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_after,
|
|
|
|
|
const Resource& reason_resource);
|
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.
|
2020-04-28 12:24:33 +02:00
|
|
|
void OnResourceUsageStateMeasured(ResourceUsageState usage_state);
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
private:
|
2020-04-20 12:04:12 +02:00
|
|
|
absl::optional<ResourceUsageState> usage_state_;
|
|
|
|
|
ResourceListener* listener_;
|
2019-12-10 14:14:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // CALL_ADAPTATION_RESOURCE_H_
|