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/frame_sender.h" | 5 #include "media/cast/sender/frame_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 base::TimeDelta FrameSender::GetAllowedInFlightMediaDuration() const { | 206 base::TimeDelta FrameSender::GetAllowedInFlightMediaDuration() const { |
207 // The total amount allowed in-flight media should equal the amount that fits | 207 // The total amount allowed in-flight media should equal the amount that fits |
208 // within the entire playout delay window, plus the amount of time it takes to | 208 // within the entire playout delay window, plus the amount of time it takes to |
209 // receive an ACK from the receiver. | 209 // receive an ACK from the receiver. |
210 // TODO(miu): Research is needed, but there is likely a better formula. | 210 // TODO(miu): Research is needed, but there is likely a better formula. |
211 return target_playout_delay_ + (current_round_trip_time_ / 2); | 211 return target_playout_delay_ + (current_round_trip_time_ / 2); |
212 } | 212 } |
213 | 213 |
214 void FrameSender::SendEncodedFrame( | 214 void FrameSender::SendEncodedFrame( |
215 int requested_bitrate_before_encode, | 215 int requested_bitrate_before_encode, |
216 scoped_ptr<SenderEncodedFrame> encoded_frame) { | 216 std::unique_ptr<SenderEncodedFrame> encoded_frame) { |
217 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 217 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
218 | 218 |
219 VLOG(2) << SENDER_SSRC << "About to send another frame: last_sent=" | 219 VLOG(2) << SENDER_SSRC << "About to send another frame: last_sent=" |
220 << last_sent_frame_id_ << ", latest_acked=" << latest_acked_frame_id_; | 220 << last_sent_frame_id_ << ", latest_acked=" << latest_acked_frame_id_; |
221 | 221 |
222 const uint32_t frame_id = encoded_frame->frame_id; | 222 const uint32_t frame_id = encoded_frame->frame_id; |
223 const bool is_first_frame_to_be_sent = last_send_time_.is_null(); | 223 const bool is_first_frame_to_be_sent = last_send_time_.is_null(); |
224 | 224 |
225 if (picture_lost_at_receiver_ && | 225 if (picture_lost_at_receiver_ && |
226 (encoded_frame->dependency == EncodedFrame::KEY)) { | 226 (encoded_frame->dependency == EncodedFrame::KEY)) { |
(...skipping 13 matching lines...) Expand all Loading... |
240 // |latest_acked_frame_id_| to indicate the receiver starts out all caught up. | 240 // |latest_acked_frame_id_| to indicate the receiver starts out all caught up. |
241 // Also, schedule the periodic frame re-send checks. | 241 // Also, schedule the periodic frame re-send checks. |
242 if (is_first_frame_to_be_sent) { | 242 if (is_first_frame_to_be_sent) { |
243 latest_acked_frame_id_ = frame_id - 1; | 243 latest_acked_frame_id_ = frame_id - 1; |
244 ScheduleNextResendCheck(); | 244 ScheduleNextResendCheck(); |
245 } | 245 } |
246 | 246 |
247 VLOG_IF(1, !is_audio_ && encoded_frame->dependency == EncodedFrame::KEY) | 247 VLOG_IF(1, !is_audio_ && encoded_frame->dependency == EncodedFrame::KEY) |
248 << SENDER_SSRC << "Sending encoded key frame, id=" << frame_id; | 248 << SENDER_SSRC << "Sending encoded key frame, id=" << frame_id; |
249 | 249 |
250 scoped_ptr<FrameEvent> encode_event(new FrameEvent()); | 250 std::unique_ptr<FrameEvent> encode_event(new FrameEvent()); |
251 encode_event->timestamp = encoded_frame->encode_completion_time; | 251 encode_event->timestamp = encoded_frame->encode_completion_time; |
252 encode_event->type = FRAME_ENCODED; | 252 encode_event->type = FRAME_ENCODED; |
253 encode_event->media_type = is_audio_ ? AUDIO_EVENT : VIDEO_EVENT; | 253 encode_event->media_type = is_audio_ ? AUDIO_EVENT : VIDEO_EVENT; |
254 encode_event->rtp_timestamp = encoded_frame->rtp_timestamp; | 254 encode_event->rtp_timestamp = encoded_frame->rtp_timestamp; |
255 encode_event->frame_id = frame_id; | 255 encode_event->frame_id = frame_id; |
256 encode_event->size = base::checked_cast<uint32_t>(encoded_frame->data.size()); | 256 encode_event->size = base::checked_cast<uint32_t>(encoded_frame->data.size()); |
257 encode_event->key_frame = encoded_frame->dependency == EncodedFrame::KEY; | 257 encode_event->key_frame = encoded_frame->dependency == EncodedFrame::KEY; |
258 encode_event->target_bitrate = requested_bitrate_before_encode; | 258 encode_event->target_bitrate = requested_bitrate_before_encode; |
259 encode_event->encoder_cpu_utilization = encoded_frame->deadline_utilization; | 259 encode_event->encoder_cpu_utilization = encoded_frame->deadline_utilization; |
260 encode_event->idealized_bitrate_utilization = | 260 encode_event->idealized_bitrate_utilization = |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 354 } |
355 | 355 |
356 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 356 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
357 congestion_control_->AckFrame(cast_feedback.ack_frame_id, now); | 357 congestion_control_->AckFrame(cast_feedback.ack_frame_id, now); |
358 if (!cast_feedback.received_later_frames.empty()) { | 358 if (!cast_feedback.received_later_frames.empty()) { |
359 // Ack the received frames. | 359 // Ack the received frames. |
360 congestion_control_->AckLaterFrames(cast_feedback.received_later_frames, | 360 congestion_control_->AckLaterFrames(cast_feedback.received_later_frames, |
361 now); | 361 now); |
362 } | 362 } |
363 | 363 |
364 scoped_ptr<FrameEvent> ack_event(new FrameEvent()); | 364 std::unique_ptr<FrameEvent> ack_event(new FrameEvent()); |
365 ack_event->timestamp = now; | 365 ack_event->timestamp = now; |
366 ack_event->type = FRAME_ACK_RECEIVED; | 366 ack_event->type = FRAME_ACK_RECEIVED; |
367 ack_event->media_type = is_audio_ ? AUDIO_EVENT : VIDEO_EVENT; | 367 ack_event->media_type = is_audio_ ? AUDIO_EVENT : VIDEO_EVENT; |
368 ack_event->rtp_timestamp = | 368 ack_event->rtp_timestamp = |
369 GetRecordedRtpTimestamp(cast_feedback.ack_frame_id); | 369 GetRecordedRtpTimestamp(cast_feedback.ack_frame_id); |
370 ack_event->frame_id = cast_feedback.ack_frame_id; | 370 ack_event->frame_id = cast_feedback.ack_frame_id; |
371 cast_environment_->logger()->DispatchFrameEvent(std::move(ack_event)); | 371 cast_environment_->logger()->DispatchFrameEvent(std::move(ack_event)); |
372 | 372 |
373 const bool is_acked_out_of_order = | 373 const bool is_acked_out_of_order = |
374 static_cast<int32_t>(cast_feedback.ack_frame_id - | 374 static_cast<int32_t>(cast_feedback.ack_frame_id - |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 VLOG(1) << SENDER_SSRC << "Dropping: In-flight duration would be too high."; | 444 VLOG(1) << SENDER_SSRC << "Dropping: In-flight duration would be too high."; |
445 return true; | 445 return true; |
446 } | 446 } |
447 | 447 |
448 // Next frame is accepted. | 448 // Next frame is accepted. |
449 return false; | 449 return false; |
450 } | 450 } |
451 | 451 |
452 } // namespace cast | 452 } // namespace cast |
453 } // namespace media | 453 } // namespace media |
OLD | NEW |