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 "media/cast/sender/video_sender.h" | 5 #include "media/cast/sender/video_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "media/cast/cast_defines.h" | 13 #include "media/cast/cast_defines.h" |
14 #include "media/cast/net/cast_transport_config.h" | 14 #include "media/cast/net/cast_transport_config.h" |
| 15 #include "media/cast/sender/performance_metrics_overlay.h" |
15 #include "media/cast/sender/video_encoder.h" | 16 #include "media/cast/sender/video_encoder.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 namespace cast { | 19 namespace cast { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // The following two constants are used to adjust the target | 23 // The following two constants are used to adjust the target |
23 // playout delay (when allowed). They were calculated using | 24 // playout delay (when allowed). They were calculated using |
24 // a combination of cast_benchmark runs and manual testing. | 25 // a combination of cast_benchmark runs and manual testing. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 video_config.use_external_encoder | 81 video_config.use_external_encoder |
81 ? NewFixedCongestionControl( | 82 ? NewFixedCongestionControl( |
82 (video_config.min_bitrate + video_config.max_bitrate) / 2) | 83 (video_config.min_bitrate + video_config.max_bitrate) / 2) |
83 : NewAdaptiveCongestionControl(cast_environment->Clock(), | 84 : NewAdaptiveCongestionControl(cast_environment->Clock(), |
84 video_config.max_bitrate, | 85 video_config.max_bitrate, |
85 video_config.min_bitrate, | 86 video_config.min_bitrate, |
86 video_config.max_frame_rate)), | 87 video_config.max_frame_rate)), |
87 frames_in_encoder_(0), | 88 frames_in_encoder_(0), |
88 last_bitrate_(0), | 89 last_bitrate_(0), |
89 playout_delay_change_cb_(playout_delay_change_cb), | 90 playout_delay_change_cb_(playout_delay_change_cb), |
| 91 last_reported_deadline_utilization_(-1.0), |
| 92 last_reported_lossy_utilization_(-1.0), |
90 weak_factory_(this) { | 93 weak_factory_(this) { |
91 video_encoder_ = VideoEncoder::Create( | 94 video_encoder_ = VideoEncoder::Create( |
92 cast_environment_, | 95 cast_environment_, |
93 video_config, | 96 video_config, |
94 status_change_cb, | 97 status_change_cb, |
95 create_vea_cb, | 98 create_vea_cb, |
96 create_video_encode_mem_cb); | 99 create_video_encode_mem_cb); |
97 if (!video_encoder_) { | 100 if (!video_encoder_) { |
98 cast_environment_->PostTask( | 101 cast_environment_->PostTask( |
99 CastEnvironment::MAIN, | 102 CastEnvironment::MAIN, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 if (bitrate != last_bitrate_) { | 190 if (bitrate != last_bitrate_) { |
188 video_encoder_->SetBitRate(bitrate); | 191 video_encoder_->SetBitRate(bitrate); |
189 last_bitrate_ = bitrate; | 192 last_bitrate_ = bitrate; |
190 } | 193 } |
191 | 194 |
192 if (video_frame->visible_rect().IsEmpty()) { | 195 if (video_frame->visible_rect().IsEmpty()) { |
193 VLOG(1) << "Rejecting empty video frame."; | 196 VLOG(1) << "Rejecting empty video frame."; |
194 return; | 197 return; |
195 } | 198 } |
196 | 199 |
| 200 MaybeRenderPerformanceMetricsOverlay(bitrate, |
| 201 frames_in_encoder_ + 1, |
| 202 last_reported_deadline_utilization_, |
| 203 last_reported_lossy_utilization_, |
| 204 video_frame.get()); |
| 205 |
197 if (video_encoder_->EncodeVideoFrame( | 206 if (video_encoder_->EncodeVideoFrame( |
198 video_frame, | 207 video_frame, |
199 reference_time, | 208 reference_time, |
200 base::Bind(&VideoSender::OnEncodedVideoFrame, | 209 base::Bind(&VideoSender::OnEncodedVideoFrame, |
201 weak_factory_.GetWeakPtr(), | 210 weak_factory_.GetWeakPtr(), |
202 bitrate))) { | 211 bitrate))) { |
203 frames_in_encoder_++; | 212 frames_in_encoder_++; |
204 duration_in_encoder_ += duration_added_by_next_frame; | 213 duration_in_encoder_ += duration_added_by_next_frame; |
205 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; | 214 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; |
206 last_enqueued_frame_reference_time_ = reference_time; | 215 last_enqueued_frame_reference_time_ = reference_time; |
(...skipping 19 matching lines...) Expand all Loading... |
226 return duration_in_encoder_; | 235 return duration_in_encoder_; |
227 } | 236 } |
228 } | 237 } |
229 | 238 |
230 void VideoSender::OnAck(uint32 frame_id) { | 239 void VideoSender::OnAck(uint32 frame_id) { |
231 video_encoder_->LatestFrameIdToReference(frame_id); | 240 video_encoder_->LatestFrameIdToReference(frame_id); |
232 } | 241 } |
233 | 242 |
234 void VideoSender::OnEncodedVideoFrame( | 243 void VideoSender::OnEncodedVideoFrame( |
235 int encoder_bitrate, | 244 int encoder_bitrate, |
236 scoped_ptr<EncodedFrame> encoded_frame) { | 245 scoped_ptr<SenderEncodedFrame> encoded_frame) { |
237 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 246 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
238 | 247 |
239 frames_in_encoder_--; | 248 frames_in_encoder_--; |
240 DCHECK_GE(frames_in_encoder_, 0); | 249 DCHECK_GE(frames_in_encoder_, 0); |
241 | 250 |
242 duration_in_encoder_ = | 251 duration_in_encoder_ = |
243 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; | 252 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; |
244 | 253 |
| 254 last_reported_deadline_utilization_ = encoded_frame->deadline_utilization; |
| 255 last_reported_lossy_utilization_ = encoded_frame->lossy_utilization; |
| 256 // TODO(miu): Plumb-in a utilization feedback signal back to the producer of |
| 257 // the video frames. http://crbug.com/156767 |
| 258 |
245 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 259 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
246 } | 260 } |
247 | 261 |
248 } // namespace cast | 262 } // namespace cast |
249 } // namespace media | 263 } // namespace media |
OLD | NEW |