This is part of the work for making VideoStreamEncoder responsible for configuring its source/sink and limiting the responsibility of OveruseFrameDetectorResourceAdaptationModule to only output relevant VideoSourceRestrictions. BEFORE THIS CL Prior to this CL, OveruseFrameDetector was responsible for performing AddOrUpdateSink() on the source, which it did using its nested class VideoSourceProxy. AddOrUpdateSink() could happen for both adaptation and non-adaptation related reasons. For example: - Adaptation related: AdaptUp() or AdaptDown() happens, causing updated VideoSourceRestrictions. - Non-adaptation related: VideoStreamEncoder asks the module to reconfigure the source/sink for it, such as with SetMaxFramerateAndAlignment() or SetWantsRotationApplied(). AFTER THIS CL AddOrUpdateSink() is performed by VideoSourceController, which is owned by VideoStreamEncoder. Any reconfiguration has to go through the VideoStreamEncoder. This means that: - Non-adaptation related settings happen between VideoStreamEncoder and VideoSourceController directly (without going through the adaptation module). - Adaptation related changes can be expressed in terms of VideoSourceRestrictions. OveruseFrameDetectorResourceAdaptationModule only has to output the restrictions and not know or care about other source/sink settings. For now, VideoSourceController has to know about DegradationPreference. In a future CL, the DegradationPreference logic should move back to the adaptation module. The VideoSourceRestrictions are fully capable of expressing all possible source/sink values without the "modifier" that is the degradation preference. Bug: webrtc:11222 Change-Id: I0f058c4700ca108e2d9f212e38b61f6f728aa419 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/162802 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@google.com> Cr-Commit-Position: refs/heads/master@{#30228}
90 lines
4.1 KiB
C++
90 lines
4.1 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_VIDEO_SOURCE_SINK_CONTROLLER_H_
|
|
#define VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
|
|
|
|
#include "absl/types/optional.h"
|
|
#include "api/rtp_parameters.h"
|
|
#include "api/video/video_frame.h"
|
|
#include "api/video/video_sink_interface.h"
|
|
#include "api/video/video_source_interface.h"
|
|
#include "call/adaptation/resource_adaptation_module_interface.h"
|
|
#include "rtc_base/critical_section.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// Responsible for configuring source/sink settings, i.e. performing
|
|
// rtc::VideoSourceInterface<VideoFrame>::AddOrUpdateSink(). It does this by
|
|
// storing settings internally which are converted to rtc::VideoSinkWants when
|
|
// PushSourceSinkSettings() is performed.
|
|
class VideoSourceSinkController {
|
|
public:
|
|
VideoSourceSinkController(rtc::VideoSinkInterface<VideoFrame>* sink,
|
|
rtc::VideoSourceInterface<VideoFrame>* source);
|
|
|
|
// TODO(https://crbug.com/webrtc/11222): Remove dependency on
|
|
// DegradationPreference! How degradation preference affects
|
|
// VideoSourceRestrictions should not be a responsibility of the controller,
|
|
// but of the resource adaptation module.
|
|
void SetSource(rtc::VideoSourceInterface<VideoFrame>* source,
|
|
DegradationPreference degradation_preference);
|
|
// Must be called in order for changes to settings to have an effect. This
|
|
// allows you to modify multiple properties in a single push to the sink.
|
|
void PushSourceSinkSettings();
|
|
|
|
VideoSourceRestrictions restrictions() const;
|
|
absl::optional<size_t> pixels_per_frame_upper_limit() const;
|
|
absl::optional<double> frame_rate_upper_limit() const;
|
|
bool rotation_applied() const;
|
|
int resolution_alignment() const;
|
|
|
|
// Updates the settings stored internally. In order for these settings to be
|
|
// applied to the sink, PushSourceSinkSettings() must subsequently be called.
|
|
void SetRestrictions(VideoSourceRestrictions restrictions);
|
|
void SetPixelsPerFrameUpperLimit(
|
|
absl::optional<size_t> pixels_per_frame_upper_limit);
|
|
void SetFrameRateUpperLimit(absl::optional<double> frame_rate_upper_limit);
|
|
void SetRotationApplied(bool rotation_applied);
|
|
void SetResolutionAlignment(int resolution_alignment);
|
|
|
|
// TODO(https://crbug.com/webrtc/11222): Outside of testing, this is only used
|
|
// by OveruseFrameDetectorResourceAdaptationModule::RefreshTargetFramerate().
|
|
// When the DegradationPreference logic has moved outside of this class, there
|
|
// will be no public need for this method other than testing reasons and this
|
|
// can be renamed "ForTesting".
|
|
rtc::VideoSinkWants CurrentSettingsToSinkWants() const;
|
|
|
|
private:
|
|
rtc::VideoSinkWants CurrentSettingsToSinkWantsInternal() const
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
|
|
|
// TODO(hbos): If everything is handled on the same sequence (i.e.
|
|
// VideoStreamEncoder's encoder queue) then |crit_| can be replaced by
|
|
// sequence checker. Investigate if we want to do this.
|
|
mutable rtc::CriticalSection crit_;
|
|
rtc::VideoSinkInterface<VideoFrame>* const sink_;
|
|
rtc::VideoSourceInterface<VideoFrame>* source_ RTC_GUARDED_BY(&crit_);
|
|
DegradationPreference degradation_preference_ RTC_GUARDED_BY(&crit_);
|
|
// Pixel and frame rate restrictions.
|
|
VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&crit_);
|
|
// Ensures that even if we are not restricted, the sink is never configured
|
|
// above this limit. Example: We are not CPU limited (no |restrictions_|) but
|
|
// our encoder is capped at 30 fps (= |frame_rate_upper_limit_|).
|
|
absl::optional<size_t> pixels_per_frame_upper_limit_ RTC_GUARDED_BY(&crit_);
|
|
absl::optional<double> frame_rate_upper_limit_ RTC_GUARDED_BY(&crit_);
|
|
bool rotation_applied_ RTC_GUARDED_BY(&crit_) = false;
|
|
int resolution_alignment_ RTC_GUARDED_BY(&crit_) = 1;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
|