Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/browser/media/capture/desktop_capture_device_unittest.cc

Issue 2050353002: Update webrtc::DesktopCapturer clients to implement OnCaptureResult(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/media/capture/desktop_capture_device.h" 5 #include "content/browser/media/capture/desktop_capture_device.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 storage == media::PIXEL_STORAGE_CPU); 104 storage == media::PIXEL_STORAGE_CPU);
105 DoResurrectLastOutputBuffer(); 105 DoResurrectLastOutputBuffer();
106 return std::unique_ptr<Buffer>(); 106 return std::unique_ptr<Buffer>();
107 } 107 }
108 double GetBufferPoolUtilization() const override { return 0.0; } 108 double GetBufferPoolUtilization() const override { return 0.0; }
109 }; 109 };
110 110
111 // Creates a DesktopFrame that has the first pixel bytes set to 111 // Creates a DesktopFrame that has the first pixel bytes set to
112 // kFakePixelValueFirst, and the rest of the bytes set to kFakePixelValue, for 112 // kFakePixelValueFirst, and the rest of the bytes set to kFakePixelValue, for
113 // UnpackedFrame and InvertedFrame verification. 113 // UnpackedFrame and InvertedFrame verification.
114 webrtc::BasicDesktopFrame* CreateBasicFrame(const webrtc::DesktopSize& size) { 114 unique_ptr<webrtc::BasicDesktopFrame> CreateBasicFrame(
115 webrtc::BasicDesktopFrame* frame = new webrtc::BasicDesktopFrame(size); 115 const webrtc::DesktopSize& size) {
116 unique_ptr<webrtc::BasicDesktopFrame> frame(
117 new webrtc::BasicDesktopFrame(size));
116 DCHECK_EQ(frame->size().width() * webrtc::DesktopFrame::kBytesPerPixel, 118 DCHECK_EQ(frame->size().width() * webrtc::DesktopFrame::kBytesPerPixel,
117 frame->stride()); 119 frame->stride());
118 memset(frame->data(), 120 memset(frame->data(), kFakePixelValue,
119 kFakePixelValue,
120 frame->stride() * frame->size().height()); 121 frame->stride() * frame->size().height());
121 memset(frame->data(), 122 memset(frame->data(), kFakePixelValueFirst,
122 kFakePixelValueFirst,
123 webrtc::DesktopFrame::kBytesPerPixel); 123 webrtc::DesktopFrame::kBytesPerPixel);
124 return frame; 124 return frame;
125 } 125 }
126 126
127 // DesktopFrame wrapper that flips wrapped frame upside down by inverting 127 // DesktopFrame wrapper that flips wrapped frame upside down by inverting
128 // stride. 128 // stride.
129 class InvertedDesktopFrame : public webrtc::DesktopFrame { 129 class InvertedDesktopFrame : public webrtc::DesktopFrame {
130 public: 130 public:
131 // Takes ownership of |frame|. 131 // Takes ownership of |frame|.
132 explicit InvertedDesktopFrame(webrtc::DesktopFrame* frame) 132 explicit InvertedDesktopFrame(unique_ptr<webrtc::DesktopFrame> frame)
133 : webrtc::DesktopFrame( 133 : webrtc::DesktopFrame(
134 frame->size(), 134 frame->size(),
135 -frame->stride(), 135 -frame->stride(),
136 frame->data() + (frame->size().height() - 1) * frame->stride(), 136 frame->data() + (frame->size().height() - 1) * frame->stride(),
137 frame->shared_memory()), 137 frame->shared_memory()) {
138 original_frame_(frame) {
139 set_dpi(frame->dpi()); 138 set_dpi(frame->dpi());
140 set_capture_time_ms(frame->capture_time_ms()); 139 set_capture_time_ms(frame->capture_time_ms());
141 mutable_updated_region()->Swap(frame->mutable_updated_region()); 140 mutable_updated_region()->Swap(frame->mutable_updated_region());
141 original_frame_ = std::move(frame);
142 } 142 }
143 ~InvertedDesktopFrame() override {} 143 ~InvertedDesktopFrame() override {}
144 144
145 private: 145 private:
146 std::unique_ptr<webrtc::DesktopFrame> original_frame_; 146 std::unique_ptr<webrtc::DesktopFrame> original_frame_;
147 147
148 DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame); 148 DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame);
149 }; 149 };
150 150
151 // DesktopFrame wrapper that copies the input frame and doubles the stride. 151 // DesktopFrame wrapper that copies the input frame and doubles the stride.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 void Capture(const webrtc::DesktopRegion& region) override { 197 void Capture(const webrtc::DesktopRegion& region) override {
198 webrtc::DesktopSize size; 198 webrtc::DesktopSize size;
199 if (frame_index_ % 2 == 0) { 199 if (frame_index_ % 2 == 0) {
200 size = webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1); 200 size = webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1);
201 } else { 201 } else {
202 size = webrtc::DesktopSize(kTestFrameWidth2, kTestFrameHeight2); 202 size = webrtc::DesktopSize(kTestFrameWidth2, kTestFrameHeight2);
203 } 203 }
204 frame_index_++; 204 frame_index_++;
205 205
206 webrtc::DesktopFrame* frame = CreateBasicFrame(size); 206 std::unique_ptr<webrtc::DesktopFrame> frame = CreateBasicFrame(size);
207 207
208 if (generate_inverted_frames_) { 208 if (generate_inverted_frames_) {
209 frame = new InvertedDesktopFrame(frame); 209 frame = new InvertedDesktopFrame(frame);
210 } else if (generate_cropped_frames_) { 210 } else if (generate_cropped_frames_) {
211 frame = new UnpackedDesktopFrame(frame); 211 frame = new UnpackedDesktopFrame(frame);
212 } 212 }
213 callback_->OnCaptureCompleted(frame); 213 callback_->OnCaptureResult(webrtc::DesktopCapturer::Result::SUCCESS,
214 std::move(frame));
214 } 215 }
215 216
216 bool GetScreenList(ScreenList* screens) override { return false; } 217 bool GetScreenList(ScreenList* screens) override { return false; }
217 218
218 bool SelectScreen(webrtc::ScreenId id) override { return false; } 219 bool SelectScreen(webrtc::ScreenId id) override { return false; }
219 220
220 private: 221 private:
221 Callback* callback_; 222 Callback* callback_;
222 int frame_index_; 223 int frame_index_;
223 bool generate_inverted_frames_; 224 bool generate_inverted_frames_;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 media::PIXEL_FORMAT_I420; 492 media::PIXEL_FORMAT_I420;
492 493
493 capture_device_->AllocateAndStart(capture_params, std::move(client)); 494 capture_device_->AllocateAndStart(capture_params, std::move(client));
494 495
495 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 496 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
496 done_event.Reset(); 497 done_event.Reset();
497 capture_device_->StopAndDeAllocate(); 498 capture_device_->StopAndDeAllocate();
498 499
499 // Verifies that |output_frame_| has the same data as a packed frame of the 500 // Verifies that |output_frame_| has the same data as a packed frame of the
500 // same size. 501 // same size.
501 std::unique_ptr<webrtc::BasicDesktopFrame> expected_frame(CreateBasicFrame( 502 std::unique_ptr<webrtc::BasicDesktopFrame> expected_frame = CreateBasicFrame(
502 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); 503 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1));
503 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(), 504 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(),
504 frame_size); 505 frame_size);
505 EXPECT_EQ( 506 EXPECT_EQ(
506 0, memcmp(output_frame_->data(), expected_frame->data(), frame_size)); 507 0, memcmp(output_frame_->data(), expected_frame->data(), frame_size));
507 } 508 }
508 509
509 // The test verifies that a bottom-to-top frame is converted to top-to-bottom. 510 // The test verifies that a bottom-to-top frame is converted to top-to-bottom.
510 TEST_F(DesktopCaptureDeviceTest, InvertedFrame) { 511 TEST_F(DesktopCaptureDeviceTest, InvertedFrame) {
511 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); 512 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
512 mock_capturer->set_generate_inverted_frames(true); 513 mock_capturer->set_generate_inverted_frames(true);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 frame_size); 552 frame_size);
552 for (int i = 0; i < output_frame_->size().height(); ++i) { 553 for (int i = 0; i < output_frame_->size().height(); ++i) {
553 EXPECT_EQ(0, 554 EXPECT_EQ(0,
554 memcmp(inverted_frame->data() + i * inverted_frame->stride(), 555 memcmp(inverted_frame->data() + i * inverted_frame->stride(),
555 output_frame_->data() + i * output_frame_->stride(), 556 output_frame_->data() + i * output_frame_->stride(),
556 output_frame_->stride())); 557 output_frame_->stride()));
557 } 558 }
558 } 559 }
559 560
560 } // namespace content 561 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698