| OLD | NEW |
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 storage == media::PIXEL_STORAGE_CPU); | 105 storage == media::PIXEL_STORAGE_CPU); |
| 106 DoResurrectLastOutputBuffer(); | 106 DoResurrectLastOutputBuffer(); |
| 107 return std::unique_ptr<Buffer>(); | 107 return std::unique_ptr<Buffer>(); |
| 108 } | 108 } |
| 109 double GetBufferPoolUtilization() const override { return 0.0; } | 109 double GetBufferPoolUtilization() const override { return 0.0; } |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // Creates a DesktopFrame that has the first pixel bytes set to | 112 // Creates a DesktopFrame that has the first pixel bytes set to |
| 113 // kFakePixelValueFirst, and the rest of the bytes set to kFakePixelValue, for | 113 // kFakePixelValueFirst, and the rest of the bytes set to kFakePixelValue, for |
| 114 // UnpackedFrame and InvertedFrame verification. | 114 // UnpackedFrame and InvertedFrame verification. |
| 115 webrtc::BasicDesktopFrame* CreateBasicFrame(const webrtc::DesktopSize& size) { | 115 unique_ptr<webrtc::BasicDesktopFrame> CreateBasicFrame( |
| 116 webrtc::BasicDesktopFrame* frame = new webrtc::BasicDesktopFrame(size); | 116 const webrtc::DesktopSize& size) { |
| 117 unique_ptr<webrtc::BasicDesktopFrame> frame( |
| 118 new webrtc::BasicDesktopFrame(size)); |
| 117 DCHECK_EQ(frame->size().width() * webrtc::DesktopFrame::kBytesPerPixel, | 119 DCHECK_EQ(frame->size().width() * webrtc::DesktopFrame::kBytesPerPixel, |
| 118 frame->stride()); | 120 frame->stride()); |
| 119 memset(frame->data(), | 121 memset(frame->data(), kFakePixelValue, |
| 120 kFakePixelValue, | |
| 121 frame->stride() * frame->size().height()); | 122 frame->stride() * frame->size().height()); |
| 122 memset(frame->data(), | 123 memset(frame->data(), kFakePixelValueFirst, |
| 123 kFakePixelValueFirst, | |
| 124 webrtc::DesktopFrame::kBytesPerPixel); | 124 webrtc::DesktopFrame::kBytesPerPixel); |
| 125 return frame; | 125 return frame; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // DesktopFrame wrapper that flips wrapped frame upside down by inverting | 128 // DesktopFrame wrapper that flips wrapped frame upside down by inverting |
| 129 // stride. | 129 // stride. |
| 130 class InvertedDesktopFrame : public webrtc::DesktopFrame { | 130 class InvertedDesktopFrame : public webrtc::DesktopFrame { |
| 131 public: | 131 public: |
| 132 // Takes ownership of |frame|. | 132 // Takes ownership of |frame|. |
| 133 explicit InvertedDesktopFrame(webrtc::DesktopFrame* frame) | 133 explicit InvertedDesktopFrame(unique_ptr<webrtc::DesktopFrame> frame) |
| 134 : webrtc::DesktopFrame( | 134 : webrtc::DesktopFrame( |
| 135 frame->size(), | 135 frame->size(), |
| 136 -frame->stride(), | 136 -frame->stride(), |
| 137 frame->data() + (frame->size().height() - 1) * frame->stride(), | 137 frame->data() + (frame->size().height() - 1) * frame->stride(), |
| 138 frame->shared_memory()), | 138 frame->shared_memory()) { |
| 139 original_frame_(frame) { | |
| 140 set_dpi(frame->dpi()); | 139 set_dpi(frame->dpi()); |
| 141 set_capture_time_ms(frame->capture_time_ms()); | 140 set_capture_time_ms(frame->capture_time_ms()); |
| 142 mutable_updated_region()->Swap(frame->mutable_updated_region()); | 141 mutable_updated_region()->Swap(frame->mutable_updated_region()); |
| 142 original_frame_ = std::move(frame); |
| 143 } | 143 } |
| 144 ~InvertedDesktopFrame() override {} | 144 ~InvertedDesktopFrame() override {} |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 std::unique_ptr<webrtc::DesktopFrame> original_frame_; | 147 std::unique_ptr<webrtc::DesktopFrame> original_frame_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame); | 149 DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 // DesktopFrame wrapper that copies the input frame and doubles the stride. | 152 // DesktopFrame wrapper that copies the input frame and doubles the stride. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 | 197 |
| 198 void Capture(const webrtc::DesktopRegion& region) override { | 198 void Capture(const webrtc::DesktopRegion& region) override { |
| 199 webrtc::DesktopSize size; | 199 webrtc::DesktopSize size; |
| 200 if (frame_index_ % 2 == 0) { | 200 if (frame_index_ % 2 == 0) { |
| 201 size = webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1); | 201 size = webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1); |
| 202 } else { | 202 } else { |
| 203 size = webrtc::DesktopSize(kTestFrameWidth2, kTestFrameHeight2); | 203 size = webrtc::DesktopSize(kTestFrameWidth2, kTestFrameHeight2); |
| 204 } | 204 } |
| 205 frame_index_++; | 205 frame_index_++; |
| 206 | 206 |
| 207 webrtc::DesktopFrame* frame = CreateBasicFrame(size); | 207 std::unique_ptr<webrtc::DesktopFrame> frame = CreateBasicFrame(size); |
| 208 | 208 |
| 209 if (generate_inverted_frames_) { | 209 if (generate_inverted_frames_) { |
| 210 frame = new InvertedDesktopFrame(frame); | 210 frame = new InvertedDesktopFrame(frame); |
| 211 } else if (generate_cropped_frames_) { | 211 } else if (generate_cropped_frames_) { |
| 212 frame = new UnpackedDesktopFrame(frame); | 212 frame = new UnpackedDesktopFrame(frame); |
| 213 } | 213 } |
| 214 callback_->OnCaptureCompleted(frame); | 214 callback_->OnCaptureResult(webrtc::DesktopCapturer::Result::SUCCESS, |
| 215 std::move(frame)); |
| 215 } | 216 } |
| 216 | 217 |
| 217 bool GetScreenList(ScreenList* screens) override { return false; } | 218 bool GetScreenList(ScreenList* screens) override { return false; } |
| 218 | 219 |
| 219 bool SelectScreen(webrtc::ScreenId id) override { return false; } | 220 bool SelectScreen(webrtc::ScreenId id) override { return false; } |
| 220 | 221 |
| 221 private: | 222 private: |
| 222 Callback* callback_; | 223 Callback* callback_; |
| 223 int frame_index_; | 224 int frame_index_; |
| 224 bool generate_inverted_frames_; | 225 bool generate_inverted_frames_; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 media::PIXEL_FORMAT_I420; | 493 media::PIXEL_FORMAT_I420; |
| 493 | 494 |
| 494 capture_device_->AllocateAndStart(capture_params, std::move(client)); | 495 capture_device_->AllocateAndStart(capture_params, std::move(client)); |
| 495 | 496 |
| 496 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 497 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 497 done_event.Reset(); | 498 done_event.Reset(); |
| 498 capture_device_->StopAndDeAllocate(); | 499 capture_device_->StopAndDeAllocate(); |
| 499 | 500 |
| 500 // Verifies that |output_frame_| has the same data as a packed frame of the | 501 // Verifies that |output_frame_| has the same data as a packed frame of the |
| 501 // same size. | 502 // same size. |
| 502 std::unique_ptr<webrtc::BasicDesktopFrame> expected_frame(CreateBasicFrame( | 503 std::unique_ptr<webrtc::BasicDesktopFrame> expected_frame = CreateBasicFrame( |
| 503 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1))); | 504 webrtc::DesktopSize(kTestFrameWidth1, kTestFrameHeight1)); |
| 504 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(), | 505 EXPECT_EQ(output_frame_->stride() * output_frame_->size().height(), |
| 505 frame_size); | 506 frame_size); |
| 506 EXPECT_EQ( | 507 EXPECT_EQ( |
| 507 0, memcmp(output_frame_->data(), expected_frame->data(), frame_size)); | 508 0, memcmp(output_frame_->data(), expected_frame->data(), frame_size)); |
| 508 } | 509 } |
| 509 | 510 |
| 510 // The test verifies that a bottom-to-top frame is converted to top-to-bottom. | 511 // The test verifies that a bottom-to-top frame is converted to top-to-bottom. |
| 511 TEST_F(DesktopCaptureDeviceTest, InvertedFrame) { | 512 TEST_F(DesktopCaptureDeviceTest, InvertedFrame) { |
| 512 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 513 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
| 513 mock_capturer->set_generate_inverted_frames(true); | 514 mock_capturer->set_generate_inverted_frames(true); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 frame_size); | 553 frame_size); |
| 553 for (int i = 0; i < output_frame_->size().height(); ++i) { | 554 for (int i = 0; i < output_frame_->size().height(); ++i) { |
| 554 EXPECT_EQ(0, | 555 EXPECT_EQ(0, |
| 555 memcmp(inverted_frame->data() + i * inverted_frame->stride(), | 556 memcmp(inverted_frame->data() + i * inverted_frame->stride(), |
| 556 output_frame_->data() + i * output_frame_->stride(), | 557 output_frame_->data() + i * output_frame_->stride(), |
| 557 output_frame_->stride())); | 558 output_frame_->stride())); |
| 558 } | 559 } |
| 559 } | 560 } |
| 560 | 561 |
| 561 } // namespace content | 562 } // namespace content |
| OLD | NEW |