Chromium Code Reviews| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "remoting/base/util.h" | 13 #include "remoting/base/util.h" |
| 14 #include "remoting/codec/video_decoder.h" | 14 #include "remoting/codec/video_decoder.h" |
| 15 #include "remoting/codec/video_decoder_verbatim.h" | 15 #include "remoting/codec/video_decoder_verbatim.h" |
| 16 #include "remoting/codec/video_decoder_vp8.h" | 16 #include "remoting/codec/video_decoder_vp8.h" |
| 17 #include "remoting/client/frame_consumer.h" | 17 #include "remoting/client/frame_consumer.h" |
| 18 #include "remoting/protocol/session_config.h" | 18 #include "remoting/protocol/session_config.h" |
| 19 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 19 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 20 | 20 |
| 21 #if defined(OS_ANDROID) | |
|
Sergey Ulanov
2013/09/20 18:35:15
No need to wrap this include in ifdefs (even if yo
Lambros
2013/09/25 18:40:41
Done.
| |
| 22 #include "third_party/libyuv/include/libyuv/convert_argb.h" | |
| 23 #endif // OS_ANDROID | |
| 24 | |
| 21 using base::Passed; | 25 using base::Passed; |
| 22 using remoting::protocol::ChannelConfig; | 26 using remoting::protocol::ChannelConfig; |
| 23 using remoting::protocol::SessionConfig; | 27 using remoting::protocol::SessionConfig; |
| 24 | 28 |
| 25 namespace remoting { | 29 namespace remoting { |
| 26 | 30 |
| 31 #if defined(OS_ANDROID) | |
|
Sergey Ulanov
2013/09/20 18:35:15
Can we make this more generic so it's easier to re
Lambros
2013/09/25 18:40:41
Done.
| |
| 32 class VideoDecoderWrapper : public VideoDecoder { | |
|
Sergey Ulanov
2013/09/20 18:35:15
Maybe call it RgbToBgrVideoDecoderFilter?
Lambros
2013/09/25 18:40:41
Done.
| |
| 33 public: | |
| 34 VideoDecoderWrapper(scoped_ptr<VideoDecoder> parent) | |
| 35 : parent_(parent.Pass()) { | |
| 36 } | |
| 37 | |
| 38 virtual void Initialize(const SkISize& screen_size) OVERRIDE { | |
| 39 parent_->Initialize(screen_size); | |
| 40 } | |
| 41 | |
| 42 virtual DecodeResult DecodePacket(const VideoPacket* packet) | |
| 43 OVERRIDE { | |
|
Sergey Ulanov
2013/09/20 18:35:15
nit: OVERRIDE must be on one line with the last pa
Lambros
2013/09/25 18:40:41
Hmm.. wrapping wasn't needed anyway.
| |
| 44 return parent_->DecodePacket(packet); | |
| 45 } | |
| 46 | |
| 47 virtual bool IsReadyForData() OVERRIDE { | |
|
Sergey Ulanov
2013/09/20 18:35:15
VideoDecoder interface has rotten over time. There
Lambros
2013/09/25 18:40:41
Done.
| |
| 48 return parent_->IsReadyForData(); | |
| 49 } | |
| 50 | |
| 51 virtual VideoPacketFormat::Encoding Encoding() OVERRIDE { | |
| 52 return parent_->Encoding(); | |
| 53 } | |
| 54 | |
| 55 virtual void Invalidate(const SkISize& view_size, | |
| 56 const SkRegion& region) OVERRIDE { | |
| 57 return parent_->Invalidate(view_size, region); | |
| 58 } | |
| 59 | |
| 60 virtual void RenderFrame(const SkISize& view_size, | |
| 61 const SkIRect& clip_area, | |
| 62 uint8* image_buffer, | |
| 63 int image_stride, | |
| 64 SkRegion* output_region) OVERRIDE { | |
| 65 parent_->RenderFrame(view_size, clip_area, image_buffer, image_stride, | |
| 66 output_region); | |
| 67 | |
| 68 // Byte-swap the pixels for compatibility with the android.graphics.Bitmap | |
| 69 // class. | |
| 70 static const int kBytesPerPixelRGB32 = 4; | |
|
Sergey Ulanov
2013/09/20 18:35:15
Please add this const in VideoDecoder interface an
Lambros
2013/09/25 18:40:41
Done.
| |
| 71 for (SkRegion::Iterator i(*output_region); !i.done(); i.next()) { | |
| 72 SkIRect rect = i.rect(); | |
| 73 uint8* pixels = image_buffer + (rect.top() * image_stride) + | |
| 74 (rect.left() * kBytesPerPixelRGB32); | |
| 75 libyuv::ABGRToARGB(pixels, image_stride, pixels, image_stride, | |
|
Sergey Ulanov
2013/09/20 18:35:15
It would be great if we could get data in the righ
fbarchard
2013/09/20 21:50:58
If this is coming from the codec as I420, libyuv c
Sergey Ulanov
2013/09/20 21:56:03
Decoder uses media::ScaleYUVToRGB32WithRect() for
Lambros
2013/09/25 18:40:41
Added TODO.
| |
| 76 rect.width(), rect.height()); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 virtual const SkRegion* GetImageShape() OVERRIDE { | |
| 81 return parent_->GetImageShape(); | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 scoped_ptr<VideoDecoder> parent_; | |
| 86 }; | |
| 87 #endif // OS_ANDROID | |
| 88 | |
| 27 RectangleUpdateDecoder::RectangleUpdateDecoder( | 89 RectangleUpdateDecoder::RectangleUpdateDecoder( |
| 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 90 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 29 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 91 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
| 30 scoped_refptr<FrameConsumerProxy> consumer) | 92 scoped_refptr<FrameConsumerProxy> consumer) |
| 31 : main_task_runner_(main_task_runner), | 93 : main_task_runner_(main_task_runner), |
| 32 decode_task_runner_(decode_task_runner), | 94 decode_task_runner_(decode_task_runner), |
| 33 consumer_(consumer), | 95 consumer_(consumer), |
| 34 source_size_(SkISize::Make(0, 0)), | 96 source_size_(SkISize::Make(0, 0)), |
| 35 source_dpi_(SkIPoint::Make(0, 0)), | 97 source_dpi_(SkIPoint::Make(0, 0)), |
| 36 view_size_(SkISize::Make(0, 0)), | 98 view_size_(SkISize::Make(0, 0)), |
| 37 clip_area_(SkIRect::MakeEmpty()), | 99 clip_area_(SkIRect::MakeEmpty()), |
| 38 paint_scheduled_(false), | 100 paint_scheduled_(false), |
| 39 latest_sequence_number_(0) { | 101 latest_sequence_number_(0) { |
| 40 } | 102 } |
| 41 | 103 |
| 42 RectangleUpdateDecoder::~RectangleUpdateDecoder() { | 104 RectangleUpdateDecoder::~RectangleUpdateDecoder() { |
| 43 } | 105 } |
| 44 | 106 |
| 45 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { | 107 void RectangleUpdateDecoder::Initialize(const SessionConfig& config) { |
| 46 // Initialize decoder based on the selected codec. | 108 // Initialize decoder based on the selected codec. |
| 47 ChannelConfig::Codec codec = config.video_config().codec; | 109 ChannelConfig::Codec codec = config.video_config().codec; |
| 48 if (codec == ChannelConfig::CODEC_VERBATIM) { | 110 if (codec == ChannelConfig::CODEC_VERBATIM) { |
| 49 decoder_.reset(new VideoDecoderVerbatim()); | 111 decoder_.reset(new VideoDecoderVerbatim()); |
| 50 } else if (codec == ChannelConfig::CODEC_VP8) { | 112 } else if (codec == ChannelConfig::CODEC_VP8) { |
| 51 decoder_.reset(new VideoDecoderVp8()); | 113 decoder_.reset(new VideoDecoderVp8()); |
| 52 } else { | 114 } else { |
| 53 NOTREACHED() << "Invalid Encoding found: " << codec; | 115 NOTREACHED() << "Invalid Encoding found: " << codec; |
| 54 } | 116 } |
| 117 | |
| 118 #if defined (OS_ANDROID) | |
|
Sergey Ulanov
2013/09/20 18:35:15
I think it's better to make this more generic. The
Lambros
2013/09/25 18:40:41
Done - added output format getter to FrameConsumer
| |
| 119 scoped_ptr<VideoDecoder> wrapper(new VideoDecoderWrapper(decoder_.Pass())); | |
| 120 decoder_ = wrapper.Pass(); | |
| 121 #endif // OS_ANDROID | |
| 55 } | 122 } |
| 56 | 123 |
| 57 void RectangleUpdateDecoder::DecodePacket(scoped_ptr<VideoPacket> packet, | 124 void RectangleUpdateDecoder::DecodePacket(scoped_ptr<VideoPacket> packet, |
| 58 const base::Closure& done) { | 125 const base::Closure& done) { |
| 59 DCHECK(decode_task_runner_->BelongsToCurrentThread()); | 126 DCHECK(decode_task_runner_->BelongsToCurrentThread()); |
| 60 | 127 |
| 61 base::ScopedClosureRunner done_runner(done); | 128 base::ScopedClosureRunner done_runner(done); |
| 62 | 129 |
| 63 bool decoder_needs_reset = false; | 130 bool decoder_needs_reset = false; |
| 64 bool notify_size_or_dpi_change = false; | 131 bool notify_size_or_dpi_change = false; |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 | 347 |
| 281 done.Run(); | 348 done.Run(); |
| 282 } | 349 } |
| 283 | 350 |
| 284 ChromotingStats* RectangleUpdateDecoder::GetStats() { | 351 ChromotingStats* RectangleUpdateDecoder::GetStats() { |
| 285 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 352 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 286 return &stats_; | 353 return &stats_; |
| 287 } | 354 } |
| 288 | 355 |
| 289 } // namespace remoting | 356 } // namespace remoting |
| OLD | NEW |