Chromium Code Reviews| 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" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "remoting/base/util.h" | 17 #include "remoting/base/util.h" |
| 18 #include "remoting/codec/video_decoder.h" | 18 #include "remoting/codec/video_decoder.h" |
| 19 #include "remoting/codec/video_decoder_verbatim.h" | 19 #include "remoting/codec/video_decoder_verbatim.h" |
| 20 #include "remoting/codec/video_decoder_vpx.h" | 20 #include "remoting/codec/video_decoder_vpx.h" |
| 21 #include "remoting/proto/video.pb.h" | 21 #include "remoting/proto/video.pb.h" |
| 22 #include "remoting/protocol/frame_consumer.h" | 22 #include "remoting/protocol/frame_consumer.h" |
| 23 #include "remoting/protocol/frame_stats.h" | |
| 24 #include "remoting/protocol/performance_tracker.h" | |
| 23 #include "remoting/protocol/session_config.h" | 25 #include "remoting/protocol/session_config.h" |
| 24 #include "third_party/libyuv/include/libyuv/convert_argb.h" | 26 #include "third_party/libyuv/include/libyuv/convert_argb.h" |
| 25 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 27 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 26 | 28 |
| 27 using remoting::protocol::ChannelConfig; | 29 using remoting::protocol::ChannelConfig; |
| 28 using remoting::protocol::SessionConfig; | 30 using remoting::protocol::SessionConfig; |
| 29 | 31 |
| 30 namespace remoting { | 32 namespace remoting { |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 return consumer_; | 118 return consumer_; |
| 117 } | 119 } |
| 118 | 120 |
| 119 void SoftwareVideoRenderer::ProcessVideoPacket( | 121 void SoftwareVideoRenderer::ProcessVideoPacket( |
| 120 std::unique_ptr<VideoPacket> packet, | 122 std::unique_ptr<VideoPacket> packet, |
| 121 const base::Closure& done) { | 123 const base::Closure& done) { |
| 122 DCHECK(thread_checker_.CalledOnValidThread()); | 124 DCHECK(thread_checker_.CalledOnValidThread()); |
| 123 | 125 |
| 124 base::ScopedClosureRunner done_runner(done); | 126 base::ScopedClosureRunner done_runner(done); |
| 125 | 127 |
| 126 if (perf_tracker_) | 128 std::unique_ptr<protocol::FrameStats> frame_stats(new protocol::FrameStats( |
| 127 perf_tracker_->RecordVideoPacketStats(*packet); | 129 protocol::FrameStats::GetForVideoPacket(*packet))); |
| 128 | 130 |
| 129 // If the video packet is empty then drop it. Empty packets are used to | 131 // If the video packet is empty then drop it. Empty packets are used to |
| 130 // maintain activity on the network. | 132 // maintain activity on the network. |
|
Jamie
2016/06/24 23:53:21
We are no longer just dropping the packet. Add a c
Sergey Ulanov
2016/06/25 05:34:03
Done.
| |
| 131 if (!packet->has_data() || packet->data().size() == 0) { | 133 if (!packet->has_data() || packet->data().size() == 0) { |
| 134 if (perf_tracker_) | |
| 135 perf_tracker_->RecordVideoFrameStats(*frame_stats); | |
| 132 return; | 136 return; |
| 133 } | 137 } |
| 134 | 138 |
| 135 if (packet->format().has_screen_width() && | 139 if (packet->format().has_screen_width() && |
| 136 packet->format().has_screen_height()) { | 140 packet->format().has_screen_height()) { |
| 137 source_size_.set(packet->format().screen_width(), | 141 source_size_.set(packet->format().screen_width(), |
| 138 packet->format().screen_height()); | 142 packet->format().screen_height()); |
| 139 } | 143 } |
| 140 | 144 |
| 141 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { | 145 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { |
| 142 webrtc::DesktopVector source_dpi(packet->format().x_dpi(), | 146 webrtc::DesktopVector source_dpi(packet->format().x_dpi(), |
| 143 packet->format().y_dpi()); | 147 packet->format().y_dpi()); |
| 144 if (!source_dpi.equals(source_dpi_)) { | 148 if (!source_dpi.equals(source_dpi_)) { |
| 145 source_dpi_ = source_dpi; | 149 source_dpi_ = source_dpi; |
| 146 } | 150 } |
| 147 } | 151 } |
| 148 | 152 |
| 149 if (source_size_.is_empty()) { | 153 if (source_size_.is_empty()) { |
| 150 LOG(ERROR) << "Received VideoPacket with unknown size."; | 154 LOG(ERROR) << "Received VideoPacket with unknown size."; |
| 151 return; | 155 return; |
| 152 } | 156 } |
| 153 | 157 |
| 154 std::unique_ptr<webrtc::DesktopFrame> frame = | 158 std::unique_ptr<webrtc::DesktopFrame> frame = |
| 155 consumer_->AllocateFrame(source_size_); | 159 consumer_->AllocateFrame(source_size_); |
| 156 frame->set_dpi(source_dpi_); | 160 frame->set_dpi(source_dpi_); |
| 157 | 161 |
| 158 int32_t frame_id = packet->frame_id(); | |
| 159 base::PostTaskAndReplyWithResult( | 162 base::PostTaskAndReplyWithResult( |
| 160 decode_task_runner_.get(), FROM_HERE, | 163 decode_task_runner_.get(), FROM_HERE, |
| 161 base::Bind(&DoDecodeFrame, decoder_.get(), base::Passed(&packet), | 164 base::Bind(&DoDecodeFrame, decoder_.get(), base::Passed(&packet), |
| 162 base::Passed(&frame)), | 165 base::Passed(&frame)), |
| 163 base::Bind(&SoftwareVideoRenderer::RenderFrame, | 166 base::Bind(&SoftwareVideoRenderer::RenderFrame, |
| 164 weak_factory_.GetWeakPtr(), frame_id, done_runner.Release())); | 167 weak_factory_.GetWeakPtr(), base::Passed(&frame_stats), |
| 168 done_runner.Release())); | |
| 165 } | 169 } |
| 166 | 170 |
| 167 void SoftwareVideoRenderer::RenderFrame( | 171 void SoftwareVideoRenderer::RenderFrame( |
| 168 int32_t frame_id, | 172 std::unique_ptr<protocol::FrameStats> stats, |
| 169 const base::Closure& done, | 173 const base::Closure& done, |
| 170 std::unique_ptr<webrtc::DesktopFrame> frame) { | 174 std::unique_ptr<webrtc::DesktopFrame> frame) { |
| 171 DCHECK(thread_checker_.CalledOnValidThread()); | 175 DCHECK(thread_checker_.CalledOnValidThread()); |
| 172 | 176 |
| 173 if (perf_tracker_) | 177 stats->time_decoded = base::TimeTicks::Now(); |
| 174 perf_tracker_->OnFrameDecoded(frame_id); | |
| 175 | 178 |
| 176 if (!frame) { | 179 if (!frame) { |
| 177 if (!done.is_null()) | 180 if (!done.is_null()) |
| 178 done.Run(); | 181 done.Run(); |
| 179 return; | 182 return; |
| 180 } | 183 } |
| 181 | 184 |
| 182 consumer_->DrawFrame(std::move(frame), | 185 consumer_->DrawFrame( |
| 183 base::Bind(&SoftwareVideoRenderer::OnFrameRendered, | 186 std::move(frame), |
| 184 weak_factory_.GetWeakPtr(), frame_id, done)); | 187 base::Bind(&SoftwareVideoRenderer::OnFrameRendered, |
| 188 weak_factory_.GetWeakPtr(), base::Passed(&stats), done)); | |
| 185 } | 189 } |
| 186 | 190 |
| 187 void SoftwareVideoRenderer::OnFrameRendered(int32_t frame_id, | 191 void SoftwareVideoRenderer::OnFrameRendered( |
| 188 const base::Closure& done) { | 192 std::unique_ptr<protocol::FrameStats> stats, |
| 193 const base::Closure& done) { | |
| 189 DCHECK(thread_checker_.CalledOnValidThread()); | 194 DCHECK(thread_checker_.CalledOnValidThread()); |
| 190 | 195 |
| 196 stats->time_rendered = base::TimeTicks::Now(); | |
| 191 if (perf_tracker_) | 197 if (perf_tracker_) |
| 192 perf_tracker_->OnFramePainted(frame_id); | 198 perf_tracker_->RecordVideoFrameStats(*stats); |
| 193 | 199 |
| 194 if (!done.is_null()) | 200 if (!done.is_null()) |
| 195 done.Run(); | 201 done.Run(); |
| 196 } | 202 } |
| 197 | 203 |
| 198 } // namespace remoting | 204 } // namespace remoting |
| OLD | NEW |