diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-06 22:46:00 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-06 22:46:00 +0000 |
commit | c3af26f3314bf48f478cec8128b5c15cc3f98940 (patch) | |
tree | 0d3d0802a3a9b8e05487626f90c7dbf0dcecdea9 /remoting/base | |
parent | 5bcab699da1cedb4fc666c9f5d0099574a27c2fe (diff) | |
download | chromium_src-c3af26f3314bf48f478cec8128b5c15cc3f98940.zip chromium_src-c3af26f3314bf48f478cec8128b5c15cc3f98940.tar.gz chromium_src-c3af26f3314bf48f478cec8128b5c15cc3f98940.tar.bz2 |
Use new Chromotocol code in host andclient.
1. ProtocolDecoder renamed to MessagesDecoder and moved to remoting/protocol.
2. base/protocol_util.[h|cc] split into base/util.[h|cc] and protocol/util.[h|cc].
3. Added StreamReader and StreamWriter classes for events and video channels.
4. Client and host changed to use the new protocol code.
BUG=None
TEST=Unittests
Review URL: http://codereview.chromium.org/3595012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/codec_test.cc | 2 | ||||
-rw-r--r-- | remoting/base/decoder_row_based.cc | 2 | ||||
-rw-r--r-- | remoting/base/decoder_vp8.cc | 2 | ||||
-rw-r--r-- | remoting/base/encoder_verbatim.cc | 2 | ||||
-rw-r--r-- | remoting/base/encoder_zlib.cc | 2 | ||||
-rw-r--r-- | remoting/base/mock_objects.h | 16 | ||||
-rw-r--r-- | remoting/base/multiple_array_input_stream.cc | 29 | ||||
-rw-r--r-- | remoting/base/multiple_array_input_stream.h | 20 | ||||
-rw-r--r-- | remoting/base/multiple_array_input_stream_unittest.cc | 7 | ||||
-rw-r--r-- | remoting/base/protocol_decoder.cc | 151 | ||||
-rw-r--r-- | remoting/base/protocol_decoder.h | 72 | ||||
-rw-r--r-- | remoting/base/protocol_decoder_unittest.cc | 121 | ||||
-rw-r--r-- | remoting/base/protocol_util.cc | 43 | ||||
-rw-r--r-- | remoting/base/protocol_util.h | 27 | ||||
-rw-r--r-- | remoting/base/util.cc | 26 | ||||
-rw-r--r-- | remoting/base/util.h | 16 |
16 files changed, 75 insertions, 463 deletions
diff --git a/remoting/base/codec_test.cc b/remoting/base/codec_test.cc index 2736c3e..62b98607 100644 --- a/remoting/base/codec_test.cc +++ b/remoting/base/codec_test.cc @@ -11,7 +11,7 @@ #include "remoting/base/decoder.h" #include "remoting/base/encoder.h" #include "remoting/base/mock_objects.h" -#include "remoting/base/protocol_util.h" +#include "remoting/base/util.h" #include "testing/gtest/include/gtest/gtest.h" static const int kWidth = 320; diff --git a/remoting/base/decoder_row_based.cc b/remoting/base/decoder_row_based.cc index 2f4290a..65c74c5 100644 --- a/remoting/base/decoder_row_based.cc +++ b/remoting/base/decoder_row_based.cc @@ -7,7 +7,7 @@ #include "remoting/base/decompressor.h" #include "remoting/base/decompressor_zlib.h" #include "remoting/base/decompressor_verbatim.h" -#include "remoting/base/protocol_util.h" +#include "remoting/base/util.h" namespace remoting { diff --git a/remoting/base/decoder_vp8.cc b/remoting/base/decoder_vp8.cc index 0ede4ab..452cd1f 100644 --- a/remoting/base/decoder_vp8.cc +++ b/remoting/base/decoder_vp8.cc @@ -6,7 +6,7 @@ #include "media/base/media.h" #include "media/base/yuv_convert.h" -#include "remoting/base/protocol_util.h" +#include "remoting/base/util.h" extern "C" { #define VPX_CODEC_DISABLE_COMPAT 1 diff --git a/remoting/base/encoder_verbatim.cc b/remoting/base/encoder_verbatim.cc index d831006..b636670 100644 --- a/remoting/base/encoder_verbatim.cc +++ b/remoting/base/encoder_verbatim.cc @@ -8,7 +8,7 @@ #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/util.h" #include "remoting/base/protocol/chromotocol.pb.h" namespace remoting { diff --git a/remoting/base/encoder_zlib.cc b/remoting/base/encoder_zlib.cc index 390a46ad..f807e85 100644 --- a/remoting/base/encoder_zlib.cc +++ b/remoting/base/encoder_zlib.cc @@ -9,7 +9,7 @@ #include "media/base/data_buffer.h" #include "remoting/base/capture_data.h" #include "remoting/base/compressor_zlib.h" -#include "remoting/base/protocol_util.h" +#include "remoting/base/util.h" #include "remoting/base/protocol/chromotocol.pb.h" namespace remoting { diff --git a/remoting/base/mock_objects.h b/remoting/base/mock_objects.h index 7565f22..12143ad 100644 --- a/remoting/base/mock_objects.h +++ b/remoting/base/mock_objects.h @@ -8,26 +8,10 @@ #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" namespace remoting { -class MockProtocolDecoder : public ProtocolDecoder { - public: - MockProtocolDecoder() {} - - MOCK_METHOD2(ParseClientMessages, - void(scoped_refptr<media::DataBuffer> data, - ClientMessageList* messages)); - MOCK_METHOD2(ParseHostMessages, - void(scoped_refptr<media::DataBuffer> data, - HostMessageList* messages)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockProtocolDecoder); -}; - class MockEncoder : public Encoder { public: MockEncoder() {} diff --git a/remoting/base/multiple_array_input_stream.cc b/remoting/base/multiple_array_input_stream.cc index e5b8f94..ab0ba45 100644 --- a/remoting/base/multiple_array_input_stream.cc +++ b/remoting/base/multiple_array_input_stream.cc @@ -9,22 +9,26 @@ namespace remoting { -MultipleArrayInputStream::MultipleArrayInputStream(int count) - : buffer_count_(count), - current_buffer_(0), +MultipleArrayInputStream::MultipleArrayInputStream() + : current_buffer_(0), current_buffer_offset_(0), position_(0), last_returned_size_(0) { - DCHECK_GT(buffer_count_, 0); - buffers_.reset(new const uint8*[buffer_count_]); - buffer_sizes_.reset(new int[buffer_count_]); } MultipleArrayInputStream::~MultipleArrayInputStream() { } +void MultipleArrayInputStream::AddBuffer( + const char* buffer, int size) { + DCHECK_EQ(position_, 0); // Haven't started reading. + buffers_.push_back(buffer); + buffer_sizes_.push_back(size); + DCHECK_EQ(buffers_.size(), buffer_sizes_.size()); +} + bool MultipleArrayInputStream::Next(const void** data, int* size) { - if (current_buffer_ < buffer_count_) { + if (current_buffer_ < buffers_.size()) { // Also reply with that is remaining in the current buffer. last_returned_size_ = buffer_sizes_[current_buffer_] - current_buffer_offset_; @@ -49,7 +53,7 @@ bool MultipleArrayInputStream::Next(const void** data, int* size) { void MultipleArrayInputStream::BackUp(int count) { DCHECK_LE(count, last_returned_size_); DCHECK_EQ(0, current_buffer_offset_); - DCHECK_GT(current_buffer_, 0); + DCHECK_GT(current_buffer_, 0u); // Rewind one buffer. --current_buffer_; @@ -63,7 +67,7 @@ bool MultipleArrayInputStream::Skip(int count) { DCHECK_GE(count, 0); last_returned_size_ = 0; - while (count && current_buffer_ < buffer_count_) { + while (count && current_buffer_ < buffers_.size()) { int read = std::min( count, buffer_sizes_[current_buffer_] - current_buffer_offset_); @@ -86,11 +90,4 @@ int64 MultipleArrayInputStream::ByteCount() const { return position_; } -void MultipleArrayInputStream::SetBuffer( - int n, const uint8* buffer, int size) { - CHECK(n < buffer_count_); - buffers_[n] = buffer; - buffer_sizes_[n] = size; -} - } // namespace remoting diff --git a/remoting/base/multiple_array_input_stream.h b/remoting/base/multiple_array_input_stream.h index a1b5f01..7747da5 100644 --- a/remoting/base/multiple_array_input_stream.h +++ b/remoting/base/multiple_array_input_stream.h @@ -5,8 +5,9 @@ #ifndef REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ #define REMOTING_BASE_MULTIPLE_ARRAY_INPUT_STREAM_H_ +#include <vector> + #include "base/basictypes.h" -#include "base/scoped_ptr.h" #include "google/protobuf/io/zero_copy_stream.h" namespace remoting { @@ -19,24 +20,23 @@ class MultipleArrayInputStream : // Construct a MultipleArrayInputStream with |count| backing arrays. // TODO(hclam): Consider adding block size to see if it has a performance // gain. - explicit MultipleArrayInputStream(int count); + MultipleArrayInputStream(); virtual ~MultipleArrayInputStream(); + // Add a new buffer to the list. + void AddBuffer(const char* buffer, int size); + + // google::protobuf::io::ZeroCopyInputStream interface. virtual bool Next(const void** data, int* size); virtual void BackUp(int count); virtual bool Skip(int count); virtual int64 ByteCount() const; - // Set the n-th buffer to be |buffer|. - void SetBuffer(int n, const uint8* buffer, int size); - private: - scoped_array<const uint8*> buffers_; - scoped_array<int> buffer_sizes_; - - const int buffer_count_; + std::vector<const char*> buffers_; + std::vector<int> buffer_sizes_; - int current_buffer_; + size_t current_buffer_; int current_buffer_offset_; int position_; int last_returned_size_; diff --git a/remoting/base/multiple_array_input_stream_unittest.cc b/remoting/base/multiple_array_input_stream_unittest.cc index d8397c7..1d705fe 100644 --- a/remoting/base/multiple_array_input_stream_unittest.cc +++ b/remoting/base/multiple_array_input_stream_unittest.cc @@ -4,11 +4,14 @@ #include <string> +#include "base/scoped_ptr.h" #include "remoting/base/multiple_array_input_stream.h" #include "testing/gtest/include/gtest/gtest.h" namespace remoting { +// TODO(sergeyu): Add SCOPED_TRACE() for ReadFromInput() and ReadString(). + static size_t ReadFromInput(MultipleArrayInputStream* input, void* data, size_t size) { uint8* out = reinterpret_cast<uint8*>(data); @@ -64,11 +67,11 @@ static void PrepareData(scoped_ptr<MultipleArrayInputStream>* stream) { segments += 2; } - MultipleArrayInputStream* mstream = new MultipleArrayInputStream(segments); + MultipleArrayInputStream* mstream = new MultipleArrayInputStream(); const char* data = kTestData.c_str(); for (int i = 0; i < segments; ++i) { int size = i % 2 == 0 ? 1 : 2; - mstream->SetBuffer(i, reinterpret_cast<const uint8*>(data), size); + mstream->AddBuffer(data, size); data += size; } stream->reset(mstream); diff --git a/remoting/base/protocol_decoder.cc b/remoting/base/protocol_decoder.cc deleted file mode 100644 index 10d2413..0000000 --- a/remoting/base/protocol_decoder.cc +++ /dev/null @@ -1,151 +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/base/protocol_decoder.h" - -#include "base/logging.h" -#include "remoting/base/multiple_array_input_stream.h" -#include "talk/base/byteorder.h" - -namespace remoting { - -ProtocolDecoder::ProtocolDecoder() - : last_read_position_(0), - available_bytes_(0), - next_payload_(0), - next_payload_known_(false) { -} - -ProtocolDecoder::~ProtocolDecoder() {} - -void ProtocolDecoder::ParseClientMessages(scoped_refptr<media::DataBuffer> data, - ClientMessageList* messages) { - ParseMessages<ChromotingClientMessage>(data, messages); -} - -void ProtocolDecoder::ParseHostMessages(scoped_refptr<media::DataBuffer> data, - HostMessageList* messages) { - ParseMessages<ChromotingHostMessage>(data, messages); -} - -template <typename T> -void ProtocolDecoder::ParseMessages(scoped_refptr<media::DataBuffer> data, - std::list<T*>* messages) { - // If this is the first data in the processing queue, then set the - // last read position to 0. - if (data_list_.empty()) - last_read_position_ = 0; - - // First enqueue the data received. - data_list_.push_back(data); - available_bytes_ += data->GetDataSize(); - - // Then try to parse one message until we can't parse anymore. - T* message; - while (ParseOneMessage<T>(&message)) { - messages->push_back(message); - } -} - -template <typename T> -bool ProtocolDecoder::ParseOneMessage(T** message) { - // Determine the payload size. If we already know it, then skip this - // part. - // We have the value set to -1 for checking later. - int next_payload = -1; - if (!next_payload_known_ && GetPayloadSize(&next_payload)) { - DCHECK_NE(-1, next_payload); - next_payload_ = next_payload; - next_payload_known_ = true; - } - - // If the next payload size is still not known or we don't have enough - // data for parsing then exit. - if (!next_payload_known_ || available_bytes_ < next_payload_) - return false; - next_payload_known_ = false; - - // Extract data from |data_list_| used to form a full protocol buffer. - DataList buffers; - std::deque<const uint8*> buffer_pointers; - std::deque<int> buffer_sizes; - while (next_payload_ > 0 && !data_list_.empty()) { - scoped_refptr<media::DataBuffer> buffer = data_list_.front(); - size_t read_bytes = std::min(buffer->GetDataSize() - last_read_position_, - next_payload_); - - buffers.push_back(buffer); - buffer_pointers.push_back(buffer->GetData() + last_read_position_); - buffer_sizes.push_back(read_bytes); - - // Adjust counters. - last_read_position_ += read_bytes; - next_payload_ -= read_bytes; - available_bytes_ -= read_bytes; - - // If the front buffer is fully read, remove it from the queue. - if (buffer->GetDataSize() == last_read_position_) { - data_list_.pop_front(); - last_read_position_ = 0; - } - } - DCHECK_EQ(0UL, next_payload_); - DCHECK_EQ(buffers.size(), buffer_pointers.size()); - DCHECK_EQ(buffers.size(), buffer_sizes.size()); - - // Create a MultipleArrayInputStream for parsing. - MultipleArrayInputStream stream(buffers.size()); - for (size_t i = 0; i < buffers.size(); ++i) { - stream.SetBuffer(i, buffer_pointers[i], buffer_sizes[i]); - } - - // And finally it is parsing. - *message = new T(); - bool ret = (*message)->ParseFromZeroCopyStream(&stream); - if (!ret) - delete *message; - return ret; -} - -bool ProtocolDecoder::GetPayloadSize(int* size) { - // The header has a size of 4 bytes. - const size_t kHeaderSize = sizeof(int32); - - if (available_bytes_ < kHeaderSize) - return false; - - std::string header; - while (header.length() < kHeaderSize && !data_list_.empty()) { - scoped_refptr<media::DataBuffer> buffer = data_list_.front(); - - // Find out how many bytes we need and how many bytes are available in this - // buffer. - int needed_bytes = kHeaderSize - header.length(); - int available_bytes = buffer->GetDataSize() - last_read_position_; - - // Then append the required bytes into the header and advance the last - // read position. - int read_bytes = std::min(needed_bytes, available_bytes); - header.append( - reinterpret_cast<const char*>(buffer->GetData()) + last_read_position_, - read_bytes); - last_read_position_ += read_bytes; - available_bytes_ -= read_bytes; - - // If the buffer is depleted then remove it from the queue. - if (last_read_position_ == buffer->GetDataSize()) { - last_read_position_ = 0; - data_list_.pop_front(); - } - } - - if (header.length() == kHeaderSize) { - *size = talk_base::GetBE32(header.c_str()); - return true; - } - NOTREACHED() << "Unable to extract payload size"; - return false; -} - -} // namespace remoting diff --git a/remoting/base/protocol_decoder.h b/remoting/base/protocol_decoder.h deleted file mode 100644 index fed196f..0000000 --- a/remoting/base/protocol_decoder.h +++ /dev/null @@ -1,72 +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_BASE_PROTOCOL_DECODER_H_ -#define REMOTING_BASE_PROTOCOL_DECODER_H_ - -#include <deque> -#include <list> - -#include "base/ref_counted.h" -#include "google/protobuf/message_lite.h" -#include "media/base/data_buffer.h" -#include "remoting/base/protocol/chromotocol.pb.h" - -namespace remoting { - -typedef std::list<ChromotingHostMessage*> HostMessageList; -typedef std::list<ChromotingClientMessage*> ClientMessageList; - -// A protocol decoder is used to decode data transmitted in the chromoting -// network. -// TODO(hclam): Defines the interface and implement methods. -class ProtocolDecoder { - public: - ProtocolDecoder(); - - virtual ~ProtocolDecoder(); - - // Parse data received from network into ClientMessages. Ownership of |data| - // is passed to this object and output is written to |messages|. - virtual void ParseClientMessages(scoped_refptr<media::DataBuffer> data, - ClientMessageList* messages); - - // Parse data received from network into HostMessages. Ownership of |data| - // is passed to this object and output is written to |messages|. - virtual void ParseHostMessages(scoped_refptr<media::DataBuffer> data, - HostMessageList* messages); - - private: - // A private method used to parse data received from network into protocol - // buffers. - template <typename T> - void ParseMessages(scoped_refptr<media::DataBuffer> data, - std::list<T*>* messages); - - // Parse one message from |data_list_|. Return true if sucessful. - template <typename T> - bool ParseOneMessage(T** messages); - - // A utility method to read payload size of the protocol buffer from the - // data list. Return false if we don't have enough data. - bool GetPayloadSize(int* size); - - typedef std::deque<scoped_refptr<media::DataBuffer> > DataList; - DataList data_list_; - size_t last_read_position_; - - // Count the number of bytes in |data_list_| not read. - size_t available_bytes_; - - // Stores the size of the next payload if known. - size_t next_payload_; - - // True if the size of the next payload is known. After one payload is read, - // this is reset to false. - bool next_payload_known_; -}; - -} // namespace remoting - -#endif // REMOTING_BASE_PROTOCOL_DECODER_H_ diff --git a/remoting/base/protocol_decoder_unittest.cc b/remoting/base/protocol_decoder_unittest.cc deleted file mode 100644 index ae4ba85..0000000 --- a/remoting/base/protocol_decoder_unittest.cc +++ /dev/null @@ -1,121 +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 <string> - -#include "base/scoped_ptr.h" -#include "base/stl_util-inl.h" -#include "media/base/data_buffer.h" -#include "remoting/base/protocol_decoder.h" -#include "remoting/base/protocol_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace remoting { - -static const int kWidth = 640; -static const int kHeight = 480; -static const std::string kTestData = "Chromoting rockz"; - -static void AppendMessage(const ChromotingHostMessage& msg, - std::string* buffer) { - // Contains one encoded message. - scoped_refptr<media::DataBuffer> encoded_msg; - encoded_msg = SerializeAndFrameMessage(msg); - buffer->append(reinterpret_cast<const char*>(encoded_msg->GetData()), - encoded_msg->GetDataSize()); -} - -// Construct and prepare data in the |output_stream|. -static void PrepareData(uint8** buffer, int* size) { - // Contains all encoded messages. - std::string encoded_data; - - // The first message is InitClient. - ChromotingHostMessage msg; - msg.mutable_init_client()->set_width(kWidth); - msg.mutable_init_client()->set_height(kHeight); - AppendMessage(msg, &encoded_data); - msg.Clear(); - - // Then append 10 update sequences to the data. - for (int i = 0; i < 10; ++i) { - msg.mutable_begin_update_stream(); - AppendMessage(msg, &encoded_data); - msg.Clear(); - - msg.mutable_update_stream_packet()->mutable_rect_data()-> - set_sequence_number(0); - msg.mutable_update_stream_packet()->mutable_rect_data()-> - set_data(kTestData); - AppendMessage(msg, &encoded_data); - msg.Clear(); - - msg.mutable_end_update_stream(); - AppendMessage(msg, &encoded_data); - msg.Clear(); - } - - *size = encoded_data.length(); - *buffer = new uint8[*size]; - memcpy(*buffer, encoded_data.c_str(), *size); -} - -TEST(ProtocolDecoderTest, BasicOperations) { - // Prepare encoded data for testing. - int size; - uint8* test_data; - PrepareData(&test_data, &size); - scoped_array<uint8> memory_deleter(test_data); - - // Then simulate using ProtocolDecoder to decode variable - // size of encoded data. - // The first thing to do is to generate a variable size of data. This is done - // by iterating the following array for read sizes. - const int kReadSizes[] = {1, 2, 3, 1}; - - ProtocolDecoder decoder; - - // Then feed the protocol decoder using the above generated data and the - // read pattern. - HostMessageList message_list; - for (int i = 0; i < size;) { - // First generate the amount to feed the decoder. - int read = std::min(size - i, kReadSizes[i % arraysize(kReadSizes)]); - - // And then prepare a DataBuffer for feeding it. - scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(read); - memcpy(buffer->GetWritableData(), test_data + i, read); - buffer->SetDataSize(read); - decoder.ParseHostMessages(buffer, &message_list); - i += read; - } - - // Then verify the decoded messages. - EXPECT_EQ(31u, message_list.size()); - ASSERT_TRUE(message_list.size() > 0); - EXPECT_TRUE(message_list.front()->has_init_client()); - delete message_list.front(); - message_list.pop_front(); - - for (HostMessageList::iterator it = message_list.begin(); - it != message_list.end(); ++it) { - ChromotingHostMessage* message = *it; - int type = (i - 1) % 3; - if (type == 0) { - // Begin update stream. - EXPECT_TRUE(message->has_begin_update_stream()); - } else if (type == 1) { - // Partial update stream. - EXPECT_TRUE(message->has_update_stream_packet()); - EXPECT_EQ(kTestData, - message->update_stream_packet().rect_data().data()); - } else if (type == 2) { - // End update stream. - EXPECT_TRUE(message->has_end_update_stream()); - } - } - STLDeleteElements(&message_list); -} - -} // namespace remoting diff --git a/remoting/base/protocol_util.cc b/remoting/base/protocol_util.cc deleted file mode 100644 index f009eb3..0000000 --- a/remoting/base/protocol_util.cc +++ /dev/null @@ -1,43 +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/base/protocol_util.h" - -#include "base/basictypes.h" -#include "base/hash_tables.h" -#include "base/logging.h" -#include "talk/base/byteorder.h" - -namespace remoting { - -scoped_refptr<media::DataBuffer> SerializeAndFrameMessage( - const google::protobuf::MessageLite& msg) { - - // Create a buffer with 4 extra bytes. This is used as prefix to write an - // int32 of the serialized message size for framing. - const int kExtraBytes = sizeof(int32); - int size = msg.ByteSize() + kExtraBytes; - scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(size); - talk_base::SetBE32(buffer->GetWritableData(), msg.GetCachedSize()); - msg.SerializeWithCachedSizesToArray(buffer->GetWritableData() + kExtraBytes); - buffer->SetDataSize(size); - return buffer; -} - -int GetBytesPerPixel(PixelFormat format) { - // Note: The order is important here for performance. This is sorted from the - // most common to the less common (PixelFormatAscii is mostly used - // just for testing). - switch (format) { - case PixelFormatRgb24: return 3; - case PixelFormatRgb565: return 2; - case PixelFormatRgb32: return 4; - case PixelFormatAscii: return 1; - default: - NOTREACHED() << "Pixel format not supported"; - return 0; - } -} - -} // namespace remoting diff --git a/remoting/base/protocol_util.h b/remoting/base/protocol_util.h deleted file mode 100644 index 94cdc2f..0000000 --- a/remoting/base/protocol_util.h +++ /dev/null @@ -1,27 +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_BASE_PROTOCOL_UTIL_H_ -#define REMOTING_BASE_PROTOCOL_UTIL_H_ - -#include "google/protobuf/message_lite.h" -#include "media/base/data_buffer.h" -#include "remoting/base/protocol/chromotocol.pb.h" - -// This file defines utility methods used for encoding and decoding the protocol -// used in Chromoting. -namespace remoting { - -// Serialize the Protocol Buffer message and provide sufficient framing for -// sending it over the wire. -// This will provide sufficient prefix and suffix for the receiver side to -// decode the message. -scoped_refptr<media::DataBuffer> SerializeAndFrameMessage( - const google::protobuf::MessageLite& msg); - -int GetBytesPerPixel(PixelFormat format); - -} // namespace remoting - -#endif // REMOTING_BASE_PROTOCOL_UTIL_H_ diff --git a/remoting/base/util.cc b/remoting/base/util.cc new file mode 100644 index 0000000..8ccbd23 --- /dev/null +++ b/remoting/base/util.cc @@ -0,0 +1,26 @@ +// 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/base/util.h" + +#include "base/logging.h" + +namespace remoting { + +int GetBytesPerPixel(PixelFormat format) { + // Note: The order is important here for performance. This is sorted from the + // most common to the less common (PixelFormatAscii is mostly used + // just for testing). + switch (format) { + case PixelFormatRgb24: return 3; + case PixelFormatRgb565: return 2; + case PixelFormatRgb32: return 4; + case PixelFormatAscii: return 1; + default: + NOTREACHED() << "Pixel format not supported"; + return 0; + } +} + +} // namespace remoting diff --git a/remoting/base/util.h b/remoting/base/util.h new file mode 100644 index 0000000..adfbc89 --- /dev/null +++ b/remoting/base/util.h @@ -0,0 +1,16 @@ +// 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_UTIL_H_ +#define REMOTING_BASE_UTIL_H_ + +#include "remoting/base/protocol/chromotocol.pb.h" + +namespace remoting { + +int GetBytesPerPixel(PixelFormat format); + +} // namespace remoting + +#endif // REMOTING_BASE_UTIL_H_ |