| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/video_sender/video_sender.h" | 5 #include "media/cast/video_sender/video_sender.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 VideoSender::VideoSender( | 53 VideoSender::VideoSender( |
| 54 scoped_refptr<CastEnvironment> cast_environment, | 54 scoped_refptr<CastEnvironment> cast_environment, |
| 55 const VideoSenderConfig& video_config, | 55 const VideoSenderConfig& video_config, |
| 56 VideoEncoderController* const video_encoder_controller, | 56 VideoEncoderController* const video_encoder_controller, |
| 57 PacedPacketSender* const paced_packet_sender) | 57 PacedPacketSender* const paced_packet_sender) |
| 58 : rtp_max_delay_( | 58 : rtp_max_delay_( |
| 59 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), | 59 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), |
| 60 max_frame_rate_(video_config.max_frame_rate), | 60 max_frame_rate_(video_config.max_frame_rate), |
| 61 cast_environment_(cast_environment), | 61 cast_environment_(cast_environment), |
| 62 rtcp_feedback_(new LocalRtcpVideoSenderFeedback(this)), | 62 rtcp_feedback_(new LocalRtcpVideoSenderFeedback(this)), |
| 63 rtp_sender_(new RtpSender(cast_environment->Clock(), NULL, &video_config, | 63 rtp_sender_(new RtpSender(cast_environment, NULL, &video_config, |
| 64 paced_packet_sender)), | 64 paced_packet_sender)), |
| 65 last_acked_frame_id_(-1), | 65 last_acked_frame_id_(-1), |
| 66 last_sent_frame_id_(-1), | 66 last_sent_frame_id_(-1), |
| 67 duplicate_ack_(0), | 67 duplicate_ack_(0), |
| 68 last_skip_count_(0), | 68 last_skip_count_(0), |
| 69 congestion_control_(cast_environment->Clock(), | 69 congestion_control_(cast_environment->Clock(), |
| 70 video_config.congestion_control_back_off, | 70 video_config.congestion_control_back_off, |
| 71 video_config.max_bitrate, | 71 video_config.max_bitrate, |
| 72 video_config.min_bitrate, | 72 video_config.min_bitrate, |
| 73 video_config.start_bitrate), | 73 video_config.start_bitrate), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 crypto::SymmetricKey* key = crypto::SymmetricKey::Import( | 96 crypto::SymmetricKey* key = crypto::SymmetricKey::Import( |
| 97 crypto::SymmetricKey::AES, video_config.aes_key); | 97 crypto::SymmetricKey::AES, video_config.aes_key); |
| 98 encryptor_.reset(new crypto::Encryptor()); | 98 encryptor_.reset(new crypto::Encryptor()); |
| 99 encryptor_->Init(key, crypto::Encryptor::CTR, std::string()); | 99 encryptor_->Init(key, crypto::Encryptor::CTR, std::string()); |
| 100 } else if (video_config.aes_iv_mask.size() != 0 || | 100 } else if (video_config.aes_iv_mask.size() != 0 || |
| 101 video_config.aes_key.size() != 0) { | 101 video_config.aes_key.size() != 0) { |
| 102 DCHECK(false) << "Invalid crypto configuration"; | 102 DCHECK(false) << "Invalid crypto configuration"; |
| 103 } | 103 } |
| 104 | 104 |
| 105 rtcp_.reset(new Rtcp( | 105 rtcp_.reset(new Rtcp( |
| 106 cast_environment_->Clock(), | 106 cast_environment_, |
| 107 rtcp_feedback_.get(), | 107 rtcp_feedback_.get(), |
| 108 paced_packet_sender, | 108 paced_packet_sender, |
| 109 rtp_video_sender_statistics_.get(), | 109 rtp_video_sender_statistics_.get(), |
| 110 NULL, | 110 NULL, |
| 111 video_config.rtcp_mode, | 111 video_config.rtcp_mode, |
| 112 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 112 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
| 113 video_config.sender_ssrc, | 113 video_config.sender_ssrc, |
| 114 video_config.incoming_feedback_ssrc, | 114 video_config.incoming_feedback_ssrc, |
| 115 video_config.rtcp_c_name)); | 115 video_config.rtcp_c_name)); |
| 116 } | 116 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 | 305 |
| 306 void VideoSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) { | 306 void VideoSender::OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) { |
| 307 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 307 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 308 base::TimeDelta rtt; | 308 base::TimeDelta rtt; |
| 309 base::TimeDelta avg_rtt; | 309 base::TimeDelta avg_rtt; |
| 310 base::TimeDelta min_rtt; | 310 base::TimeDelta min_rtt; |
| 311 base::TimeDelta max_rtt; | 311 base::TimeDelta max_rtt; |
| 312 | 312 |
| 313 if (rtcp_->Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt)) { | 313 if (rtcp_->Rtt(&rtt, &avg_rtt, &min_rtt, &max_rtt)) { |
| 314 cast_environment_->Logging()->InsertGenericEvent(kRttMs, |
| 315 rtt.InMilliseconds()); |
| 314 // Don't use a RTT lower than our average. | 316 // Don't use a RTT lower than our average. |
| 315 rtt = std::max(rtt, avg_rtt); | 317 rtt = std::max(rtt, avg_rtt); |
| 316 } else { | 318 } else { |
| 317 // We have no measured value use default. | 319 // We have no measured value use default. |
| 318 rtt = base::TimeDelta::FromMilliseconds(kStartRttMs); | 320 rtt = base::TimeDelta::FromMilliseconds(kStartRttMs); |
| 319 } | 321 } |
| 320 if (cast_feedback.missing_frames_and_packets_.empty()) { | 322 if (cast_feedback.missing_frames_and_packets_.empty()) { |
| 321 // No lost packets. | 323 // No lost packets. |
| 322 int resend_frame = -1; | 324 int resend_frame = -1; |
| 323 if (last_sent_frame_id_ == -1) return; | 325 if (last_sent_frame_id_ == -1) return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 video_encoder_controller_->SetBitRate(new_bitrate); | 360 video_encoder_controller_->SetBitRate(new_bitrate); |
| 359 } | 361 } |
| 360 } | 362 } |
| 361 ReceivedAck(cast_feedback.ack_frame_id_); | 363 ReceivedAck(cast_feedback.ack_frame_id_); |
| 362 } | 364 } |
| 363 | 365 |
| 364 void VideoSender::ReceivedAck(uint32 acked_frame_id) { | 366 void VideoSender::ReceivedAck(uint32 acked_frame_id) { |
| 365 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 367 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 366 VLOG(1) << "ReceivedAck:" << acked_frame_id; | 368 VLOG(1) << "ReceivedAck:" << acked_frame_id; |
| 367 last_acked_frame_id_ = static_cast<int>(acked_frame_id); | 369 last_acked_frame_id_ = static_cast<int>(acked_frame_id); |
| 370 cast_environment_->Logging()->InsertGenericEvent(kAckReceived, |
| 371 acked_frame_id); |
| 372 VLOG(1) << "ReceivedAck:" << static_cast<int>(acked_frame_id); |
| 373 last_acked_frame_id_ = acked_frame_id; |
| 368 UpdateFramesInFlight(); | 374 UpdateFramesInFlight(); |
| 369 } | 375 } |
| 370 | 376 |
| 371 void VideoSender::UpdateFramesInFlight() { | 377 void VideoSender::UpdateFramesInFlight() { |
| 372 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 378 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 373 if (last_sent_frame_id_ != -1) { | 379 if (last_sent_frame_id_ != -1) { |
| 374 DCHECK_LE(0, last_sent_frame_id_); | 380 DCHECK_LE(0, last_sent_frame_id_); |
| 375 uint32 frames_in_flight; | 381 uint32 frames_in_flight; |
| 376 if (last_acked_frame_id_ != -1) { | 382 if (last_acked_frame_id_ != -1) { |
| 377 DCHECK_LE(0, last_acked_frame_id_); | 383 DCHECK_LE(0, last_acked_frame_id_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 394 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 400 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 395 MissingFramesAndPacketsMap missing_frames_and_packets; | 401 MissingFramesAndPacketsMap missing_frames_and_packets; |
| 396 PacketIdSet missing; | 402 PacketIdSet missing; |
| 397 missing_frames_and_packets.insert(std::make_pair(resend_frame_id, missing)); | 403 missing_frames_and_packets.insert(std::make_pair(resend_frame_id, missing)); |
| 398 rtp_sender_->ResendPackets(missing_frames_and_packets); | 404 rtp_sender_->ResendPackets(missing_frames_and_packets); |
| 399 last_send_time_ = cast_environment_->Clock()->NowTicks(); | 405 last_send_time_ = cast_environment_->Clock()->NowTicks(); |
| 400 } | 406 } |
| 401 | 407 |
| 402 } // namespace cast | 408 } // namespace cast |
| 403 } // namespace media | 409 } // namespace media |
| OLD | NEW |