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/net/rtp/rtp_sender.h" | 5 #include "media/cast/net/rtp/rtp_sender.h" |
6 | 6 |
7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "media/cast/constants.h" | 10 #include "media/cast/constants.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 void RtpSender::ResendPackets( | 54 void RtpSender::ResendPackets( |
55 const MissingFramesAndPacketsMap& missing_frames_and_packets, | 55 const MissingFramesAndPacketsMap& missing_frames_and_packets, |
56 bool cancel_rtx_if_not_in_list, const DedupInfo& dedup_info) { | 56 bool cancel_rtx_if_not_in_list, const DedupInfo& dedup_info) { |
57 // Iterate over all frames in the list. | 57 // Iterate over all frames in the list. |
58 for (MissingFramesAndPacketsMap::const_iterator it = | 58 for (MissingFramesAndPacketsMap::const_iterator it = |
59 missing_frames_and_packets.begin(); | 59 missing_frames_and_packets.begin(); |
60 it != missing_frames_and_packets.end(); | 60 it != missing_frames_and_packets.end(); |
61 ++it) { | 61 ++it) { |
62 SendPacketVector packets_to_resend; | 62 SendPacketVector packets_to_resend; |
63 uint8 frame_id = it->first; | 63 uint8_t frame_id = it->first; |
64 // Set of packets that the receiver wants us to re-send. | 64 // Set of packets that the receiver wants us to re-send. |
65 // If empty, we need to re-send all packets for this frame. | 65 // If empty, we need to re-send all packets for this frame. |
66 const PacketIdSet& missing_packet_set = it->second; | 66 const PacketIdSet& missing_packet_set = it->second; |
67 | 67 |
68 bool resend_all = missing_packet_set.find(kRtcpCastAllPacketsLost) != | 68 bool resend_all = missing_packet_set.find(kRtcpCastAllPacketsLost) != |
69 missing_packet_set.end(); | 69 missing_packet_set.end(); |
70 bool resend_last = missing_packet_set.find(kRtcpCastLastPacket) != | 70 bool resend_last = missing_packet_set.find(kRtcpCastLastPacket) != |
71 missing_packet_set.end(); | 71 missing_packet_set.end(); |
72 | 72 |
73 const SendPacketVector* stored_packets = storage_.GetFrame8(frame_id); | 73 const SendPacketVector* stored_packets = storage_.GetFrame8(frame_id); |
74 if (!stored_packets) | 74 if (!stored_packets) |
75 continue; | 75 continue; |
76 | 76 |
77 for (SendPacketVector::const_iterator it = stored_packets->begin(); | 77 for (SendPacketVector::const_iterator it = stored_packets->begin(); |
78 it != stored_packets->end(); ++it) { | 78 it != stored_packets->end(); ++it) { |
79 const PacketKey& packet_key = it->first; | 79 const PacketKey& packet_key = it->first; |
80 const uint16 packet_id = packet_key.packet_id; | 80 const uint16_t packet_id = packet_key.packet_id; |
81 | 81 |
82 // Should we resend the packet? | 82 // Should we resend the packet? |
83 bool resend = resend_all; | 83 bool resend = resend_all; |
84 | 84 |
85 // Should we resend it because it's in the missing_packet_set? | 85 // Should we resend it because it's in the missing_packet_set? |
86 if (!resend && | 86 if (!resend && |
87 missing_packet_set.find(packet_id) != missing_packet_set.end()) { | 87 missing_packet_set.find(packet_id) != missing_packet_set.end()) { |
88 resend = true; | 88 resend = true; |
89 } | 89 } |
90 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
103 UpdateSequenceNumber(&packet_copy->data); | 103 UpdateSequenceNumber(&packet_copy->data); |
104 packets_to_resend.push_back(std::make_pair(packet_key, packet_copy)); | 104 packets_to_resend.push_back(std::make_pair(packet_key, packet_copy)); |
105 } else if (cancel_rtx_if_not_in_list) { | 105 } else if (cancel_rtx_if_not_in_list) { |
106 transport_->CancelSendingPacket(it->first); | 106 transport_->CancelSendingPacket(it->first); |
107 } | 107 } |
108 } | 108 } |
109 transport_->ResendPackets(packets_to_resend, dedup_info); | 109 transport_->ResendPackets(packets_to_resend, dedup_info); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void RtpSender::CancelSendingFrames(const std::vector<uint32>& frame_ids) { | 113 void RtpSender::CancelSendingFrames(const std::vector<uint32_t>& frame_ids) { |
114 for (std::vector<uint32>::const_iterator i = frame_ids.begin(); | 114 for (std::vector<uint32_t>::const_iterator i = frame_ids.begin(); |
115 i != frame_ids.end(); ++i) { | 115 i != frame_ids.end(); ++i) { |
116 const SendPacketVector* stored_packets = storage_.GetFrame8(*i & 0xFF); | 116 const SendPacketVector* stored_packets = storage_.GetFrame8(*i & 0xFF); |
117 if (!stored_packets) | 117 if (!stored_packets) |
118 continue; | 118 continue; |
119 for (SendPacketVector::const_iterator j = stored_packets->begin(); | 119 for (SendPacketVector::const_iterator j = stored_packets->begin(); |
120 j != stored_packets->end(); ++j) { | 120 j != stored_packets->end(); ++j) { |
121 transport_->CancelSendingPacket(j->first); | 121 transport_->CancelSendingPacket(j->first); |
122 } | 122 } |
123 storage_.ReleaseFrame(*i); | 123 storage_.ReleaseFrame(*i); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 void RtpSender::ResendFrameForKickstart(uint32 frame_id, | 127 void RtpSender::ResendFrameForKickstart(uint32_t frame_id, |
128 base::TimeDelta dedupe_window) { | 128 base::TimeDelta dedupe_window) { |
129 // Send the last packet of the encoded frame to kick start | 129 // Send the last packet of the encoded frame to kick start |
130 // retransmission. This gives enough information to the receiver what | 130 // retransmission. This gives enough information to the receiver what |
131 // packets and frames are missing. | 131 // packets and frames are missing. |
132 MissingFramesAndPacketsMap missing_frames_and_packets; | 132 MissingFramesAndPacketsMap missing_frames_and_packets; |
133 PacketIdSet missing; | 133 PacketIdSet missing; |
134 missing.insert(kRtcpCastLastPacket); | 134 missing.insert(kRtcpCastLastPacket); |
135 missing_frames_and_packets.insert(std::make_pair(frame_id, missing)); | 135 missing_frames_and_packets.insert(std::make_pair(frame_id, missing)); |
136 | 136 |
137 // Sending this extra packet is to kick-start the session. There is | 137 // Sending this extra packet is to kick-start the session. There is |
138 // no need to optimize re-transmission for this case. | 138 // no need to optimize re-transmission for this case. |
139 DedupInfo dedup_info; | 139 DedupInfo dedup_info; |
140 dedup_info.resend_interval = dedupe_window; | 140 dedup_info.resend_interval = dedupe_window; |
141 ResendPackets(missing_frames_and_packets, false, dedup_info); | 141 ResendPackets(missing_frames_and_packets, false, dedup_info); |
142 } | 142 } |
143 | 143 |
144 void RtpSender::UpdateSequenceNumber(Packet* packet) { | 144 void RtpSender::UpdateSequenceNumber(Packet* packet) { |
145 // TODO(miu): This is an abstraction violation. This needs to be a part of | 145 // TODO(miu): This is an abstraction violation. This needs to be a part of |
146 // the overall packet (de)serialization consolidation. | 146 // the overall packet (de)serialization consolidation. |
147 static const int kByteOffsetToSequenceNumber = 2; | 147 static const int kByteOffsetToSequenceNumber = 2; |
148 base::BigEndianWriter big_endian_writer( | 148 base::BigEndianWriter big_endian_writer( |
149 reinterpret_cast<char*>((&packet->front()) + kByteOffsetToSequenceNumber), | 149 reinterpret_cast<char*>((&packet->front()) + kByteOffsetToSequenceNumber), |
150 sizeof(uint16)); | 150 sizeof(uint16_t)); |
151 big_endian_writer.WriteU16(packetizer_->NextSequenceNumber()); | 151 big_endian_writer.WriteU16(packetizer_->NextSequenceNumber()); |
152 } | 152 } |
153 | 153 |
154 int64 RtpSender::GetLastByteSentForFrame(uint32 frame_id) { | 154 int64_t RtpSender::GetLastByteSentForFrame(uint32_t frame_id) { |
155 const SendPacketVector* stored_packets = storage_.GetFrame8(frame_id & 0xFF); | 155 const SendPacketVector* stored_packets = storage_.GetFrame8(frame_id & 0xFF); |
156 if (!stored_packets) | 156 if (!stored_packets) |
157 return 0; | 157 return 0; |
158 PacketKey last_packet_key = stored_packets->rbegin()->first; | 158 PacketKey last_packet_key = stored_packets->rbegin()->first; |
159 return transport_->GetLastByteSentForPacket(last_packet_key); | 159 return transport_->GetLastByteSentForPacket(last_packet_key); |
160 } | 160 } |
161 | 161 |
162 } // namespace cast | 162 } // namespace cast |
163 } // namespace media | 163 } // namespace media |
OLD | NEW |