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/host/encoder_verbatim.h" | 5 #include "remoting/base/encoder_verbatim.h" |
6 | 6 |
7 #include "gfx/rect.h" | 7 #include "gfx/rect.h" |
8 #include "media/base/data_buffer.h" | 8 #include "media/base/data_buffer.h" |
| 9 #include "remoting/base/capture_data.h" |
9 #include "remoting/base/protocol_util.h" | 10 #include "remoting/base/protocol_util.h" |
10 #include "remoting/base/protocol/chromotocol.pb.h" | 11 #include "remoting/base/protocol/chromotocol.pb.h" |
11 | 12 |
12 namespace remoting { | 13 namespace remoting { |
13 | 14 |
14 using media::DataBuffer; | 15 using media::DataBuffer; |
15 | 16 |
16 void EncoderVerbatim::Encode(scoped_refptr<Capturer::CaptureData> capture_data, | 17 void EncoderVerbatim::Encode(scoped_refptr<CaptureData> capture_data, |
17 bool key_frame, | 18 bool key_frame, |
18 DataAvailableCallback* data_available_callback) { | 19 DataAvailableCallback* data_available_callback) { |
19 int num_rects = capture_data->dirty_rects().size(); | 20 int num_rects = capture_data->dirty_rects().size(); |
20 for (int i = 0; i < num_rects; i++) { | 21 for (int i = 0; i < num_rects; i++) { |
21 const gfx::Rect& dirty_rect = capture_data->dirty_rects()[i]; | 22 const gfx::Rect& dirty_rect = capture_data->dirty_rects()[i]; |
22 HostMessage* msg = new HostMessage(); | 23 HostMessage* msg = new HostMessage(); |
23 UpdateStreamPacketMessage* packet = msg->mutable_update_stream_packet(); | 24 UpdateStreamPacketMessage* packet = msg->mutable_update_stream_packet(); |
24 | 25 |
25 if (EncodeRect(dirty_rect, capture_data, packet)) { | 26 if (EncodeRect(dirty_rect.x(), dirty_rect.y(), dirty_rect.width(), |
| 27 dirty_rect.height(), capture_data, packet)) { |
26 // Prepare the end rect content. | 28 // Prepare the end rect content. |
27 packet->mutable_end_rect(); | 29 packet->mutable_end_rect(); |
28 | 30 |
29 EncodingState state = EncodingInProgress; | 31 EncodingState state = EncodingInProgress; |
30 if (i == 0) { | 32 if (i == 0) { |
31 state |= EncodingStarting; | 33 state |= EncodingStarting; |
32 } | 34 } |
33 if (i == num_rects - 1) { | 35 if (i == num_rects - 1) { |
34 state |= EncodingEnded; | 36 state |= EncodingEnded; |
35 } | 37 } |
36 data_available_callback->Run(msg, state); | 38 data_available_callback->Run(msg, state); |
37 } | 39 } |
38 } | 40 } |
39 | 41 |
40 delete data_available_callback; | 42 delete data_available_callback; |
41 } | 43 } |
42 | 44 |
43 bool EncoderVerbatim::EncodeRect( | 45 bool EncoderVerbatim::EncodeRect( |
44 const gfx::Rect& dirty, | 46 int x, int y, int width, int height, |
45 const scoped_refptr<Capturer::CaptureData>& capture_data, | 47 const scoped_refptr<CaptureData>& capture_data, |
46 UpdateStreamPacketMessage* packet) { | 48 UpdateStreamPacketMessage* packet) { |
47 // Prepare the begin rect content. | 49 // Prepare the begin rect content. |
48 packet->mutable_begin_rect()->set_x(dirty.x()); | 50 packet->mutable_begin_rect()->set_x(x); |
49 packet->mutable_begin_rect()->set_y(dirty.y()); | 51 packet->mutable_begin_rect()->set_y(y); |
50 packet->mutable_begin_rect()->set_width(dirty.width()); | 52 packet->mutable_begin_rect()->set_width(width); |
51 packet->mutable_begin_rect()->set_height(dirty.height()); | 53 packet->mutable_begin_rect()->set_height(height); |
52 packet->mutable_begin_rect()->set_encoding(EncodingNone); | 54 packet->mutable_begin_rect()->set_encoding(EncodingNone); |
53 packet->mutable_begin_rect()->set_pixel_format(capture_data->pixel_format()); | 55 packet->mutable_begin_rect()->set_pixel_format(capture_data->pixel_format()); |
54 | 56 |
55 // Calculate the size of output. | 57 // Calculate the size of output. |
56 int bytes_per_pixel = GetBytesPerPixel(capture_data->pixel_format()); | 58 int bytes_per_pixel = GetBytesPerPixel(capture_data->pixel_format()); |
57 int row_size = bytes_per_pixel * dirty.width(); | 59 int row_size = bytes_per_pixel * width; |
58 int output_size = 0; | 60 int output_size = 0; |
59 for (int i = 0; i < Capturer::DataPlanes::kPlaneCount; ++i) { | 61 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
60 // TODO(hclam): Handle YUV since the height would be different. | 62 // TODO(hclam): Handle YUV since the height would be different. |
61 const uint8* in = capture_data->data_planes().data[i]; | 63 const uint8* in = capture_data->data_planes().data[i]; |
62 if (!in) continue; | 64 if (!in) continue; |
63 output_size += row_size * dirty.height(); | 65 output_size += row_size * height; |
64 } | 66 } |
65 | 67 |
66 // Resize the output data buffer. | 68 // Resize the output data buffer. |
67 packet->mutable_rect_data()->mutable_data()->resize(output_size); | 69 packet->mutable_rect_data()->mutable_data()->resize(output_size); |
68 uint8* out = reinterpret_cast<uint8*>( | 70 uint8* out = reinterpret_cast<uint8*>( |
69 &((*packet->mutable_rect_data()->mutable_data())[0])); | 71 &((*packet->mutable_rect_data()->mutable_data())[0])); |
70 | 72 |
71 for (int i = 0; i < Capturer::DataPlanes::kPlaneCount; ++i) { | 73 for (int i = 0; i < DataPlanes::kPlaneCount; ++i) { |
72 const uint8* in = capture_data->data_planes().data[i]; | 74 const uint8* in = capture_data->data_planes().data[i]; |
73 // Skip over planes that don't have data. | 75 // Skip over planes that don't have data. |
74 if (!in) continue; | 76 if (!in) continue; |
75 | 77 |
76 // TODO(hclam): Handle YUV since the height would be different. | 78 // TODO(hclam): Handle YUV since the height would be different. |
77 for (int j = 0; j < dirty.height(); ++j) { | 79 for (int j = 0; j < height; ++j) { |
78 DCHECK_LE(row_size, capture_data->data_planes().strides[i]); | 80 DCHECK_LE(row_size, capture_data->data_planes().strides[i]); |
79 memcpy(out, in, row_size); | 81 memcpy(out, in, row_size); |
80 in += capture_data->data_planes().strides[i]; | 82 in += capture_data->data_planes().strides[i]; |
81 out += row_size; | 83 out += row_size; |
82 } | 84 } |
83 } | 85 } |
84 return true; | 86 return true; |
85 } | 87 } |
86 | 88 |
87 } // namespace remoting | 89 } // namespace remoting |
OLD | NEW |