| 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_verbatim.h" | 5 #include "remoting/base/decoder_verbatim.h" |
| 6 | 6 |
| 7 #include "remoting/base/protocol_util.h" | 7 #include "remoting/base/protocol_util.h" |
| 8 | 8 |
| 9 namespace remoting { | 9 namespace remoting { |
| 10 | 10 |
| 11 DecoderVerbatim::DecoderVerbatim() | 11 DecoderVerbatim::DecoderVerbatim() |
| 12 : state_(kWaitingForBeginRect), | 12 : state_(kWaitingForBeginRect), |
| 13 rect_x_(0), | 13 rect_x_(0), |
| 14 rect_y_(0), | 14 rect_y_(0), |
| 15 rect_width_(0), | 15 rect_width_(0), |
| 16 rect_height_(0), | 16 rect_height_(0), |
| 17 bytes_per_pixel_(0), | 17 bytes_per_pixel_(0), |
| 18 updated_rects_(NULL), | 18 updated_rects_(NULL), |
| 19 reverse_rows_(true) { | 19 reverse_rows_(true) { |
| 20 encoding_ = EncodingNone; |
| 20 } | 21 } |
| 21 | 22 |
| 22 bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame, | 23 bool DecoderVerbatim::BeginDecode(scoped_refptr<media::VideoFrame> frame, |
| 23 UpdatedRects* updated_rects, | 24 UpdatedRects* updated_rects, |
| 24 Task* partial_decode_done, | 25 Task* partial_decode_done, |
| 25 Task* decode_done) { | 26 Task* decode_done) { |
| 26 DCHECK(!partial_decode_done_.get()); | 27 DCHECK(!partial_decode_done_.get()); |
| 27 DCHECK(!decode_done_.get()); | 28 DCHECK(!decode_done_.get()); |
| 28 DCHECK(!updated_rects_); | 29 DCHECK(!updated_rects_); |
| 29 DCHECK_EQ(kWaitingForBeginRect, state_); | 30 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 31 DCHECK(!started_); |
| 30 | 32 |
| 31 partial_decode_done_.reset(partial_decode_done); | 33 partial_decode_done_.reset(partial_decode_done); |
| 32 decode_done_.reset(decode_done); | 34 decode_done_.reset(decode_done); |
| 33 updated_rects_ = updated_rects; | 35 updated_rects_ = updated_rects; |
| 34 | 36 |
| 35 // TODO(hclam): Check if we can accept the color format of the video frame | 37 // TODO(hclam): Check if we can accept the color format of the video frame |
| 36 // and the codec. | 38 // and the codec. |
| 37 frame_ = frame; | 39 frame_ = frame; |
| 40 |
| 41 started_ = true; |
| 38 return true; | 42 return true; |
| 39 } | 43 } |
| 40 | 44 |
| 41 bool DecoderVerbatim::PartialDecode(HostMessage* message) { | 45 bool DecoderVerbatim::PartialDecode(HostMessage* message) { |
| 42 scoped_ptr<HostMessage> msg_deleter(message); | 46 scoped_ptr<HostMessage> msg_deleter(message); |
| 43 DCHECK(message->has_update_stream_packet()); | 47 DCHECK(message->has_update_stream_packet()); |
| 48 DCHECK(started_); |
| 44 | 49 |
| 45 bool ret = true; | 50 bool ret = true; |
| 46 if (message->update_stream_packet().has_begin_rect()) | 51 if (message->update_stream_packet().has_begin_rect()) |
| 47 ret = HandleBeginRect(message); | 52 ret = HandleBeginRect(message); |
| 48 if (ret && message->update_stream_packet().has_rect_data()) | 53 if (ret && message->update_stream_packet().has_rect_data()) |
| 49 ret = HandleRectData(message); | 54 ret = HandleRectData(message); |
| 50 if (ret && message->update_stream_packet().has_end_rect()) | 55 if (ret && message->update_stream_packet().has_end_rect()) |
| 51 ret = HandleEndRect(message); | 56 ret = HandleEndRect(message); |
| 52 return ret; | 57 return ret; |
| 53 } | 58 } |
| 54 | 59 |
| 55 void DecoderVerbatim::EndDecode() { | 60 void DecoderVerbatim::EndDecode() { |
| 56 DCHECK_EQ(kWaitingForBeginRect, state_); | 61 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 62 DCHECK(started_); |
| 63 |
| 57 decode_done_->Run(); | 64 decode_done_->Run(); |
| 58 | 65 |
| 59 partial_decode_done_.reset(); | 66 partial_decode_done_.reset(); |
| 60 decode_done_.reset(); | 67 decode_done_.reset(); |
| 61 frame_ = NULL; | 68 frame_ = NULL; |
| 62 updated_rects_ = NULL; | 69 updated_rects_ = NULL; |
| 70 started_ = false; |
| 63 } | 71 } |
| 64 | 72 |
| 65 bool DecoderVerbatim::HandleBeginRect(HostMessage* message) { | 73 bool DecoderVerbatim::HandleBeginRect(HostMessage* message) { |
| 66 DCHECK_EQ(kWaitingForBeginRect, state_); | 74 DCHECK_EQ(kWaitingForBeginRect, state_); |
| 67 state_ = kWaitingForRectData; | 75 state_ = kWaitingForRectData; |
| 68 | 76 |
| 69 rect_width_ = message->update_stream_packet().begin_rect().width(); | 77 rect_width_ = message->update_stream_packet().begin_rect().width(); |
| 70 rect_height_ = message->update_stream_packet().begin_rect().height(); | 78 rect_height_ = message->update_stream_packet().begin_rect().height(); |
| 71 rect_x_ = message->update_stream_packet().begin_rect().x(); | 79 rect_x_ = message->update_stream_packet().begin_rect().x(); |
| 72 rect_y_ = message->update_stream_packet().begin_rect().y(); | 80 rect_y_ = message->update_stream_packet().begin_rect().y(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 return true; | 126 return true; |
| 119 } | 127 } |
| 120 | 128 |
| 121 bool DecoderVerbatim::HandleEndRect(HostMessage* message) { | 129 bool DecoderVerbatim::HandleEndRect(HostMessage* message) { |
| 122 DCHECK_EQ(kWaitingForRectData, state_); | 130 DCHECK_EQ(kWaitingForRectData, state_); |
| 123 state_ = kWaitingForBeginRect; | 131 state_ = kWaitingForBeginRect; |
| 124 return true; | 132 return true; |
| 125 } | 133 } |
| 126 | 134 |
| 127 } // namespace remoting | 135 } // namespace remoting |
| OLD | NEW |