| 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 <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.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/frame_consumer.h" | 20 #include "remoting/protocol/frame_consumer.h" |
| 20 #include "remoting/protocol/session_config.h" | 21 #include "remoting/protocol/session_config.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 23 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 23 | 24 |
| 24 using webrtc::DesktopFrame; | 25 using webrtc::DesktopFrame; |
| 25 | 26 |
| 26 namespace remoting { | 27 namespace remoting { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 const int kFrameWidth = 200; | 31 const int kFrameWidth = 200; |
| 31 const int kFrameHeight = 200; | 32 const int kFrameHeight = 200; |
| 32 | 33 |
| 33 class TestFrameConsumer : public protocol::FrameConsumer { | 34 class TestFrameConsumer : public protocol::FrameConsumer { |
| 34 public: | 35 public: |
| 35 TestFrameConsumer() {} | 36 TestFrameConsumer() {} |
| 36 ~TestFrameConsumer() override {} | 37 ~TestFrameConsumer() override {} |
| 37 | 38 |
| 38 scoped_ptr<DesktopFrame> WaitForNextFrame(base::Closure* out_done_callback) { | 39 std::unique_ptr<DesktopFrame> WaitForNextFrame( |
| 40 base::Closure* out_done_callback) { |
| 39 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 41 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 40 frame_run_loop_.reset(new base::RunLoop()); | 42 frame_run_loop_.reset(new base::RunLoop()); |
| 41 frame_run_loop_->Run(); | 43 frame_run_loop_->Run(); |
| 42 frame_run_loop_.reset(); | 44 frame_run_loop_.reset(); |
| 43 *out_done_callback = last_frame_done_callback_; | 45 *out_done_callback = last_frame_done_callback_; |
| 44 last_frame_done_callback_.Reset(); | 46 last_frame_done_callback_.Reset(); |
| 45 return std::move(last_frame_); | 47 return std::move(last_frame_); |
| 46 } | 48 } |
| 47 | 49 |
| 48 // FrameConsumer interface. | 50 // FrameConsumer interface. |
| 49 scoped_ptr<DesktopFrame> AllocateFrame( | 51 std::unique_ptr<DesktopFrame> AllocateFrame( |
| 50 const webrtc::DesktopSize& size) override { | 52 const webrtc::DesktopSize& size) override { |
| 51 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 53 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 52 return make_scoped_ptr(new webrtc::BasicDesktopFrame(size)); | 54 return base::WrapUnique(new webrtc::BasicDesktopFrame(size)); |
| 53 } | 55 } |
| 54 | 56 |
| 55 void DrawFrame(scoped_ptr<DesktopFrame> frame, | 57 void DrawFrame(std::unique_ptr<DesktopFrame> frame, |
| 56 const base::Closure& done) override { | 58 const base::Closure& done) override { |
| 57 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 59 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 58 last_frame_ = std::move(frame); | 60 last_frame_ = std::move(frame); |
| 59 last_frame_done_callback_ = done; | 61 last_frame_done_callback_ = done; |
| 60 frame_run_loop_->Quit(); | 62 frame_run_loop_->Quit(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 PixelFormat GetPixelFormat() override { | 65 PixelFormat GetPixelFormat() override { |
| 64 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); | 66 EXPECT_TRUE(thread_checker_.CalledOnValidThread()); |
| 65 return FORMAT_BGRA; | 67 return FORMAT_BGRA; |
| 66 } | 68 } |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 base::ThreadChecker thread_checker_; | 71 base::ThreadChecker thread_checker_; |
| 70 | 72 |
| 71 scoped_ptr<base::RunLoop> frame_run_loop_; | 73 std::unique_ptr<base::RunLoop> frame_run_loop_; |
| 72 | 74 |
| 73 scoped_ptr<DesktopFrame> last_frame_; | 75 std::unique_ptr<DesktopFrame> last_frame_; |
| 74 base::Closure last_frame_done_callback_; | 76 base::Closure last_frame_done_callback_; |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 scoped_ptr<DesktopFrame> CreateTestFrame(int index) { | 79 std::unique_ptr<DesktopFrame> CreateTestFrame(int index) { |
| 78 scoped_ptr<DesktopFrame> frame(new webrtc::BasicDesktopFrame( | 80 std::unique_ptr<DesktopFrame> frame(new webrtc::BasicDesktopFrame( |
| 79 webrtc::DesktopSize(kFrameWidth, kFrameHeight))); | 81 webrtc::DesktopSize(kFrameWidth, kFrameHeight))); |
| 80 | 82 |
| 81 for (int y = 0; y < kFrameHeight; y++) { | 83 for (int y = 0; y < kFrameHeight; y++) { |
| 82 for (int x = 0; x < kFrameWidth; x++) { | 84 for (int x = 0; x < kFrameWidth; x++) { |
| 83 uint8_t* out = frame->data() + x * DesktopFrame::kBytesPerPixel + | 85 uint8_t* out = frame->data() + x * DesktopFrame::kBytesPerPixel + |
| 84 y * frame->stride(); | 86 y * frame->stride(); |
| 85 out[0] = index + x + y * kFrameWidth; | 87 out[0] = index + x + y * kFrameWidth; |
| 86 out[1] = index + x + y * kFrameWidth + 1; | 88 out[1] = index + x + y * kFrameWidth + 1; |
| 87 out[2] = index + x + y * kFrameWidth + 2; | 89 out[2] = index + x + y * kFrameWidth + 2; |
| 88 out[3] = 0; | 90 out[3] = 0; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 &frame_consumer_, nullptr)); | 140 &frame_consumer_, nullptr)); |
| 139 renderer_->OnSessionConfig( | 141 renderer_->OnSessionConfig( |
| 140 *protocol::SessionConfig::ForTestWithVerbatimVideo()); | 142 *protocol::SessionConfig::ForTestWithVerbatimVideo()); |
| 141 } | 143 } |
| 142 | 144 |
| 143 protected: | 145 protected: |
| 144 base::MessageLoop message_loop_; | 146 base::MessageLoop message_loop_; |
| 145 base::Thread decode_thread_; | 147 base::Thread decode_thread_; |
| 146 | 148 |
| 147 TestFrameConsumer frame_consumer_; | 149 TestFrameConsumer frame_consumer_; |
| 148 scoped_ptr<SoftwareVideoRenderer> renderer_; | 150 std::unique_ptr<SoftwareVideoRenderer> renderer_; |
| 149 | 151 |
| 150 VideoEncoderVerbatim encoder_; | 152 VideoEncoderVerbatim encoder_; |
| 151 }; | 153 }; |
| 152 | 154 |
| 153 TEST_F(SoftwareVideoRendererTest, DecodeFrame) { | 155 TEST_F(SoftwareVideoRendererTest, DecodeFrame) { |
| 154 const int kFrameCount = 5; | 156 const int kFrameCount = 5; |
| 155 | 157 |
| 156 ScopedVector<DesktopFrame> test_frames; | 158 ScopedVector<DesktopFrame> test_frames; |
| 157 | 159 |
| 158 // std::vector<bool> doesn't allow to get pointer to individual values, so | 160 // std::vector<bool> doesn't allow to get pointer to individual values, so |
| 159 // int needs to be used instead. | 161 // int needs to be used instead. |
| 160 std::vector<int> callback_called(kFrameCount); | 162 std::vector<int> callback_called(kFrameCount); |
| 161 | 163 |
| 162 for (int frame_index = 0; frame_index < kFrameCount; frame_index++) { | 164 for (int frame_index = 0; frame_index < kFrameCount; frame_index++) { |
| 163 test_frames.push_back(CreateTestFrame(frame_index)); | 165 test_frames.push_back(CreateTestFrame(frame_index)); |
| 164 callback_called[frame_index] = 0; | 166 callback_called[frame_index] = 0; |
| 165 | 167 |
| 166 renderer_->ProcessVideoPacket( | 168 renderer_->ProcessVideoPacket( |
| 167 encoder_.Encode(*test_frames[frame_index]), | 169 encoder_.Encode(*test_frames[frame_index]), |
| 168 base::Bind(&SetTrue, &(callback_called[frame_index]))); | 170 base::Bind(&SetTrue, &(callback_called[frame_index]))); |
| 169 } | 171 } |
| 170 | 172 |
| 171 for (int frame_index = 0; frame_index < kFrameCount; frame_index++) { | 173 for (int frame_index = 0; frame_index < kFrameCount; frame_index++) { |
| 172 base::Closure done_callback; | 174 base::Closure done_callback; |
| 173 scoped_ptr<DesktopFrame> decoded_frame = | 175 std::unique_ptr<DesktopFrame> decoded_frame = |
| 174 frame_consumer_.WaitForNextFrame(&done_callback); | 176 frame_consumer_.WaitForNextFrame(&done_callback); |
| 175 | 177 |
| 176 EXPECT_FALSE(callback_called[frame_index]); | 178 EXPECT_FALSE(callback_called[frame_index]); |
| 177 done_callback.Run(); | 179 done_callback.Run(); |
| 178 EXPECT_TRUE(callback_called[frame_index]); | 180 EXPECT_TRUE(callback_called[frame_index]); |
| 179 | 181 |
| 180 EXPECT_TRUE(CompareFrames(*test_frames[frame_index], *decoded_frame)); | 182 EXPECT_TRUE(CompareFrames(*test_frames[frame_index], *decoded_frame)); |
| 181 } | 183 } |
| 182 } | 184 } |
| 183 | 185 |
| 184 } // namespace remoting | 186 } // namespace remoting |
| OLD | NEW |