| 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/decoder_zlib.h" | 5 #include "remoting/base/decoder_zlib.h" |
| 6 | 6 |
| 7 #include "remoting/base/decompressor_zlib.h" | 7 #include "remoting/base/decompressor_zlib.h" |
| 8 #include "remoting/base/protocol_util.h" | 8 #include "remoting/base/protocol_util.h" |
| 9 | 9 |
| 10 namespace remoting { | 10 namespace remoting { |
| 11 | 11 |
| 12 DecoderZlib::DecoderZlib() | 12 DecoderZlib::DecoderZlib() |
| 13 : state_(kWaitingForBeginRect), | 13 : state_(kWaitingForBeginRect), |
| 14 rect_x_(0), | 14 rect_x_(0), |
| 15 rect_y_(0), | 15 rect_y_(0), |
| 16 rect_width_(0), | 16 rect_width_(0), |
| 17 rect_height_(0), | 17 rect_height_(0), |
| 18 bytes_per_pixel_(0), | 18 bytes_per_pixel_(0), |
| 19 updated_rects_(NULL), | 19 updated_rects_(NULL), |
| 20 row_pos_(0), | 20 row_pos_(0), |
| 21 row_y_(0), | 21 row_y_(0), |
| 22 // TODO(hclam): We should use the information from the update stream | 22 // TODO(hclam): We should use the information from the update stream |
| 23 // to determine whether we should reverse the rows or not. | 23 // to determine whether we should reverse the rows or not. |
| 24 // But for simplicity we set to be always true. | 24 // But for simplicity we set to be always true. |
| 25 reverse_rows_(true) { | 25 reverse_rows_(true) { |
| 26 encoding_ = EncodingZlib; |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool DecoderZlib::BeginDecode(scoped_refptr<media::VideoFrame> frame, | 29 bool DecoderZlib::BeginDecode(scoped_refptr<media::VideoFrame> frame, |
| 29 UpdatedRects* updated_rects, | 30 UpdatedRects* updated_rects, |
| 30 Task* partial_decode_done, | 31 Task* partial_decode_done, |
| 31 Task* decode_done) { | 32 Task* decode_done) { |
| 32 DCHECK(!partial_decode_done_.get()); | 33 DCHECK(!partial_decode_done_.get()); |
| 33 DCHECK(!decode_done_.get()); | 34 DCHECK(!decode_done_.get()); |
| 34 DCHECK(!updated_rects_); | 35 DCHECK(!updated_rects_); |
| 35 DCHECK_EQ(kWaitingForBeginRect, state_); | 36 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 37 DCHECK(!started_); |
| 36 | 38 |
| 37 if (static_cast<PixelFormat>(frame->format()) != PixelFormatRgb32) { | 39 if (static_cast<PixelFormat>(frame->format()) != PixelFormatRgb32) { |
| 38 LOG(INFO) << "DecoderZlib only supports RGB32."; | 40 LOG(INFO) << "DecoderZlib only supports RGB32."; |
| 39 return false; | 41 return false; |
| 40 } | 42 } |
| 41 | 43 |
| 42 partial_decode_done_.reset(partial_decode_done); | 44 partial_decode_done_.reset(partial_decode_done); |
| 43 decode_done_.reset(decode_done); | 45 decode_done_.reset(decode_done); |
| 44 updated_rects_ = updated_rects; | 46 updated_rects_ = updated_rects; |
| 45 frame_ = frame; | 47 frame_ = frame; |
| 46 | 48 |
| 47 // Create the decompressor. | 49 // Create the decompressor. |
| 48 decompressor_.reset(new DecompressorZlib()); | 50 decompressor_.reset(new DecompressorZlib()); |
| 51 |
| 52 started_ = true; |
| 49 return true; | 53 return true; |
| 50 } | 54 } |
| 51 | 55 |
| 52 bool DecoderZlib::PartialDecode(HostMessage* message) { | 56 bool DecoderZlib::PartialDecode(HostMessage* message) { |
| 53 scoped_ptr<HostMessage> msg_deleter(message); | 57 scoped_ptr<HostMessage> msg_deleter(message); |
| 54 DCHECK(message->has_update_stream_packet()); | 58 DCHECK(message->has_update_stream_packet()); |
| 59 DCHECK(started_); |
| 55 | 60 |
| 56 bool ret = true; | 61 bool ret = true; |
| 57 if (message->update_stream_packet().has_begin_rect()) | 62 if (message->update_stream_packet().has_begin_rect()) |
| 58 ret = HandleBeginRect(message); | 63 ret = HandleBeginRect(message); |
| 59 if (ret && message->update_stream_packet().has_rect_data()) | 64 if (ret && message->update_stream_packet().has_rect_data()) |
| 60 ret = HandleRectData(message); | 65 ret = HandleRectData(message); |
| 61 if (ret && message->update_stream_packet().has_end_rect()) | 66 if (ret && message->update_stream_packet().has_end_rect()) |
| 62 ret = HandleEndRect(message); | 67 ret = HandleEndRect(message); |
| 63 return ret; | 68 return ret; |
| 64 } | 69 } |
| 65 | 70 |
| 66 void DecoderZlib::EndDecode() { | 71 void DecoderZlib::EndDecode() { |
| 67 DCHECK_EQ(kWaitingForBeginRect, state_); | 72 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 73 DCHECK(started_); |
| 74 |
| 68 decode_done_->Run(); | 75 decode_done_->Run(); |
| 69 | 76 |
| 70 partial_decode_done_.reset(); | 77 partial_decode_done_.reset(); |
| 71 decode_done_.reset(); | 78 decode_done_.reset(); |
| 72 updated_rects_ = NULL; | 79 updated_rects_ = NULL; |
| 73 frame_ = NULL; | 80 frame_ = NULL; |
| 74 decompressor_.reset(); | 81 decompressor_.reset(); |
| 82 started_ = false; |
| 75 } | 83 } |
| 76 | 84 |
| 77 bool DecoderZlib::HandleBeginRect(HostMessage* message) { | 85 bool DecoderZlib::HandleBeginRect(HostMessage* message) { |
| 78 DCHECK_EQ(kWaitingForBeginRect, state_); | 86 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 79 state_ = kWaitingForRectData; | 87 state_ = kWaitingForRectData; |
| 80 | 88 |
| 81 rect_width_ = message->update_stream_packet().begin_rect().width(); | 89 rect_width_ = message->update_stream_packet().begin_rect().width(); |
| 82 rect_height_ = message->update_stream_packet().begin_rect().height(); | 90 rect_height_ = message->update_stream_packet().begin_rect().height(); |
| 83 rect_x_ = message->update_stream_packet().begin_rect().x(); | 91 rect_x_ = message->update_stream_packet().begin_rect().x(); |
| 84 rect_y_ = message->update_stream_packet().begin_rect().y(); | 92 rect_y_ = message->update_stream_packet().begin_rect().y(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 state_ = kWaitingForBeginRect; | 158 state_ = kWaitingForBeginRect; |
| 151 | 159 |
| 152 updated_rects_->clear(); | 160 updated_rects_->clear(); |
| 153 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_, | 161 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_, |
| 154 rect_width_, rect_height_)); | 162 rect_width_, rect_height_)); |
| 155 partial_decode_done_->Run(); | 163 partial_decode_done_->Run(); |
| 156 return true; | 164 return true; |
| 157 } | 165 } |
| 158 | 166 |
| 159 } // namespace remoting | 167 } // namespace remoting |
| OLD | NEW |