diff options
Diffstat (limited to 'remoting/base/encoder_zlib.cc')
-rw-r--r-- | remoting/base/encoder_zlib.cc | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/remoting/base/encoder_zlib.cc b/remoting/base/encoder_zlib.cc index ddbe923..e184fd3 100644 --- a/remoting/base/encoder_zlib.cc +++ b/remoting/base/encoder_zlib.cc @@ -26,7 +26,7 @@ EncoderZlib::~EncoderZlib() {} void EncoderZlib::Encode(scoped_refptr<CaptureData> capture_data, bool key_frame, DataAvailableCallback* data_available_callback) { - CHECK(capture_data->pixel_format() == PixelFormatRgb32) + CHECK(capture_data->pixel_format() == PIXEL_FORMAT_RGB32) << "Zlib Encoder only works with RGB32. Got " << capture_data->pixel_format(); capture_data_ = capture_data; @@ -51,24 +51,22 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor, const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format()); const int row_size = bytes_per_pixel * rect.width(); - ChromotingHostMessage* message = new ChromotingHostMessage(); - RectangleUpdatePacket* update = message->mutable_rectangle_update(); - PrepareUpdateStart(rect, update); + VideoPacket* packet = new VideoPacket(); + PrepareUpdateStart(rect, packet); const uint8* in = capture_data_->data_planes().data[0] + rect.y() * strides + rect.x() * bytes_per_pixel; // TODO(hclam): Fill in the sequence number. - uint8* out = GetOutputBuffer(update, packet_size_); + uint8* out = GetOutputBuffer(packet, packet_size_); int filled = 0; int row_x = 0; int row_y = 0; bool compress_again = true; while (compress_again) { // Prepare a message for sending out. - if (!message) { - message = new ChromotingHostMessage(); - update = message->mutable_rectangle_update(); - out = GetOutputBuffer(update, packet_size_); + if (!packet) { + packet = new VideoPacket(); + out = GetOutputBuffer(packet, packet_size_); filled = 0; } @@ -91,15 +89,14 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor, // We have reached the end of stream. if (!compress_again) { - update->set_flags(update->flags() | RectangleUpdatePacket::LAST_PACKET); + packet->set_flags(packet->flags() | VideoPacket::LAST_PACKET); } // If we have filled the message or we have reached the end of stream. if (filled == packet_size_ || !compress_again) { - message->mutable_rectangle_update()->mutable_encoded_rect()-> - resize(filled); - SubmitMessage(message, rect_index); - message = NULL; + packet->mutable_data()->resize(filled); + SubmitMessage(packet, rect_index); + packet = NULL; } // Reached the end of input row and we're not at the last row. @@ -112,40 +109,27 @@ void EncoderZlib::EncodeRect(CompressorZlib* compressor, } void EncoderZlib::PrepareUpdateStart(const gfx::Rect& rect, - RectangleUpdatePacket* update) { - - update->set_flags(update->flags() | RectangleUpdatePacket::FIRST_PACKET); - RectangleFormat* format = update->mutable_format(); + VideoPacket* packet) { + packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET); + VideoPacketFormat* format = packet->mutable_format(); format->set_x(rect.x()); format->set_y(rect.y()); format->set_width(rect.width()); format->set_height(rect.height()); - format->set_encoding(EncodingZlib); + format->set_encoding(VideoPacketFormat::ENCODING_ZLIB); format->set_pixel_format(capture_data_->pixel_format()); } -uint8* EncoderZlib::GetOutputBuffer(RectangleUpdatePacket* update, - size_t size) { - update->mutable_encoded_rect()->resize(size); +uint8* EncoderZlib::GetOutputBuffer(VideoPacket* packet, size_t size) { + packet->mutable_data()->resize(size); // TODO(ajwong): Is there a better way to do this at all??? return const_cast<uint8*>(reinterpret_cast<const uint8*>( - update->mutable_encoded_rect()->data())); + packet->mutable_data()->data())); } -void EncoderZlib::SubmitMessage(ChromotingHostMessage* message, - size_t rect_index) { - EncodingState state = EncodingInProgress; - const RectangleUpdatePacket& update = message->rectangle_update(); - if (rect_index == 0 && - (update.flags() | RectangleUpdatePacket::FIRST_PACKET)) { - state |= EncodingStarting; - } - if (rect_index == capture_data_->dirty_rects().size() - 1 && - (update.flags() | RectangleUpdatePacket::LAST_PACKET)) { - state |= EncodingEnded; - } - callback_->Run(message, state); +void EncoderZlib::SubmitMessage(VideoPacket* packet, size_t rect_index) { + callback_->Run(packet); } } // namespace remoting |