| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "remoting/client/software_video_renderer.h" | 5 #include "remoting/client/software_video_renderer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "remoting/client/frame_consumer.h" | 17 #include "remoting/client/frame_consumer.h" |
| 17 #include "remoting/codec/video_encoder_verbatim.h" | 18 #include "remoting/codec/video_encoder_verbatim.h" |
| 18 #include "remoting/proto/video.pb.h" | 19 #include "remoting/proto/video.pb.h" |
| 19 #include "remoting/protocol/session_config.h" | 20 #include "remoting/protocol/session_config.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 22 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 22 | 23 |
| 23 using webrtc::DesktopFrame; | 24 using webrtc::DesktopFrame; |
| 24 | 25 |
| 25 namespace remoting { | 26 namespace remoting { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const int kFrameWidth = 200; | 30 const int kFrameWidth = 200; |
| 30 const int kFrameHeight = 200; | 31 const int kFrameHeight = 200; |
| 31 | 32 |
| 32 class TestFrameConsumer : public FrameConsumer { | 33 class TestFrameConsumer : public FrameConsumer { |
| 33 public: | 34 public: |
| 34 TestFrameConsumer() {} | 35 TestFrameConsumer() {} |
| 35 ~TestFrameConsumer() override {} | 36 ~TestFrameConsumer() override {} |
| 36 | 37 |
| 37 scoped_ptr<DesktopFrame> WaitForNextFrame( | 38 scoped_ptr<DesktopFrame> WaitForNextFrame(base::Closure* out_done_callback) { |
| 38 base::Closure* out_done_callback) { | |
| 39 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 39 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 40 frame_run_loop_.reset(new base::RunLoop()); | 40 frame_run_loop_.reset(new base::RunLoop()); |
| 41 frame_run_loop_->Run(); | 41 frame_run_loop_->Run(); |
| 42 frame_run_loop_.reset(); | 42 frame_run_loop_.reset(); |
| 43 *out_done_callback = last_frame_done_callback_; | 43 *out_done_callback = last_frame_done_callback_; |
| 44 last_frame_done_callback_.Reset(); | 44 last_frame_done_callback_.Reset(); |
| 45 return last_frame_.Pass(); | 45 return std::move(last_frame_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // FrameConsumer interface. | 48 // FrameConsumer interface. |
| 49 scoped_ptr<DesktopFrame> AllocateFrame( | 49 scoped_ptr<DesktopFrame> AllocateFrame( |
| 50 const webrtc::DesktopSize& size) override { | 50 const webrtc::DesktopSize& size) override { |
| 51 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 51 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 52 return make_scoped_ptr(new webrtc::BasicDesktopFrame(size)); | 52 return make_scoped_ptr(new webrtc::BasicDesktopFrame(size)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void DrawFrame(scoped_ptr<DesktopFrame> frame, | 55 void DrawFrame(scoped_ptr<DesktopFrame> frame, |
| 56 const base::Closure& done) override { | 56 const base::Closure& done) override { |
| 57 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 57 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 58 last_frame_ = frame.Pass(); | 58 last_frame_ = std::move(frame); |
| 59 last_frame_done_callback_ = done; | 59 last_frame_done_callback_ = done; |
| 60 frame_run_loop_->Quit(); | 60 frame_run_loop_->Quit(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 PixelFormat GetPixelFormat() override { | 63 PixelFormat GetPixelFormat() override { |
| 64 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 64 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 65 return FORMAT_BGRA; | 65 return FORMAT_BGRA; |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 if (index == 0) { | 92 if (index == 0) { |
| 93 frame->mutable_updated_region()->SetRect( | 93 frame->mutable_updated_region()->SetRect( |
| 94 webrtc::DesktopRect::MakeWH(kFrameWidth, kFrameHeight)); | 94 webrtc::DesktopRect::MakeWH(kFrameWidth, kFrameHeight)); |
| 95 } else { | 95 } else { |
| 96 frame->mutable_updated_region()->SetRect( | 96 frame->mutable_updated_region()->SetRect( |
| 97 webrtc::DesktopRect::MakeWH(index, index)); | 97 webrtc::DesktopRect::MakeWH(index, index)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 return frame.Pass(); | 100 return frame; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Returns true when frames a and b are equivalent. | 103 // Returns true when frames a and b are equivalent. |
| 104 bool CompareFrames(const DesktopFrame& a, const DesktopFrame& b) { | 104 bool CompareFrames(const DesktopFrame& a, const DesktopFrame& b) { |
| 105 if (!a.size().equals(b.size()) || | 105 if (!a.size().equals(b.size()) || |
| 106 !a.updated_region().Equals(b.updated_region())) { | 106 !a.updated_region().Equals(b.updated_region())) { |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 | 109 |
| 110 for (webrtc::DesktopRegion::Iterator i(a.updated_region()); !i.IsAtEnd(); | 110 for (webrtc::DesktopRegion::Iterator i(a.updated_region()); !i.IsAtEnd(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 EXPECT_FALSE(callback_called[frame_index]); | 176 EXPECT_FALSE(callback_called[frame_index]); |
| 177 done_callback.Run(); | 177 done_callback.Run(); |
| 178 EXPECT_TRUE(callback_called[frame_index]); | 178 EXPECT_TRUE(callback_called[frame_index]); |
| 179 | 179 |
| 180 EXPECT_TRUE(CompareFrames(*test_frames[frame_index], *decoded_frame)); | 180 EXPECT_TRUE(CompareFrames(*test_frames[frame_index], *decoded_frame)); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace remoting | 184 } // namespace remoting |
| OLD | NEW |