| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/base/encoder_verbatim.h" | 5 #include "remoting/base/encoder_verbatim.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gfx/rect.h" | 8 #include "gfx/rect.h" |
| 9 #include "media/base/data_buffer.h" | 9 #include "media/base/data_buffer.h" |
| 10 #include "remoting/base/capture_data.h" | 10 #include "remoting/base/capture_data.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 // TODO(garykac): This assumes that the rect fits into a single packet. | 47 // TODO(garykac): This assumes that the rect fits into a single packet. |
| 48 // Fix this by modeling after code in encoder_zlib.cc | 48 // Fix this by modeling after code in encoder_zlib.cc |
| 49 void EncoderVerbatim::EncodeRect(const gfx::Rect& rect, size_t rect_index) { | 49 void EncoderVerbatim::EncodeRect(const gfx::Rect& rect, size_t rect_index) { |
| 50 CHECK(capture_data_->data_planes().data[0]); | 50 CHECK(capture_data_->data_planes().data[0]); |
| 51 const int stride = capture_data_->data_planes().strides[0]; | 51 const int stride = capture_data_->data_planes().strides[0]; |
| 52 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); | 52 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); |
| 53 const int row_size = bytes_per_pixel * rect.width(); | 53 const int row_size = bytes_per_pixel * rect.width(); |
| 54 | 54 |
| 55 VideoPacket* packet = new VideoPacket(); | 55 ChromotingHostMessage* message = new ChromotingHostMessage(); |
| 56 PrepareUpdateStart(rect, packet); | 56 RectangleUpdatePacket* update = message->mutable_rectangle_update(); |
| 57 PrepareUpdateStart(rect, update); |
| 57 | 58 |
| 58 const uint8* in = capture_data_->data_planes().data[0] + | 59 const uint8* in = capture_data_->data_planes().data[0] + |
| 59 rect.y() * stride + | 60 rect.y() * stride + |
| 60 rect.x() * bytes_per_pixel; | 61 rect.x() * bytes_per_pixel; |
| 61 // TODO(hclam): Fill in the sequence number. | 62 // TODO(hclam): Fill in the sequence number. |
| 62 uint8* out = GetOutputBuffer(packet, packet_size_); | 63 uint8* out = GetOutputBuffer(update, packet_size_); |
| 63 int total_bytes = 0; | 64 int total_bytes = 0; |
| 64 for (int y = 0; y < rect.height(); y++) { | 65 for (int y = 0; y < rect.height(); y++) { |
| 65 memcpy(out, in, row_size); | 66 memcpy(out, in, row_size); |
| 66 out += row_size; | 67 out += row_size; |
| 67 in += stride; | 68 in += stride; |
| 68 total_bytes += row_size; | 69 total_bytes += row_size; |
| 69 } | 70 } |
| 70 | 71 |
| 71 // We have reached the end of stream. | 72 // We have reached the end of stream. |
| 72 packet->set_flags(packet->flags() | VideoPacket::LAST_PACKET); | 73 update->set_flags(update->flags() | RectangleUpdatePacket::LAST_PACKET); |
| 73 | 74 |
| 74 // If we have filled the message or we have reached the end of stream. | 75 // If we have filled the message or we have reached the end of stream. |
| 75 packet->mutable_data()->resize(total_bytes); | 76 message->mutable_rectangle_update()->mutable_encoded_rect()-> |
| 76 SubmitMessage(packet, rect_index); | 77 resize(total_bytes); |
| 78 SubmitMessage(message, rect_index); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void EncoderVerbatim::PrepareUpdateStart(const gfx::Rect& rect, | 81 void EncoderVerbatim::PrepareUpdateStart(const gfx::Rect& rect, |
| 80 VideoPacket* packet) { | 82 RectangleUpdatePacket* update) { |
| 81 | 83 |
| 82 packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); | 84 update->set_flags(update->flags() | RectangleUpdatePacket::FIRST_PACKET); |
| 83 VideoPacketFormat* format = packet->mutable_format(); | 85 RectangleFormat* format = update->mutable_format(); |
| 84 | 86 |
| 85 format->set_x(rect.x()); | 87 format->set_x(rect.x()); |
| 86 format->set_y(rect.y()); | 88 format->set_y(rect.y()); |
| 87 format->set_width(rect.width()); | 89 format->set_width(rect.width()); |
| 88 format->set_height(rect.height()); | 90 format->set_height(rect.height()); |
| 89 format->set_encoding(VideoPacketFormat::ENCODING_VERBATIM); | 91 format->set_encoding(EncodingNone); |
| 90 format->set_pixel_format(capture_data_->pixel_format()); | 92 format->set_pixel_format(capture_data_->pixel_format()); |
| 91 } | 93 } |
| 92 | 94 |
| 93 uint8* EncoderVerbatim::GetOutputBuffer(VideoPacket* packet, size_t size) { | 95 uint8* EncoderVerbatim::GetOutputBuffer(RectangleUpdatePacket* update, |
| 94 packet->mutable_data()->resize(size); | 96 size_t size) { |
| 97 update->mutable_encoded_rect()->resize(size); |
| 95 // TODO(ajwong): Is there a better way to do this at all??? | 98 // TODO(ajwong): Is there a better way to do this at all??? |
| 96 return const_cast<uint8*>(reinterpret_cast<const uint8*>( | 99 return const_cast<uint8*>(reinterpret_cast<const uint8*>( |
| 97 packet->mutable_data()->data())); | 100 update->mutable_encoded_rect()->data())); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void EncoderVerbatim::SubmitMessage(VideoPacket* packet, size_t rect_index) { | 103 void EncoderVerbatim::SubmitMessage(ChromotingHostMessage* message, |
| 101 callback_->Run(packet); | 104 size_t rect_index) { |
| 105 EncodingState state = EncodingInProgress; |
| 106 const RectangleUpdatePacket& update = message->rectangle_update(); |
| 107 if (rect_index == 0 && |
| 108 (update.flags() | RectangleUpdatePacket::FIRST_PACKET)) { |
| 109 state |= EncodingStarting; |
| 110 } |
| 111 if (rect_index == capture_data_->dirty_rects().size() - 1 && |
| 112 (update.flags() | RectangleUpdatePacket::LAST_PACKET)) { |
| 113 state |= EncodingEnded; |
| 114 } |
| 115 callback_->Run(message, state); |
| 102 } | 116 } |
| 103 | 117 |
| 104 } // namespace remoting | 118 } // namespace remoting |
| OLD | NEW |