OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_row_based.h" | 5 #include "remoting/base/encoder_row_based.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "remoting/base/capture_data.h" | 8 #include "remoting/base/capture_data.h" |
9 #include "remoting/base/compressor_verbatim.h" | 9 #include "remoting/base/compressor_verbatim.h" |
10 #include "remoting/base/compressor_zlib.h" | 10 #include "remoting/base/compressor_zlib.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { | 81 void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
82 CHECK(capture_data_->data_planes().data[0]); | 82 CHECK(capture_data_->data_planes().data[0]); |
83 const int strides = capture_data_->data_planes().strides[0]; | 83 const int strides = capture_data_->data_planes().strides[0]; |
84 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); | 84 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); |
85 const int row_size = bytes_per_pixel * rect.width(); | 85 const int row_size = bytes_per_pixel * rect.width(); |
86 | 86 |
87 compressor_->Reset(); | 87 compressor_->Reset(); |
88 | 88 |
89 VideoPacket* packet = new VideoPacket(); | 89 scoped_ptr<VideoPacket> packet(new VideoPacket()); |
90 PrepareUpdateStart(rect, packet); | 90 PrepareUpdateStart(rect, packet.get()); |
91 const uint8* in = capture_data_->data_planes().data[0] + | 91 const uint8* in = capture_data_->data_planes().data[0] + |
92 rect.fTop * strides + rect.fLeft * bytes_per_pixel; | 92 rect.fTop * strides + rect.fLeft * bytes_per_pixel; |
93 // TODO(hclam): Fill in the sequence number. | 93 // TODO(hclam): Fill in the sequence number. |
94 uint8* out = GetOutputBuffer(packet, packet_size_); | 94 uint8* out = GetOutputBuffer(packet.get(), packet_size_); |
95 int filled = 0; | 95 int filled = 0; |
96 int row_pos = 0; // Position in the current row in bytes. | 96 int row_pos = 0; // Position in the current row in bytes. |
97 int row_y = 0; // Current row. | 97 int row_y = 0; // Current row. |
98 bool compress_again = true; | 98 bool compress_again = true; |
99 while (compress_again) { | 99 while (compress_again) { |
100 // Prepare a message for sending out. | 100 // Prepare a message for sending out. |
101 if (!packet) { | 101 if (!packet.get()) { |
102 packet = new VideoPacket(); | 102 packet.reset(new VideoPacket()); |
103 out = GetOutputBuffer(packet, packet_size_); | 103 out = GetOutputBuffer(packet.get(), packet_size_); |
104 filled = 0; | 104 filled = 0; |
105 } | 105 } |
106 | 106 |
107 Compressor::CompressorFlush flush = Compressor::CompressorNoFlush; | 107 Compressor::CompressorFlush flush = Compressor::CompressorNoFlush; |
108 if (row_y == rect.height() - 1) { | 108 if (row_y == rect.height() - 1) { |
109 flush = Compressor::CompressorFinish; | 109 flush = Compressor::CompressorFinish; |
110 } | 110 } |
111 | 111 |
112 int consumed = 0; | 112 int consumed = 0; |
113 int written = 0; | 113 int written = 0; |
(...skipping 11 matching lines...) Expand all Loading... |
125 capture_data_->client_sequence_number()); | 125 capture_data_->client_sequence_number()); |
126 if (last) | 126 if (last) |
127 packet->set_flags(packet->flags() | VideoPacket::LAST_PARTITION); | 127 packet->set_flags(packet->flags() | VideoPacket::LAST_PARTITION); |
128 DCHECK(row_pos == row_size); | 128 DCHECK(row_pos == row_size); |
129 DCHECK(row_y == rect.height() - 1); | 129 DCHECK(row_y == rect.height() - 1); |
130 } | 130 } |
131 | 131 |
132 // If we have filled the message or we have reached the end of stream. | 132 // If we have filled the message or we have reached the end of stream. |
133 if (filled == packet_size_ || !compress_again) { | 133 if (filled == packet_size_ || !compress_again) { |
134 packet->mutable_data()->resize(filled); | 134 packet->mutable_data()->resize(filled); |
135 callback_.Run(packet); | 135 callback_.Run(packet.Pass()); |
136 packet = NULL; | |
137 } | 136 } |
138 | 137 |
139 // Reached the end of input row and we're not at the last row. | 138 // Reached the end of input row and we're not at the last row. |
140 if (row_pos == row_size && row_y < rect.height() - 1) { | 139 if (row_pos == row_size && row_y < rect.height() - 1) { |
141 row_pos = 0; | 140 row_pos = 0; |
142 in += strides; | 141 in += strides; |
143 ++row_y; | 142 ++row_y; |
144 } | 143 } |
145 } | 144 } |
146 } | 145 } |
(...skipping 15 matching lines...) Expand all Loading... |
162 } | 161 } |
163 } | 162 } |
164 | 163 |
165 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { | 164 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { |
166 packet->mutable_data()->resize(size); | 165 packet->mutable_data()->resize(size); |
167 // TODO(ajwong): Is there a better way to do this at all??? | 166 // TODO(ajwong): Is there a better way to do this at all??? |
168 return const_cast<uint8*>(reinterpret_cast<const uint8*>( | 167 return const_cast<uint8*>(reinterpret_cast<const uint8*>( |
169 packet->mutable_data()->data())); | 168 packet->mutable_data()->data())); |
170 } | 169 } |
171 | 170 |
172 | |
173 } // namespace remoting | 171 } // namespace remoting |
OLD | NEW |