This CL implements a Resource that aggressively reports overuse or underuse until the encoded stream has the max pixels specified. The pixel limit is controlled with a field trial, e.g: --force-fieldtrials="WebRTC-PixelLimitResource/Enabled-307200/" This caps the resolution to 307200 (=640x480). This can be used by the TestBed to simulate being CPU limited. Note that the resource doesn't care about degradation preference at the moment, so if the degradation preference would be set to "maintain-resolution" the PixelLimitResource would never stop reporting overuse and we would quickly get a low-FPS stream. PixelLimitResource runs a repeating task and reports overuse, underuse or neither every 5 seconds. This ensures we quickly reach the desired resolution. Unit tests are added. I did not add any integration tests (I think that's overkill for a testing-only resource) but I have manually verified that this works as intended. This CL also moves the FakeVideoStreamInputStateProvider into a test/ folder and exposes video_stream_adapter.cc's GetLowerResolutionThan(). Bug: webrtc:12261 Change-Id: Ifbf7c4c05e9dd2843543589bebef3f49b18c38c0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/195600 Reviewed-by: Evan Shrubsole <eshr@google.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32771}
61 lines
2.2 KiB
C++
61 lines
2.2 KiB
C++
/*
|
|
* Copyright 2020 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.
|
|
*/
|
|
|
|
#ifndef VIDEO_ADAPTATION_PIXEL_LIMIT_RESOURCE_H_
|
|
#define VIDEO_ADAPTATION_PIXEL_LIMIT_RESOURCE_H_
|
|
|
|
#include <string>
|
|
|
|
#include "absl/types/optional.h"
|
|
#include "api/adaptation/resource.h"
|
|
#include "api/scoped_refptr.h"
|
|
#include "call/adaptation/video_stream_input_state_provider.h"
|
|
#include "rtc_base/task_utils/repeating_task.h"
|
|
#include "rtc_base/thread_annotations.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// An adaptation resource designed to be used in the TestBed. Used to simulate
|
|
// being CPU limited.
|
|
//
|
|
// Periodically reports "overuse" or "underuse" (every 5 seconds) until the
|
|
// stream is within the bounds specified in terms of a maximum resolution and
|
|
// one resolution step lower than that (this avoids toggling when this is the
|
|
// only resource in play). When multiple resources come in to play some amount
|
|
// of toggling is still possible in edge cases but that is OK for testing
|
|
// purposes.
|
|
class PixelLimitResource : public Resource {
|
|
public:
|
|
static rtc::scoped_refptr<PixelLimitResource> Create(
|
|
TaskQueueBase* task_queue,
|
|
VideoStreamInputStateProvider* input_state_provider);
|
|
|
|
PixelLimitResource(TaskQueueBase* task_queue,
|
|
VideoStreamInputStateProvider* input_state_provider);
|
|
~PixelLimitResource() override;
|
|
|
|
void SetMaxPixels(int max_pixels);
|
|
|
|
// Resource implementation.
|
|
std::string Name() const override { return "PixelLimitResource"; }
|
|
void SetResourceListener(ResourceListener* listener) override;
|
|
|
|
private:
|
|
TaskQueueBase* const task_queue_;
|
|
VideoStreamInputStateProvider* const input_state_provider_;
|
|
absl::optional<int> max_pixels_ RTC_GUARDED_BY(task_queue_);
|
|
webrtc::ResourceListener* listener_ RTC_GUARDED_BY(task_queue_);
|
|
RepeatingTaskHandle repeating_task_ RTC_GUARDED_BY(task_queue_);
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // VIDEO_ADAPTATION_PIXEL_LIMIT_RESOURCE_H_
|