diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index ea59b0aba0..b4b5af556d 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -336,6 +336,7 @@ class VideoStreamEncoder::VideoSourceProxy { } // Limit to configured max framerate. wants.max_framerate_fps = std::min(max_framerate_, wants.max_framerate_fps); + wants.partial_frames = true; return wants; } @@ -713,8 +714,24 @@ void VideoStreamEncoder::ConfigureQualityScaler() { void VideoStreamEncoder::OnFrame(const VideoFrame& video_frame) { RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); + + const VideoFrame::PartialFrameDescription* partial_desc = + video_frame.partial_frame_description(); VideoFrame incoming_frame = video_frame; + if (video_frame.cache_buffer_for_partial_updates()) { + VideoFrameBuffer* input_buffer = video_frame.video_frame_buffer(); + if (!partial_frame_assembler_.ApplyPartialUpdate( + input_buffer, &incoming_frame, partial_desc)) { + // Can't apply new image to the cached buffer because of some error. + // Nothing sensible to encode. + // Detailed error message is already logged by |ApplyPartialUpdate()|. + return; + } + } else { + partial_frame_assembler_.Reset(); + } + // Local time in webrtc time base. int64_t current_time_us = clock_->TimeInMicroseconds(); int64_t current_time_ms = current_time_us / rtc::kNumMicrosecsPerMillisec; diff --git a/video/video_stream_encoder.h b/video/video_stream_encoder.h index 577ca5b562..0c9cb3c828 100644 --- a/video/video_stream_encoder.h +++ b/video/video_stream_encoder.h @@ -33,6 +33,7 @@ #include "rtc_base/sequenced_task_checker.h" #include "rtc_base/task_queue.h" #include "video/overuse_frame_detector.h" +#include "video/partial_frame_assembler.h" namespace webrtc { @@ -295,6 +296,9 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface, // the worker thread. std::atomic pending_frame_drops_; + PartialFrameAssembler partial_frame_assembler_ + RTC_GUARDED_BY(incoming_frame_race_checker_); + // All public methods are proxied to |encoder_queue_|. It must must be // destroyed first to make sure no tasks are run that use other members. rtc::TaskQueue encoder_queue_;