2019-12-10 14:14:09 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright 2019 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_H_
|
|
|
|
|
#define CALL_ADAPTATION_RESOURCE_H_
|
|
|
|
|
|
2020-02-25 16:26:01 +01:00
|
|
|
#include <string>
|
2020-02-06 12:49:57 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "absl/types/optional.h"
|
2020-05-11 16:29:22 +02:00
|
|
|
#include "api/scoped_refptr.h"
|
2020-04-17 13:48:21 +02:00
|
|
|
#include "call/adaptation/video_source_restrictions.h"
|
|
|
|
|
#include "call/adaptation/video_stream_input_state.h"
|
2020-05-11 16:29:22 +02:00
|
|
|
#include "rtc_base/ref_count.h"
|
2020-05-12 18:49:07 +02:00
|
|
|
#include "rtc_base/task_queue.h"
|
2019-12-10 14:14:09 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
class Resource;
|
|
|
|
|
|
2019-12-10 14:14:09 +01:00
|
|
|
enum class ResourceUsageState {
|
|
|
|
|
// Action is needed to minimze the load on this resource.
|
|
|
|
|
kOveruse,
|
2020-04-20 12:04:12 +02:00
|
|
|
// Increasing the load on this resource is desired, if possible.
|
2019-12-10 14:14:09 +01:00
|
|
|
kUnderuse,
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-28 16:22:42 +02:00
|
|
|
const char* ResourceUsageStateToString(ResourceUsageState usage_state);
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
class ResourceListener {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~ResourceListener();
|
|
|
|
|
|
|
|
|
|
// Informs the listener of a new measurement of resource usage. This means
|
2020-05-11 16:29:22 +02:00
|
|
|
// that |resource->usage_state()| is now up-to-date.
|
|
|
|
|
virtual void OnResourceUsageStateMeasured(
|
|
|
|
|
rtc::scoped_refptr<Resource> resource) = 0;
|
2020-02-06 12:49:57 +01:00
|
|
|
};
|
|
|
|
|
|
2020-05-11 16:29:22 +02:00
|
|
|
class Resource : public rtc::RefCountInterface {
|
2019-12-10 14:14:09 +01:00
|
|
|
public:
|
2020-04-20 12:04:12 +02:00
|
|
|
// By default, usage_state() is null until a measurement is made.
|
2020-02-06 12:49:57 +01:00
|
|
|
Resource();
|
2020-05-11 16:29:22 +02:00
|
|
|
~Resource() override;
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-05-12 18:49:07 +02:00
|
|
|
void Initialize(rtc::TaskQueue* encoder_queue,
|
|
|
|
|
rtc::TaskQueue* resource_adaptation_queue);
|
|
|
|
|
|
2020-04-20 12:04:12 +02:00
|
|
|
void SetResourceListener(ResourceListener* listener);
|
|
|
|
|
|
|
|
|
|
absl::optional<ResourceUsageState> usage_state() const;
|
|
|
|
|
void ClearUsageState();
|
2020-02-06 12:49:57 +01:00
|
|
|
|
2020-04-17 13:48:21 +02:00
|
|
|
// This method allows the Resource to reject a proposed adaptation in the "up"
|
|
|
|
|
// direction if it predicts this would cause overuse of this resource. The
|
|
|
|
|
// default implementation unconditionally returns true (= allowed).
|
|
|
|
|
virtual bool IsAdaptationUpAllowed(
|
|
|
|
|
const VideoStreamInputState& input_state,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_before,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_after,
|
2020-05-11 16:29:22 +02:00
|
|
|
rtc::scoped_refptr<Resource> reason_resource) const;
|
2020-04-28 12:24:33 +02:00
|
|
|
virtual void OnAdaptationApplied(
|
|
|
|
|
const VideoStreamInputState& input_state,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_before,
|
|
|
|
|
const VideoSourceRestrictions& restrictions_after,
|
2020-05-11 16:29:22 +02:00
|
|
|
rtc::scoped_refptr<Resource> reason_resource);
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-02-25 16:26:01 +01:00
|
|
|
virtual std::string name() const = 0;
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
protected:
|
2020-05-12 18:49:07 +02:00
|
|
|
rtc::TaskQueue* encoder_queue() const;
|
|
|
|
|
rtc::TaskQueue* resource_adaptation_queue() const;
|
|
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
// Updates the usage state and informs all registered listeners.
|
2020-04-28 12:24:33 +02:00
|
|
|
void OnResourceUsageStateMeasured(ResourceUsageState usage_state);
|
2019-12-10 14:14:09 +01:00
|
|
|
|
2020-02-06 12:49:57 +01:00
|
|
|
private:
|
2020-05-12 18:49:07 +02:00
|
|
|
rtc::TaskQueue* encoder_queue_;
|
|
|
|
|
rtc::TaskQueue* resource_adaptation_queue_;
|
|
|
|
|
absl::optional<ResourceUsageState> usage_state_
|
|
|
|
|
RTC_GUARDED_BY(resource_adaptation_queue_);
|
|
|
|
|
ResourceListener* listener_ RTC_GUARDED_BY(resource_adaptation_queue_);
|
2019-12-10 14:14:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // CALL_ADAPTATION_RESOURCE_H_
|