diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 00:54:47 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 00:54:47 +0000 |
commit | be2da4de5227f4f1cbb8455a58045c5e51076474 (patch) | |
tree | d69b7cb3b045d01adb953b007086fbe9c864af40 /remoting/host | |
parent | 452390cc7dc08a33a2c9b5729372b830f6966095 (diff) | |
download | chromium_src-be2da4de5227f4f1cbb8455a58045c5e51076474.zip chromium_src-be2da4de5227f4f1cbb8455a58045c5e51076474.tar.gz chromium_src-be2da4de5227f4f1cbb8455a58045c5e51076474.tar.bz2 |
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
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/capturer.h | 62 | ||||
-rw-r--r-- | remoting/host/capturer_fake.cc | 2 | ||||
-rw-r--r-- | remoting/host/capturer_fake_ascii.cc | 2 | ||||
-rw-r--r-- | remoting/host/capturer_gdi.cc | 2 | ||||
-rw-r--r-- | remoting/host/capturer_mac.cc | 2 | ||||
-rw-r--r-- | remoting/host/capturer_mac_unittest.cc | 6 | ||||
-rw-r--r-- | remoting/host/chromoting_host.cc | 3 | ||||
-rw-r--r-- | remoting/host/chromoting_host.h | 8 | ||||
-rw-r--r-- | remoting/host/encoder.h | 61 | ||||
-rw-r--r-- | remoting/host/encoder_verbatim.cc | 87 | ||||
-rw-r--r-- | remoting/host/encoder_verbatim.h | 36 | ||||
-rw-r--r-- | remoting/host/encoder_vp8.cc | 133 | ||||
-rw-r--r-- | remoting/host/encoder_vp8.h | 61 | ||||
-rw-r--r-- | remoting/host/encoder_vp8_unittest.cc | 68 | ||||
-rw-r--r-- | remoting/host/mock_objects.h | 14 | ||||
-rw-r--r-- | remoting/host/session_manager.cc | 6 | ||||
-rw-r--r-- | remoting/host/session_manager.h | 8 | ||||
-rw-r--r-- | remoting/host/session_manager_unittest.cc | 11 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 2 |
19 files changed, 28 insertions, 546 deletions
diff --git a/remoting/host/capturer.h b/remoting/host/capturer.h index 6e16098..30d6737 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 9ffe5bf..eee2d5a 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 d0d7479..ccdbfcf 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 7f54aa9..6190819 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 52d58c3..bfb031a 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 e59a0bb..a172b15 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 3c349fa..7795de1 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 ee15b47a..d281b97 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/encoder.h b/remoting/host/encoder.h deleted file mode 100644 index ee43c94..0000000 --- a/remoting/host/encoder.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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_HOST_ENCODER_H_ -#define REMOTING_HOST_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; -} - -namespace remoting { - -class HostMessage; - -// A class to perform the task of encoding a continous stream of -// images. -// This class operates asynchronously to enable maximum throughput. -class Encoder { - public: - - // EncodingState is a bitfield that tracks the state of the encoding. - // An encoding that consists of a single block could concievably be starting - // inprogress and ended at the same time. - enum { - EncodingStarting = 1 << 0, - EncodingInProgress = 1 << 1, - EncodingEnded = 1 << 2 - }; - typedef int EncodingState; - - // DataAvailableCallback is called as blocks of data are made available - // from the encoder. Data made available by the encoder is in the form - // of HostMessage to reduce the amount of memory copies. - // The callback takes ownership of the HostMessage and is responsible for - // deleting it. - typedef Callback2<HostMessage*, EncodingState>::Type DataAvailableCallback; - - virtual ~Encoder() {} - - // Encode an image stored in |capture_data|. - // - // If |key_frame| is true, the encoder should not reference - // previous encode and encode the full frame. - // - // When encoded data is available, partial or full |data_available_callback| - // is called. - virtual void Encode(scoped_refptr<Capturer::CaptureData> capture_data, - bool key_frame, - DataAvailableCallback* data_available_callback) = 0; -}; - -} // namespace remoting - -#endif // REMOTING_HOST_ENCODER_H_ diff --git a/remoting/host/encoder_verbatim.cc b/remoting/host/encoder_verbatim.cc deleted file mode 100644 index fd9dadf..0000000 --- a/remoting/host/encoder_verbatim.cc +++ /dev/null @@ -1,87 +0,0 @@ -// 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. - -#include "remoting/host/encoder_verbatim.h" - -#include "gfx/rect.h" -#include "media/base/data_buffer.h" -#include "remoting/base/protocol_util.h" -#include "remoting/base/protocol/chromotocol.pb.h" - -namespace remoting { - -using media::DataBuffer; - -void EncoderVerbatim::Encode(scoped_refptr<Capturer::CaptureData> capture_data, - bool key_frame, - DataAvailableCallback* data_available_callback) { - int num_rects = capture_data->dirty_rects().size(); - for (int i = 0; i < num_rects; i++) { - const gfx::Rect& dirty_rect = capture_data->dirty_rects()[i]; - HostMessage* msg = new HostMessage(); - UpdateStreamPacketMessage* packet = msg->mutable_update_stream_packet(); - - if (EncodeRect(dirty_rect, capture_data, packet)) { - // Prepare the end rect content. - packet->mutable_end_rect(); - - EncodingState state = EncodingInProgress; - if (i == 0) { - state |= EncodingStarting; - } - if (i == num_rects - 1) { - state |= EncodingEnded; - } - data_available_callback->Run(msg, state); - } - } - - delete data_available_callback; -} - -bool EncoderVerbatim::EncodeRect( - const gfx::Rect& dirty, - const scoped_refptr<Capturer::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_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 output_size = 0; - for (int i = 0; i < Capturer::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(); - } - - // Resize the output data buffer. - packet->mutable_rect_data()->mutable_data()->resize(output_size); - uint8* out = reinterpret_cast<uint8*>( - &((*packet->mutable_rect_data()->mutable_data())[0])); - - for (int i = 0; i < Capturer::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) { - DCHECK_LE(row_size, capture_data->data_planes().strides[i]); - memcpy(out, in, row_size); - in += capture_data->data_planes().strides[i]; - out += row_size; - } - } - return true; -} - -} // namespace remoting diff --git a/remoting/host/encoder_verbatim.h b/remoting/host/encoder_verbatim.h deleted file mode 100644 index 175b954..0000000 --- a/remoting/host/encoder_verbatim.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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_HOST_ENCODER_VERBATIM_H_ -#define REMOTING_HOST_ENCODER_VERBATIM_H_ - -#include "remoting/host/encoder.h" - -namespace remoting { - -class UpdateStreamPacket; - -// EncoderVerbatim implements Encoder and simply copies input to the output -// buffer verbatim. -class EncoderVerbatim : public Encoder { - public: - EncoderVerbatim() {} - virtual ~EncoderVerbatim() {} - - virtual void Encode(scoped_refptr<Capturer::CaptureData> capture_data, - bool key_frame, - DataAvailableCallback* data_available_callback); - - private: - // 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, - UpdateStreamPacketMessage* msg); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_ENCODER_VERBATIM_H_ diff --git a/remoting/host/encoder_vp8.cc b/remoting/host/encoder_vp8.cc deleted file mode 100644 index 231acd5..0000000 --- a/remoting/host/encoder_vp8.cc +++ /dev/null @@ -1,133 +0,0 @@ -// 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. - -#include "base/logging.h" -#include "media/base/callback.h" -#include "media/base/data_buffer.h" -#include "remoting/host/encoder_vp8.h" - -extern "C" { -// TODO(garykac): Rix with correct path to vp8 header. -#include "remoting/third_party/on2/include/vp8cx.h" -} - -namespace remoting { - -EncoderVp8::EncoderVp8() - : initialized_(false), - last_timestamp_(0) { -} - -EncoderVp8::~EncoderVp8() { -} - -bool EncoderVp8::Init() { - // TODO(hclam): Now always assume we receive YV12. May need to extend this - // so we can do color space conversion manually. - image_.fmt = IMG_FMT_YV12; - image_.w = width_; - image_.h = height_; - - on2_codec_enc_cfg_t config; - on2_codec_err_t result = on2_codec_enc_config_default(&on2_codec_vp8_cx_algo, - &config, 0); - - // TODO(hclam): Adjust the parameters. - config.g_w = width_; - config.g_h = height_; - config.g_pass = ON2_RC_ONE_PASS; - config.g_profile = 1; - config.g_threads = 2; - config.rc_target_bitrate = 1000000; - config.rc_min_quantizer = 0; - config.rc_max_quantizer = 15; - config.g_timebase.num = 1; - config.g_timebase.den = 30; - - if (on2_codec_enc_init(&codec_, &on2_codec_vp8_cx_algo, &config, 0)) - return false; - - on2_codec_control_(&codec_, VP8E_SET_CPUUSED, -15); - return true; -} - -void EncoderVp8::Encode(const DirtyRects& dirty_rects, - const uint8** input_data, - const int* strides, - bool key_frame, - UpdateStreamPacketHeader* header, - scoped_refptr<media::DataBuffer>* output_data, - bool* encode_done, - Task* data_available_task) { - // This will allow the task be called when this method exits. - media::AutoTaskRunner task(data_available_task); - *encode_done = false; - - // TODO(hclam): We only initialize the encoder once. We may have to - // allow encoder be initialized with difference sizes. - if (!initialized_) { - if (!Init()) { - LOG(ERROR) << "Can't initialize VP8 encoder"; - return; - } - initialized_ = true; - } - - // Assume the capturer has done the color space conversion. - if (!input_data || !strides) - return; - - image_.planes[0] = (unsigned char*)input_data[0]; - image_.planes[1] = (unsigned char*)input_data[1]; - image_.planes[2] = (unsigned char*)input_data[2]; - image_.stride[0] = strides[0]; - image_.stride[1] = strides[1]; - image_.stride[2] = strides[2]; - - // Do the actual encoding. - if (on2_codec_encode(&codec_, &image_, - last_timestamp_, 1, 0, ON2_DL_REALTIME)) { - return; - } - - // TODO(hclam): fix this. - last_timestamp_ += 100; - - // Read the encoded data. - on2_codec_iter_t iter = NULL; - bool got_data = false; - - // TODO(hclam: We assume one frame of input will get exactly one frame of - // output. This assumption may not be valid. - while (!got_data) { - on2_codec_cx_pkt_t* packet = on2_codec_get_cx_data(&codec_, &iter); - if (!packet) - continue; - - switch (packet->kind) { - case ON2_CODEC_CX_FRAME_PKT: - got_data = true; - *encode_done = true; - *output_data = new media::DataBuffer(packet->data.frame.sz); - memcpy((*output_data)->GetWritableData(), - packet->data.frame.buf, - packet->data.frame.sz); - break; - default: - break; - } - } - return; -} - -void EncoderVp8::SetSize(int width, int height) { - width_ = width; - height_ = height; -} - -void EncoderVp8::SetPixelFormat(PixelFormat pixel_format) { - pixel_format_ = pixel_format; -} - -} // namespace remoting diff --git a/remoting/host/encoder_vp8.h b/remoting/host/encoder_vp8.h deleted file mode 100644 index 1cd16ac..0000000 --- a/remoting/host/encoder_vp8.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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_HOST_ENCODER_VP8_H_ -#define REMOTING_HOST_ENCODER_VP8_H_ - -#include "remoting/host/encoder.h" - -#include "remoting/base/protocol/chromotocol.pb.h" - -extern "C" { -// TODO(garykac): fix this link with the correct path to on2 -#include "remoting/third_party/on2/include/on2_encoder.h" -} // extern "C" - -namespace media { - -class DataBuffer; - -} // namespace media - -namespace remoting { - -// A class that uses VP8 to perform encoding. -class EncoderVp8 : public Encoder { - public: - EncoderVp8(); - virtual ~EncoderVp8(); - - virtual void Encode(const DirtyRects& dirty_rects, - const uint8** input_data, - const int* strides, - bool key_frame, - UpdateStreamPacketHeader* header, - scoped_refptr<media::DataBuffer>* output_data, - bool* encode_done, - Task* data_available_task); - virtual void SetSize(int width, int height); - virtual void SetPixelFormat(PixelFormat pixel_format); - - private: - // Setup the VP8 encoder. - bool Init(); - - // True if the encoder is initialized. - bool initialized_; - - int width_; - int height_; - PixelFormat pixel_format_; - on2_codec_ctx_t codec_; - on2_image_t image_; - int last_timestamp_; - - DISALLOW_COPY_AND_ASSIGN(EncoderVp8); -}; - -} // namespace remoting - -#endif // REMOTING_HOST_ENCODER_VP8_H_ diff --git a/remoting/host/encoder_vp8_unittest.cc b/remoting/host/encoder_vp8_unittest.cc deleted file mode 100644 index 0b29830..0000000 --- a/remoting/host/encoder_vp8_unittest.cc +++ /dev/null @@ -1,68 +0,0 @@ -// 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. - -#include "media/base/data_buffer.h" -#include "remoting/base/pixel_format.h" -#include "remoting/host/encoder_vp8.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace remoting { - -static const int kWidth = 1024; -static const int kHeight = 768; -static const PixelFormat kPixelFormat = kPixelFormat_YV12; - -static void GenerateData(uint8* data, int size) { - for (int i = 0; i < size; ++i) { - data[i] = i; - } -} - -class EncodeDoneHandler - : public base::RefCountedThreadSafe<EncodeDoneHandler> { - public: - MOCK_METHOD0(EncodeDone, void()); -}; - -TEST(EncoderVp8Test, SimpleEncode) { - EncoderVp8 encoder; - encoder.SetSize(kWidth, kHeight); - encoder.SetPixelFormat(kPixelFormat); - - DirtyRects rects; - rects.push_back(gfx::Rect(kWidth, kHeight)); - - // Prepare memory for encoding. - int strides[3]; - strides[0] = kWidth; - strides[1] = strides[2] = kWidth / 2; - - uint8* planes[3]; - planes[0] = new uint8[kWidth * kHeight]; - planes[1] = new uint8[kWidth * kHeight / 4]; - planes[2] = new uint8[kWidth * kHeight / 4]; - GenerateData(planes[0], kWidth * kHeight); - GenerateData(planes[1], kWidth * kHeight / 4); - GenerateData(planes[2], kWidth * kHeight / 4); - - scoped_refptr<EncodeDoneHandler> handler = new EncodeDoneHandler(); - UpdateStreamPacketHeader* header = new UpdateStreamPacketHeader(); - scoped_refptr<media::DataBuffer> encoded_data; - bool encode_done = false; - EXPECT_CALL(*handler, EncodeDone()); - encoder.Encode(rects, const_cast<const uint8**>(planes), - strides, true, header, &encoded_data, &encode_done, - NewRunnableMethod(handler.get(), - &EncodeDoneHandler::EncodeDone)); - - EXPECT_TRUE(encode_done); - ASSERT_TRUE(encoded_data.get()); - EXPECT_NE(0u, encoded_data->GetBufferSize()); - - delete [] planes[0]; - delete [] planes[1]; - delete [] planes[2]; -} - -} // namespace remoting diff --git a/remoting/host/mock_objects.h b/remoting/host/mock_objects.h index f4135f2..f58ac3b 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 5be8b56d..ebfafeba 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 c2a2149..83c437a 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 e6d8114..239eb97 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 a83dfc8..1c89fa3 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) |