Revert "Delete video source proxying in WebRtcVideoSendStream"
This reverts commit b66003ca79cd34f65ef964a5e3b4766bc97a5659.
Reason for revert: Causes bot failures in Chromium, see https://chromium-review.googlesource.com/c/chromium/src/+/1470391
Original change's description:
> Delete video source proxying in WebRtcVideoSendStream
>
> Bug: webrtc:10147
> Change-Id: Ib9f399e79d99f7d8db53fa38ef4b92986913ac26
> Reviewed-on: https://webrtc-review.googlesource.com/c/121569
> Reviewed-by: Erik Språng <sprang@webrtc.org>
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#26633}
TBR=nisse@webrtc.org,sprang@webrtc.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: webrtc:10147
No-Try: True
Change-Id: I80395333d2be8fd3329c0bcdd6ed33d994a01ae3
Reviewed-on: https://webrtc-review.googlesource.com/c/122940
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Christian Fremerey <chfremer@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26672}
diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc
index 9c97bd1..e001872 100644
--- a/media/engine/webrtc_video_engine.cc
+++ b/media/engine/webrtc_video_engine.cc
@@ -1567,6 +1567,7 @@
enable_cpu_overuse_detection_(enable_cpu_overuse_detection),
source_(nullptr),
stream_(nullptr),
+ encoder_sink_(nullptr),
parameters_(std::move(config), options, max_bitrate_bps, codec_settings),
rtp_parameters_(CreateRtpParametersWithEncodings(sp)),
sending_(false) {
@@ -1662,7 +1663,7 @@
// Switch to the new source.
source_ = source;
if (source && stream_) {
- stream_->SetSource(source_, GetDegradationPreference());
+ stream_->SetSource(this, GetDegradationPreference());
}
return true;
}
@@ -1842,7 +1843,7 @@
UpdateSendState();
}
if (new_degradation_preference) {
- stream_->SetSource(source_, GetDegradationPreference());
+ stream_->SetSource(this, GetDegradationPreference());
}
return webrtc::RTCError::OK();
}
@@ -2023,6 +2024,39 @@
UpdateSendState();
}
+void WebRtcVideoChannel::WebRtcVideoSendStream::RemoveSink(
+ rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) {
+ RTC_DCHECK_RUN_ON(&thread_checker_);
+ RTC_DCHECK(encoder_sink_ == sink);
+ encoder_sink_ = nullptr;
+ source_->RemoveSink(sink);
+}
+
+void WebRtcVideoChannel::WebRtcVideoSendStream::AddOrUpdateSink(
+ rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
+ const rtc::VideoSinkWants& wants) {
+ if (worker_thread_ == rtc::Thread::Current()) {
+ // AddOrUpdateSink is called on |worker_thread_| if this is the first
+ // registration of |sink|.
+ RTC_DCHECK_RUN_ON(&thread_checker_);
+ encoder_sink_ = sink;
+ source_->AddOrUpdateSink(encoder_sink_, wants);
+ } else {
+ // Subsequent calls to AddOrUpdateSink will happen on the encoder task
+ // queue.
+ invoker_.AsyncInvoke<void>(
+ RTC_FROM_HERE, worker_thread_, [this, sink, wants] {
+ RTC_DCHECK_RUN_ON(&thread_checker_);
+ // |sink| may be invalidated after this task was posted since
+ // RemoveSink is called on the worker thread.
+ bool encoder_sink_valid = (sink == encoder_sink_);
+ if (source_ && encoder_sink_valid) {
+ source_->AddOrUpdateSink(encoder_sink_, wants);
+ }
+ });
+ }
+}
+
VideoSenderInfo WebRtcVideoChannel::WebRtcVideoSendStream::GetVideoSenderInfo(
bool log_stats) {
VideoSenderInfo info;
@@ -2145,7 +2179,7 @@
parameters_.encoder_config.encoder_specific_settings = NULL;
if (source_) {
- stream_->SetSource(source_, GetDegradationPreference());
+ stream_->SetSource(this, GetDegradationPreference());
}
// Call stream_->Start() if necessary conditions are met.
diff --git a/media/engine/webrtc_video_engine.h b/media/engine/webrtc_video_engine.h
index 464c78f..a3d5a2f 100644
--- a/media/engine/webrtc_video_engine.h
+++ b/media/engine/webrtc_video_engine.h
@@ -254,7 +254,8 @@
const std::vector<VideoCodecSettings>& codecs);
// Wrapper for the sender part.
- class WebRtcVideoSendStream {
+ class WebRtcVideoSendStream
+ : public rtc::VideoSourceInterface<webrtc::VideoFrame> {
public:
WebRtcVideoSendStream(
webrtc::Call* call,
@@ -275,6 +276,14 @@
void SetFrameEncryptor(
rtc::scoped_refptr<webrtc::FrameEncryptorInterface> frame_encryptor);
+ // Implements rtc::VideoSourceInterface<webrtc::VideoFrame>.
+ // WebRtcVideoSendStream acts as a source to the webrtc::VideoSendStream
+ // in |stream_|. This is done to proxy VideoSinkWants from the encoder to
+ // the worker thread.
+ void AddOrUpdateSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink,
+ const rtc::VideoSinkWants& wants) override;
+ void RemoveSink(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink) override;
+
bool SetVideoSend(const VideoOptions* options,
rtc::VideoSourceInterface<webrtc::VideoFrame>* source);
@@ -332,7 +341,8 @@
RTC_GUARDED_BY(&thread_checker_);
webrtc::VideoSendStream* stream_ RTC_GUARDED_BY(&thread_checker_);
-
+ rtc::VideoSinkInterface<webrtc::VideoFrame>* encoder_sink_
+ RTC_GUARDED_BY(&thread_checker_);
// Contains settings that are the same for all streams in the MediaChannel,
// such as codecs, header extensions, and the global bitrate limit for the
// entire channel.