This turned out to be a bit complicated, mostly related to the tests, but here's what's changed: * No AsyncInvoker (and avoid ClearInternal) in WebRtcVideoSendStream (WVSS) * The reason it was there is due to a "design leak" from VideoSourceSinkController/VideoStreamEncoder where the former uses locks in all methods and is unaware of a threading model. That design affected downstream objects, pushed the need for an async hop into WVSS and added a lock. A suggestion was made to address this in a follow-up change, here: https://webrtc-review.googlesource.com/c/src/+/165684 * All methods in VideoSourceSinkController are now called on a known and checked sequence and this CL removes the lock. This also makes checking state consistent (i.e. calling a getter twice in a row on the same sequence, will always return the same value, avoiding race with other threads). * Handling of reporting state changes from the encoder queue to the VSSC, is done by VideoStreamEncoder. * VideoSendStreamImpl is still instantiated on the incorrect thread [1] but has two initialization steps [2]. The second one already runs on the right thread. Addressing that TODO [1] is something we should do but it has side effects to consider. For the purposes of this CL the steps relating to the encoder (setting the sink pointer) have been moved to [2]. [1] https://source.chromium.org/chromium/chromium/src/+/master:third_party/webrtc/video/video_send_stream.cc;l=94 [2] https://source.chromium.org/chromium/chromium/src/+/master:third_party/webrtc/video/video_send_stream.cc;drc=f4a9991cce74a37d006438ec0e366313ed33162e;l=115 Bug: webrtc:11222, webrtc:11908 Change-Id: Ie46d46e3a52bbe225951b4bd580ecb8cc9cad873 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184508 Reviewed-by: Henrik Boström <hbos@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32150}
86 lines
3.5 KiB
C++
86 lines
3.5 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 <string>
|
|
|
|
#include "absl/types/optional.h"
|
|
#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"
|
|
#include "rtc_base/synchronization/sequence_checker.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);
|
|
|
|
~VideoSourceSinkController();
|
|
|
|
void SetSource(rtc::VideoSourceInterface<VideoFrame>* source);
|
|
bool HasSource() const;
|
|
|
|
// 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);
|
|
|
|
private:
|
|
rtc::VideoSinkWants CurrentSettingsToSinkWants() const
|
|
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.
|
|
SequenceChecker sequence_checker_;
|
|
|
|
rtc::VideoSinkInterface<VideoFrame>* const sink_;
|
|
rtc::VideoSourceInterface<VideoFrame>* source_
|
|
RTC_GUARDED_BY(&sequence_checker_);
|
|
// Pixel and frame rate restrictions.
|
|
VideoSourceRestrictions restrictions_ RTC_GUARDED_BY(&sequence_checker_);
|
|
// 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(&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;
|
|
};
|
|
|
|
} // namespace webrtc
|
|
|
|
#endif // VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
|