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

Unified Diff: remoting/client/software_video_renderer_unittest.cc

Issue 1288063004: Simplify FrameConsumer interface. Remove FrameProducer interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/client/software_video_renderer.cc ('k') | remoting/protocol/monitored_video_stub.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/software_video_renderer_unittest.cc
diff --git a/remoting/client/software_video_renderer_unittest.cc b/remoting/client/software_video_renderer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e10a034104aaaa14f03ed7e7f9c0bea4ebbdf511
--- /dev/null
+++ b/remoting/client/software_video_renderer_unittest.cc
@@ -0,0 +1,182 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/client/software_video_renderer.h"
+
+#include <vector>
+
+#include "base/bind.h"
+#include "base/memory/scoped_vector.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/threading/thread.h"
+#include "remoting/client/frame_consumer.h"
+#include "remoting/codec/video_encoder_verbatim.h"
+#include "remoting/proto/video.pb.h"
+#include "remoting/protocol/session_config.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
+
+using webrtc::DesktopFrame;
+
+namespace remoting {
+
+namespace {
+
+const int kFrameWidth = 200;
+const int kFrameHeight = 200;
+
+class TestFrameConsumer : public FrameConsumer {
+ public:
+ TestFrameConsumer() {}
+ ~TestFrameConsumer() override {}
+
+ scoped_ptr<DesktopFrame> WaitForNextFrame(
+ base::Closure* out_done_callback) {
+ EXPECT_TRUE(thread_checker_.CalledOnValidThread());
+ frame_run_loop_.reset(new base::RunLoop());
+ frame_run_loop_->Run();
+ frame_run_loop_.reset();
+ *out_done_callback = last_frame_done_callback_;
+ last_frame_done_callback_.Reset();
+ return last_frame_.Pass();
+ }
+
+ // FrameConsumer interface.
+ scoped_ptr<DesktopFrame> AllocateFrame(
+ const webrtc::DesktopSize& size) override {
+ EXPECT_TRUE(thread_checker_.CalledOnValidThread());
+ return make_scoped_ptr(new webrtc::BasicDesktopFrame(size));
+ }
+
+ void DrawFrame(scoped_ptr<DesktopFrame> frame,
+ const base::Closure& done) override {
+ EXPECT_TRUE(thread_checker_.CalledOnValidThread());
+ last_frame_ = frame.Pass();
+ last_frame_done_callback_ = done;
+ frame_run_loop_->Quit();
+ }
+
+ PixelFormat GetPixelFormat() override {
+ EXPECT_TRUE(thread_checker_.CalledOnValidThread());
+ return FORMAT_BGRA;
+ }
+
+ private:
+ base::ThreadChecker thread_checker_;
+
+ scoped_ptr<base::RunLoop> frame_run_loop_;
+
+ scoped_ptr<DesktopFrame> last_frame_;
+ base::Closure last_frame_done_callback_;
+};
+
+scoped_ptr<DesktopFrame> CreateTestFrame(int index) {
+ scoped_ptr<DesktopFrame> frame(new webrtc::BasicDesktopFrame(
+ webrtc::DesktopSize(kFrameWidth, kFrameHeight)));
+
+ for (int y = 0; y < kFrameHeight; y++) {
+ for (int x = 0; x < kFrameWidth; x++) {
+ uint8_t* out = frame->data() + x * DesktopFrame::kBytesPerPixel +
+ y * frame->stride();
+ out[0] = index + x + y * kFrameWidth;
+ out[1] = index + x + y * kFrameWidth + 1;
+ out[2] = index + x + y * kFrameWidth + 2;
+ out[3] = 0;
+ }
+ }
+
+ if (index == 0) {
+ frame->mutable_updated_region()->SetRect(
+ webrtc::DesktopRect::MakeWH(kFrameWidth, kFrameHeight));
+ } else {
+ frame->mutable_updated_region()->SetRect(
+ webrtc::DesktopRect::MakeWH(index, index));
+ }
+
+ return frame.Pass();
+}
+
+// Returns true when frames a and b are equivalent.
+bool CompareFrames(const DesktopFrame& a, const DesktopFrame& b) {
+ if (!a.size().equals(b.size()) ||
+ !a.updated_region().Equals(b.updated_region())) {
+ return false;
+ }
+
+ for (webrtc::DesktopRegion::Iterator i(a.updated_region()); !i.IsAtEnd();
+ i.Advance()) {
+ for (int row = i.rect().top(); row < i.rect().bottom(); ++row) {
+ if (memcmp(a.data() + a.stride() * row +
+ i.rect().left() * DesktopFrame::kBytesPerPixel,
+ b.data() + b.stride() * row +
+ i.rect().left() * DesktopFrame::kBytesPerPixel,
+ i.rect().width() * DesktopFrame::kBytesPerPixel) != 0) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+// Helper to set value at |out| to 1.
+void SetTrue(int* out) {
+ *out = 1;
+}
+
+} // namespace
+
+class SoftwareVideoRendererTest : public ::testing::Test {
+ public:
+ SoftwareVideoRendererTest() : decode_thread_("TestDecodeThread") {
+ decode_thread_.Start();
+ renderer_.reset(new SoftwareVideoRenderer(decode_thread_.task_runner(),
+ &frame_consumer_));
+ renderer_->OnSessionConfig(
+ *protocol::SessionConfig::ForTestWithVerbatimVideo());
+ }
+
+ protected:
+ base::MessageLoop message_loop_;
+ base::Thread decode_thread_;
+
+ TestFrameConsumer frame_consumer_;
+ scoped_ptr<SoftwareVideoRenderer> renderer_;
+
+ VideoEncoderVerbatim encoder_;
+};
+
+TEST_F(SoftwareVideoRendererTest, DecodeFrame) {
+ const int kFrameCount = 5;
+
+ ScopedVector<DesktopFrame> test_frames;
+
+ // std::vector<bool> doesn't allow to get pointer to individual values, so
+ // int needs to be used instead.
+ std::vector<int> callback_called(kFrameCount);
+
+ for (int frame_index = 0; frame_index < kFrameCount; frame_index++) {
+ test_frames.push_back(CreateTestFrame(frame_index));
+ callback_called[frame_index] = 0;
+
+ renderer_->ProcessVideoPacket(
+ encoder_.Encode(*test_frames[frame_index]),
+ base::Bind(&SetTrue, &(callback_called[frame_index])));
+ }
+
+ for (int frame_index = 0; frame_index < kFrameCount; frame_index++) {
+ base::Closure done_callback;
+ scoped_ptr<DesktopFrame> decoded_frame =
+ frame_consumer_.WaitForNextFrame(&done_callback);
+
+ EXPECT_FALSE(callback_called[frame_index]);
+ done_callback.Run();
+ EXPECT_TRUE(callback_called[frame_index]);
+
+ EXPECT_TRUE(CompareFrames(*test_frames[frame_index], *decoded_frame));
+ }
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/client/software_video_renderer.cc ('k') | remoting/protocol/monitored_video_stub.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698