OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/client/rectangle_update_decoder.h" | 5 #include "remoting/client/rectangle_update_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace remoting { | 25 namespace remoting { |
26 | 26 |
27 RectangleUpdateDecoder::RectangleUpdateDecoder( | 27 RectangleUpdateDecoder::RectangleUpdateDecoder( |
28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
29 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 29 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
30 scoped_refptr<FrameConsumerProxy> consumer) | 30 scoped_refptr<FrameConsumerProxy> consumer) |
31 : main_task_runner_(main_task_runner), | 31 : main_task_runner_(main_task_runner), |
32 decode_task_runner_(decode_task_runner), | 32 decode_task_runner_(decode_task_runner), |
33 consumer_(consumer), | 33 consumer_(consumer), |
| 34 source_size_(SkISize::Make(0, 0)), |
| 35 source_dpi_(SkIPoint::Make(0, 0)), |
| 36 view_size_(SkISize::Make(0, 0)), |
| 37 clip_area_(SkIRect::MakeEmpty()), |
34 paint_scheduled_(false), | 38 paint_scheduled_(false), |
35 latest_sequence_number_(0) { | 39 latest_sequence_number_(0) { |
36 } | 40 } |
37 | 41 |
38 RectangleUpdateDecoder::~RectangleUpdateDecoder() { | 42 RectangleUpdateDecoder::~RectangleUpdateDecoder() { |
39 } | 43 } |
40 | 44 |
41 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { | 45 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { |
42 // Initialize decoder based on the selected codec. | 46 // Initialize decoder based on the selected codec. |
43 ChannelConfig::Codec codec = config.video_config().codec; | 47 ChannelConfig::Codec codec = config.video_config().codec; |
(...skipping 11 matching lines...) Expand all Loading... |
55 DCHECK(decode_task_runner_->BelongsToCurrentThread()); | 59 DCHECK(decode_task_runner_->BelongsToCurrentThread()); |
56 | 60 |
57 base::ScopedClosureRunner done_runner(done); | 61 base::ScopedClosureRunner done_runner(done); |
58 | 62 |
59 bool decoder_needs_reset = false; | 63 bool decoder_needs_reset = false; |
60 bool notify_size_or_dpi_change = false; | 64 bool notify_size_or_dpi_change = false; |
61 | 65 |
62 // If the packet includes screen size or DPI information, store them. | 66 // If the packet includes screen size or DPI information, store them. |
63 if (packet->format().has_screen_width() && | 67 if (packet->format().has_screen_width() && |
64 packet->format().has_screen_height()) { | 68 packet->format().has_screen_height()) { |
65 webrtc::DesktopSize source_size(packet->format().screen_width(), | 69 SkISize source_size = SkISize::Make(packet->format().screen_width(), |
66 packet->format().screen_height()); | 70 packet->format().screen_height()); |
67 if (!source_size_.equals(source_size)) { | 71 if (source_size_ != source_size) { |
68 source_size_ = source_size; | 72 source_size_ = source_size; |
69 decoder_needs_reset = true; | 73 decoder_needs_reset = true; |
70 notify_size_or_dpi_change = true; | 74 notify_size_or_dpi_change = true; |
71 } | 75 } |
72 } | 76 } |
73 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { | 77 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { |
74 webrtc::DesktopVector source_dpi(packet->format().x_dpi(), | 78 SkIPoint source_dpi(SkIPoint::Make(packet->format().x_dpi(), |
75 packet->format().y_dpi()); | 79 packet->format().y_dpi())); |
76 if (!source_dpi.equals(source_dpi_)) { | 80 if (source_dpi != source_dpi_) { |
77 source_dpi_ = source_dpi; | 81 source_dpi_ = source_dpi; |
78 notify_size_or_dpi_change = true; | 82 notify_size_or_dpi_change = true; |
79 } | 83 } |
80 } | 84 } |
81 | 85 |
82 // If we've never seen a screen size, ignore the packet. | 86 // If we've never seen a screen size, ignore the packet. |
83 if (source_size_.is_empty()) | 87 if (source_size_.isZero()) |
84 return; | 88 return; |
85 | 89 |
86 if (decoder_needs_reset) | 90 if (decoder_needs_reset) |
87 decoder_->Initialize(source_size_); | 91 decoder_->Initialize(source_size_); |
88 if (notify_size_or_dpi_change) | 92 if (notify_size_or_dpi_change) |
89 consumer_->SetSourceSize(source_size_, source_dpi_); | 93 consumer_->SetSourceSize(source_size_, source_dpi_); |
90 | 94 |
91 if (!decoder_->IsReadyForData()) { | 95 if (!decoder_->IsReadyForData()) { |
92 // TODO(ajwong): This whole thing should move into an invalid state. | 96 // TODO(ajwong): This whole thing should move into an invalid state. |
93 LOG(ERROR) << "Decoder is unable to process data. Dropping packet."; | 97 LOG(ERROR) << "Decoder is unable to process data. Dropping packet."; |
(...skipping 10 matching lines...) Expand all Loading... |
104 paint_scheduled_ = true; | 108 paint_scheduled_ = true; |
105 decode_task_runner_->PostTask( | 109 decode_task_runner_->PostTask( |
106 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DoPaint, this)); | 110 FROM_HERE, base::Bind(&RectangleUpdateDecoder::DoPaint, this)); |
107 } | 111 } |
108 | 112 |
109 void RectangleUpdateDecoder::DoPaint() { | 113 void RectangleUpdateDecoder::DoPaint() { |
110 DCHECK(paint_scheduled_); | 114 DCHECK(paint_scheduled_); |
111 paint_scheduled_ = false; | 115 paint_scheduled_ = false; |
112 | 116 |
113 // If the view size is empty or we have no output buffers ready, return. | 117 // If the view size is empty or we have no output buffers ready, return. |
114 if (buffers_.empty() || view_size_.is_empty()) | 118 if (buffers_.empty() || view_size_.isEmpty()) |
115 return; | 119 return; |
116 | 120 |
117 // If no Decoder is initialized, or the host dimensions are empty, return. | 121 // If no Decoder is initialized, or the host dimensions are empty, return. |
118 if (!decoder_.get() || source_size_.is_empty()) | 122 if (!decoder_.get() || source_size_.isEmpty()) |
119 return; | 123 return; |
120 | 124 |
121 // Draw the invalidated region to the buffer. | 125 // Draw the invalidated region to the buffer. |
122 webrtc::DesktopFrame* buffer = buffers_.front(); | 126 webrtc::DesktopFrame* buffer = buffers_.front(); |
123 webrtc::DesktopRegion output_region; | 127 SkRegion output_region; |
124 decoder_->RenderFrame(view_size_, clip_area_, | 128 decoder_->RenderFrame(view_size_, clip_area_, |
125 buffer->data(), | 129 buffer->data(), |
126 buffer->stride(), | 130 buffer->stride(), |
127 &output_region); | 131 &output_region); |
128 | 132 |
129 // Notify the consumer that painting is done. | 133 // Notify the consumer that painting is done. |
130 if (!output_region.is_empty()) { | 134 if (!output_region.isEmpty()) { |
131 buffers_.pop_front(); | 135 buffers_.pop_front(); |
132 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region); | 136 consumer_->ApplyBuffer(view_size_, clip_area_, buffer, output_region); |
133 } | 137 } |
134 } | 138 } |
135 | 139 |
136 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) { | 140 void RectangleUpdateDecoder::RequestReturnBuffers(const base::Closure& done) { |
137 if (!decode_task_runner_->BelongsToCurrentThread()) { | 141 if (!decode_task_runner_->BelongsToCurrentThread()) { |
138 decode_task_runner_->PostTask( | 142 decode_task_runner_->PostTask( |
139 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers, | 143 FROM_HERE, base::Bind(&RectangleUpdateDecoder::RequestReturnBuffers, |
140 this, done)); | 144 this, done)); |
(...skipping 17 matching lines...) Expand all Loading... |
158 return; | 162 return; |
159 } | 163 } |
160 | 164 |
161 DCHECK(clip_area_.width() <= buffer->size().width() && | 165 DCHECK(clip_area_.width() <= buffer->size().width() && |
162 clip_area_.height() <= buffer->size().height()); | 166 clip_area_.height() <= buffer->size().height()); |
163 | 167 |
164 buffers_.push_back(buffer); | 168 buffers_.push_back(buffer); |
165 SchedulePaint(); | 169 SchedulePaint(); |
166 } | 170 } |
167 | 171 |
168 void RectangleUpdateDecoder::InvalidateRegion( | 172 void RectangleUpdateDecoder::InvalidateRegion(const SkRegion& region) { |
169 const webrtc::DesktopRegion& region) { | |
170 if (!decode_task_runner_->BelongsToCurrentThread()) { | 173 if (!decode_task_runner_->BelongsToCurrentThread()) { |
171 decode_task_runner_->PostTask( | 174 decode_task_runner_->PostTask( |
172 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion, | 175 FROM_HERE, base::Bind(&RectangleUpdateDecoder::InvalidateRegion, |
173 this, region)); | 176 this, region)); |
174 return; | 177 return; |
175 } | 178 } |
176 | 179 |
177 if (decoder_.get()) { | 180 if (decoder_.get()) { |
178 decoder_->Invalidate(view_size_, region); | 181 decoder_->Invalidate(view_size_, region); |
179 SchedulePaint(); | 182 SchedulePaint(); |
180 } | 183 } |
181 } | 184 } |
182 | 185 |
183 void RectangleUpdateDecoder::SetOutputSizeAndClip( | 186 void RectangleUpdateDecoder::SetOutputSizeAndClip(const SkISize& view_size, |
184 const webrtc::DesktopSize& view_size, | 187 const SkIRect& clip_area) { |
185 const webrtc::DesktopRect& clip_area) { | |
186 if (!decode_task_runner_->BelongsToCurrentThread()) { | 188 if (!decode_task_runner_->BelongsToCurrentThread()) { |
187 decode_task_runner_->PostTask( | 189 decode_task_runner_->PostTask( |
188 FROM_HERE, base::Bind(&RectangleUpdateDecoder::SetOutputSizeAndClip, | 190 FROM_HERE, base::Bind(&RectangleUpdateDecoder::SetOutputSizeAndClip, |
189 this, view_size, clip_area)); | 191 this, view_size, clip_area)); |
190 return; | 192 return; |
191 } | 193 } |
192 | 194 |
193 // The whole frame needs to be repainted if the scaling factor has changed. | 195 // The whole frame needs to be repainted if the scaling factor has changed. |
194 if (!view_size_.equals(view_size) && decoder_.get()) { | 196 if (view_size_ != view_size && decoder_.get()) { |
195 webrtc::DesktopRegion region; | 197 SkRegion region; |
196 region.AddRect(webrtc::DesktopRect::MakeSize(view_size)); | 198 region.op(SkIRect::MakeSize(view_size), SkRegion::kUnion_Op); |
197 decoder_->Invalidate(view_size, region); | 199 decoder_->Invalidate(view_size, region); |
198 } | 200 } |
199 | 201 |
200 if (!view_size_.equals(view_size) || | 202 if (view_size_ != view_size || |
201 !clip_area_.equals(clip_area)) { | 203 clip_area_ != clip_area) { |
202 view_size_ = view_size; | 204 view_size_ = view_size; |
203 clip_area_ = clip_area; | 205 clip_area_ = clip_area; |
204 | 206 |
205 // Return buffers that are smaller than needed to the consumer for | 207 // Return buffers that are smaller than needed to the consumer for |
206 // reuse/reallocation. | 208 // reuse/reallocation. |
207 std::list<webrtc::DesktopFrame*>::iterator i = buffers_.begin(); | 209 std::list<webrtc::DesktopFrame*>::iterator i = buffers_.begin(); |
208 while (i != buffers_.end()) { | 210 while (i != buffers_.end()) { |
209 if ((*i)->size().width() < clip_area_.width() || | 211 if ((*i)->size().width() < clip_area_.width() || |
210 (*i)->size().height() < clip_area_.height()) { | 212 (*i)->size().height() < clip_area_.height()) { |
211 consumer_->ReturnBuffer(*i); | 213 consumer_->ReturnBuffer(*i); |
212 i = buffers_.erase(i); | 214 i = buffers_.erase(i); |
213 } else { | 215 } else { |
214 ++i; | 216 ++i; |
215 } | 217 } |
216 } | 218 } |
217 | 219 |
218 SchedulePaint(); | 220 SchedulePaint(); |
219 } | 221 } |
220 } | 222 } |
221 | 223 |
222 const webrtc::DesktopRegion* RectangleUpdateDecoder::GetBufferShape() { | 224 const SkRegion* RectangleUpdateDecoder::GetBufferShape() { |
223 return decoder_->GetImageShape(); | 225 return decoder_->GetImageShape(); |
224 } | 226 } |
225 | 227 |
226 void RectangleUpdateDecoder::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, | 228 void RectangleUpdateDecoder::ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
227 const base::Closure& done) { | 229 const base::Closure& done) { |
228 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 230 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
229 | 231 |
230 // If the video packet is empty then drop it. Empty packets are used to | 232 // If the video packet is empty then drop it. Empty packets are used to |
231 // maintain activity on the network. | 233 // maintain activity on the network. |
232 if (!packet->has_data() || packet->data().size() == 0) { | 234 if (!packet->has_data() || packet->data().size() == 0) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 280 |
279 done.Run(); | 281 done.Run(); |
280 } | 282 } |
281 | 283 |
282 ChromotingStats* RectangleUpdateDecoder::GetStats() { | 284 ChromotingStats* RectangleUpdateDecoder::GetStats() { |
283 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 285 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
284 return &stats_; | 286 return &stats_; |
285 } | 287 } |
286 | 288 |
287 } // namespace remoting | 289 } // namespace remoting |
OLD | NEW |