From be2da4de5227f4f1cbb8455a58045c5e51076474 Mon Sep 17 00:00:00 2001
From: "hclam@chromium.org"
 <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Fri, 23 Jul 2010 00:54:47 +0000
Subject: [PATCH] Moving Encoder and Decoder to remoting/base

Putting Encder and Decoder together so we can have test that tests both
of them.

TEST=remoting_unittests

Review URL: http://codereview.chromium.org/2840036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53427 0039d316-1c4b-4281-b951-d872f2087c98
---
 chrome/service/DEPS                           |  1 +
 chrome/service/service_process.cc             |  3 +-
 remoting/base/capture_data.h                  | 75 +++++++++++++++++++
 remoting/{client => base}/decoder.h           |  6 +-
 remoting/{client => base}/decoder_verbatim.cc |  2 +-
 remoting/{client => base}/decoder_verbatim.h  |  8 +-
 .../decoder_verbatim_unittest.cc              |  2 +-
 remoting/{host => base}/encoder.h             | 10 +--
 remoting/{host => base}/encoder_verbatim.cc   | 30 ++++----
 remoting/{host => base}/encoder_verbatim.h    | 14 ++--
 remoting/{host => base}/encoder_vp8.cc        |  0
 remoting/{host => base}/encoder_vp8.h         |  6 +-
 .../{host => base}/encoder_vp8_unittest.cc    |  0
 remoting/base/mock_objects.h                  | 16 ++++
 remoting/client/mock_objects.h                |  1 -
 remoting/client/plugin/pepper_view.cc         |  2 +-
 remoting/client/plugin/pepper_view.h          |  2 +-
 remoting/client/x11_view.cc                   |  2 +-
 remoting/client/x11_view.h                    |  2 +-
 remoting/host/capturer.h                      | 62 +--------------
 remoting/host/capturer_fake.cc                |  2 +-
 remoting/host/capturer_fake_ascii.cc          |  2 +-
 remoting/host/capturer_gdi.cc                 |  2 +-
 remoting/host/capturer_mac.cc                 |  2 +-
 remoting/host/capturer_mac_unittest.cc        |  6 +-
 remoting/host/chromoting_host.cc              |  3 +
 remoting/host/chromoting_host.h               |  8 +-
 remoting/host/mock_objects.h                  | 14 ----
 remoting/host/session_manager.cc              |  6 +-
 remoting/host/session_manager.h               |  8 +-
 remoting/host/session_manager_unittest.cc     | 11 ++-
 remoting/host/simple_host_process.cc          |  2 +-
 remoting/remoting.gyp                         | 25 ++++---
 33 files changed, 178 insertions(+), 157 deletions(-)
 create mode 100644 remoting/base/capture_data.h
 rename remoting/{client => base}/decoder.h (97%)
 rename remoting/{client => base}/decoder_verbatim.cc (98%)
 rename remoting/{client => base}/decoder_verbatim.h (88%)
 rename remoting/{client => base}/decoder_verbatim_unittest.cc (98%)
 rename remoting/{host => base}/encoder.h (88%)
 rename remoting/{host => base}/encoder_verbatim.cc (74%)
 rename remoting/{host => base}/encoder_verbatim.h (67%)
 rename remoting/{host => base}/encoder_vp8.cc (100%)
 rename remoting/{host => base}/encoder_vp8.h (92%)
 rename remoting/{host => base}/encoder_vp8_unittest.cc (100%)

diff --git a/chrome/service/DEPS b/chrome/service/DEPS
index 804d3c24dab44..6563aaa09dba9 100644
--- a/chrome/service/DEPS
+++ b/chrome/service/DEPS
@@ -1,4 +1,5 @@
 include_rules = [
   # For Chromoting Host Process
+  "+remoting/base",
   "+remoting/host",
 ]
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index 408be6525d3c3..4d757ae9e2944 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -9,9 +9,9 @@
 #include "net/base/network_change_notifier.h"
 
 #if defined(ENABLE_REMOTING)
+#include "remoting/base/encoder_verbatim.h"
 #include "remoting/host/chromoting_host.h"
 #include "remoting/host/chromoting_host_context.h"
-#include "remoting/host/encoder_verbatim.h"
 #include "remoting/host/host_config.h"
 
 #if defined(OS_WIN)
@@ -97,4 +97,3 @@ ServiceProcess::~ServiceProcess() {
   DCHECK(cloud_print_proxy_list_.size() == 0);
   g_service_process = NULL;
 }
-
diff --git a/remoting/base/capture_data.h b/remoting/base/capture_data.h
new file mode 100644
index 0000000000000..2ac8a1210c2d2
--- /dev/null
+++ b/remoting/base/capture_data.h
@@ -0,0 +1,75 @@
+// Copyright (c) 2010 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.
+
+#ifndef REMOTING_BASE_CAPTURE_DATA_H_
+#define REMOTING_BASE_CAPTURE_DATA_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "gfx/rect.h"
+#include "remoting/base/protocol/chromotocol.pb.h"
+
+namespace remoting {
+
+typedef std::vector<gfx::Rect> RectVector;
+
+struct DataPlanes {
+  static const int kPlaneCount = 3;
+  uint8* data[kPlaneCount];
+  int strides[kPlaneCount];
+
+  DataPlanes() {
+    for (int i = 0; i < kPlaneCount; ++i) {
+      data[i] = NULL;
+      strides[i] = 0;
+    }
+  }
+};
+
+// Stores the data and information of a capture to pass off to the
+// encoding thread.
+class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
+ public:
+  CaptureData(const DataPlanes &data_planes,
+              int width,
+              int height,
+              PixelFormat format) :
+      data_planes_(data_planes), dirty_rects_(),
+      width_(width), height_(height), pixel_format_(format) { }
+
+  // Get the data_planes data of the last capture.
+  const DataPlanes& data_planes() const { return data_planes_; }
+
+  // Get the list of updated rectangles in the last capture. The result is
+  // written into |rects|.
+  const RectVector& dirty_rects() const { return dirty_rects_; }
+
+  // Get the width of the image captured.
+  int width() const { return width_; }
+
+  // Get the height of the image captured.
+  int height() const { return height_; }
+
+  // Get the pixel format of the image captured.
+  PixelFormat pixel_format() const { return pixel_format_; }
+
+  // Mutating methods.
+  RectVector& mutable_dirty_rects() { return dirty_rects_; }
+
+ private:
+  const DataPlanes data_planes_;
+  RectVector dirty_rects_;
+  int width_;
+  int height_;
+  PixelFormat pixel_format_;
+
+  friend class base::RefCountedThreadSafe<CaptureData>;
+  ~CaptureData() {}
+};
+
+}  // namespace remoting
+
+#endif  // REMOTING_BASE_CAPTURE_DATA_H_
diff --git a/remoting/client/decoder.h b/remoting/base/decoder.h
similarity index 97%
rename from remoting/client/decoder.h
rename to remoting/base/decoder.h
index 4d083bdfc9a83..1df477d897425 100644
--- a/remoting/client/decoder.h
+++ b/remoting/base/decoder.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef REMOTING_CLIENT_DECODER_H_
-#define REMOTING_CLIENT_DECODER_H_
+#ifndef REMOTING_BASE_DECODER_H_
+#define REMOTING_BASE_DECODER_H_
 
 #include <vector>
 
@@ -111,4 +111,4 @@ class Decoder {
 
 }  // namespace remoting
 
-#endif  // REMOTING_CLIENT_DECODER_H_
+#endif  // REMOTING_BASE_DECODER_H_
diff --git a/remoting/client/decoder_verbatim.cc b/remoting/base/decoder_verbatim.cc
similarity index 98%
rename from remoting/client/decoder_verbatim.cc
rename to remoting/base/decoder_verbatim.cc
index d27d265acbe6e..e17310d2546e2 100644
--- a/remoting/client/decoder_verbatim.cc
+++ b/remoting/base/decoder_verbatim.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "remoting/client/decoder_verbatim.h"
+#include "remoting/base/decoder_verbatim.h"
 
 #include "remoting/base/protocol_util.h"
 
diff --git a/remoting/client/decoder_verbatim.h b/remoting/base/decoder_verbatim.h
similarity index 88%
rename from remoting/client/decoder_verbatim.h
rename to remoting/base/decoder_verbatim.h
index 6efc732420979..ba97b5ee1a9c3 100644
--- a/remoting/client/decoder_verbatim.h
+++ b/remoting/base/decoder_verbatim.h
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef REMOTING_CLIENT_DECODER_VERBATIM_H_
-#define REMOTING_CLIENT_DECODER_VERBATIM_H_
+#ifndef REMOTING_BASE_DECODER_VERBATIM_H_
+#define REMOTING_BASE_DECODER_VERBATIM_H_
 
-#include "remoting/client/decoder.h"
+#include "remoting/base/decoder.h"
 
 namespace remoting {
 
@@ -53,4 +53,4 @@ class DecoderVerbatim : public Decoder {
 
 }  // namespace remoting
 
-#endif  // REMOTING_CLIENT_DECODER_VERBATIM_H_
+#endif  // REMOTING_BASE_DECODER_VERBATIM_H_
diff --git a/remoting/client/decoder_verbatim_unittest.cc b/remoting/base/decoder_verbatim_unittest.cc
similarity index 98%
rename from remoting/client/decoder_verbatim_unittest.cc
rename to remoting/base/decoder_verbatim_unittest.cc
index d541d2202af35..f32b08cbbe069 100644
--- a/remoting/client/decoder_verbatim_unittest.cc
+++ b/remoting/base/decoder_verbatim_unittest.cc
@@ -3,7 +3,7 @@
 // found in the LICENSE file.
 
 #include "media/base/video_frame.h"
-#include "remoting/client/decoder_verbatim.h"
+#include "remoting/base/decoder_verbatim.h"
 #include "remoting/client/mock_objects.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
diff --git a/remoting/host/encoder.h b/remoting/base/encoder.h
similarity index 88%
rename from remoting/host/encoder.h
rename to remoting/base/encoder.h
index ee43c94ebf064..0c1fd50f5583e 100644
--- a/remoting/host/encoder.h
+++ b/remoting/base/encoder.h
@@ -2,14 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef REMOTING_HOST_ENCODER_H_
-#define REMOTING_HOST_ENCODER_H_
+#ifndef REMOTING_BASE_ENCODER_H_
+#define REMOTING_BASE_ENCODER_H_
 
 #include "base/basictypes.h"
 #include "base/callback.h"
 #include "media/base/data_buffer.h"
 #include "remoting/base/protocol/chromotocol.pb.h"
-#include "remoting/host/capturer.h"
 
 namespace media {
   class DataBuffer;
@@ -17,6 +16,7 @@ namespace media {
 
 namespace remoting {
 
+class CaptureData;
 class HostMessage;
 
 // A class to perform the task of encoding a continous stream of
@@ -51,11 +51,11 @@ class Encoder {
   //
   // When encoded data is available, partial or full |data_available_callback|
   // is called.
-  virtual void Encode(scoped_refptr<Capturer::CaptureData> capture_data,
+  virtual void Encode(scoped_refptr<CaptureData> capture_data,
                       bool key_frame,
                       DataAvailableCallback* data_available_callback) = 0;
 };
 
 }  // namespace remoting
 
-#endif  // REMOTING_HOST_ENCODER_H_
+#endif  // REMOTING_BASE_ENCODER_H_
diff --git a/remoting/host/encoder_verbatim.cc b/remoting/base/encoder_verbatim.cc
similarity index 74%
rename from remoting/host/encoder_verbatim.cc
rename to remoting/base/encoder_verbatim.cc
index fd9dadf4b2d93..f6cc2cac6387c 100644
--- a/remoting/host/encoder_verbatim.cc
+++ b/remoting/base/encoder_verbatim.cc
@@ -2,10 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "remoting/host/encoder_verbatim.h"
+#include "remoting/base/encoder_verbatim.h"
 
 #include "gfx/rect.h"
 #include "media/base/data_buffer.h"
+#include "remoting/base/capture_data.h"
 #include "remoting/base/protocol_util.h"
 #include "remoting/base/protocol/chromotocol.pb.h"
 
@@ -13,7 +14,7 @@ namespace remoting {
 
 using media::DataBuffer;
 
-void EncoderVerbatim::Encode(scoped_refptr<Capturer::CaptureData> capture_data,
+void EncoderVerbatim::Encode(scoped_refptr<CaptureData> capture_data,
                              bool key_frame,
                              DataAvailableCallback* data_available_callback) {
   int num_rects = capture_data->dirty_rects().size();
@@ -22,7 +23,8 @@ void EncoderVerbatim::Encode(scoped_refptr<Capturer::CaptureData> capture_data,
     HostMessage* msg = new HostMessage();
     UpdateStreamPacketMessage* packet = msg->mutable_update_stream_packet();
 
-    if (EncodeRect(dirty_rect, capture_data, packet)) {
+    if (EncodeRect(dirty_rect.x(), dirty_rect.y(), dirty_rect.width(),
+                   dirty_rect.height(), capture_data, packet)) {
       // Prepare the end rect content.
       packet->mutable_end_rect();
 
@@ -41,26 +43,26 @@ void EncoderVerbatim::Encode(scoped_refptr<Capturer::CaptureData> capture_data,
 }
 
 bool EncoderVerbatim::EncodeRect(
-    const gfx::Rect& dirty,
-    const scoped_refptr<Capturer::CaptureData>& capture_data,
+    int x, int y, int width, int height,
+    const scoped_refptr<CaptureData>& capture_data,
     UpdateStreamPacketMessage* packet) {
   // Prepare the begin rect content.
-  packet->mutable_begin_rect()->set_x(dirty.x());
-  packet->mutable_begin_rect()->set_y(dirty.y());
-  packet->mutable_begin_rect()->set_width(dirty.width());
-  packet->mutable_begin_rect()->set_height(dirty.height());
+  packet->mutable_begin_rect()->set_x(x);
+  packet->mutable_begin_rect()->set_y(y);
+  packet->mutable_begin_rect()->set_width(width);
+  packet->mutable_begin_rect()->set_height(height);
   packet->mutable_begin_rect()->set_encoding(EncodingNone);
   packet->mutable_begin_rect()->set_pixel_format(capture_data->pixel_format());
 
   // Calculate the size of output.
   int bytes_per_pixel = GetBytesPerPixel(capture_data->pixel_format());
-  int row_size = bytes_per_pixel * dirty.width();
+  int row_size = bytes_per_pixel * width;
   int output_size = 0;
-  for (int i = 0; i < Capturer::DataPlanes::kPlaneCount; ++i) {
+  for (int i = 0; i < DataPlanes::kPlaneCount; ++i) {
     // TODO(hclam): Handle YUV since the height would be different.
     const uint8* in = capture_data->data_planes().data[i];
     if (!in) continue;
-    output_size += row_size * dirty.height();
+    output_size += row_size * height;
   }
 
   // Resize the output data buffer.
@@ -68,13 +70,13 @@ bool EncoderVerbatim::EncodeRect(
   uint8* out = reinterpret_cast<uint8*>(
       &((*packet->mutable_rect_data()->mutable_data())[0]));
 
-  for (int i = 0; i < Capturer::DataPlanes::kPlaneCount; ++i) {
+  for (int i = 0; i < DataPlanes::kPlaneCount; ++i) {
     const uint8* in = capture_data->data_planes().data[i];
     // Skip over planes that don't have data.
     if (!in) continue;
 
     // TODO(hclam): Handle YUV since the height would be different.
-    for (int j = 0; j < dirty.height(); ++j) {
+    for (int j = 0; j < height; ++j) {
       DCHECK_LE(row_size, capture_data->data_planes().strides[i]);
       memcpy(out, in, row_size);
       in += capture_data->data_planes().strides[i];
diff --git a/remoting/host/encoder_verbatim.h b/remoting/base/encoder_verbatim.h
similarity index 67%
rename from remoting/host/encoder_verbatim.h
rename to remoting/base/encoder_verbatim.h
index 175b95417a20d..dd019fca9e6b4 100644
--- a/remoting/host/encoder_verbatim.h
+++ b/remoting/base/encoder_verbatim.h
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef REMOTING_HOST_ENCODER_VERBATIM_H_
-#define REMOTING_HOST_ENCODER_VERBATIM_H_
+#ifndef REMOTING_BASE_ENCODER_VERBATIM_H_
+#define REMOTING_BASE_ENCODER_VERBATIM_H_
 
-#include "remoting/host/encoder.h"
+#include "remoting/base/encoder.h"
 
 namespace remoting {
 
@@ -18,7 +18,7 @@ class EncoderVerbatim : public Encoder {
   EncoderVerbatim() {}
   virtual ~EncoderVerbatim() {}
 
-  virtual void Encode(scoped_refptr<Capturer::CaptureData> capture_data,
+  virtual void Encode(scoped_refptr<CaptureData> capture_data,
                       bool key_frame,
                       DataAvailableCallback* data_available_callback);
 
@@ -26,11 +26,11 @@ class EncoderVerbatim : public Encoder {
   // Encode a single dirty rect. Called by Encode(). Output is written
   // to |msg|.
   // Returns false if there is an error.
-  bool EncodeRect(const gfx::Rect& dirty,
-                  const scoped_refptr<Capturer::CaptureData>& capture_data,
+  bool EncodeRect(int x, int y, int width, int height,
+                  const scoped_refptr<CaptureData>& capture_data,
                   UpdateStreamPacketMessage* msg);
 };
 
 }  // namespace remoting
 
-#endif  // REMOTING_HOST_ENCODER_VERBATIM_H_
+#endif  // REMOTING_BASE_ENCODER_VERBATIM_H_
diff --git a/remoting/host/encoder_vp8.cc b/remoting/base/encoder_vp8.cc
similarity index 100%
rename from remoting/host/encoder_vp8.cc
rename to remoting/base/encoder_vp8.cc
diff --git a/remoting/host/encoder_vp8.h b/remoting/base/encoder_vp8.h
similarity index 92%
rename from remoting/host/encoder_vp8.h
rename to remoting/base/encoder_vp8.h
index 1cd16acd4bef4..4b8b539cdf27b 100644
--- a/remoting/host/encoder_vp8.h
+++ b/remoting/base/encoder_vp8.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef REMOTING_HOST_ENCODER_VP8_H_
-#define REMOTING_HOST_ENCODER_VP8_H_
+#ifndef REMOTING_BASE_ENCODER_VP8_H_
+#define REMOTING_BASE_ENCODER_VP8_H_
 
 #include "remoting/host/encoder.h"
 
@@ -58,4 +58,4 @@ class EncoderVp8 : public Encoder {
 
 }  // namespace remoting
 
-#endif  // REMOTING_HOST_ENCODER_VP8_H_
+#endif  // REMOTING_BASE_ENCODER_VP8_H_
diff --git a/remoting/host/encoder_vp8_unittest.cc b/remoting/base/encoder_vp8_unittest.cc
similarity index 100%
rename from remoting/host/encoder_vp8_unittest.cc
rename to remoting/base/encoder_vp8_unittest.cc
diff --git a/remoting/base/mock_objects.h b/remoting/base/mock_objects.h
index a61830ee4dcde..7565f220db136 100644
--- a/remoting/base/mock_objects.h
+++ b/remoting/base/mock_objects.h
@@ -5,6 +5,9 @@
 #ifndef REMOTING_BASE_MOCK_OBJECTS_H_
 #define REMOTING_BASE_MOCK_OBJECTS_H_
 
+#include "remoting/base/capture_data.h"
+#include "remoting/base/decoder.h"
+#include "remoting/base/encoder.h"
 #include "remoting/base/protocol_decoder.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
@@ -25,6 +28,19 @@ class MockProtocolDecoder : public ProtocolDecoder {
   DISALLOW_COPY_AND_ASSIGN(MockProtocolDecoder);
 };
 
+class MockEncoder : public Encoder {
+ public:
+  MockEncoder() {}
+
+  MOCK_METHOD3(Encode, void(
+      scoped_refptr<CaptureData> capture_data,
+      bool key_frame,
+      DataAvailableCallback* data_available_callback));
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(MockEncoder);
+};
+
 }  // namespace remoting
 
 #endif  // REMOTING_BASE_MOCK_OBJECTS_H_
diff --git a/remoting/client/mock_objects.h b/remoting/client/mock_objects.h
index 06ed801cfd120..bee3581eef402 100644
--- a/remoting/client/mock_objects.h
+++ b/remoting/client/mock_objects.h
@@ -6,7 +6,6 @@
 #define REMOTING_CLIENT_MOCK_OBJECTS_H_
 
 #include "base/ref_counted.h"
-#include "remoting/client/decoder.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
 namespace remoting {
diff --git a/remoting/client/plugin/pepper_view.cc b/remoting/client/plugin/pepper_view.cc
index ce38289841dc9..5b96226c60e5d 100644
--- a/remoting/client/plugin/pepper_view.cc
+++ b/remoting/client/plugin/pepper_view.cc
@@ -5,7 +5,7 @@
 #include "remoting/client/plugin/pepper_view.h"
 
 #include "base/message_loop.h"
-#include "remoting/client/decoder_verbatim.h"
+#include "remoting/base/decoder_verbatim.h"
 #include "remoting/client/plugin/chromoting_plugin.h"
 #include "remoting/client/plugin/pepper_util.h"
 #include "third_party/ppapi/cpp/device_context_2d.h"
diff --git a/remoting/client/plugin/pepper_view.h b/remoting/client/plugin/pepper_view.h
index 3622ab337f81a..0a3147ea5a73e 100644
--- a/remoting/client/plugin/pepper_view.h
+++ b/remoting/client/plugin/pepper_view.h
@@ -17,8 +17,8 @@
 #include "base/scoped_ptr.h"
 #include "base/task.h"
 #include "media/base/video_frame.h"
+#include "remoting/base/decoder.h"
 #include "remoting/client/chromoting_view.h"
-#include "remoting/client/decoder.h"
 #include "third_party/ppapi/cpp/device_context_2d.h"
 
 namespace remoting {
diff --git a/remoting/client/x11_view.cc b/remoting/client/x11_view.cc
index e4b59ae2c4bd7..fe30291d01e6d 100644
--- a/remoting/client/x11_view.cc
+++ b/remoting/client/x11_view.cc
@@ -10,7 +10,7 @@
 #include <X11/extensions/Xcomposite.h>
 
 #include "base/logging.h"
-#include "remoting/client/decoder_verbatim.h"
+#include "remoting/base/decoder_verbatim.h"
 
 namespace remoting {
 
diff --git a/remoting/client/x11_view.h b/remoting/client/x11_view.h
index 73e63c7d0b707..28255755215b3 100644
--- a/remoting/client/x11_view.h
+++ b/remoting/client/x11_view.h
@@ -8,7 +8,7 @@
 #include "base/basictypes.h"
 #include "base/scoped_ptr.h"
 #include "media/base/video_frame.h"
-#include "remoting/client/decoder.h"
+#include "remoting/base/decoder.h"
 #include "remoting/client/chromoting_view.h"
 
 typedef unsigned long XID;
diff --git a/remoting/host/capturer.h b/remoting/host/capturer.h
index 6e16098104a04..30d67370497b1 100644
--- a/remoting/host/capturer.h
+++ b/remoting/host/capturer.h
@@ -5,19 +5,14 @@
 #ifndef REMOTING_HOST_CAPTURER_H_
 #define REMOTING_HOST_CAPTURER_H_
 
-#include <vector>
-
 #include "base/basictypes.h"
 #include "base/callback.h"
 #include "base/lock.h"
 #include "base/task.h"
-#include "gfx/rect.h"
-#include "remoting/base/protocol/chromotocol.pb.h"
+#include "remoting/base/capture_data.h"
 
 namespace remoting {
 
-typedef std::vector<gfx::Rect> RectVector;
-
 // A class to perform the task of capturing the image of a window.
 // The capture action is asynchronous to allow maximum throughput.
 //
@@ -27,61 +22,6 @@ typedef std::vector<gfx::Rect> RectVector;
 //    happening.
 class Capturer {
  public:
-
-  struct DataPlanes {
-    static const int kPlaneCount = 3;
-    uint8* data[kPlaneCount];
-    int strides[kPlaneCount];
-
-    DataPlanes() {
-      for (int i = 0; i < kPlaneCount; ++i) {
-        data[i] = NULL;
-        strides[i] = 0;
-      }
-    }
-  };
-
-  // Stores the data and information of a capture to pass off to the
-  // encoding thread.
-  class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
-   public:
-    CaptureData(const DataPlanes &data_planes,
-                int width,
-                int height,
-                PixelFormat format) :
-            data_planes_(data_planes), dirty_rects_(),
-            width_(width), height_(height), pixel_format_(format) { }
-
-    // Get the data_planes data of the last capture.
-    const DataPlanes& data_planes() const { return data_planes_; }
-
-    // Get the list of updated rectangles in the last capture. The result is
-    // written into |rects|.
-    const RectVector& dirty_rects() const { return dirty_rects_; }
-
-    // Get the width of the image captured.
-    int width() const { return width_; }
-
-    // Get the height of the image captured.
-    int height() const { return height_; }
-
-    // Get the pixel format of the image captured.
-    PixelFormat pixel_format() const { return pixel_format_; }
-
-    // Mutating methods.
-    RectVector& mutable_dirty_rects() { return dirty_rects_; }
-
-   private:
-    const DataPlanes data_planes_;
-    RectVector dirty_rects_;
-    int width_;
-    int height_;
-    PixelFormat pixel_format_;
-
-    friend class base::RefCountedThreadSafe<CaptureData>;
-    ~CaptureData() {}
-  };
-
   // CaptureCompletedCallback is called when the capturer has completed.
   typedef Callback1<scoped_refptr<CaptureData> >::Type CaptureCompletedCallback;
 
diff --git a/remoting/host/capturer_fake.cc b/remoting/host/capturer_fake.cc
index 9ffe5bfdf4be6..eee2d5aa58cb3 100644
--- a/remoting/host/capturer_fake.cc
+++ b/remoting/host/capturer_fake.cc
@@ -23,7 +23,7 @@ CapturerFake::~CapturerFake() {
 void CapturerFake::CaptureRects(const RectVector& rects,
                                 CaptureCompletedCallback* callback) {
   GenerateImage();
-  Capturer::DataPlanes planes;
+  DataPlanes planes;
   planes.data[0] = buffers_[current_buffer_].get();
   planes.strides[0] = bytes_per_row_;
 
diff --git a/remoting/host/capturer_fake_ascii.cc b/remoting/host/capturer_fake_ascii.cc
index d0d7479d7daab..ccdbfcf221cb3 100644
--- a/remoting/host/capturer_fake_ascii.cc
+++ b/remoting/host/capturer_fake_ascii.cc
@@ -21,7 +21,7 @@ CapturerFakeAscii::~CapturerFakeAscii() {
 void CapturerFakeAscii::CaptureRects(const RectVector& rects,
                                      CaptureCompletedCallback* callback) {
   GenerateImage();
-  Capturer::DataPlanes planes;
+  DataPlanes planes;
   planes.data[0] = buffers_[current_buffer_].get();
   planes.strides[0] = bytes_per_row_;
   scoped_refptr<CaptureData> capture_data(new CaptureData(planes,
diff --git a/remoting/host/capturer_gdi.cc b/remoting/host/capturer_gdi.cc
index 7f54aa97077fc..6190819be6a56 100644
--- a/remoting/host/capturer_gdi.cc
+++ b/remoting/host/capturer_gdi.cc
@@ -79,7 +79,7 @@ void CapturerGdi::ScreenConfigurationChanged() {
 
 void CapturerGdi::CaptureRects(const RectVector& rects,
                                CaptureCompletedCallback* callback) {
-  Capturer::DataPlanes planes;
+  DataPlanes planes;
   planes.data[0] = static_cast<uint8*>(buffers_[current_buffer_]);
   planes.strides[0] = bytes_per_row_;
 
diff --git a/remoting/host/capturer_mac.cc b/remoting/host/capturer_mac.cc
index 52d58c3fdbf58..bfb031a15acd8 100644
--- a/remoting/host/capturer_mac.cc
+++ b/remoting/host/capturer_mac.cc
@@ -93,7 +93,7 @@ void CapturerMac::CaptureRects(const RectVector& rects,
                buffers_[current_buffer_].get());
   glPopClientAttrib();
 
-  Capturer::DataPlanes planes;
+  DataPlanes planes;
   planes.data[0] = buffers_[current_buffer_].get();
   planes.strides[0] = bytes_per_row_;
 
diff --git a/remoting/host/capturer_mac_unittest.cc b/remoting/host/capturer_mac_unittest.cc
index e59a0bb62dad5..a172b1584af04 100644
--- a/remoting/host/capturer_mac_unittest.cc
+++ b/remoting/host/capturer_mac_unittest.cc
@@ -28,7 +28,7 @@ class CapturerMacTest : public testing::Test {
 class CapturerCallback {
  public:
   explicit CapturerCallback(const RectVector& rects) : rects_(rects) { }
-  void CaptureDoneCallback(scoped_refptr<Capturer::CaptureData> capture_data);
+  void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
 
  protected:
   RectVector rects_;
@@ -38,7 +38,7 @@ class CapturerCallback {
 };
 
 void CapturerCallback::CaptureDoneCallback(
-    scoped_refptr<Capturer::CaptureData> capture_data) {
+    scoped_refptr<CaptureData> capture_data) {
   CGDirectDisplayID mainDevice = CGMainDisplayID();
   int width = CGDisplayPixelsWide(mainDevice);
   int height = CGDisplayPixelsHigh(mainDevice);
@@ -46,7 +46,7 @@ void CapturerCallback::CaptureDoneCallback(
   EXPECT_EQ(rects_, capture_data->dirty_rects());
   EXPECT_EQ(width, capture_data->width());
   EXPECT_EQ(height, capture_data->height());
-  const Capturer::DataPlanes &planes = capture_data->data_planes();
+  const DataPlanes &planes = capture_data->data_planes();
   EXPECT_TRUE(planes.data[0] != NULL);
   EXPECT_TRUE(planes.data[1] == NULL);
   EXPECT_TRUE(planes.data[2] == NULL);
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 3c349fa8c8ece..7795de15c80b9 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -8,8 +8,11 @@
 #include "base/task.h"
 #include "build/build_config.h"
 #include "remoting/base/constants.h"
+#include "remoting/base/encoder.h"
 #include "remoting/base/protocol_decoder.h"
 #include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/capturer.h"
+#include "remoting/host/event_executor.h"
 #include "remoting/host/host_config.h"
 #include "remoting/host/session_manager.h"
 #include "remoting/jingle_glue/jingle_channel.h"
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index ee15b47ad755a..d281b97978c6b 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -8,12 +8,8 @@
 #include <string>
 
 #include "base/thread.h"
-#include "remoting/host/capturer.h"
 #include "remoting/host/client_connection.h"
-#include "remoting/host/encoder.h"
-#include "remoting/host/event_executor.h"
 #include "remoting/host/heartbeat_sender.h"
-#include "remoting/host/session_manager.h"
 #include "remoting/jingle_glue/jingle_client.h"
 #include "remoting/jingle_glue/jingle_thread.h"
 
@@ -21,8 +17,12 @@ class Task;
 
 namespace remoting {
 
+class Capturer;
 class ChromotingHostContext;
+class Encoder;
+class EventExecutor;
 class MutableHostConfig;
+class SessionManager;
 
 // A class to implement the functionality of a host process.
 //
diff --git a/remoting/host/mock_objects.h b/remoting/host/mock_objects.h
index f4135f2d1bc54..f58ac3b008e22 100644
--- a/remoting/host/mock_objects.h
+++ b/remoting/host/mock_objects.h
@@ -9,7 +9,6 @@
 #include "remoting/base/protocol_decoder.h"
 #include "remoting/host/capturer.h"
 #include "remoting/host/client_connection.h"
-#include "remoting/host/encoder.h"
 #include "remoting/host/event_executor.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
@@ -32,19 +31,6 @@ class MockCapturer : public Capturer {
   DISALLOW_COPY_AND_ASSIGN(MockCapturer);
 };
 
-class MockEncoder : public Encoder {
- public:
-  MockEncoder() {}
-
-  MOCK_METHOD3(Encode, void(
-      scoped_refptr<Capturer::CaptureData> capture_data,
-      bool key_frame,
-      DataAvailableCallback* data_available_callback));
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockEncoder);
-};
-
 class MockEventExecutor : public EventExecutor {
  public:
   MockEventExecutor() {}
diff --git a/remoting/host/session_manager.cc b/remoting/host/session_manager.cc
index 5be8b56d317f5..ebfafebafb26a 100644
--- a/remoting/host/session_manager.cc
+++ b/remoting/host/session_manager.cc
@@ -10,9 +10,9 @@
 #include "base/scoped_ptr.h"
 #include "base/stl_util-inl.h"
 #include "media/base/data_buffer.h"
+#include "remoting/base/capture_data.h"
 #include "remoting/base/protocol_decoder.h"
 #include "remoting/host/client_connection.h"
-#include "remoting/host/encoder.h"
 
 namespace remoting {
 
@@ -219,7 +219,7 @@ void SessionManager::DoCapture() {
 }
 
 void SessionManager::CaptureDoneCallback(
-    scoped_refptr<Capturer::CaptureData> capture_data) {
+    scoped_refptr<CaptureData> capture_data) {
   // TODO(hclam): There is a bug if the capturer doesn't produce any dirty rects.
   DCHECK_EQ(capture_loop_, MessageLoop::current());
   encode_loop_->PostTask(
@@ -381,7 +381,7 @@ void SessionManager::DoRemoveAllClients() {
 // Encoder thread --------------------------------------------------------------
 
 void SessionManager::DoEncode(
-    scoped_refptr<Capturer::CaptureData> capture_data) {
+    scoped_refptr<CaptureData> capture_data) {
   DCHECK_EQ(encode_loop_, MessageLoop::current());
 
   // TODO(hclam): Enable |force_refresh| if a new client was
diff --git a/remoting/host/session_manager.h b/remoting/host/session_manager.h
index c2a21496ffa7c..83c437a973ccb 100644
--- a/remoting/host/session_manager.h
+++ b/remoting/host/session_manager.h
@@ -12,9 +12,9 @@
 #include "base/ref_counted.h"
 #include "base/scoped_ptr.h"
 #include "base/time.h"
+#include "remoting/base/encoder.h"
 #include "remoting/base/protocol/chromotocol.pb.h"
 #include "remoting/host/capturer.h"
-#include "remoting/host/encoder.h"
 
 namespace media {
 
@@ -24,7 +24,7 @@ class DataBuffer;
 
 namespace remoting {
 
-class Encoder;
+class CaptureData;
 class ClientConnection;
 
 // A class for controlling and coordinate Capturer, Encoder
@@ -115,7 +115,7 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> {
   void ScheduleNextCapture();
 
   void DoCapture();
-  void CaptureDoneCallback(scoped_refptr<Capturer::CaptureData> capture_data);
+  void CaptureDoneCallback(scoped_refptr<CaptureData> capture_data);
   void DoFinishEncode();
 
   void DoGetInitInfo(scoped_refptr<ClientConnection> client);
@@ -142,7 +142,7 @@ class SessionManager : public base::RefCountedThreadSafe<SessionManager> {
 
   // Encoder thread -----------------------------------------------------------
 
-  void DoEncode(scoped_refptr<Capturer::CaptureData> capture_data);
+  void DoEncode(scoped_refptr<CaptureData> capture_data);
 
   // EncodeDataAvailableTask takes ownership of header and is responsible for
   // deleting it.
diff --git a/remoting/host/session_manager_unittest.cc b/remoting/host/session_manager_unittest.cc
index e6d81140886de..239eb97a11073 100644
--- a/remoting/host/session_manager_unittest.cc
+++ b/remoting/host/session_manager_unittest.cc
@@ -4,6 +4,7 @@
 
 #include "base/message_loop.h"
 #include "base/task.h"
+#include "remoting/base/mock_objects.h"
 #include "remoting/host/mock_objects.h"
 #include "remoting/host/session_manager.h"
 #include "testing/gmock/include/gmock/gmock.h"
@@ -80,15 +81,13 @@ TEST_F(SessionManagerTest, OneRecordCycle) {
 
   RectVector update_rects;
   update_rects.push_back(gfx::Rect(0, 0, 10, 10));
-  Capturer::DataPlanes planes;
-  for (int i = 0; i < Capturer::DataPlanes::kPlaneCount; ++i) {
+  DataPlanes planes;
+  for (int i = 0; i < DataPlanes::kPlaneCount; ++i) {
     planes.data[i] = reinterpret_cast<uint8*>(i);
     planes.strides[i] = kWidth * 4;
   }
-  scoped_refptr<Capturer::CaptureData> data(new Capturer::CaptureData(planes,
-                                                                      kWidth,
-                                                                      kHeight,
-                                                                      kFormat));
+  scoped_refptr<CaptureData> data(new CaptureData(planes, kWidth,
+                                                  kHeight, kFormat));
   // Set the recording rate to very low to avoid capture twice.
   record_->SetMaxRate(0.01);
 
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index a83dfc8407836..1c89fa3248ebb 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -26,10 +26,10 @@
 #include "base/nss_util.h"
 #include "base/scoped_nsautorelease_pool.h"
 #include "base/thread.h"
+#include "remoting/base/encoder_verbatim.h"
 #include "remoting/host/capturer_fake.h"
 #include "remoting/host/chromoting_host.h"
 #include "remoting/host/chromoting_host_context.h"
-#include "remoting/host/encoder_verbatim.h"
 #include "remoting/host/json_host_config.h"
 
 #if defined(OS_WIN)
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 85718e351fc71..3c601d3bc9356 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -129,14 +129,24 @@
       # depend on chromotocol_proto_lib for headers.
       'hard_dependency': 1,
       'sources': [
+        'base/capture_data.h',
         'base/compressor.h',
         'base/compressor_zlib.cc',
         'base/compressor_zlib.h',
         'base/constants.cc',
         'base/constants.h',
+        'base/decoder.h',
+        'base/decoder_verbatim.cc',
+        'base/decoder_verbatim.h',
         'base/decompressor.h',
         'base/decompressor_zlib.cc',
         'base/decompressor_zlib.h',
+        'base/encoder.h',
+        'base/encoder_verbatim.cc',
+        'base/encoder_verbatim.h',
+        # TODO(hclam): Enable VP8 in the build.
+        #'base/encoder_vp8.cc',
+        #'base/encoder_vp8.h',
         'base/multiple_array_input_stream.cc',
         'base/multiple_array_input_stream.h',
         'base/protocol_decoder.cc',
@@ -166,12 +176,6 @@
         'host/differ.cc',
         'host/differ_block.h',
         'host/differ_block.cc',
-        'host/encoder.h',
-        'host/encoder_verbatim.cc',
-        'host/encoder_verbatim.h',
-        # TODO(hclam): Enable VP8 in the build.
-        #'host/encoder_vp8.cc',
-        #'host/encoder_vp8.h',
         'host/event_executor.h',
         'host/session_manager.cc',
         'host/session_manager.h',
@@ -231,9 +235,6 @@
         'client/client_context.h',
         'client/client_util.cc',
         'client/client_util.h',
-        'client/decoder.h',
-        'client/decoder_verbatim.cc',
-        'client/decoder_verbatim.h',
         'client/host_connection.h',
         'client/input_handler.h',
         'client/jingle_host_connection.cc',
@@ -342,12 +343,14 @@
       ],
       'sources': [
         'base/compressor_zlib_unittest.cc',
+        'base/decoder_verbatim_unittest.cc',
         'base/decompressor_zlib_unittest.cc',
+        # TODO(hclam): Enable VP8 in the build.
+        #'base/encoder_vp8_unittest.cc',
         'base/mock_objects.h',
         'base/multiple_array_input_stream_unittest.cc',
         'base/protocol_decoder_unittest.cc',
         'client/mock_objects.h',
-        'client/decoder_verbatim_unittest.cc',
         'host/chromoting_host_context_unittest.cc',
         'host/client_connection_unittest.cc',
         'host/differ_unittest.cc',
@@ -355,8 +358,6 @@
         'host/json_host_config_unittest.cc',
         'host/mock_objects.h',
         'host/session_manager_unittest.cc',
-        # TODO(hclam): Enable VP8 in the build.
-        #'host/encoder_vp8_unittest.cc',
         'jingle_glue/jingle_thread_unittest.cc',
         'jingle_glue/jingle_channel_unittest.cc',
         'jingle_glue/iq_request_unittest.cc',
-- 
GitLab