resource.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2019 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef API_ADAPTATION_RESOURCE_H_
  11. #define API_ADAPTATION_RESOURCE_H_
  12. #include <string>
  13. #include "api/scoped_refptr.h"
  14. #include "rtc_base/ref_count.h"
  15. #include "rtc_base/system/rtc_export.h"
  16. namespace webrtc {
  17. class Resource;
  18. enum class ResourceUsageState {
  19. // Action is needed to minimze the load on this resource.
  20. kOveruse,
  21. // Increasing the load on this resource is desired, if possible.
  22. kUnderuse,
  23. };
  24. RTC_EXPORT const char* ResourceUsageStateToString(
  25. ResourceUsageState usage_state);
  26. class RTC_EXPORT ResourceListener {
  27. public:
  28. virtual ~ResourceListener();
  29. virtual void OnResourceUsageStateMeasured(
  30. rtc::scoped_refptr<Resource> resource,
  31. ResourceUsageState usage_state) = 0;
  32. };
  33. // A Resource monitors an implementation-specific resource. It may report
  34. // kOveruse or kUnderuse when resource usage is high or low enough that we
  35. // should perform some sort of mitigation to fulfil the resource's constraints.
  36. //
  37. // The methods on this interface are invoked on the adaptation task queue.
  38. // Resource usage measurements may be performed on an any task queue.
  39. //
  40. // The Resource is reference counted to prevent use-after-free when posting
  41. // between task queues. As such, the implementation MUST NOT make any
  42. // assumptions about which task queue Resource is destructed on.
  43. class RTC_EXPORT Resource : public rtc::RefCountInterface {
  44. public:
  45. Resource();
  46. // Destruction may happen on any task queue.
  47. ~Resource() override;
  48. virtual std::string Name() const = 0;
  49. // The |listener| may be informed of resource usage measurements on any task
  50. // queue, but not after this method is invoked with the null argument.
  51. virtual void SetResourceListener(ResourceListener* listener) = 0;
  52. };
  53. } // namespace webrtc
  54. #endif // API_ADAPTATION_RESOURCE_H_