From e1aa22f89215c7bad05e08b818431f583ed6621a Mon Sep 17 00:00:00 2001 From: Guido Urdaneta Date: Mon, 30 Mar 2020 23:02:14 +0200 Subject: [PATCH] [InsertableStreams] Set video frame transformer if RTP stream already started. Test in https://chromium-review.googlesource.com/c/chromium/src/+/2127927 Bug: chromium:1065836 Change-Id: Idf3f41285e23ac829f69f1bc95b1def3a73af8d6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/172400 Reviewed-by: Magnus Flodman Reviewed-by: Rasmus Brandt Reviewed-by: Marina Ciocea Commit-Queue: Guido Urdaneta Cr-Commit-Position: refs/heads/master@{#30948} --- call/video_receive_stream.h | 5 +++++ media/engine/fake_webrtc_call.h | 4 ++++ media/engine/webrtc_video_engine.cc | 4 ++++ video/rtp_video_stream_receiver.cc | 14 ++++++++++++++ video/rtp_video_stream_receiver.h | 5 +++++ video/video_receive_stream.cc | 6 ++++++ video/video_receive_stream.h | 2 ++ 7 files changed, 40 insertions(+) diff --git a/call/video_receive_stream.h b/call/video_receive_stream.h index 765d8027bf..388c28be24 100644 --- a/call/video_receive_stream.h +++ b/call/video_receive_stream.h @@ -300,6 +300,11 @@ class VideoReceiveStream { virtual void SetFrameDecryptor( rtc::scoped_refptr frame_decryptor) = 0; + // Allows a frame transformer to be attached to a VideoReceiveStream after + // creation without resetting the decoder state. + virtual void SetDepacketizerToDecoderFrameTransformer( + rtc::scoped_refptr frame_transformer) = 0; + // Sets and returns recording state. The old state is moved out // of the video receive stream and returned to the caller, and |state| // is moved in. If the state's callback is set, it will be called with diff --git a/media/engine/fake_webrtc_call.h b/media/engine/fake_webrtc_call.h index 5179323c80..4404dec5df 100644 --- a/media/engine/fake_webrtc_call.h +++ b/media/engine/fake_webrtc_call.h @@ -229,6 +229,10 @@ class FakeVideoReceiveStream final : public webrtc::VideoReceiveStream { void SetFrameDecryptor(rtc::scoped_refptr frame_decryptor) override {} + void SetDepacketizerToDecoderFrameTransformer( + rtc::scoped_refptr frame_transformer) + override {} + RecordingState SetAndGetRecordingState(RecordingState state, bool generate_key_frame) override { return RecordingState(); diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 5ecd221dd2..22856b0589 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -2565,6 +2565,8 @@ void WebRtcVideoChannel::WebRtcVideoSendStream:: frame_transformer) { RTC_DCHECK_RUN_ON(&thread_checker_); parameters_.config.frame_transformer = std::move(frame_transformer); + if (stream_) + RecreateWebRtcStream(); } void WebRtcVideoChannel::WebRtcVideoSendStream::RecreateWebRtcStream() { @@ -3041,6 +3043,8 @@ void WebRtcVideoChannel::WebRtcVideoReceiveStream:: rtc::scoped_refptr frame_transformer) { config_.frame_transformer = frame_transformer; + if (stream_) + stream_->SetDepacketizerToDecoderFrameTransformer(frame_transformer); } WebRtcVideoChannel::VideoCodecSettings::VideoCodecSettings() diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc index 4a2eb8d692..aecbf4fe54 100644 --- a/video/rtp_video_stream_receiver.cc +++ b/video/rtp_video_stream_receiver.cc @@ -881,6 +881,20 @@ void RtpVideoStreamReceiver::SetFrameDecryptor( buffered_frame_decryptor_->SetFrameDecryptor(std::move(frame_decryptor)); } +void RtpVideoStreamReceiver::SetDepacketizerToDecoderFrameTransformer( + rtc::scoped_refptr frame_transformer) { + RTC_DCHECK_RUN_ON(&network_tc_); + if (!frame_transformer_delegate_) { + frame_transformer_delegate_ = new rtc::RefCountedObject< + RtpVideoStreamReceiverFrameTransformerDelegate>( + this, std::move(frame_transformer), rtc::Thread::Current()); + frame_transformer_delegate_->Init(); + } else { + RTC_LOG(LS_ERROR) + << "Attempting to replace an existing frame transformer in a receiver"; + } +} + void RtpVideoStreamReceiver::UpdateRtt(int64_t max_rtt_ms) { if (nack_module_) nack_module_->UpdateRtt(max_rtt_ms); diff --git a/video/rtp_video_stream_receiver.h b/video/rtp_video_stream_receiver.h index 03070db51d..ba617fd02b 100644 --- a/video/rtp_video_stream_receiver.h +++ b/video/rtp_video_stream_receiver.h @@ -164,6 +164,11 @@ class RtpVideoStreamReceiver : public LossNotificationSender, void SetFrameDecryptor( rtc::scoped_refptr frame_decryptor); + // Sets a frame transformer after a stream has started, if no transformer + // has previously been set. Does not reset the decoder state. + void SetDepacketizerToDecoderFrameTransformer( + rtc::scoped_refptr frame_transformer); + // Called by VideoReceiveStream when stats are updated. void UpdateRtt(int64_t max_rtt_ms); diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc index 246daadb81..b2b96db9bf 100644 --- a/video/video_receive_stream.cc +++ b/video/video_receive_stream.cc @@ -535,6 +535,12 @@ void VideoReceiveStream::SetFrameDecryptor( rtp_video_stream_receiver_.SetFrameDecryptor(std::move(frame_decryptor)); } +void VideoReceiveStream::SetDepacketizerToDecoderFrameTransformer( + rtc::scoped_refptr frame_transformer) { + rtp_video_stream_receiver_.SetDepacketizerToDecoderFrameTransformer( + std::move(frame_transformer)); +} + void VideoReceiveStream::SendNack(const std::vector& sequence_numbers, bool buffering_allowed) { RTC_DCHECK(buffering_allowed); diff --git a/video/video_receive_stream.h b/video/video_receive_stream.h index a93a45a1b4..c1ebf2b600 100644 --- a/video/video_receive_stream.h +++ b/video/video_receive_stream.h @@ -99,6 +99,8 @@ class VideoReceiveStream : public webrtc::VideoReceiveStream, void SetFrameDecryptor( rtc::scoped_refptr frame_decryptor) override; + void SetDepacketizerToDecoderFrameTransformer( + rtc::scoped_refptr frame_transformer) override; // Implements rtc::VideoSinkInterface. void OnFrame(const VideoFrame& video_frame) override;