• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef API_ADAPTATION_RESOURCE_H_
12 #define API_ADAPTATION_RESOURCE_H_
13 
14 #include <string>
15 
16 #include "api/scoped_refptr.h"
17 #include "rtc_base/ref_count.h"
18 #include "rtc_base/system/rtc_export.h"
19 
20 namespace webrtc {
21 
22 class Resource;
23 
24 enum class ResourceUsageState {
25   // Action is needed to minimze the load on this resource.
26   kOveruse,
27   // Increasing the load on this resource is desired, if possible.
28   kUnderuse,
29 };
30 
31 RTC_EXPORT const char* ResourceUsageStateToString(
32     ResourceUsageState usage_state);
33 
34 class RTC_EXPORT ResourceListener {
35  public:
36   virtual ~ResourceListener();
37 
38   virtual void OnResourceUsageStateMeasured(
39       rtc::scoped_refptr<Resource> resource,
40       ResourceUsageState usage_state) = 0;
41 };
42 
43 // A Resource monitors an implementation-specific resource. It may report
44 // kOveruse or kUnderuse when resource usage is high or low enough that we
45 // should perform some sort of mitigation to fulfil the resource's constraints.
46 //
47 // The methods on this interface are invoked on the adaptation task queue.
48 // Resource usage measurements may be performed on an any task queue.
49 //
50 // The Resource is reference counted to prevent use-after-free when posting
51 // between task queues. As such, the implementation MUST NOT make any
52 // assumptions about which task queue Resource is destructed on.
53 class RTC_EXPORT Resource : public rtc::RefCountInterface {
54  public:
55   Resource();
56   // Destruction may happen on any task queue.
57   ~Resource() override;
58 
59   virtual std::string Name() const = 0;
60   // The |listener| may be informed of resource usage measurements on any task
61   // queue, but not after this method is invoked with the null argument.
62   virtual void SetResourceListener(ResourceListener* listener) = 0;
63 };
64 
65 }  // namespace webrtc
66 
67 #endif  // API_ADAPTATION_RESOURCE_H_
68