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 VIDEO_ADAPTATION_PIXEL_LIMIT_RESOURCE_H_ 12 #define VIDEO_ADAPTATION_PIXEL_LIMIT_RESOURCE_H_ 13 14 #include <string> 15 16 #include "absl/types/optional.h" 17 #include "api/adaptation/resource.h" 18 #include "api/scoped_refptr.h" 19 #include "call/adaptation/video_stream_input_state_provider.h" 20 #include "rtc_base/task_utils/repeating_task.h" 21 #include "rtc_base/thread_annotations.h" 22 23 namespace webrtc { 24 25 // An adaptation resource designed to be used in the TestBed. Used to simulate 26 // being CPU limited. 27 // 28 // Periodically reports "overuse" or "underuse" (every 5 seconds) until the 29 // stream is within the bounds specified in terms of a maximum resolution and 30 // one resolution step lower than that (this avoids toggling when this is the 31 // only resource in play). When multiple resources come in to play some amount 32 // of toggling is still possible in edge cases but that is OK for testing 33 // purposes. 34 class PixelLimitResource : public Resource { 35 public: 36 static rtc::scoped_refptr<PixelLimitResource> Create( 37 TaskQueueBase* task_queue, 38 VideoStreamInputStateProvider* input_state_provider); 39 40 PixelLimitResource(TaskQueueBase* task_queue, 41 VideoStreamInputStateProvider* input_state_provider); 42 ~PixelLimitResource() override; 43 44 void SetMaxPixels(int max_pixels); 45 46 // Resource implementation. Name()47 std::string Name() const override { return "PixelLimitResource"; } 48 void SetResourceListener(ResourceListener* listener) override; 49 50 private: 51 TaskQueueBase* const task_queue_; 52 VideoStreamInputStateProvider* const input_state_provider_; 53 absl::optional<int> max_pixels_ RTC_GUARDED_BY(task_queue_); 54 webrtc::ResourceListener* listener_ RTC_GUARDED_BY(task_queue_); 55 RepeatingTaskHandle repeating_task_ RTC_GUARDED_BY(task_queue_); 56 }; 57 58 } // namespace webrtc 59 60 #endif // VIDEO_ADAPTATION_PIXEL_LIMIT_RESOURCE_H_ 61