| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 VideoPacketFormat::Encoding encoding, | 49 VideoPacketFormat::Encoding encoding, |
| 50 int packet_size) | 50 int packet_size) |
| 51 : encoding_(encoding), | 51 : encoding_(encoding), |
| 52 compressor_(compressor), | 52 compressor_(compressor), |
| 53 screen_size_(SkISize::Make(0,0)), | 53 screen_size_(SkISize::Make(0,0)), |
| 54 packet_size_(packet_size) { | 54 packet_size_(packet_size) { |
| 55 } | 55 } |
| 56 | 56 |
| 57 EncoderRowBased::~EncoderRowBased() {} | 57 EncoderRowBased::~EncoderRowBased() {} |
| 58 | 58 |
| 59 void EncoderRowBased::Encode(scoped_refptr<CaptureData> capture_data, | 59 void EncoderRowBased::Encode( |
| 60 bool key_frame, | 60 scoped_refptr<CaptureData> capture_data, |
| 61 DataAvailableCallback* data_available_callback) { | 61 bool key_frame, |
| 62 const DataAvailableCallback& data_available_callback) { |
| 62 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) | 63 CHECK(capture_data->pixel_format() == media::VideoFrame::RGB32) |
| 63 << "RowBased Encoder only works with RGB32. Got " | 64 << "RowBased Encoder only works with RGB32. Got " |
| 64 << capture_data->pixel_format(); | 65 << capture_data->pixel_format(); |
| 65 capture_data_ = capture_data; | 66 capture_data_ = capture_data; |
| 66 callback_.reset(data_available_callback); | 67 callback_ = data_available_callback; |
| 67 | 68 |
| 68 const SkRegion& region = capture_data->dirty_region(); | 69 const SkRegion& region = capture_data->dirty_region(); |
| 69 SkRegion::Iterator iter(region); | 70 SkRegion::Iterator iter(region); |
| 70 while (!iter.done()) { | 71 while (!iter.done()) { |
| 71 SkIRect rect = iter.rect(); | 72 SkIRect rect = iter.rect(); |
| 72 iter.next(); | 73 iter.next(); |
| 73 EncodeRect(rect, iter.done()); | 74 EncodeRect(rect, iter.done()); |
| 74 } | 75 } |
| 75 | 76 |
| 76 capture_data_ = NULL; | 77 capture_data_ = NULL; |
| 77 callback_.reset(); | 78 callback_.Reset(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { | 81 void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) { |
| 81 CHECK(capture_data_->data_planes().data[0]); | 82 CHECK(capture_data_->data_planes().data[0]); |
| 82 const int strides = capture_data_->data_planes().strides[0]; | 83 const int strides = capture_data_->data_planes().strides[0]; |
| 83 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); | 84 const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); |
| 84 const int row_size = bytes_per_pixel * rect.width(); | 85 const int row_size = bytes_per_pixel * rect.width(); |
| 85 | 86 |
| 86 compressor_->Reset(); | 87 compressor_->Reset(); |
| 87 | 88 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 capture_data_->client_sequence_number()); | 125 capture_data_->client_sequence_number()); |
| 125 if (last) | 126 if (last) |
| 126 packet->set_flags(packet->flags() | VideoPacket::LAST_PARTITION); | 127 packet->set_flags(packet->flags() | VideoPacket::LAST_PARTITION); |
| 127 DCHECK(row_pos == row_size); | 128 DCHECK(row_pos == row_size); |
| 128 DCHECK(row_y == rect.height() - 1); | 129 DCHECK(row_y == rect.height() - 1); |
| 129 } | 130 } |
| 130 | 131 |
| 131 // 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. |
| 132 if (filled == packet_size_ || !compress_again) { | 133 if (filled == packet_size_ || !compress_again) { |
| 133 packet->mutable_data()->resize(filled); | 134 packet->mutable_data()->resize(filled); |
| 134 callback_->Run(packet); | 135 callback_.Run(packet); |
| 135 packet = NULL; | 136 packet = NULL; |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Reached the end of input row and we're not at the last row. | 139 // Reached the end of input row and we're not at the last row. |
| 139 if (row_pos == row_size && row_y < rect.height() - 1) { | 140 if (row_pos == row_size && row_y < rect.height() - 1) { |
| 140 row_pos = 0; | 141 row_pos = 0; |
| 141 in += strides; | 142 in += strides; |
| 142 ++row_y; | 143 ++row_y; |
| 143 } | 144 } |
| 144 } | 145 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 163 | 164 |
| 164 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { | 165 uint8* EncoderRowBased::GetOutputBuffer(VideoPacket* packet, size_t size) { |
| 165 packet->mutable_data()->resize(size); | 166 packet->mutable_data()->resize(size); |
| 166 // TODO(ajwong): Is there a better way to do this at all??? | 167 // TODO(ajwong): Is there a better way to do this at all??? |
| 167 return const_cast<uint8*>(reinterpret_cast<const uint8*>( | 168 return const_cast<uint8*>(reinterpret_cast<const uint8*>( |
| 168 packet->mutable_data()->data())); | 169 packet->mutable_data()->data())); |
| 169 } | 170 } |
| 170 | 171 |
| 171 | 172 |
| 172 } // namespace remoting | 173 } // namespace remoting |
| OLD | NEW |