| 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 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 updated_rects_ = updated_rects; | 46 updated_rects_ = updated_rects; |
| 47 frame_ = frame; | 47 frame_ = frame; |
| 48 | 48 |
| 49 // Create the decompressor. | 49 // Create the decompressor. |
| 50 decompressor_.reset(new DecompressorZlib()); | 50 decompressor_.reset(new DecompressorZlib()); |
| 51 | 51 |
| 52 started_ = true; | 52 started_ = true; |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool DecoderZlib::PartialDecode(HostMessage* message) { | 56 bool DecoderZlib::PartialDecode(ChromotingHostMessage* message) { |
| 57 scoped_ptr<HostMessage> msg_deleter(message); | 57 scoped_ptr<ChromotingHostMessage> msg_deleter(message); |
| 58 DCHECK(message->has_update_stream_packet()); | 58 DCHECK(message->has_update_stream_packet()); |
| 59 DCHECK(started_); | 59 DCHECK(started_); |
| 60 | 60 |
| 61 bool ret = true; | 61 bool ret = true; |
| 62 if (message->update_stream_packet().has_begin_rect()) | 62 if (message->update_stream_packet().has_begin_rect()) |
| 63 ret = HandleBeginRect(message); | 63 ret = HandleBeginRect(message); |
| 64 if (ret && message->update_stream_packet().has_rect_data()) | 64 if (ret && message->update_stream_packet().has_rect_data()) |
| 65 ret = HandleRectData(message); | 65 ret = HandleRectData(message); |
| 66 if (ret && message->update_stream_packet().has_end_rect()) | 66 if (ret && message->update_stream_packet().has_end_rect()) |
| 67 ret = HandleEndRect(message); | 67 ret = HandleEndRect(message); |
| 68 return ret; | 68 return ret; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DecoderZlib::EndDecode() { | 71 void DecoderZlib::EndDecode() { |
| 72 DCHECK_EQ(kWaitingForBeginRect, state_); | 72 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 73 DCHECK(started_); | 73 DCHECK(started_); |
| 74 | 74 |
| 75 decode_done_->Run(); | 75 decode_done_->Run(); |
| 76 | 76 |
| 77 partial_decode_done_.reset(); | 77 partial_decode_done_.reset(); |
| 78 decode_done_.reset(); | 78 decode_done_.reset(); |
| 79 updated_rects_ = NULL; | 79 updated_rects_ = NULL; |
| 80 frame_ = NULL; | 80 frame_ = NULL; |
| 81 decompressor_.reset(); | 81 decompressor_.reset(); |
| 82 started_ = false; | 82 started_ = false; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool DecoderZlib::HandleBeginRect(HostMessage* message) { | 85 bool DecoderZlib::HandleBeginRect(ChromotingHostMessage* message) { |
| 86 DCHECK_EQ(kWaitingForBeginRect, state_); | 86 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 87 state_ = kWaitingForRectData; | 87 state_ = kWaitingForRectData; |
| 88 | 88 |
| 89 rect_width_ = message->update_stream_packet().begin_rect().width(); | 89 rect_width_ = message->update_stream_packet().begin_rect().width(); |
| 90 rect_height_ = message->update_stream_packet().begin_rect().height(); | 90 rect_height_ = message->update_stream_packet().begin_rect().height(); |
| 91 rect_x_ = message->update_stream_packet().begin_rect().x(); | 91 rect_x_ = message->update_stream_packet().begin_rect().x(); |
| 92 rect_y_ = message->update_stream_packet().begin_rect().y(); | 92 rect_y_ = message->update_stream_packet().begin_rect().y(); |
| 93 | 93 |
| 94 PixelFormat pixel_format = | 94 PixelFormat pixel_format = |
| 95 message->update_stream_packet().begin_rect().pixel_format(); | 95 message->update_stream_packet().begin_rect().pixel_format(); |
| 96 | 96 |
| 97 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) { | 97 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) { |
| 98 NOTREACHED() << "Pixel format of message doesn't match the video frame. " | 98 NOTREACHED() << "Pixel format of message doesn't match the video frame. " |
| 99 "Expected vs received = " | 99 "Expected vs received = " |
| 100 << frame_->format() << " vs " << pixel_format | 100 << frame_->format() << " vs " << pixel_format |
| 101 << " Color space conversion required."; | 101 << " Color space conversion required."; |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bytes_per_pixel_ = GetBytesPerPixel(pixel_format); | 105 bytes_per_pixel_ = GetBytesPerPixel(pixel_format); |
| 106 row_pos_ = 0; | 106 row_pos_ = 0; |
| 107 row_y_ = 0; | 107 row_y_ = 0; |
| 108 return true; | 108 return true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool DecoderZlib::HandleRectData(HostMessage* message) { | 111 bool DecoderZlib::HandleRectData(ChromotingHostMessage* message) { |
| 112 DCHECK_EQ(kWaitingForRectData, state_); | 112 DCHECK_EQ(kWaitingForRectData, state_); |
| 113 DCHECK_EQ(0, | 113 DCHECK_EQ(0, |
| 114 message->update_stream_packet().rect_data().sequence_number()); | 114 message->update_stream_packet().rect_data().sequence_number()); |
| 115 | 115 |
| 116 const uint8* in = | 116 const uint8* in = |
| 117 (const uint8*)message->update_stream_packet().rect_data().data().data(); | 117 (const uint8*)message->update_stream_packet().rect_data().data().data(); |
| 118 const int in_size = | 118 const int in_size = |
| 119 message->update_stream_packet().rect_data().data().size(); | 119 message->update_stream_packet().rect_data().data().size(); |
| 120 const int row_size = rect_width_ * bytes_per_pixel_; | 120 const int row_size = rect_width_ * bytes_per_pixel_; |
| 121 int stride = frame_->stride(media::VideoFrame::kRGBPlane); | 121 int stride = frame_->stride(media::VideoFrame::kRGBPlane); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 146 // If this row is completely filled then move onto the next row. | 146 // If this row is completely filled then move onto the next row. |
| 147 if (row_pos_ == row_size) { | 147 if (row_pos_ == row_size) { |
| 148 ++row_y_; | 148 ++row_y_; |
| 149 row_pos_ = 0; | 149 row_pos_ = 0; |
| 150 out += stride; | 150 out += stride; |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 return true; | 153 return true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool DecoderZlib::HandleEndRect(HostMessage* message) { | 156 bool DecoderZlib::HandleEndRect(ChromotingHostMessage* message) { |
| 157 DCHECK_EQ(kWaitingForRectData, state_); | 157 DCHECK_EQ(kWaitingForRectData, state_); |
| 158 state_ = kWaitingForBeginRect; | 158 state_ = kWaitingForBeginRect; |
| 159 | 159 |
| 160 updated_rects_->clear(); | 160 updated_rects_->clear(); |
| 161 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_, | 161 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_, |
| 162 rect_width_, rect_height_)); | 162 rect_width_, rect_height_)); |
| 163 partial_decode_done_->Run(); | 163 partial_decode_done_->Run(); |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace remoting | 167 } // namespace remoting |
| OLD | NEW |