xref: /aosp_15_r20/external/webrtc/call/adaptation/resource_adaptation_processor_interface.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2020 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 CALL_ADAPTATION_RESOURCE_ADAPTATION_PROCESSOR_INTERFACE_H_
12 #define CALL_ADAPTATION_RESOURCE_ADAPTATION_PROCESSOR_INTERFACE_H_
13 
14 #include <map>
15 #include <vector>
16 
17 #include "absl/types/optional.h"
18 #include "api/adaptation/resource.h"
19 #include "api/rtp_parameters.h"
20 #include "api/scoped_refptr.h"
21 #include "api/task_queue/task_queue_base.h"
22 #include "api/video/video_adaptation_counters.h"
23 #include "api/video/video_frame.h"
24 #include "call/adaptation/adaptation_constraint.h"
25 #include "call/adaptation/encoder_settings.h"
26 #include "call/adaptation/video_source_restrictions.h"
27 
28 namespace webrtc {
29 
30 class ResourceLimitationsListener {
31  public:
32   virtual ~ResourceLimitationsListener();
33 
34   // The limitations on a resource were changed. This does not mean the current
35   // video restrictions have changed.
36   virtual void OnResourceLimitationChanged(
37       rtc::scoped_refptr<Resource> resource,
38       const std::map<rtc::scoped_refptr<Resource>, VideoAdaptationCounters>&
39           resource_limitations) = 0;
40 };
41 
42 // The Resource Adaptation Processor is responsible for reacting to resource
43 // usage measurements (e.g. overusing or underusing CPU). When a resource is
44 // overused the Processor is responsible for performing mitigations in order to
45 // consume less resources.
46 class ResourceAdaptationProcessorInterface {
47  public:
48   virtual ~ResourceAdaptationProcessorInterface();
49 
50   virtual void AddResourceLimitationsListener(
51       ResourceLimitationsListener* limitations_listener) = 0;
52   virtual void RemoveResourceLimitationsListener(
53       ResourceLimitationsListener* limitations_listener) = 0;
54   // Starts or stops listening to resources, effectively enabling or disabling
55   // processing. May be called from anywhere.
56   // TODO(https://crbug.com/webrtc/11172): Automatically register and unregister
57   // with AddResource() and RemoveResource() instead. When the processor is
58   // multi-stream aware, stream-specific resouces will get added and removed
59   // over time.
60   virtual void AddResource(rtc::scoped_refptr<Resource> resource) = 0;
61   virtual std::vector<rtc::scoped_refptr<Resource>> GetResources() const = 0;
62   virtual void RemoveResource(rtc::scoped_refptr<Resource> resource) = 0;
63 };
64 
65 }  // namespace webrtc
66 
67 #endif  // CALL_ADAPTATION_RESOURCE_ADAPTATION_PROCESSOR_INTERFACE_H_
68