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 |
(...skipping 24 matching lines...) Expand all Loading... |
35 updated_rects_ = updated_rects; | 35 updated_rects_ = updated_rects; |
36 | 36 |
37 // 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 |
38 // and the codec. | 38 // and the codec. |
39 frame_ = frame; | 39 frame_ = frame; |
40 | 40 |
41 started_ = true; | 41 started_ = true; |
42 return true; | 42 return true; |
43 } | 43 } |
44 | 44 |
45 bool DecoderVerbatim::PartialDecode(HostMessage* message) { | 45 bool DecoderVerbatim::PartialDecode(ChromotingHostMessage* message) { |
46 scoped_ptr<HostMessage> msg_deleter(message); | 46 scoped_ptr<ChromotingHostMessage> msg_deleter(message); |
47 DCHECK(message->has_update_stream_packet()); | 47 DCHECK(message->has_update_stream_packet()); |
48 DCHECK(started_); | 48 DCHECK(started_); |
49 | 49 |
50 bool ret = true; | 50 bool ret = true; |
51 if (message->update_stream_packet().has_begin_rect()) | 51 if (message->update_stream_packet().has_begin_rect()) |
52 ret = HandleBeginRect(message); | 52 ret = HandleBeginRect(message); |
53 if (ret && message->update_stream_packet().has_rect_data()) | 53 if (ret && message->update_stream_packet().has_rect_data()) |
54 ret = HandleRectData(message); | 54 ret = HandleRectData(message); |
55 if (ret && message->update_stream_packet().has_end_rect()) | 55 if (ret && message->update_stream_packet().has_end_rect()) |
56 ret = HandleEndRect(message); | 56 ret = HandleEndRect(message); |
57 return ret; | 57 return ret; |
58 } | 58 } |
59 | 59 |
60 void DecoderVerbatim::EndDecode() { | 60 void DecoderVerbatim::EndDecode() { |
61 DCHECK_EQ(kWaitingForBeginRect, state_); | 61 DCHECK_EQ(kWaitingForBeginRect, state_); |
62 DCHECK(started_); | 62 DCHECK(started_); |
63 | 63 |
64 decode_done_->Run(); | 64 decode_done_->Run(); |
65 | 65 |
66 partial_decode_done_.reset(); | 66 partial_decode_done_.reset(); |
67 decode_done_.reset(); | 67 decode_done_.reset(); |
68 frame_ = NULL; | 68 frame_ = NULL; |
69 updated_rects_ = NULL; | 69 updated_rects_ = NULL; |
70 started_ = false; | 70 started_ = false; |
71 } | 71 } |
72 | 72 |
73 bool DecoderVerbatim::HandleBeginRect(HostMessage* message) { | 73 bool DecoderVerbatim::HandleBeginRect(ChromotingHostMessage* message) { |
74 DCHECK_EQ(kWaitingForBeginRect, state_); | 74 DCHECK_EQ(kWaitingForBeginRect, state_); |
75 state_ = kWaitingForRectData; | 75 state_ = kWaitingForRectData; |
76 | 76 |
77 rect_width_ = message->update_stream_packet().begin_rect().width(); | 77 rect_width_ = message->update_stream_packet().begin_rect().width(); |
78 rect_height_ = message->update_stream_packet().begin_rect().height(); | 78 rect_height_ = message->update_stream_packet().begin_rect().height(); |
79 rect_x_ = message->update_stream_packet().begin_rect().x(); | 79 rect_x_ = message->update_stream_packet().begin_rect().x(); |
80 rect_y_ = message->update_stream_packet().begin_rect().y(); | 80 rect_y_ = message->update_stream_packet().begin_rect().y(); |
81 | 81 |
82 PixelFormat pixel_format = | 82 PixelFormat pixel_format = |
83 message->update_stream_packet().begin_rect().pixel_format(); | 83 message->update_stream_packet().begin_rect().pixel_format(); |
84 | 84 |
85 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) { | 85 if (static_cast<PixelFormat>(frame_->format()) != pixel_format) { |
86 NOTREACHED() << "Pixel format of message doesn't match the video frame. " | 86 NOTREACHED() << "Pixel format of message doesn't match the video frame. " |
87 "Expected vs received = " | 87 "Expected vs received = " |
88 << frame_->format() << " vs " << pixel_format | 88 << frame_->format() << " vs " << pixel_format |
89 << " Color space conversion required."; | 89 << " Color space conversion required."; |
90 return false; | 90 return false; |
91 } | 91 } |
92 | 92 |
93 bytes_per_pixel_ = GetBytesPerPixel(pixel_format); | 93 bytes_per_pixel_ = GetBytesPerPixel(pixel_format); |
94 return true; | 94 return true; |
95 } | 95 } |
96 | 96 |
97 bool DecoderVerbatim::HandleRectData(HostMessage* message) { | 97 bool DecoderVerbatim::HandleRectData(ChromotingHostMessage* message) { |
98 DCHECK_EQ(kWaitingForRectData, state_); | 98 DCHECK_EQ(kWaitingForRectData, state_); |
99 DCHECK_EQ(0, | 99 DCHECK_EQ(0, |
100 message->update_stream_packet().rect_data().sequence_number()); | 100 message->update_stream_packet().rect_data().sequence_number()); |
101 | 101 |
102 // Copy the data line by line. | 102 // Copy the data line by line. |
103 const int src_stride = bytes_per_pixel_ * rect_width_; | 103 const int src_stride = bytes_per_pixel_ * rect_width_; |
104 const char* src = | 104 const char* src = |
105 message->update_stream_packet().rect_data().data().c_str(); | 105 message->update_stream_packet().rect_data().data().c_str(); |
106 int src_stride_dir = src_stride; | 106 int src_stride_dir = src_stride; |
107 if (reverse_rows_) { | 107 if (reverse_rows_) { |
(...skipping 11 matching lines...) Expand all Loading... |
119 src += src_stride_dir; | 119 src += src_stride_dir; |
120 } | 120 } |
121 | 121 |
122 updated_rects_->clear(); | 122 updated_rects_->clear(); |
123 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_, | 123 updated_rects_->push_back(gfx::Rect(rect_x_, rect_y_, |
124 rect_width_, rect_height_)); | 124 rect_width_, rect_height_)); |
125 partial_decode_done_->Run(); | 125 partial_decode_done_->Run(); |
126 return true; | 126 return true; |
127 } | 127 } |
128 | 128 |
129 bool DecoderVerbatim::HandleEndRect(HostMessage* message) { | 129 bool DecoderVerbatim::HandleEndRect(ChromotingHostMessage* message) { |
130 DCHECK_EQ(kWaitingForRectData, state_); | 130 DCHECK_EQ(kWaitingForRectData, state_); |
131 state_ = kWaitingForBeginRect; | 131 state_ = kWaitingForBeginRect; |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 } // namespace remoting | 135 } // namespace remoting |
OLD | NEW |