| 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/framer/cast_message_builder.h" | 5 #include "media/cast/framer/cast_message_builder.h" |
| 6 | 6 |
| 7 #include "media/cast/cast_defines.h" | 7 #include "media/cast/cast_defines.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 namespace cast { | 10 namespace cast { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 waiting_for_key_frame_ = false; | 47 waiting_for_key_frame_ = false; |
| 48 cast_msg_.missing_frames_and_packets_.clear(); | 48 cast_msg_.missing_frames_and_packets_.clear(); |
| 49 cast_msg_.ack_frame_id_ = frame_id; | 49 cast_msg_.ack_frame_id_ = frame_id; |
| 50 last_update_time_ = clock_->NowTicks(); | 50 last_update_time_ = clock_->NowTicks(); |
| 51 // We might have other complete frames waiting after we receive the last | 51 // We might have other complete frames waiting after we receive the last |
| 52 // packet in the key-frame. | 52 // packet in the key-frame. |
| 53 UpdateAckMessage(); | 53 UpdateAckMessage(); |
| 54 } else { | 54 } else { |
| 55 if (!UpdateAckMessage()) return; | 55 if (!UpdateAckMessage()) |
| 56 return; |
| 56 | 57 |
| 57 BuildPacketList(); | 58 BuildPacketList(); |
| 58 } | 59 } |
| 59 // Send cast message. | 60 // Send cast message. |
| 60 VLOG(1) << "Send cast message Ack:" << static_cast<int>(frame_id); | 61 VLOG(1) << "Send cast message Ack:" << static_cast<int>(frame_id); |
| 61 cast_feedback_->CastFeedback(cast_msg_); | 62 cast_feedback_->CastFeedback(cast_msg_); |
| 62 } | 63 } |
| 63 | 64 |
| 64 bool CastMessageBuilder::UpdateAckMessage() { | 65 bool CastMessageBuilder::UpdateAckMessage() { |
| 65 if (!decoder_faster_than_max_frame_rate_) { | 66 if (!decoder_faster_than_max_frame_rate_) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 79 } else { | 80 } else { |
| 80 acked_last_frame_ = true; | 81 acked_last_frame_ = true; |
| 81 last_acked_frame_id_++; | 82 last_acked_frame_id_++; |
| 82 // Note: frame skipping and slowdown ACK is not supported at the same | 83 // Note: frame skipping and slowdown ACK is not supported at the same |
| 83 // time; and it's not needed since we can skip frames to catch up. | 84 // time; and it's not needed since we can skip frames to catch up. |
| 84 } | 85 } |
| 85 } else { | 86 } else { |
| 86 uint32 frame_id = frame_id_map_->LastContinuousFrame(); | 87 uint32 frame_id = frame_id_map_->LastContinuousFrame(); |
| 87 | 88 |
| 88 // Is it a new frame? | 89 // Is it a new frame? |
| 89 if (last_acked_frame_id_ == frame_id) return false; | 90 if (last_acked_frame_id_ == frame_id) |
| 91 return false; |
| 90 | 92 |
| 91 last_acked_frame_id_ = frame_id; | 93 last_acked_frame_id_ = frame_id; |
| 92 acked_last_frame_ = true; | 94 acked_last_frame_ = true; |
| 93 } | 95 } |
| 94 cast_msg_.ack_frame_id_ = last_acked_frame_id_; | 96 cast_msg_.ack_frame_id_ = last_acked_frame_id_; |
| 95 cast_msg_.missing_frames_and_packets_.clear(); | 97 cast_msg_.missing_frames_and_packets_.clear(); |
| 96 last_update_time_ = clock_->NowTicks(); | 98 last_update_time_ = clock_->NowTicks(); |
| 97 return true; | 99 return true; |
| 98 } | 100 } |
| 99 | 101 |
| 100 bool CastMessageBuilder::TimeToSendNextCastMessage( | 102 bool CastMessageBuilder::TimeToSendNextCastMessage( |
| 101 base::TimeTicks* time_to_send) { | 103 base::TimeTicks* time_to_send) { |
| 102 // We haven't received any packets. | 104 // We haven't received any packets. |
| 103 if (last_update_time_.is_null() && frame_id_map_->Empty()) return false; | 105 if (last_update_time_.is_null() && frame_id_map_->Empty()) |
| 106 return false; |
| 104 | 107 |
| 105 *time_to_send = last_update_time_ + | 108 *time_to_send = last_update_time_ + base::TimeDelta::FromMilliseconds( |
| 106 base::TimeDelta::FromMilliseconds(kCastMessageUpdateIntervalMs); | 109 kCastMessageUpdateIntervalMs); |
| 107 return true; | 110 return true; |
| 108 } | 111 } |
| 109 | 112 |
| 110 void CastMessageBuilder::UpdateCastMessage() { | 113 void CastMessageBuilder::UpdateCastMessage() { |
| 111 RtcpCastMessage message(media_ssrc_); | 114 RtcpCastMessage message(media_ssrc_); |
| 112 if (!UpdateCastMessageInternal(&message)) return; | 115 if (!UpdateCastMessageInternal(&message)) |
| 116 return; |
| 113 | 117 |
| 114 // Send cast message. | 118 // Send cast message. |
| 115 cast_feedback_->CastFeedback(message); | 119 cast_feedback_->CastFeedback(message); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void CastMessageBuilder::Reset() { | 122 void CastMessageBuilder::Reset() { |
| 119 waiting_for_key_frame_ = true; | 123 waiting_for_key_frame_ = true; |
| 120 cast_msg_.ack_frame_id_ = kStartFrameId; | 124 cast_msg_.ack_frame_id_ = kStartFrameId; |
| 121 cast_msg_.missing_frames_and_packets_.clear(); | 125 cast_msg_.missing_frames_and_packets_.clear(); |
| 122 time_last_nacked_map_.clear(); | 126 time_last_nacked_map_.clear(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 144 return true; | 148 return true; |
| 145 } | 149 } |
| 146 | 150 |
| 147 void CastMessageBuilder::BuildPacketList() { | 151 void CastMessageBuilder::BuildPacketList() { |
| 148 base::TimeTicks now = clock_->NowTicks(); | 152 base::TimeTicks now = clock_->NowTicks(); |
| 149 | 153 |
| 150 // Clear message NACK list. | 154 // Clear message NACK list. |
| 151 cast_msg_.missing_frames_and_packets_.clear(); | 155 cast_msg_.missing_frames_and_packets_.clear(); |
| 152 | 156 |
| 153 // Are we missing packets? | 157 // Are we missing packets? |
| 154 if (frame_id_map_->Empty()) return; | 158 if (frame_id_map_->Empty()) |
| 159 return; |
| 155 | 160 |
| 156 uint32 newest_frame_id = frame_id_map_->NewestFrameId(); | 161 uint32 newest_frame_id = frame_id_map_->NewestFrameId(); |
| 157 uint32 next_expected_frame_id = cast_msg_.ack_frame_id_ + 1; | 162 uint32 next_expected_frame_id = cast_msg_.ack_frame_id_ + 1; |
| 158 | 163 |
| 159 // Iterate over all frames. | 164 // Iterate over all frames. |
| 160 for (; !IsNewerFrameId(next_expected_frame_id, newest_frame_id); | 165 for (; !IsNewerFrameId(next_expected_frame_id, newest_frame_id); |
| 161 ++next_expected_frame_id) { | 166 ++next_expected_frame_id) { |
| 162 TimeLastNackMap::iterator it = | 167 TimeLastNackMap::iterator it = |
| 163 time_last_nacked_map_.find(next_expected_frame_id); | 168 time_last_nacked_map_.find(next_expected_frame_id); |
| 164 if (it != time_last_nacked_map_.end()) { | 169 if (it != time_last_nacked_map_.end()) { |
| 165 // We have sent a NACK in this frame before, make sure enough time have | 170 // We have sent a NACK in this frame before, make sure enough time have |
| 166 // passed. | 171 // passed. |
| 167 if (now - it->second < | 172 if (now - it->second < |
| 168 base::TimeDelta::FromMilliseconds(kNackRepeatIntervalMs)) { | 173 base::TimeDelta::FromMilliseconds(kNackRepeatIntervalMs)) { |
| 169 continue; | 174 continue; |
| 170 } | 175 } |
| 171 } | 176 } |
| 172 | 177 |
| 173 PacketIdSet missing; | 178 PacketIdSet missing; |
| 174 if (frame_id_map_->FrameExists(next_expected_frame_id)) { | 179 if (frame_id_map_->FrameExists(next_expected_frame_id)) { |
| 175 bool last_frame = (newest_frame_id == next_expected_frame_id); | 180 bool last_frame = (newest_frame_id == next_expected_frame_id); |
| 176 frame_id_map_->GetMissingPackets(next_expected_frame_id, last_frame, | 181 frame_id_map_->GetMissingPackets( |
| 177 &missing); | 182 next_expected_frame_id, last_frame, &missing); |
| 178 if (!missing.empty()) { | 183 if (!missing.empty()) { |
| 179 time_last_nacked_map_[next_expected_frame_id] = now; | 184 time_last_nacked_map_[next_expected_frame_id] = now; |
| 180 cast_msg_.missing_frames_and_packets_.insert( | 185 cast_msg_.missing_frames_and_packets_.insert( |
| 181 std::make_pair(next_expected_frame_id, missing)); | 186 std::make_pair(next_expected_frame_id, missing)); |
| 182 } | 187 } |
| 183 } else { | 188 } else { |
| 184 time_last_nacked_map_[next_expected_frame_id] = now; | 189 time_last_nacked_map_[next_expected_frame_id] = now; |
| 185 missing.insert(kRtcpCastAllPacketsLost); | 190 missing.insert(kRtcpCastAllPacketsLost); |
| 186 cast_msg_.missing_frames_and_packets_[next_expected_frame_id] = missing; | 191 cast_msg_.missing_frames_and_packets_[next_expected_frame_id] = missing; |
| 187 } | 192 } |
| 188 } | 193 } |
| 189 } | 194 } |
| 190 | 195 |
| 191 } // namespace cast | 196 } // namespace cast |
| 192 } // namespace media | 197 } // namespace media |
| OLD | NEW |