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.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-06-03 09:24:06 +02:00
|
|
|
#ifndef API_ADAPTATION_RESOURCE_H_
|
|
|
|
|
#define API_ADAPTATION_RESOURCE_H_
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-02-25 16:26:01 +01:00
|
|
|
#include <string>
|
2020-02-06 12:49:57 +01:00
|
|
|
|
2024-06-06 11:01:02 +00:00
|
|
|
#include "api/ref_count.h"
|
2020-05-11 16:29:22 +02:00
|
|
|
#include "api/scoped_refptr.h"
|
2020-06-16 19:10:17 +02:00
|
|
|
#include "rtc_base/system/rtc_export.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-06-16 19:10:17 +02:00
|
|
|
RTC_EXPORT const char* ResourceUsageStateToString(
|
|
|
|
|
ResourceUsageState usage_state);
|
2020-05-28 16:22:42 +02:00
|
|
|
|
2020-06-16 19:10:17 +02:00
|
|
|
class RTC_EXPORT ResourceListener {
|
2020-02-06 12:49:57 +01:00
|
|
|
public:
|
|
|
|
|
virtual ~ResourceListener();
|
|
|
|
|
|
2020-05-11 16:29:22 +02:00
|
|
|
virtual void OnResourceUsageStateMeasured(
|
2020-06-03 09:21:34 +02:00
|
|
|
rtc::scoped_refptr<Resource> resource,
|
|
|
|
|
ResourceUsageState usage_state) = 0;
|
2020-02-06 12:49:57 +01:00
|
|
|
};
|
|
|
|
|
|
2020-06-03 09:21:34 +02:00
|
|
|
// A Resource monitors an implementation-specific resource. It may report
|
2020-06-01 17:59:05 +02:00
|
|
|
// kOveruse or kUnderuse when resource usage is high or low enough that we
|
|
|
|
|
// should perform some sort of mitigation to fulfil the resource's constraints.
|
|
|
|
|
//
|
2020-06-03 09:21:34 +02:00
|
|
|
// The methods on this interface are invoked on the adaptation task queue.
|
|
|
|
|
// Resource usage measurements may be performed on an any task queue.
|
2020-06-01 17:59:05 +02:00
|
|
|
//
|
|
|
|
|
// The Resource is reference counted to prevent use-after-free when posting
|
|
|
|
|
// between task queues. As such, the implementation MUST NOT make any
|
|
|
|
|
// assumptions about which task queue Resource is destructed on.
|
2024-06-06 11:01:02 +00:00
|
|
|
class RTC_EXPORT Resource : public RefCountInterface {
|
2019-12-10 14:14:09 +01:00
|
|
|
public:
|
2020-02-06 12:49:57 +01:00
|
|
|
Resource();
|
2020-06-01 17:59:05 +02:00
|
|
|
// Destruction may happen on any task queue.
|
2020-05-11 16:29:22 +02:00
|
|
|
~Resource() override;
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-06-01 17:59:05 +02:00
|
|
|
virtual std::string Name() const = 0;
|
2021-07-25 21:50:14 +02:00
|
|
|
// The `listener` may be informed of resource usage measurements on any task
|
2020-06-03 09:21:34 +02:00
|
|
|
// queue, but not after this method is invoked with the null argument.
|
2020-06-02 13:02:36 +02:00
|
|
|
virtual void SetResourceListener(ResourceListener* listener) = 0;
|
2019-12-10 14:14:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2020-06-03 09:24:06 +02:00
|
|
|
#endif // API_ADAPTATION_RESOURCE_H_
|