| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 framer_.reset(new Framer(cast_environment->Clock(), | 120 framer_.reset(new Framer(cast_environment->Clock(), |
| 121 incoming_payload_feedback_.get(), | 121 incoming_payload_feedback_.get(), |
| 122 video_config.incoming_ssrc, | 122 video_config.incoming_ssrc, |
| 123 video_config.decoder_faster_than_max_frame_rate, | 123 video_config.decoder_faster_than_max_frame_rate, |
| 124 max_unacked_frames)); | 124 max_unacked_frames)); |
| 125 if (!video_config.use_external_decoder) { | 125 if (!video_config.use_external_decoder) { |
| 126 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); | 126 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 rtcp_.reset( | 129 rtcp_.reset( |
| 130 new Rtcp(cast_environment_->Clock(), | 130 new Rtcp(cast_environment_, |
| 131 NULL, | 131 NULL, |
| 132 packet_sender, | 132 packet_sender, |
| 133 NULL, | 133 NULL, |
| 134 rtp_video_receiver_statistics_.get(), | 134 rtp_video_receiver_statistics_.get(), |
| 135 video_config.rtcp_mode, | 135 video_config.rtcp_mode, |
| 136 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 136 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
| 137 video_config.feedback_ssrc, | 137 video_config.feedback_ssrc, |
| 138 video_config.incoming_ssrc, | 138 video_config.incoming_ssrc, |
| 139 video_config.rtcp_c_name)); | 139 video_config.rtcp_c_name)); |
| 140 } | 140 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // the next frame or we are running out of time and have to pull the following | 242 // the next frame or we are running out of time and have to pull the following |
| 243 // frame. | 243 // frame. |
| 244 // If the frame it too old to be rendered we set the don't show flag in the | 244 // If the frame it too old to be rendered we set the don't show flag in the |
| 245 // video bitstream where possible. | 245 // video bitstream where possible. |
| 246 bool VideoReceiver::PullEncodedVideoFrame(uint32 rtp_timestamp, | 246 bool VideoReceiver::PullEncodedVideoFrame(uint32 rtp_timestamp, |
| 247 bool next_frame, scoped_ptr<EncodedVideoFrame>* encoded_frame, | 247 bool next_frame, scoped_ptr<EncodedVideoFrame>* encoded_frame, |
| 248 base::TimeTicks* render_time) { | 248 base::TimeTicks* render_time) { |
| 249 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 249 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 250 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 250 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 251 *render_time = GetRenderTime(now, rtp_timestamp); | 251 *render_time = GetRenderTime(now, rtp_timestamp); |
| 252 base::TimeDelta diff = now - *render_time; |
| 253 |
| 254 cast_environment_->Logging()->InsertFrameEvent(kVideoRenderDelay, |
| 255 rtp_timestamp, diff.InMilliseconds()); |
| 252 | 256 |
| 253 // Minimum time before a frame is due to be rendered before we pull it for | 257 // Minimum time before a frame is due to be rendered before we pull it for |
| 254 // decode. | 258 // decode. |
| 255 base::TimeDelta min_wait_delta = frame_delay_; | 259 base::TimeDelta min_wait_delta = frame_delay_; |
| 256 base::TimeDelta time_until_render = *render_time - now; | 260 base::TimeDelta time_until_render = *render_time - now; |
| 257 if (!next_frame && (time_until_render > min_wait_delta)) { | 261 if (!next_frame && (time_until_render > min_wait_delta)) { |
| 258 // Example: | 262 // Example: |
| 259 // We have decoded frame 1 and we have received the complete frame 3, but | 263 // We have decoded frame 1 and we have received the complete frame 3, but |
| 260 // not frame 2. If we still have time before frame 3 should be rendered we | 264 // not frame 2. If we still have time before frame 3 should be rendered we |
| 261 // will wait for 2 to arrive, however if 2 never show up this timer will hit | 265 // will wait for 2 to arrive, however if 2 never show up this timer will hit |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 388 |
| 385 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 389 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 386 if (time_incoming_packet_.is_null() || now - time_incoming_packet_ > | 390 if (time_incoming_packet_.is_null() || now - time_incoming_packet_ > |
| 387 base::TimeDelta::FromMilliseconds(kMinTimeBetweenOffsetUpdatesMs)) { | 391 base::TimeDelta::FromMilliseconds(kMinTimeBetweenOffsetUpdatesMs)) { |
| 388 if (time_incoming_packet_.is_null()) InitializeTimers(); | 392 if (time_incoming_packet_.is_null()) InitializeTimers(); |
| 389 incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; | 393 incoming_rtp_timestamp_ = rtp_header.webrtc.header.timestamp; |
| 390 time_incoming_packet_ = now; | 394 time_incoming_packet_ = now; |
| 391 time_incoming_packet_updated_ = true; | 395 time_incoming_packet_updated_ = true; |
| 392 } | 396 } |
| 393 | 397 |
| 398 cast_environment_->Logging()->InsertPacketEvent(kPacketReceived, |
| 399 rtp_header.webrtc.header.timestamp, rtp_header.frame_id, |
| 400 rtp_header.packet_id, rtp_header.max_packet_id, payload_size); |
| 401 |
| 394 bool complete = framer_->InsertPacket(payload_data, payload_size, rtp_header); | 402 bool complete = framer_->InsertPacket(payload_data, payload_size, rtp_header); |
| 395 | 403 |
| 396 if (!complete) return; // Video frame not complete; wait for more packets. | 404 if (!complete) return; // Video frame not complete; wait for more packets. |
| 397 if (queued_encoded_callbacks_.empty()) return; // No pending callback. | 405 if (queued_encoded_callbacks_.empty()) return; // No pending callback. |
| 398 | 406 |
| 399 VideoFrameEncodedCallback callback = queued_encoded_callbacks_.front(); | 407 VideoFrameEncodedCallback callback = queued_encoded_callbacks_.front(); |
| 400 queued_encoded_callbacks_.pop_front(); | 408 queued_encoded_callbacks_.pop_front(); |
| 401 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 409 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
| 402 base::Bind(&VideoReceiver::GetEncodedVideoFrame, | 410 base::Bind(&VideoReceiver::GetEncodedVideoFrame, |
| 403 weak_factory_.GetWeakPtr(), callback)); | 411 weak_factory_.GetWeakPtr(), callback)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 457 } |
| 450 | 458 |
| 451 void VideoReceiver::SendNextRtcpReport() { | 459 void VideoReceiver::SendNextRtcpReport() { |
| 452 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 460 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 453 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); | 461 rtcp_->SendRtcpFromRtpReceiver(NULL, NULL); |
| 454 ScheduleNextRtcpReport(); | 462 ScheduleNextRtcpReport(); |
| 455 } | 463 } |
| 456 | 464 |
| 457 } // namespace cast | 465 } // namespace cast |
| 458 } // namespace media | 466 } // namespace media |
| OLD | NEW |