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 28 matching lines...) Expand all Loading... |
39 std::unique_ptr<VideoPacket> packet, | 39 std::unique_ptr<VideoPacket> packet, |
40 std::unique_ptr<webrtc::DesktopFrame> frame) { | 40 std::unique_ptr<webrtc::DesktopFrame> frame) { |
41 if (!decoder->DecodePacket(*packet, frame.get())) | 41 if (!decoder->DecodePacket(*packet, frame.get())) |
42 frame.reset(); | 42 frame.reset(); |
43 return frame; | 43 return frame; |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 SoftwareVideoRenderer::SoftwareVideoRenderer(protocol::FrameConsumer* consumer) | 48 SoftwareVideoRenderer::SoftwareVideoRenderer(protocol::FrameConsumer* consumer) |
49 : consumer_(consumer), | 49 : consumer_(consumer), weak_factory_(this) { |
50 weak_factory_(this) { | |
51 thread_checker_.DetachFromThread(); | 50 thread_checker_.DetachFromThread(); |
52 } | 51 } |
53 | 52 |
54 SoftwareVideoRenderer::SoftwareVideoRenderer( | 53 SoftwareVideoRenderer::SoftwareVideoRenderer( |
55 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, | 54 scoped_refptr<base::SingleThreadTaskRunner> decode_task_runner, |
56 protocol::FrameConsumer* consumer, | 55 protocol::FrameConsumer* consumer, |
57 protocol::PerformanceTracker* perf_tracker) | 56 protocol::FrameStatsConsumer* stats_consumer) |
58 : decode_task_runner_(decode_task_runner), | 57 : decode_task_runner_(decode_task_runner), |
59 consumer_(consumer), | 58 consumer_(consumer), |
60 perf_tracker_(perf_tracker), | 59 stats_consumer_(stats_consumer), |
61 weak_factory_(this) {} | 60 weak_factory_(this) {} |
62 | 61 |
63 SoftwareVideoRenderer::~SoftwareVideoRenderer() { | 62 SoftwareVideoRenderer::~SoftwareVideoRenderer() { |
64 if (decoder_) | 63 if (decoder_) |
65 decode_task_runner_->DeleteSoon(FROM_HERE, decoder_.release()); | 64 decode_task_runner_->DeleteSoon(FROM_HERE, decoder_.release()); |
66 } | 65 } |
67 | 66 |
68 bool SoftwareVideoRenderer::Initialize( | 67 bool SoftwareVideoRenderer::Initialize( |
69 const ClientContext& client_context, | 68 const ClientContext& client_context, |
70 protocol::PerformanceTracker* perf_tracker) { | 69 protocol::FrameStatsConsumer* stats_consumer) { |
71 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(thread_checker_.CalledOnValidThread()); |
72 decode_task_runner_ = client_context.decode_task_runner(); | 71 decode_task_runner_ = client_context.decode_task_runner(); |
73 perf_tracker_ = perf_tracker; | 72 stats_consumer_ = stats_consumer; |
74 return true; | 73 return true; |
75 } | 74 } |
76 | 75 |
77 void SoftwareVideoRenderer::OnSessionConfig( | 76 void SoftwareVideoRenderer::OnSessionConfig( |
78 const protocol::SessionConfig& config) { | 77 const protocol::SessionConfig& config) { |
79 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
80 | 79 |
81 // Initialize decoder based on the selected codec. | 80 // Initialize decoder based on the selected codec. |
82 ChannelConfig::Codec codec = config.video_config().codec; | 81 ChannelConfig::Codec codec = config.video_config().codec; |
83 if (codec == ChannelConfig::CODEC_VERBATIM) { | 82 if (codec == ChannelConfig::CODEC_VERBATIM) { |
(...skipping 14 matching lines...) Expand all Loading... |
98 | 97 |
99 protocol::VideoStub* SoftwareVideoRenderer::GetVideoStub() { | 98 protocol::VideoStub* SoftwareVideoRenderer::GetVideoStub() { |
100 DCHECK(thread_checker_.CalledOnValidThread()); | 99 DCHECK(thread_checker_.CalledOnValidThread()); |
101 return this; | 100 return this; |
102 } | 101 } |
103 | 102 |
104 protocol::FrameConsumer* SoftwareVideoRenderer::GetFrameConsumer() { | 103 protocol::FrameConsumer* SoftwareVideoRenderer::GetFrameConsumer() { |
105 return consumer_; | 104 return consumer_; |
106 } | 105 } |
107 | 106 |
| 107 protocol::FrameStatsConsumer* SoftwareVideoRenderer::GetFrameStatsConsumer() { |
| 108 return stats_consumer_; |
| 109 } |
| 110 |
108 void SoftwareVideoRenderer::ProcessVideoPacket( | 111 void SoftwareVideoRenderer::ProcessVideoPacket( |
109 std::unique_ptr<VideoPacket> packet, | 112 std::unique_ptr<VideoPacket> packet, |
110 const base::Closure& done) { | 113 const base::Closure& done) { |
111 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
112 | 115 |
113 base::ScopedClosureRunner done_runner(done); | 116 base::ScopedClosureRunner done_runner(done); |
114 | 117 |
115 std::unique_ptr<protocol::FrameStats> frame_stats(new protocol::FrameStats( | 118 std::unique_ptr<protocol::FrameStats> frame_stats(new protocol::FrameStats()); |
116 protocol::FrameStats::GetForVideoPacket(*packet))); | 119 frame_stats->host_stats = |
| 120 protocol::HostFrameStats::GetForVideoPacket(*packet); |
| 121 frame_stats->client_stats.time_received = base::TimeTicks::Now(); |
117 | 122 |
118 // If the video packet is empty then there is nothing to decode. Empty packets | 123 // If the video packet is empty then there is nothing to decode. Empty packets |
119 // are used to maintain activity on the network. Stats for such packets still | 124 // are used to maintain activity on the network. Stats for such packets still |
120 // need to be reported. | 125 // need to be reported. |
121 if (!packet->has_data() || packet->data().size() == 0) { | 126 if (!packet->has_data() || packet->data().size() == 0) { |
122 if (perf_tracker_) | 127 if (stats_consumer_) |
123 perf_tracker_->RecordVideoFrameStats(*frame_stats); | 128 stats_consumer_->OnVideoFrameStats(*frame_stats); |
124 return; | 129 return; |
125 } | 130 } |
126 | 131 |
127 if (packet->format().has_screen_width() && | 132 if (packet->format().has_screen_width() && |
128 packet->format().has_screen_height()) { | 133 packet->format().has_screen_height()) { |
129 source_size_.set(packet->format().screen_width(), | 134 source_size_.set(packet->format().screen_width(), |
130 packet->format().screen_height()); | 135 packet->format().screen_height()); |
131 } | 136 } |
132 | 137 |
133 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { | 138 if (packet->format().has_x_dpi() && packet->format().has_y_dpi()) { |
(...skipping 21 matching lines...) Expand all Loading... |
155 weak_factory_.GetWeakPtr(), base::Passed(&frame_stats), | 160 weak_factory_.GetWeakPtr(), base::Passed(&frame_stats), |
156 done_runner.Release())); | 161 done_runner.Release())); |
157 } | 162 } |
158 | 163 |
159 void SoftwareVideoRenderer::RenderFrame( | 164 void SoftwareVideoRenderer::RenderFrame( |
160 std::unique_ptr<protocol::FrameStats> stats, | 165 std::unique_ptr<protocol::FrameStats> stats, |
161 const base::Closure& done, | 166 const base::Closure& done, |
162 std::unique_ptr<webrtc::DesktopFrame> frame) { | 167 std::unique_ptr<webrtc::DesktopFrame> frame) { |
163 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
164 | 169 |
165 stats->time_decoded = base::TimeTicks::Now(); | 170 stats->client_stats.time_decoded = base::TimeTicks::Now(); |
166 | |
167 if (!frame) { | 171 if (!frame) { |
168 if (!done.is_null()) | 172 if (!done.is_null()) |
169 done.Run(); | 173 done.Run(); |
170 return; | 174 return; |
171 } | 175 } |
172 | 176 |
173 consumer_->DrawFrame( | 177 consumer_->DrawFrame( |
174 std::move(frame), | 178 std::move(frame), |
175 base::Bind(&SoftwareVideoRenderer::OnFrameRendered, | 179 base::Bind(&SoftwareVideoRenderer::OnFrameRendered, |
176 weak_factory_.GetWeakPtr(), base::Passed(&stats), done)); | 180 weak_factory_.GetWeakPtr(), base::Passed(&stats), done)); |
177 } | 181 } |
178 | 182 |
179 void SoftwareVideoRenderer::OnFrameRendered( | 183 void SoftwareVideoRenderer::OnFrameRendered( |
180 std::unique_ptr<protocol::FrameStats> stats, | 184 std::unique_ptr<protocol::FrameStats> stats, |
181 const base::Closure& done) { | 185 const base::Closure& done) { |
182 DCHECK(thread_checker_.CalledOnValidThread()); | 186 DCHECK(thread_checker_.CalledOnValidThread()); |
183 | 187 |
184 stats->time_rendered = base::TimeTicks::Now(); | 188 stats->client_stats.time_rendered = base::TimeTicks::Now(); |
185 if (perf_tracker_) | 189 if (stats_consumer_) |
186 perf_tracker_->RecordVideoFrameStats(*stats); | 190 stats_consumer_->OnVideoFrameStats(*stats); |
187 | 191 |
188 if (!done.is_null()) | 192 if (!done.is_null()) |
189 done.Run(); | 193 done.Run(); |
190 } | 194 } |
191 | 195 |
192 } // namespace remoting | 196 } // namespace remoting |
OLD | NEW |