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