OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/software_video_renderer.h" | 5 #include "remoting/client/software_video_renderer.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // This class wraps a VideoDecoder and byte-swaps the pixels for compatibility | 30 // This class wraps a VideoDecoder and byte-swaps the pixels for compatibility |
31 // with the android.graphics.Bitmap class. | 31 // with the android.graphics.Bitmap class. |
32 // TODO(lambroslambrou): Refactor so that the VideoDecoder produces data | 32 // TODO(lambroslambrou): Refactor so that the VideoDecoder produces data |
33 // in the right byte-order, instead of swapping it here. | 33 // in the right byte-order, instead of swapping it here. |
34 class RgbToBgrVideoDecoderFilter : public VideoDecoder { | 34 class RgbToBgrVideoDecoderFilter : public VideoDecoder { |
35 public: | 35 public: |
36 RgbToBgrVideoDecoderFilter(scoped_ptr<VideoDecoder> parent) | 36 RgbToBgrVideoDecoderFilter(scoped_ptr<VideoDecoder> parent) |
37 : parent_(parent.Pass()) { | 37 : parent_(parent.Pass()) { |
38 } | 38 } |
39 | 39 |
40 void Initialize(const webrtc::DesktopSize& screen_size) override { | |
41 parent_->Initialize(screen_size); | |
42 } | |
43 | |
44 bool DecodePacket(const VideoPacket& packet) override { | 40 bool DecodePacket(const VideoPacket& packet) override { |
45 return parent_->DecodePacket(packet); | 41 return parent_->DecodePacket(packet); |
46 } | 42 } |
47 | 43 |
48 void Invalidate(const webrtc::DesktopSize& view_size, | 44 void Invalidate(const webrtc::DesktopSize& view_size, |
49 const webrtc::DesktopRegion& region) override { | 45 const webrtc::DesktopRegion& region) override { |
50 return parent_->Invalidate(view_size, region); | 46 return parent_->Invalidate(view_size, region); |
51 } | 47 } |
52 | 48 |
53 void RenderFrame(const webrtc::DesktopSize& view_size, | 49 void RenderFrame(const webrtc::DesktopSize& view_size, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 scoped_ptr<VideoDecoder> wrapper( | 154 scoped_ptr<VideoDecoder> wrapper( |
159 new RgbToBgrVideoDecoderFilter(decoder_.Pass())); | 155 new RgbToBgrVideoDecoderFilter(decoder_.Pass())); |
160 decoder_ = wrapper.Pass(); | 156 decoder_ = wrapper.Pass(); |
161 } | 157 } |
162 } | 158 } |
163 | 159 |
164 void SoftwareVideoRenderer::Core::DecodePacket(scoped_ptr<VideoPacket> packet, | 160 void SoftwareVideoRenderer::Core::DecodePacket(scoped_ptr<VideoPacket> packet, |
165 const base::Closure& done) { | 161 const base::Closure& done) { |
166 DCHECK(decode_task_runner_->BelongsToCurrentThread()); | 162 DCHECK(decode_task_runner_->BelongsToCurrentThread()); |
167 | 163 |
168 bool decoder_needs_reset = false; | |
169 bool notify_size_or_dpi_change = false; | 164 bool notify_size_or_dpi_change = false; |
170 | 165 |
171 // If the packet includes screen size or DPI information, store them. | 166 // If the packet includes screen size or DPI information, store them. |
172 if (packet->format().has_screen_width() && | 167 if (packet->format().has_screen_width() && |
173 packet->format().has_screen_height()) { | 168 packet->format().has_screen_height()) { |
174 webrtc::DesktopSize source_size(packet->format().screen_width(), | 169 webrtc::DesktopSize source_size(packet->format().screen_width(), |
175 packet->format().screen_height()); | 170 packet->format().screen_height()); |
176 if (!source_size_.equals(source_size)) { | 171 if (!source_size_.equals(source_size)) { |
177 source_size_ = source_size; | 172 source_size_ = source_size; |
178 decoder_needs_reset = true; | |
179 notify_size_or_dpi_change = true; | 173 notify_size_or_dpi_change = true; |
180 } | 174 } |
181 } | 175 } |
182 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { | 176 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { |
183 webrtc::DesktopVector source_dpi(packet->format().x_dpi(), | 177 webrtc::DesktopVector source_dpi(packet->format().x_dpi(), |
184 packet->format().y_dpi()); | 178 packet->format().y_dpi()); |
185 if (!source_dpi.equals(source_dpi_)) { | 179 if (!source_dpi.equals(source_dpi_)) { |
186 source_dpi_ = source_dpi; | 180 source_dpi_ = source_dpi; |
187 notify_size_or_dpi_change = true; | 181 notify_size_or_dpi_change = true; |
188 } | 182 } |
189 } | 183 } |
190 | 184 |
191 // If we've never seen a screen size, ignore the packet. | 185 // If we've never seen a screen size, ignore the packet. |
192 if (source_size_.is_empty()) { | 186 if (source_size_.is_empty()) { |
193 main_task_runner_->PostTask(FROM_HERE, base::Bind(done)); | 187 main_task_runner_->PostTask(FROM_HERE, base::Bind(done)); |
194 return; | 188 return; |
195 } | 189 } |
196 | 190 |
197 if (decoder_needs_reset) | |
198 decoder_->Initialize(source_size_); | |
199 if (notify_size_or_dpi_change) | 191 if (notify_size_or_dpi_change) |
200 consumer_->SetSourceSize(source_size_, source_dpi_); | 192 consumer_->SetSourceSize(source_size_, source_dpi_); |
201 | 193 |
202 if (decoder_->DecodePacket(*packet.get())) { | 194 if (decoder_->DecodePacket(*packet.get())) { |
203 SchedulePaint(); | 195 SchedulePaint(); |
204 } else { | 196 } else { |
205 LOG(ERROR) << "DecodePacket() failed."; | 197 LOG(ERROR) << "DecodePacket() failed."; |
206 } | 198 } |
207 | 199 |
208 main_task_runner_->PostTask(FROM_HERE, base::Bind(done)); | 200 main_task_runner_->PostTask(FROM_HERE, base::Bind(done)); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 DCHECK(CalledOnValidThread()); | 395 DCHECK(CalledOnValidThread()); |
404 | 396 |
405 // Record the latency between the packet being received and presented. | 397 // Record the latency between the packet being received and presented. |
406 base::TimeDelta decode_time = base::Time::Now() - decode_start; | 398 base::TimeDelta decode_time = base::Time::Now() - decode_start; |
407 stats_.RecordDecodeTime(decode_time.InMilliseconds()); | 399 stats_.RecordDecodeTime(decode_time.InMilliseconds()); |
408 | 400 |
409 decode_task_runner_->PostTask(FROM_HERE, done); | 401 decode_task_runner_->PostTask(FROM_HERE, done); |
410 } | 402 } |
411 | 403 |
412 } // namespace remoting | 404 } // namespace remoting |
OLD | NEW |