Commit c4bda27d authored by Ilya Nikolaevskiy's avatar Ilya Nikolaevskiy Committed by Commit Bot

Set VideoFrameFeedback in WebRtcVideoTrackSource

This forward webrtc SinkWants signal to the capturers.
Currently only tab capturer respects these signals and it's done on a best-effort basis.
Therefore, adaptation code is going to stay in case of capturer not supporting the signal
in current conditions.

Bug: chromium:1116430
Change-Id: I70da52786241564c2cd2c668ac882651789d367d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386743
Commit-Queue: Ilya Nikolaevskiy <ilnik@chromium.org>
Auto-Submit: Ilya Nikolaevskiy <ilnik@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806180}
parent 0aa210bf
......@@ -109,6 +109,11 @@ void WebRtcVideoTrackSource::SetCustomFrameAdaptationParamsForTesting(
custom_frame_adaptation_params_for_testing_ = params;
}
void WebRtcVideoTrackSource::SetSinkWantsForTesting(
const rtc::VideoSinkWants& sink_wants) {
video_adapter()->OnSinkWants(sink_wants);
}
WebRtcVideoTrackSource::SourceState WebRtcVideoTrackSource::state() const {
// TODO(nisse): What's supposed to change this state?
return MediaSourceInterface::SourceState::kLive;
......@@ -126,6 +131,13 @@ absl::optional<bool> WebRtcVideoTrackSource::needs_denoising() const {
return needs_denoising_;
}
void WebRtcVideoTrackSource::SetFrameFeedback(
scoped_refptr<media::VideoFrame> frame) {
media::VideoFrameFeedback* feedback = frame->feedback();
feedback->max_pixels = video_adapter()->GetTargetPixels();
feedback->max_framerate_fps = video_adapter()->GetMaxFramerate();
}
void WebRtcVideoTrackSource::OnFrameCaptured(
scoped_refptr<media::VideoFrame> frame) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......@@ -144,6 +156,8 @@ void WebRtcVideoTrackSource::OnFrameCaptured(
return;
}
SetFrameFeedback(frame);
// Compute what rectangular region has changed since the last frame
// that we successfully delivered to the base class method
// rtc::AdaptedVideoTrackSource::OnFrame(). This region is going to be
......
......@@ -41,6 +41,8 @@ class PLATFORM_EXPORT WebRtcVideoTrackSource
void SetCustomFrameAdaptationParamsForTesting(
const FrameAdaptationParams& params);
void SetSinkWantsForTesting(const rtc::VideoSinkWants& sink_wants);
SourceState state() const override;
bool remote() const override;
......@@ -52,6 +54,8 @@ class PLATFORM_EXPORT WebRtcVideoTrackSource
using webrtc::VideoTrackSourceInterface::RemoveSink;
private:
void SetFrameFeedback(scoped_refptr<media::VideoFrame> frame);
FrameAdaptationParams ComputeAdaptationParams(int width,
int height,
int64_t time_us);
......
......@@ -56,6 +56,20 @@ class WebRtcVideoTrackSourceTest
track_source_->OnFrameCaptured(frame);
}
void SendTestFrameAndVerifyFeedback(
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
const gfx::Size& natural_size,
media::VideoFrame::StorageType storage_type,
int max_pixels,
float max_framerate) {
scoped_refptr<media::VideoFrame> frame =
CreateTestFrame(coded_size, visible_rect, natural_size, storage_type);
track_source_->OnFrameCaptured(frame);
EXPECT_EQ(frame->feedback()->max_pixels, max_pixels);
EXPECT_EQ(frame->feedback()->max_framerate_fps, max_framerate);
}
void SendTestFrameWithUpdateRect(
const gfx::Size& coded_size,
const gfx::Rect& visible_rect,
......@@ -130,6 +144,24 @@ TEST_P(WebRtcVideoTrackSourceTest, CropFrameTo640360) {
SendTestFrame(kCodedSize, kVisibleRect, kNaturalSize, storage_type);
}
TEST_P(WebRtcVideoTrackSourceTest, SetsFeedback) {
const gfx::Size kCodedSize(640, 480);
const gfx::Rect kVisibleRect(0, 60, 640, 360);
const gfx::Size kNaturalSize(640, 360);
const gfx::Size kScaleToSize = gfx::Size(320, 180);
const float k5Fps = 5.0;
const media::VideoFrame::StorageType storage_type = GetParam();
rtc::VideoSinkWants sink_wants;
sink_wants.max_pixel_count = kScaleToSize.GetArea();
sink_wants.max_framerate_fps = static_cast<int>(k5Fps);
track_source_->SetSinkWantsForTesting(sink_wants);
EXPECT_CALL(mock_sink_, OnFrame(_));
SendTestFrameAndVerifyFeedback(kCodedSize, kVisibleRect, kNaturalSize,
storage_type, kScaleToSize.GetArea(), k5Fps);
}
TEST_P(WebRtcVideoTrackSourceTest, CropFrameTo320320) {
const gfx::Size kCodedSize(640, 480);
const gfx::Rect kVisibleRect(80, 0, 480, 480);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment