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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "third_party/libyuv/include/libyuv/convert_argb.h" | 24 #include "third_party/libyuv/include/libyuv/convert_argb.h" |
25 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 25 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
26 | 26 |
27 using remoting::protocol::ChannelConfig; | 27 using remoting::protocol::ChannelConfig; |
28 using remoting::protocol::SessionConfig; | 28 using remoting::protocol::SessionConfig; |
29 | 29 |
30 namespace remoting { | 30 namespace remoting { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // This class wraps a VideoDecoder and byte-swaps the pixels for compatibility | |
35 // with the android.graphics.Bitmap class. | |
36 // TODO(lambroslambrou): Refactor so that the VideoDecoder produces data | |
37 // in the right byte-order, instead of swapping it here. | |
38 class RgbToBgrVideoDecoderFilter : public VideoDecoder { | |
39 public: | |
40 RgbToBgrVideoDecoderFilter(std::unique_ptr<VideoDecoder> parent) | |
41 : parent_(std::move(parent)) {} | |
42 | |
43 bool DecodePacket(const VideoPacket& packet, | |
44 webrtc::DesktopFrame* frame) override { | |
45 if (!parent_->DecodePacket(packet, frame)) | |
46 return false; | |
47 for (webrtc::DesktopRegion::Iterator i(frame->updated_region()); | |
48 !i.IsAtEnd(); i.Advance()) { | |
49 webrtc::DesktopRect rect = i.rect(); | |
50 uint8_t* pixels = frame->data() + (rect.top() * frame->stride()) + | |
51 (rect.left() * webrtc::DesktopFrame::kBytesPerPixel); | |
52 libyuv::ABGRToARGB(pixels, frame->stride(), pixels, frame->stride(), | |
53 rect.width(), rect.height()); | |
54 } | |
55 | |
56 return true; | |
57 } | |
58 | |
59 private: | |
60 std::unique_ptr<VideoDecoder> parent_; | |
61 }; | |
62 | |
63 std::unique_ptr<webrtc::DesktopFrame> DoDecodeFrame( | 34 std::unique_ptr<webrtc::DesktopFrame> DoDecodeFrame( |
64 VideoDecoder* decoder, | 35 VideoDecoder* decoder, |
65 std::unique_ptr<VideoPacket> packet, | 36 std::unique_ptr<VideoPacket> packet, |
66 std::unique_ptr<webrtc::DesktopFrame> frame) { | 37 std::unique_ptr<webrtc::DesktopFrame> frame) { |
67 if (!decoder->DecodePacket(*packet, frame.get())) | 38 if (!decoder->DecodePacket(*packet, frame.get())) |
68 frame.reset(); | 39 frame.reset(); |
69 return frame; | 40 return frame; |
70 } | 41 } |
71 | 42 |
72 } // namespace | 43 } // namespace |
(...skipping 21 matching lines...) Expand all Loading... |
94 if (codec == ChannelConfig::CODEC_VERBATIM) { | 65 if (codec == ChannelConfig::CODEC_VERBATIM) { |
95 decoder_.reset(new VideoDecoderVerbatim()); | 66 decoder_.reset(new VideoDecoderVerbatim()); |
96 } else if (codec == ChannelConfig::CODEC_VP8) { | 67 } else if (codec == ChannelConfig::CODEC_VP8) { |
97 decoder_ = VideoDecoderVpx::CreateForVP8(); | 68 decoder_ = VideoDecoderVpx::CreateForVP8(); |
98 } else if (codec == ChannelConfig::CODEC_VP9) { | 69 } else if (codec == ChannelConfig::CODEC_VP9) { |
99 decoder_ = VideoDecoderVpx::CreateForVP9(); | 70 decoder_ = VideoDecoderVpx::CreateForVP9(); |
100 } else { | 71 } else { |
101 NOTREACHED() << "Invalid Encoding found: " << codec; | 72 NOTREACHED() << "Invalid Encoding found: " << codec; |
102 } | 73 } |
103 | 74 |
104 if (consumer_->GetPixelFormat() == protocol::FrameConsumer::FORMAT_RGBA) { | 75 decoder_->SetPixelFormat( |
105 decoder_ = | 76 (consumer_->GetPixelFormat() == protocol::FrameConsumer::FORMAT_BGRA) |
106 base::WrapUnique(new RgbToBgrVideoDecoderFilter(std::move(decoder_))); | 77 ? VideoDecoder::PixelFormat::BGRA |
107 } | 78 : VideoDecoder::PixelFormat::RGBA); |
108 } | 79 } |
109 | 80 |
110 protocol::VideoStub* SoftwareVideoRenderer::GetVideoStub() { | 81 protocol::VideoStub* SoftwareVideoRenderer::GetVideoStub() { |
111 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
112 return this; | 83 return this; |
113 } | 84 } |
114 | 85 |
115 protocol::FrameConsumer* SoftwareVideoRenderer::GetFrameConsumer() { | 86 protocol::FrameConsumer* SoftwareVideoRenderer::GetFrameConsumer() { |
116 return consumer_; | 87 return consumer_; |
117 } | 88 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 DCHECK(thread_checker_.CalledOnValidThread()); | 160 DCHECK(thread_checker_.CalledOnValidThread()); |
190 | 161 |
191 if (perf_tracker_) | 162 if (perf_tracker_) |
192 perf_tracker_->OnFramePainted(frame_id); | 163 perf_tracker_->OnFramePainted(frame_id); |
193 | 164 |
194 if (!done.is_null()) | 165 if (!done.is_null()) |
195 done.Run(); | 166 done.Run(); |
196 } | 167 } |
197 | 168 |
198 } // namespace remoting | 169 } // namespace remoting |
OLD | NEW |