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 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 bool GetPacketTimeInformation(base::TimeTicks* time_incoming_packet, | 50 bool GetPacketTimeInformation(base::TimeTicks* time_incoming_packet, |
51 uint32* incoming_rtp_timestamp) { | 51 uint32* incoming_rtp_timestamp) { |
52 *time_incoming_packet = time_incoming_packet_; | 52 *time_incoming_packet = time_incoming_packet_; |
53 *incoming_rtp_timestamp = incoming_rtp_timestamp_; | 53 *incoming_rtp_timestamp = incoming_rtp_timestamp_; |
54 bool time_updated = time_updated_; | 54 bool time_updated = time_updated_; |
55 time_updated_ = false; | 55 time_updated_ = false; |
56 return time_updated; | 56 return time_updated; |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 base::TickClock* clock_; // Not owned by this class. | 60 base::TickClock* const clock_; // Not owned by this class. |
61 VideoReceiver* video_receiver_; | 61 VideoReceiver* video_receiver_; |
62 bool time_updated_; | 62 bool time_updated_; |
63 base::TimeTicks time_incoming_packet_; | 63 base::TimeTicks time_incoming_packet_; |
64 uint32 incoming_rtp_timestamp_; | 64 uint32 incoming_rtp_timestamp_; |
65 }; | 65 }; |
66 | 66 |
67 // Local implementation of RtpPayloadFeedback (defined in rtp_defines.h) | 67 // Local implementation of RtpPayloadFeedback (defined in rtp_defines.h) |
68 // Used to convey cast-specific feedback from receiver to sender. | 68 // Used to convey cast-specific feedback from receiver to sender. |
69 // Callback triggered by the Framer (cast message builder). | 69 // Callback triggered by the Framer (cast message builder). |
70 class LocalRtpVideoFeedback : public RtpPayloadFeedback { | 70 class LocalRtpVideoFeedback : public RtpPayloadFeedback { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 framer_.reset(new Framer(cast_environment->Clock(), | 128 framer_.reset(new Framer(cast_environment->Clock(), |
129 incoming_payload_feedback_.get(), | 129 incoming_payload_feedback_.get(), |
130 video_config.incoming_ssrc, | 130 video_config.incoming_ssrc, |
131 video_config.decoder_faster_than_max_frame_rate, | 131 video_config.decoder_faster_than_max_frame_rate, |
132 max_unacked_frames)); | 132 max_unacked_frames)); |
133 if (!video_config.use_external_decoder) { | 133 if (!video_config.use_external_decoder) { |
134 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); | 134 video_decoder_.reset(new VideoDecoder(video_config, cast_environment)); |
135 } | 135 } |
136 | 136 |
137 rtcp_.reset( | 137 rtcp_.reset( |
138 new Rtcp(cast_environment_->Clock(), | 138 new Rtcp(cast_environment_, |
139 NULL, | 139 NULL, |
140 packet_sender, | 140 packet_sender, |
141 NULL, | 141 NULL, |
142 rtp_video_receiver_statistics_.get(), | 142 rtp_video_receiver_statistics_.get(), |
143 video_config.rtcp_mode, | 143 video_config.rtcp_mode, |
144 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), | 144 base::TimeDelta::FromMilliseconds(video_config.rtcp_interval), |
145 false, | 145 false, |
146 video_config.feedback_ssrc, | 146 video_config.feedback_ssrc, |
147 video_config.rtcp_c_name)); | 147 video_config.rtcp_c_name)); |
148 | 148 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // Should we pull the encoded video frame from the framer? decided by if this is | 217 // Should we pull the encoded video frame from the framer? decided by if this is |
218 // the next frame or we are running out of time and have to pull the following | 218 // the next frame or we are running out of time and have to pull the following |
219 // frame. | 219 // frame. |
220 // If the frame it too old to be rendered we set the don't show flag in the | 220 // If the frame it too old to be rendered we set the don't show flag in the |
221 // video bitstream where possible. | 221 // video bitstream where possible. |
222 bool VideoReceiver::PullEncodedVideoFrame(uint32 rtp_timestamp, | 222 bool VideoReceiver::PullEncodedVideoFrame(uint32 rtp_timestamp, |
223 bool next_frame, scoped_ptr<EncodedVideoFrame>* encoded_frame, | 223 bool next_frame, scoped_ptr<EncodedVideoFrame>* encoded_frame, |
224 base::TimeTicks* render_time) { | 224 base::TimeTicks* render_time) { |
225 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 225 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
226 *render_time = GetRenderTime(now, rtp_timestamp); | 226 *render_time = GetRenderTime(now, rtp_timestamp); |
| 227 base::TimeDelta diff = now - *render_time; |
| 228 |
| 229 cast_environment_->Logging()->InsertFrameEvent(kVideoRenderDelay, |
| 230 rtp_timestamp, diff.InMilliseconds()); |
227 | 231 |
228 // Minimum time before a frame is due to be rendered before we pull it for | 232 // Minimum time before a frame is due to be rendered before we pull it for |
229 // decode. | 233 // decode. |
230 base::TimeDelta min_wait_delta = frame_delay_; | 234 base::TimeDelta min_wait_delta = frame_delay_; |
231 base::TimeDelta time_until_render = *render_time - now; | 235 base::TimeDelta time_until_render = *render_time - now; |
232 if (!next_frame && (time_until_render > min_wait_delta)) { | 236 if (!next_frame && (time_until_render > min_wait_delta)) { |
233 // Example: | 237 // Example: |
234 // We have decoded frame 1 and we have received the complete frame 3, but | 238 // We have decoded frame 1 and we have received the complete frame 3, but |
235 // not frame 2. If we still have time before frame 3 should be rendered we | 239 // not frame 2. If we still have time before frame 3 should be rendered we |
236 // will wait for 2 to arrive, however if 2 never show up this timer will hit | 240 // will wait for 2 to arrive, however if 2 never show up this timer will hit |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 rtcp_->IncomingRtcpPacket(packet, length); | 348 rtcp_->IncomingRtcpPacket(packet, length); |
345 } else { | 349 } else { |
346 rtp_receiver_.ReceivedPacket(packet, length); | 350 rtp_receiver_.ReceivedPacket(packet, length); |
347 } | 351 } |
348 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); | 352 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, callback); |
349 } | 353 } |
350 | 354 |
351 void VideoReceiver::IncomingRtpPacket(const uint8* payload_data, | 355 void VideoReceiver::IncomingRtpPacket(const uint8* payload_data, |
352 size_t payload_size, | 356 size_t payload_size, |
353 const RtpCastHeader& rtp_header) { | 357 const RtpCastHeader& rtp_header) { |
| 358 cast_environment_->Logging()->InsertPacketEvent(kPacketReceived, |
| 359 rtp_header.webrtc.header.timestamp, rtp_header.frame_id, |
| 360 rtp_header.packet_id, rtp_header.max_packet_id, payload_size); |
| 361 |
354 bool complete = framer_->InsertPacket(payload_data, payload_size, rtp_header); | 362 bool complete = framer_->InsertPacket(payload_data, payload_size, rtp_header); |
355 | 363 |
356 if (!complete) return; // Video frame not complete; wait for more packets. | 364 if (!complete) return; // Video frame not complete; wait for more packets. |
357 if (queued_encoded_callbacks_.empty()) return; // No pending callback. | 365 if (queued_encoded_callbacks_.empty()) return; // No pending callback. |
358 | 366 |
359 VideoFrameEncodedCallback callback = queued_encoded_callbacks_.front(); | 367 VideoFrameEncodedCallback callback = queued_encoded_callbacks_.front(); |
360 queued_encoded_callbacks_.pop_front(); | 368 queued_encoded_callbacks_.pop_front(); |
361 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, | 369 cast_environment_->PostTask(CastEnvironment::MAIN, FROM_HERE, |
362 base::Bind(&VideoReceiver::GetEncodedVideoFrame, | 370 base::Bind(&VideoReceiver::GetEncodedVideoFrame, |
363 weak_factory_.GetWeakPtr(), callback)); | 371 weak_factory_.GetWeakPtr(), callback)); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 weak_factory_.GetWeakPtr()), time_to_next); | 411 weak_factory_.GetWeakPtr()), time_to_next); |
404 } | 412 } |
405 | 413 |
406 void VideoReceiver::SendNextRtcpReport() { | 414 void VideoReceiver::SendNextRtcpReport() { |
407 rtcp_->SendRtcpReport(incoming_ssrc_); | 415 rtcp_->SendRtcpReport(incoming_ssrc_); |
408 ScheduleNextRtcpReport(); | 416 ScheduleNextRtcpReport(); |
409 } | 417 } |
410 | 418 |
411 } // namespace cast | 419 } // namespace cast |
412 } // namespace media | 420 } // namespace media |
OLD | NEW |