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_receiver/video_receiver.h" | 5 #include "media/cast/video_receiver/video_receiver.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 | 84 |
85 private: | 85 private: |
86 RtpReceiver* rtp_receiver_; | 86 RtpReceiver* rtp_receiver_; |
87 | 87 |
88 DISALLOW_IMPLICIT_CONSTRUCTORS(LocalRtpReceiverStatistics); | 88 DISALLOW_IMPLICIT_CONSTRUCTORS(LocalRtpReceiverStatistics); |
89 }; | 89 }; |
90 | 90 |
91 VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment, | 91 VideoReceiver::VideoReceiver(scoped_refptr<CastEnvironment> cast_environment, |
92 const VideoReceiverConfig& video_config, | 92 const VideoReceiverConfig& video_config, |
93 transport::PacedPacketSender* const packet_sender) | 93 transport::PacedPacketSender* const packet_sender, |
| 94 const SetTargetDelayCallback& target_delay_cb) |
94 : cast_environment_(cast_environment), | 95 : cast_environment_(cast_environment), |
95 event_subscriber_(kReceiverRtcpEventHistorySize, | 96 event_subscriber_(kReceiverRtcpEventHistorySize, |
96 ReceiverRtcpEventSubscriber::kVideoEventSubscriber), | 97 ReceiverRtcpEventSubscriber::kVideoEventSubscriber), |
97 codec_(video_config.codec), | 98 codec_(video_config.codec), |
98 target_delay_delta_( | 99 target_delay_delta_( |
99 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), | 100 base::TimeDelta::FromMilliseconds(video_config.rtp_max_delay_ms)), |
100 frame_delay_(base::TimeDelta::FromMilliseconds( | 101 frame_delay_(base::TimeDelta::FromMilliseconds( |
101 1000 / video_config.max_frame_rate)), | 102 1000 / video_config.max_frame_rate)), |
102 incoming_payload_callback_(new LocalRtpVideoData(this)), | 103 incoming_payload_callback_(new LocalRtpVideoData(this)), |
103 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), | 104 incoming_payload_feedback_(new LocalRtpVideoFeedback(this)), |
104 rtp_receiver_(cast_environment_->Clock(), | 105 rtp_receiver_(cast_environment_->Clock(), |
105 NULL, | 106 NULL, |
106 &video_config, | 107 &video_config, |
107 incoming_payload_callback_.get()), | 108 incoming_payload_callback_.get()), |
108 rtp_video_receiver_statistics_( | 109 rtp_video_receiver_statistics_( |
109 new LocalRtpReceiverStatistics(&rtp_receiver_)), | 110 new LocalRtpReceiverStatistics(&rtp_receiver_)), |
110 time_offset_counter_(0), | 111 time_offset_counter_(0), |
111 decryptor_(), | 112 decryptor_(), |
112 time_incoming_packet_updated_(false), | 113 time_incoming_packet_updated_(false), |
113 incoming_rtp_timestamp_(0), | 114 incoming_rtp_timestamp_(0), |
| 115 target_delay_cb_(target_delay_cb), |
114 weak_factory_(this) { | 116 weak_factory_(this) { |
115 int max_unacked_frames = | 117 int max_unacked_frames = |
116 video_config.rtp_max_delay_ms * video_config.max_frame_rate / 1000; | 118 video_config.rtp_max_delay_ms * video_config.max_frame_rate / 1000; |
117 DCHECK(max_unacked_frames) << "Invalid argument"; | 119 DCHECK(max_unacked_frames) << "Invalid argument"; |
118 | 120 |
119 decryptor_.Initialize(video_config.aes_key, video_config.aes_iv_mask); | 121 decryptor_.Initialize(video_config.aes_key, video_config.aes_iv_mask); |
120 framer_.reset(new Framer(cast_environment->Clock(), | 122 framer_.reset(new Framer(cast_environment->Clock(), |
121 incoming_payload_feedback_.get(), | 123 incoming_payload_feedback_.get(), |
122 video_config.incoming_ssrc, | 124 video_config.incoming_ssrc, |
123 video_config.decoder_faster_than_max_frame_rate, | 125 video_config.decoder_faster_than_max_frame_rate, |
124 max_unacked_frames)); | 126 max_unacked_frames)); |
125 | 127 |
126 if (!video_config.use_external_decoder) { | 128 if (!video_config.use_external_decoder) { |
127 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); | 129 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); |
128 } | 130 } |
129 | 131 |
130 rtcp_.reset( | 132 rtcp_.reset( |
131 new Rtcp(cast_environment_, | 133 new Rtcp(cast_environment_, |
132 NULL, | 134 NULL, |
133 NULL, | 135 NULL, |
134 packet_sender, | 136 packet_sender, |
135 NULL, | 137 NULL, |
136 rtp_video_receiver_statistics_.get(), | 138 rtp_video_receiver_statistics_.get(), |
137 video_config.rtcp_mode, | 139 video_config.rtcp_mode, |
138 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 140 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
139 video_config.feedback_ssrc, | 141 video_config.feedback_ssrc, |
140 video_config.incoming_ssrc, | 142 video_config.incoming_ssrc, |
141 video_config.rtcp_c_name)); | 143 video_config.rtcp_c_name)); |
| 144 // Set the target delay that will be conveyed to the sender. |
| 145 rtcp_->SetTargetDelay(target_delay_delta_); |
142 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_); | 146 cast_environment_->Logging()->AddRawEventSubscriber(&event_subscriber_); |
143 memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_)); | 147 memset(frame_id_to_rtp_timestamp_, 0, sizeof(frame_id_to_rtp_timestamp_)); |
144 } | 148 } |
145 | 149 |
146 VideoReceiver::~VideoReceiver() { | 150 VideoReceiver::~VideoReceiver() { |
147 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_); | 151 cast_environment_->Logging()->RemoveRawEventSubscriber(&event_subscriber_); |
148 } | 152 } |
149 | 153 |
150 void VideoReceiver::InitializeTimers() { | 154 void VideoReceiver::InitializeTimers() { |
151 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 155 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 } | 391 } |
388 } | 392 } |
389 // Reset |time_incoming_packet_updated_| to enable a future measurement. | 393 // Reset |time_incoming_packet_updated_| to enable a future measurement. |
390 time_incoming_packet_updated_ = false; | 394 time_incoming_packet_updated_ = false; |
391 // Compute the actual rtp_timestamp_in_ticks based on the current timestamp. | 395 // Compute the actual rtp_timestamp_in_ticks based on the current timestamp. |
392 if (!rtcp_->RtpTimestampInSenderTime( | 396 if (!rtcp_->RtpTimestampInSenderTime( |
393 kVideoFrequency, rtp_timestamp, &rtp_timestamp_in_ticks)) { | 397 kVideoFrequency, rtp_timestamp, &rtp_timestamp_in_ticks)) { |
394 // This can fail if we have not received any RTCP packets in a long time. | 398 // This can fail if we have not received any RTCP packets in a long time. |
395 return now; | 399 return now; |
396 } | 400 } |
| 401 |
397 base::TimeTicks render_time = | 402 base::TimeTicks render_time = |
398 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_; | 403 rtp_timestamp_in_ticks + time_offset_ + target_delay_delta_; |
399 if (last_render_time_ > render_time) | 404 if (last_render_time_ > render_time) |
400 render_time = last_render_time_; | 405 render_time = last_render_time_; |
401 last_render_time_ = render_time; | 406 last_render_time_ = render_time; |
402 return render_time; | 407 return render_time; |
403 } | 408 } |
404 | 409 |
405 void VideoReceiver::IncomingPacket(scoped_ptr<Packet> packet) { | 410 void VideoReceiver::IncomingPacket(scoped_ptr<Packet> packet) { |
406 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 411 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 weak_factory_.GetWeakPtr()), | 533 weak_factory_.GetWeakPtr()), |
529 time_to_next); | 534 time_to_next); |
530 } | 535 } |
531 | 536 |
532 void VideoReceiver::SendNextRtcpReport() { | 537 void VideoReceiver::SendNextRtcpReport() { |
533 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 538 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
534 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); | 539 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); |
535 ScheduleNextRtcpReport(); | 540 ScheduleNextRtcpReport(); |
536 } | 541 } |
537 | 542 |
| 543 void VideoReceiver::UpdateTargetDelay() { |
| 544 NOTIMPLEMENTED(); |
| 545 rtcp_->SetTargetDelay(target_delay_delta_); |
| 546 target_delay_cb_.Run(target_delay_delta_); |
| 547 } |
| 548 |
538 } // namespace cast | 549 } // namespace cast |
539 } // namespace media | 550 } // namespace media |
OLD | NEW |