Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/optional.h" | 8 #include "base/optional.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
| 11 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" | 11 #include "content/renderer/media/webrtc/webrtc_video_capturer_adapter.h" |
| 12 #include "gpu/command_buffer/common/mailbox_holder.h" | 12 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 13 #include "media/base/video_frame.h" | 13 #include "media/base/video_frame.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {} | 17 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {} |
| 18 } // anonymous namespace | 18 } // anonymous namespace |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 class WebRtcVideoCapturerAdapterTest | 22 class WebRtcVideoCapturerAdapterTest |
| 23 : public rtc::VideoSinkInterface<webrtc::VideoFrame>, | 23 : public rtc::VideoSinkInterface<webrtc::VideoFrame>, |
| 24 public ::testing::Test { | 24 public ::testing::Test { |
| 25 public: | 25 public: |
| 26 WebRtcVideoCapturerAdapterTest() | 26 WebRtcVideoCapturerAdapterTest() |
| 27 : adapter_(false), | 27 : adapter_(new WebRtcVideoCapturerAdapter( |
| 28 false, | |
| 29 blink::WebMediaStreamTrack::ContentHintType::None)), | |
| 28 output_frame_width_(0), | 30 output_frame_width_(0), |
| 29 output_frame_height_(0) { | 31 output_frame_height_(0) { |
| 30 adapter_.AddOrUpdateSink(this, rtc::VideoSinkWants()); | 32 adapter_->AddOrUpdateSink(this, rtc::VideoSinkWants()); |
| 31 } | 33 } |
| 32 ~WebRtcVideoCapturerAdapterTest() override { | 34 ~WebRtcVideoCapturerAdapterTest() override { |
| 33 adapter_.RemoveSink(this); | 35 adapter_->RemoveSink(this); |
| 34 } | 36 } |
| 35 | 37 |
| 36 void TestSourceCropFrame(int capture_width, | 38 void TestSourceCropFrame(int capture_width, |
| 37 int capture_height, | 39 int capture_height, |
| 38 int cropped_width, | 40 int cropped_width, |
| 39 int cropped_height, | 41 int cropped_height, |
| 40 int natural_width, | 42 int natural_width, |
| 41 int natural_height) { | 43 int natural_height) { |
| 42 const int horiz_crop = ((capture_width - cropped_width) / 2); | 44 const int horiz_crop = ((capture_width - cropped_width) / 2); |
| 43 const int vert_crop = ((capture_height - cropped_height) / 2); | 45 const int vert_crop = ((capture_height - cropped_height) / 2); |
| 44 | 46 |
| 45 gfx::Size coded_size(capture_width, capture_height); | 47 gfx::Size coded_size(capture_width, capture_height); |
| 46 gfx::Size natural_size(natural_width, natural_height); | 48 gfx::Size natural_size(natural_width, natural_height); |
| 47 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height); | 49 gfx::Rect view_rect(horiz_crop, vert_crop, cropped_width, cropped_height); |
| 48 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( | 50 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( |
| 49 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size, | 51 media::PIXEL_FORMAT_I420, coded_size, view_rect, natural_size, |
| 50 base::TimeDelta()); | 52 base::TimeDelta()); |
| 51 adapter_.OnFrameCaptured(frame); | 53 adapter_->OnFrameCaptured(frame); |
| 52 EXPECT_EQ(natural_width, output_frame_width_); | 54 EXPECT_EQ(natural_width, output_frame_width_); |
| 53 EXPECT_EQ(natural_height, output_frame_height_); | 55 EXPECT_EQ(natural_height, output_frame_height_); |
| 54 } | 56 } |
| 55 | 57 |
| 56 void TestSourceTextureFrame() { | 58 void TestSourceTextureFrame() { |
| 57 EXPECT_TRUE(message_loop_.IsCurrent()); | 59 EXPECT_TRUE(message_loop_.IsCurrent()); |
| 58 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = { | 60 gpu::MailboxHolder holders[media::VideoFrame::kMaxPlanes] = { |
| 59 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5)}; | 61 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5)}; |
| 60 scoped_refptr<media::VideoFrame> frame = | 62 scoped_refptr<media::VideoFrame> frame = |
| 61 media::VideoFrame::WrapNativeTextures( | 63 media::VideoFrame::WrapNativeTextures( |
| 62 media::PIXEL_FORMAT_ARGB, holders, base::Bind(&ReleaseMailboxCB), | 64 media::PIXEL_FORMAT_ARGB, holders, base::Bind(&ReleaseMailboxCB), |
| 63 gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10), | 65 gfx::Size(10, 10), gfx::Rect(10, 10), gfx::Size(10, 10), |
| 64 base::TimeDelta()); | 66 base::TimeDelta()); |
| 65 adapter_.OnFrameCaptured(frame); | 67 adapter_->OnFrameCaptured(frame); |
| 66 ASSERT_TRUE(output_frame_); | 68 ASSERT_TRUE(output_frame_); |
| 67 rtc::scoped_refptr<webrtc::VideoFrameBuffer> texture_frame = | 69 rtc::scoped_refptr<webrtc::VideoFrameBuffer> texture_frame = |
| 68 output_frame_->video_frame_buffer(); | 70 output_frame_->video_frame_buffer(); |
| 69 EXPECT_EQ(media::VideoFrame::STORAGE_OPAQUE, | 71 EXPECT_EQ(media::VideoFrame::STORAGE_OPAQUE, |
| 70 static_cast<media::VideoFrame*>(texture_frame->native_handle()) | 72 static_cast<media::VideoFrame*>(texture_frame->native_handle()) |
| 71 ->storage_type()); | 73 ->storage_type()); |
| 72 | 74 |
| 73 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copied_frame = | 75 rtc::scoped_refptr<webrtc::VideoFrameBuffer> copied_frame = |
| 74 texture_frame->NativeToI420Buffer(); | 76 texture_frame->NativeToI420Buffer(); |
| 75 EXPECT_TRUE(copied_frame); | 77 EXPECT_TRUE(copied_frame); |
| 76 EXPECT_TRUE(copied_frame->DataY()); | 78 EXPECT_TRUE(copied_frame->DataY()); |
| 77 EXPECT_TRUE(copied_frame->DataU()); | 79 EXPECT_TRUE(copied_frame->DataU()); |
| 78 EXPECT_TRUE(copied_frame->DataV()); | 80 EXPECT_TRUE(copied_frame->DataV()); |
| 79 } | 81 } |
| 80 | 82 |
| 81 // rtc::VideoSinkInterface | 83 // rtc::VideoSinkInterface |
| 82 void OnFrame(const webrtc::VideoFrame& frame) override { | 84 void OnFrame(const webrtc::VideoFrame& frame) override { |
| 83 output_frame_ = base::Optional<webrtc::VideoFrame>(frame); | 85 output_frame_ = base::Optional<webrtc::VideoFrame>(frame); |
| 84 output_frame_width_ = frame.width(); | 86 output_frame_width_ = frame.width(); |
| 85 output_frame_height_ = frame.height(); | 87 output_frame_height_ = frame.height(); |
| 86 } | 88 } |
| 87 | 89 |
| 90 void TestContentHintResolutionAdaptation( | |
| 91 bool is_screencast, | |
| 92 blink::WebMediaStreamTrack::ContentHintType construction_content_hint, | |
| 93 bool expect_initial_downscale, | |
| 94 blink::WebMediaStreamTrack::ContentHintType set_content_hint, | |
| 95 bool expect_final_downscale) { | |
| 96 // Reset and configure adapter to the test. | |
| 97 adapter_->RemoveSink(this); | |
| 98 adapter_.reset(new WebRtcVideoCapturerAdapter(is_screencast, | |
| 99 construction_content_hint)); | |
| 100 | |
| 101 const int kInputWidth = 1280; | |
| 102 const int kInputHeight = 720; | |
| 103 gfx::Size size(kInputWidth, kInputHeight); | |
|
emircan
2016/12/19 21:14:27
const
pbos
2016/12/19 21:42:26
Done.
| |
| 104 scoped_refptr<media::VideoFrame> frame = media::VideoFrame::CreateFrame( | |
| 105 media::PIXEL_FORMAT_I420, size, gfx::Rect(size), size, | |
| 106 base::TimeDelta()); | |
| 107 | |
| 108 // Request smaller scale to make sure scaling normally kicks in. | |
| 109 rtc::VideoSinkWants wants; | |
| 110 wants.max_pixel_count = rtc::Optional<int>(kInputWidth * kInputHeight / 2); | |
| 111 adapter_->AddOrUpdateSink(this, wants); | |
| 112 | |
| 113 adapter_->OnFrameCaptured(frame); | |
| 114 if (expect_initial_downscale) { | |
| 115 EXPECT_LT(output_frame_width_, kInputWidth); | |
| 116 EXPECT_LT(output_frame_height_, kInputHeight); | |
| 117 } else { | |
| 118 EXPECT_EQ(kInputWidth, output_frame_width_); | |
| 119 EXPECT_EQ(kInputHeight, output_frame_height_); | |
| 120 } | |
| 121 | |
| 122 adapter_->SetContentHint(set_content_hint); | |
| 123 adapter_->OnFrameCaptured(frame); | |
| 124 if (expect_final_downscale) { | |
| 125 EXPECT_LT(output_frame_width_, kInputWidth); | |
| 126 EXPECT_LT(output_frame_height_, kInputHeight); | |
| 127 } else { | |
| 128 EXPECT_EQ(kInputWidth, output_frame_width_); | |
| 129 EXPECT_EQ(kInputHeight, output_frame_height_); | |
| 130 } | |
| 131 } | |
| 132 | |
| 88 private: | 133 private: |
| 89 const base::MessageLoopForIO message_loop_; | 134 const base::MessageLoopForIO message_loop_; |
| 90 const ChildProcess child_process_; | 135 const ChildProcess child_process_; |
| 91 | 136 |
| 92 WebRtcVideoCapturerAdapter adapter_; | 137 std::unique_ptr<WebRtcVideoCapturerAdapter> adapter_; |
| 93 base::Optional<webrtc::VideoFrame> output_frame_; | 138 base::Optional<webrtc::VideoFrame> output_frame_; |
| 94 int output_frame_width_; | 139 int output_frame_width_; |
| 95 int output_frame_height_; | 140 int output_frame_height_; |
| 96 }; | 141 }; |
| 97 | 142 |
| 98 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { | 143 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo640360) { |
| 99 TestSourceCropFrame(640, 480, 640, 360, 640, 360); | 144 TestSourceCropFrame(640, 480, 640, 360, 640, 360); |
| 100 } | 145 } |
| 101 | 146 |
| 102 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { | 147 TEST_F(WebRtcVideoCapturerAdapterTest, CropFrameTo320320) { |
| 103 TestSourceCropFrame(640, 480, 480, 480, 320, 320); | 148 TestSourceCropFrame(640, 480, 480, 480, 320, 320); |
| 104 } | 149 } |
| 105 | 150 |
| 106 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { | 151 TEST_F(WebRtcVideoCapturerAdapterTest, Scale720To640360) { |
| 107 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); | 152 TestSourceCropFrame(1280, 720, 1280, 720, 640, 360); |
| 108 } | 153 } |
| 109 | 154 |
| 110 TEST_F(WebRtcVideoCapturerAdapterTest, SendsWithCopyTextureFrameCallback) { | 155 TEST_F(WebRtcVideoCapturerAdapterTest, SendsWithCopyTextureFrameCallback) { |
| 111 TestSourceTextureFrame(); | 156 TestSourceTextureFrame(); |
| 112 } | 157 } |
| 113 | 158 |
| 159 TEST_F(WebRtcVideoCapturerAdapterTest, DoesNotAdaptContentHintDetail) { | |
| 160 // Non-screenshare adapter should not adapt frames when detailed is set. | |
|
emircan
2016/12/19 21:14:27
Can you parameterize these tests using GetParam()
pbos
2016/12/19 21:42:26
I added the corresponding transitions instead, hop
emircan
2016/12/19 22:37:53
I would highly recommend it because you can easily
pbos
2016/12/19 22:44:27
Ack, will go with this now be because 2/5 paramete
| |
| 161 TestContentHintResolutionAdaptation( | |
| 162 false, blink::WebMediaStreamTrack::ContentHintType::None, true, | |
| 163 blink::WebMediaStreamTrack::ContentHintType::VideoDetailed, false); | |
| 164 } | |
| 165 | |
| 166 TEST_F(WebRtcVideoCapturerAdapterTest, | |
| 167 DoesAdaptScreencastWithFluidContentHint) { | |
| 168 // Screenshare adapter should adapt frames when fluid is set. | |
| 169 TestContentHintResolutionAdaptation( | |
| 170 true, blink::WebMediaStreamTrack::ContentHintType::None, false, | |
| 171 blink::WebMediaStreamTrack::ContentHintType::VideoFluid, true); | |
| 172 } | |
| 173 | |
| 174 TEST_F(WebRtcVideoCapturerAdapterTest, | |
| 175 RespectsConstructionTimeContentHint) { | |
| 176 // Non-screenshare adapter constructed with detailed content hint should not | |
| 177 // adapt before SetContentHint is run. | |
| 178 TestContentHintResolutionAdaptation( | |
| 179 false, blink::WebMediaStreamTrack::ContentHintType::VideoDetailed, false, | |
| 180 blink::WebMediaStreamTrack::ContentHintType::VideoFluid, true); | |
| 181 } | |
| 182 | |
| 114 } // namespace content | 183 } // namespace content |
| OLD | NEW |