2020-08-14 16:58:22 +00:00
|
|
|
/*
|
|
|
|
* 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 <string>
|
2021-06-25 00:43:10 +00:00
|
|
|
#include <vector>
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
#include "absl/types/optional.h"
|
2021-06-25 00:43:10 +00:00
|
|
|
#include "api/sequence_checker.h"
|
2020-08-14 16:58:22 +00:00
|
|
|
#include "api/video/video_frame.h"
|
|
|
|
#include "api/video/video_sink_interface.h"
|
|
|
|
#include "api/video/video_source_interface.h"
|
|
|
|
#include "call/adaptation/video_source_restrictions.h"
|
2021-06-25 00:43:10 +00:00
|
|
|
#include "rtc_base/system/no_unique_address.h"
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-12-23 07:48:30 +00:00
|
|
|
~VideoSourceSinkController();
|
|
|
|
|
2020-08-14 16:58:22 +00:00
|
|
|
void SetSource(rtc::VideoSourceInterface<VideoFrame>* source);
|
2020-12-23 07:48:30 +00:00
|
|
|
bool HasSource() const;
|
|
|
|
|
2020-08-14 16:58:22 +00:00
|
|
|
// 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;
|
2021-06-25 00:43:10 +00:00
|
|
|
const std::vector<rtc::VideoSinkWants::FrameSize>& resolutions() const;
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
// 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);
|
2021-06-25 00:43:10 +00:00
|
|
|
void SetResolutions(std::vector<rtc::VideoSinkWants::FrameSize> resolutions);
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
rtc::VideoSinkWants CurrentSettingsToSinkWants() const
|
2020-12-23 07:48:30 +00:00
|
|
|
RTC_EXCLUSIVE_LOCKS_REQUIRED(sequence_checker_);
|
|
|
|
|
|
|
|
// Used to ensure that this class is called on threads/sequences that it and
|
|
|
|
// downstream implementations were designed for.
|
|
|
|
// In practice, this represent's libjingle's worker thread.
|
2021-06-25 00:43:10 +00:00
|
|
|
RTC_NO_UNIQUE_ADDRESS SequenceChecker sequence_checker_;
|
2020-08-14 16:58:22 +00:00
|
|
|
|
|
|
|
rtc::VideoSinkInterface<VideoFrame>* const sink_;
|
2020-12-23 07:48:30 +00:00
|
|
|
rtc::VideoSourceInterface<VideoFrame>* source_
|
|
|
|
RTC_GUARDED_BY(&sequence_checker_);
|
2020-08-14 16:58:22 +00:00
|
|
|
// Pixel and frame rate restrictions.
|
2020-12-23 07:48:30 +00:00
|
|
|
VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&sequence_checker_);
|
2020-08-14 16:58:22 +00:00
|
|
|
// Ensures that even if we are not restricted, the sink is never configured
|
2022-03-11 16:49:54 +00:00
|
|
|
// above this limit. Example: We are not CPU limited (no `restrictions_`) but
|
|
|
|
// our encoder is capped at 30 fps (= `frame_rate_upper_limit_`).
|
2020-12-23 07:48:30 +00:00
|
|
|
absl::optional<size_t> pixels_per_frame_upper_limit_
|
|
|
|
RTC_GUARDED_BY(&sequence_checker_);
|
|
|
|
absl::optional<double> frame_rate_upper_limit_
|
|
|
|
RTC_GUARDED_BY(&sequence_checker_);
|
|
|
|
bool rotation_applied_ RTC_GUARDED_BY(&sequence_checker_) = false;
|
|
|
|
int resolution_alignment_ RTC_GUARDED_BY(&sequence_checker_) = 1;
|
2021-06-25 00:43:10 +00:00
|
|
|
std::vector<rtc::VideoSinkWants::FrameSize> resolutions_
|
|
|
|
RTC_GUARDED_BY(&sequence_checker_);
|
2020-08-14 16:58:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
#endif // VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
|