| 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/receiver/frame_receiver.h" | 5 #include "media/cast/receiver/frame_receiver.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "media/cast/cast_config.h" | 14 #include "media/cast/cast_config.h" |
| 14 #include "media/cast/cast_defines.h" | 15 #include "media/cast/cast_defines.h" |
| 15 #include "media/cast/cast_environment.h" | 16 #include "media/cast/cast_environment.h" |
| 16 #include "media/cast/constants.h" | 17 #include "media/cast/constants.h" |
| 17 | 18 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 scoped_ptr<PacketEvent> receive_event(new PacketEvent()); | 118 scoped_ptr<PacketEvent> receive_event(new PacketEvent()); |
| 118 receive_event->timestamp = now; | 119 receive_event->timestamp = now; |
| 119 receive_event->type = PACKET_RECEIVED; | 120 receive_event->type = PACKET_RECEIVED; |
| 120 receive_event->media_type = event_media_type_; | 121 receive_event->media_type = event_media_type_; |
| 121 receive_event->rtp_timestamp = rtp_header.rtp_timestamp; | 122 receive_event->rtp_timestamp = rtp_header.rtp_timestamp; |
| 122 receive_event->frame_id = rtp_header.frame_id; | 123 receive_event->frame_id = rtp_header.frame_id; |
| 123 receive_event->packet_id = rtp_header.packet_id; | 124 receive_event->packet_id = rtp_header.packet_id; |
| 124 receive_event->max_packet_id = rtp_header.max_packet_id; | 125 receive_event->max_packet_id = rtp_header.max_packet_id; |
| 125 receive_event->size = payload_size; | 126 receive_event->size = payload_size; |
| 126 cast_environment_->logger()->DispatchPacketEvent(receive_event.Pass()); | 127 cast_environment_->logger()->DispatchPacketEvent(std::move(receive_event)); |
| 127 | 128 |
| 128 bool duplicate = false; | 129 bool duplicate = false; |
| 129 const bool complete = | 130 const bool complete = |
| 130 framer_.InsertPacket(payload_data, payload_size, rtp_header, &duplicate); | 131 framer_.InsertPacket(payload_data, payload_size, rtp_header, &duplicate); |
| 131 | 132 |
| 132 // Duplicate packets are ignored. | 133 // Duplicate packets are ignored. |
| 133 if (duplicate) | 134 if (duplicate) |
| 134 return; | 135 return; |
| 135 | 136 |
| 136 // Update lip-sync values upon receiving the first packet of each frame, or if | 137 // Update lip-sync values upon receiving the first packet of each frame, or if |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); | 176 base::TimeTicks now = cast_environment_->Clock()->NowTicks(); |
| 176 RtpTimestamp rtp_timestamp = | 177 RtpTimestamp rtp_timestamp = |
| 177 frame_id_to_rtp_timestamp_[cast_message.ack_frame_id & 0xff]; | 178 frame_id_to_rtp_timestamp_[cast_message.ack_frame_id & 0xff]; |
| 178 | 179 |
| 179 scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); | 180 scoped_ptr<FrameEvent> ack_sent_event(new FrameEvent()); |
| 180 ack_sent_event->timestamp = now; | 181 ack_sent_event->timestamp = now; |
| 181 ack_sent_event->type = FRAME_ACK_SENT; | 182 ack_sent_event->type = FRAME_ACK_SENT; |
| 182 ack_sent_event->media_type = event_media_type_; | 183 ack_sent_event->media_type = event_media_type_; |
| 183 ack_sent_event->rtp_timestamp = rtp_timestamp; | 184 ack_sent_event->rtp_timestamp = rtp_timestamp; |
| 184 ack_sent_event->frame_id = cast_message.ack_frame_id; | 185 ack_sent_event->frame_id = cast_message.ack_frame_id; |
| 185 cast_environment_->logger()->DispatchFrameEvent(ack_sent_event.Pass()); | 186 cast_environment_->logger()->DispatchFrameEvent(std::move(ack_sent_event)); |
| 186 | 187 |
| 187 ReceiverRtcpEventSubscriber::RtcpEvents rtcp_events; | 188 ReceiverRtcpEventSubscriber::RtcpEvents rtcp_events; |
| 188 event_subscriber_.GetRtcpEventsWithRedundancy(&rtcp_events); | 189 event_subscriber_.GetRtcpEventsWithRedundancy(&rtcp_events); |
| 189 transport_->SendRtcpFromRtpReceiver(rtcp_.GetLocalSsrc(), | 190 transport_->SendRtcpFromRtpReceiver(rtcp_.GetLocalSsrc(), |
| 190 rtcp_.GetRemoteSsrc(), | 191 rtcp_.GetRemoteSsrc(), |
| 191 rtcp_.ConvertToNTPAndSave(now), | 192 rtcp_.ConvertToNTPAndSave(now), |
| 192 &cast_message, | 193 &cast_message, |
| 193 target_playout_delay_, | 194 target_playout_delay_, |
| 194 &rtcp_events, | 195 &rtcp_events, |
| 195 NULL); | 196 NULL); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 287 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 287 DCHECK(is_waiting_for_consecutive_frame_); | 288 DCHECK(is_waiting_for_consecutive_frame_); |
| 288 is_waiting_for_consecutive_frame_ = false; | 289 is_waiting_for_consecutive_frame_ = false; |
| 289 EmitAvailableEncodedFrames(); | 290 EmitAvailableEncodedFrames(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void FrameReceiver::EmitOneFrame(const ReceiveEncodedFrameCallback& callback, | 293 void FrameReceiver::EmitOneFrame(const ReceiveEncodedFrameCallback& callback, |
| 293 scoped_ptr<EncodedFrame> encoded_frame) const { | 294 scoped_ptr<EncodedFrame> encoded_frame) const { |
| 294 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 295 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 295 if (!callback.is_null()) | 296 if (!callback.is_null()) |
| 296 callback.Run(encoded_frame.Pass()); | 297 callback.Run(std::move(encoded_frame)); |
| 297 } | 298 } |
| 298 | 299 |
| 299 base::TimeTicks FrameReceiver::GetPlayoutTime(const EncodedFrame& frame) const { | 300 base::TimeTicks FrameReceiver::GetPlayoutTime(const EncodedFrame& frame) const { |
| 300 base::TimeDelta target_playout_delay = target_playout_delay_; | 301 base::TimeDelta target_playout_delay = target_playout_delay_; |
| 301 if (frame.new_playout_delay_ms) { | 302 if (frame.new_playout_delay_ms) { |
| 302 target_playout_delay = base::TimeDelta::FromMilliseconds( | 303 target_playout_delay = base::TimeDelta::FromMilliseconds( |
| 303 frame.new_playout_delay_ms); | 304 frame.new_playout_delay_ms); |
| 304 } | 305 } |
| 305 return lip_sync_reference_time_ + lip_sync_drift_.Current() + | 306 return lip_sync_reference_time_ + lip_sync_drift_.Current() + |
| 306 RtpDeltaToTimeDelta(static_cast<int32_t>(frame.rtp_timestamp - | 307 RtpDeltaToTimeDelta(static_cast<int32_t>(frame.rtp_timestamp - |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 rtcp_.ConvertToNTPAndSave(now), | 351 rtcp_.ConvertToNTPAndSave(now), |
| 351 NULL, | 352 NULL, |
| 352 base::TimeDelta(), | 353 base::TimeDelta(), |
| 353 NULL, | 354 NULL, |
| 354 &stats); | 355 &stats); |
| 355 ScheduleNextRtcpReport(); | 356 ScheduleNextRtcpReport(); |
| 356 } | 357 } |
| 357 | 358 |
| 358 } // namespace cast | 359 } // namespace cast |
| 359 } // namespace media | 360 } // namespace media |
| OLD | NEW |