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 "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" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 frames_in_encoder_ + 1, | 201 frames_in_encoder_ + 1, |
| 202 last_reported_deadline_utilization_, | 202 last_reported_deadline_utilization_, |
| 203 last_reported_lossy_utilization_, | 203 last_reported_lossy_utilization_, |
| 204 video_frame.get()); | 204 video_frame.get()); |
| 205 | 205 |
| 206 if (video_encoder_->EncodeVideoFrame( | 206 if (video_encoder_->EncodeVideoFrame( |
| 207 video_frame, | 207 video_frame, |
| 208 reference_time, | 208 reference_time, |
| 209 base::Bind(&VideoSender::OnEncodedVideoFrame, | 209 base::Bind(&VideoSender::OnEncodedVideoFrame, |
| 210 weak_factory_.GetWeakPtr(), | 210 weak_factory_.GetWeakPtr(), |
| 211 video_frame, | |
| 211 bitrate))) { | 212 bitrate))) { |
| 212 frames_in_encoder_++; | 213 frames_in_encoder_++; |
| 213 duration_in_encoder_ += duration_added_by_next_frame; | 214 duration_in_encoder_ += duration_added_by_next_frame; |
| 214 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; | 215 last_enqueued_frame_rtp_timestamp_ = rtp_timestamp; |
| 215 last_enqueued_frame_reference_time_ = reference_time; | 216 last_enqueued_frame_reference_time_ = reference_time; |
| 216 } else { | 217 } else { |
| 217 VLOG(1) << "Encoder rejected a frame. Skipping..."; | 218 VLOG(1) << "Encoder rejected a frame. Skipping..."; |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 234 } else { | 235 } else { |
| 235 return duration_in_encoder_; | 236 return duration_in_encoder_; |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 | 239 |
| 239 void VideoSender::OnAck(uint32 frame_id) { | 240 void VideoSender::OnAck(uint32 frame_id) { |
| 240 video_encoder_->LatestFrameIdToReference(frame_id); | 241 video_encoder_->LatestFrameIdToReference(frame_id); |
| 241 } | 242 } |
| 242 | 243 |
| 243 void VideoSender::OnEncodedVideoFrame( | 244 void VideoSender::OnEncodedVideoFrame( |
| 245 const scoped_refptr<media::VideoFrame>& video_frame, | |
| 244 int encoder_bitrate, | 246 int encoder_bitrate, |
| 245 scoped_ptr<SenderEncodedFrame> encoded_frame) { | 247 scoped_ptr<SenderEncodedFrame> encoded_frame) { |
| 246 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 248 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 247 | 249 |
| 248 frames_in_encoder_--; | 250 frames_in_encoder_--; |
| 249 DCHECK_GE(frames_in_encoder_, 0); | 251 DCHECK_GE(frames_in_encoder_, 0); |
| 250 | 252 |
| 251 duration_in_encoder_ = | 253 duration_in_encoder_ = |
| 252 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; | 254 last_enqueued_frame_reference_time_ - encoded_frame->reference_time; |
| 253 | 255 |
| 254 last_reported_deadline_utilization_ = encoded_frame->deadline_utilization; | 256 last_reported_deadline_utilization_ = encoded_frame->deadline_utilization; |
| 255 last_reported_lossy_utilization_ = encoded_frame->lossy_utilization; | 257 last_reported_lossy_utilization_ = encoded_frame->lossy_utilization; |
| 256 // TODO(miu): Plumb-in a utilization feedback signal back to the producer of | 258 |
| 257 // the video frames. http://crbug.com/156767 | 259 // Report the stress level for non-key frames. Key frames are excepted |
| 260 // because their utilization measurements are atypical compared to the other | |
| 261 // frames in the stream, and this can misguide the producer of the input video | |
| 262 // frames. | |
|
hubbe
2015/06/02 00:23:22
I really wish we could include key frames too.
Not
miu
2015/06/02 03:07:34
Done. I thought about this for awhile, and there
| |
| 263 if (encoded_frame->dependency != EncodedFrame::KEY) { | |
| 264 // Take the greater of the two utilization values and attenuate them such | |
| 265 // that 75% utilization is reported as the maximum sustainable stress | |
| 266 // level. This provides "wiggle room," ensuring there will be sufficient | |
| 267 // CPU and bandwidth available to handle the occasional more-complex frames. | |
| 268 static const double kAttenuationFactor = 0.75; | |
| 269 const double attenuated_stress_level = | |
| 270 std::max(last_reported_deadline_utilization_, | |
| 271 last_reported_lossy_utilization_) / kAttenuationFactor; | |
| 272 if (attenuated_stress_level >= 0.0) { | |
| 273 video_frame->metadata()->SetDouble( | |
| 274 media::VideoFrameMetadata::STRESS_LEVEL, attenuated_stress_level); | |
| 275 } | |
| 276 } | |
| 258 | 277 |
| 259 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); | 278 SendEncodedFrame(encoder_bitrate, encoded_frame.Pass()); |
| 260 } | 279 } |
| 261 | 280 |
| 262 } // namespace cast | 281 } // namespace cast |
| 263 } // namespace media | 282 } // namespace media |
| OLD | NEW |