This CL is part of the Call-Level Adaptation Processing design doc: https://docs.google.com/document/d/1ZyC26yOCknrrcYa839ZWLxD6o6Gig5A3lVTh4E41074/edit?usp=sharing This gets to the heart of unblocking call-level adaptation, largely made possible due to the previous CLs in the chain. The parts of the code that are responsible for responding to resource usage signals, obtaining adaptations and applying them are moved to ResourceAdaptationProcessor in call/adaptation/. The parts of the code that are responsible for managing VideoStreamEncoder-specific resources stay inside the VideoStreamEncoderResourceManager class in video/adaptation/. After this CL lands it should soon be possible to move the Processor over to a separate task queue and let the Manager stay on the encoder queue if PostTasks are added for communication between the two objects. Bug: webrtc:11172 Change-Id: Ifa212467b4afd16e7ebfb9adfe17d2dca1cb7d67 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/173021 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@google.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31105}
101 lines
4.2 KiB
C++
101 lines
4.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 CALL_ADAPTATION_RESOURCE_ADAPTATION_PROCESSOR_H_
|
|
#define CALL_ADAPTATION_RESOURCE_ADAPTATION_PROCESSOR_H_
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
#include "absl/types/optional.h"
|
|
#include "api/rtp_parameters.h"
|
|
#include "api/video/video_frame.h"
|
|
#include "api/video/video_stream_encoder_observer.h"
|
|
#include "call/adaptation/resource.h"
|
|
#include "call/adaptation/resource_adaptation_processor_interface.h"
|
|
#include "call/adaptation/video_source_restrictions.h"
|
|
#include "call/adaptation/video_stream_adapter.h"
|
|
#include "call/adaptation/video_stream_input_state.h"
|
|
#include "call/adaptation/video_stream_input_state_provider.h"
|
|
|
|
namespace webrtc {
|
|
|
|
class ResourceAdaptationProcessor : public ResourceAdaptationProcessorInterface,
|
|
public ResourceListener {
|
|
public:
|
|
ResourceAdaptationProcessor(
|
|
VideoStreamInputStateProvider* input_state_provider,
|
|
VideoStreamEncoderObserver* encoder_stats_observer);
|
|
~ResourceAdaptationProcessor() override;
|
|
|
|
// ResourceAdaptationProcessorInterface implementation.
|
|
DegradationPreference degradation_preference() const override;
|
|
DegradationPreference effective_degradation_preference() const override;
|
|
|
|
void StartResourceAdaptation() override;
|
|
void StopResourceAdaptation() override;
|
|
void AddAdaptationListener(
|
|
ResourceAdaptationProcessorListener* adaptation_listener) override;
|
|
void AddResource(Resource* resource) override;
|
|
|
|
void SetDegradationPreference(
|
|
DegradationPreference degradation_preference) override;
|
|
void SetIsScreenshare(bool is_screenshare) override;
|
|
void ResetVideoSourceRestrictions() override;
|
|
|
|
// ResourceListener implementation.
|
|
// Triggers OnResourceUnderuse() or OnResourceOveruse().
|
|
ResourceListenerResponse OnResourceUsageStateMeasured(
|
|
const Resource& resource) override;
|
|
|
|
// May trigger 1-2 adaptations. It is meant to reduce resolution - useful if a
|
|
// frame was dropped due to its size - but if you look at the implementation
|
|
// you'll find that this is not guaranteed. It could adapt frame rate, which
|
|
// does not address the issue.
|
|
// TODO(hbos): Can we replace this by something which actually satisfies the
|
|
// resolution constraints, or get rid of it altogether?
|
|
void TriggerAdaptationDueToFrameDroppedDueToSize(
|
|
const Resource& reason_resource);
|
|
|
|
private:
|
|
bool HasSufficientInputForAdaptation(
|
|
const VideoStreamInputState& input_state) const;
|
|
|
|
// Performs the adaptation by getting the next target, applying it and
|
|
// informing listeners of the new VideoSourceRestriction and adaptation
|
|
// counters.
|
|
void OnResourceUnderuse(const Resource& reason_resource);
|
|
ResourceListenerResponse OnResourceOveruse(const Resource& reason_resource);
|
|
|
|
// Needs to be invoked any time |degradation_preference_| or |is_screenshare_|
|
|
// changes to ensure |effective_degradation_preference_| is up-to-date.
|
|
void MaybeUpdateEffectiveDegradationPreference();
|
|
// If the filtered source restrictions are different than
|
|
// |last_reported_source_restrictions_|, inform the listeners.
|
|
void MaybeUpdateVideoSourceRestrictions(const Resource* reason);
|
|
|
|
// Input and output.
|
|
VideoStreamInputStateProvider* const input_state_provider_;
|
|
VideoStreamEncoderObserver* const encoder_stats_observer_;
|
|
std::vector<ResourceAdaptationProcessorListener*> adaptation_listeners_;
|
|
std::vector<Resource*> resources_;
|
|
// Adaptation strategy settings.
|
|
DegradationPreference degradation_preference_;
|
|
DegradationPreference effective_degradation_preference_;
|
|
bool is_screenshare_;
|
|
// Responsible for generating and applying possible adaptations.
|
|
const std::unique_ptr<VideoStreamAdapter> stream_adapter_;
|
|
VideoSourceRestrictions last_reported_source_restrictions_;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // CALL_ADAPTATION_RESOURCE_ADAPTATION_PROCESSOR_H_
|