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/transport/rtp_sender/rtp_sender.h" | 5 #include "media/cast/transport/rtp_sender/rtp_sender.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "media/cast/transport/cast_transport_defines.h" | 9 #include "media/cast/transport/cast_transport_defines.h" |
10 #include "media/cast/transport/pacing/paced_sender.h" | 10 #include "media/cast/transport/pacing/paced_sender.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // Iterate over all frames in the list. | 66 // Iterate over all frames in the list. |
67 for (MissingFramesAndPacketsMap::const_iterator it = | 67 for (MissingFramesAndPacketsMap::const_iterator it = |
68 missing_frames_and_packets.begin(); | 68 missing_frames_and_packets.begin(); |
69 it != missing_frames_and_packets.end(); | 69 it != missing_frames_and_packets.end(); |
70 ++it) { | 70 ++it) { |
71 SendPacketVector packets_to_resend; | 71 SendPacketVector packets_to_resend; |
72 uint8 frame_id = it->first; | 72 uint8 frame_id = it->first; |
73 // Set of packets that the receiver wants us to re-send. | 73 // Set of packets that the receiver wants us to re-send. |
74 // If empty, we need to re-send all packets for this frame. | 74 // If empty, we need to re-send all packets for this frame. |
75 const PacketIdSet& missing_packet_set = it->second; | 75 const PacketIdSet& missing_packet_set = it->second; |
76 bool success = false; | |
77 | 76 |
78 for (uint16 packet_id = 0; ; packet_id++) { | 77 const SendPacketVector* stored_packets = storage_->GetFrame8(frame_id); |
79 // Get packet from storage. | 78 if (!stored_packets) |
80 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | 79 continue; |
81 | 80 |
82 // Check that we got at least one packet. | 81 for (SendPacketVector::const_iterator it = stored_packets->begin(); |
83 DCHECK(packet_id != 0 || success) | 82 it != stored_packets->end(); ++it) { |
84 << "Failed to resend frame " << static_cast<int>(frame_id); | 83 const PacketKey& packet_key = it->first; |
84 const uint16 packet_id = packet_key.second.second; | |
85 | 85 |
86 if (!success) break; | 86 // If the resend request doesn't include this packet then cancel |
87 | 87 // re-transmission already in queue. |
88 if (!missing_packet_set.empty() && | 88 if (!missing_packet_set.empty() && |
89 missing_packet_set.find(packet_id) == missing_packet_set.end()) { | 89 missing_packet_set.find(packet_id) == missing_packet_set.end()) { |
90 transport_->CancelSendingPacket(packets_to_resend.back().first); | 90 transport_->CancelSendingPacket(it->first); |
91 packets_to_resend.pop_back(); | |
92 } else { | 91 } else { |
93 // Resend packet to the network. | 92 // Resend packet to the network. |
94 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" | 93 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" |
95 << packet_id; | 94 << packet_id; |
96 // Set a unique incremental sequence number for every packet. | 95 // Set a unique incremental sequence number for every packet. |
97 PacketRef packet = packets_to_resend.back().second; | 96 PacketRef packet_copy = PacketStorage::FastCopyPacket(it->second); |
miu
2014/06/07 00:59:42
Dumb question: Why would we ever want a deep copy
Alpha Left Google
2014/06/07 01:15:09
Because the pacer could have one shallow in the qu
miu
2014/06/07 02:00:09
Okay. We can clean this up in a later change. It
| |
98 UpdateSequenceNumber(&packet->data); | 97 UpdateSequenceNumber(&packet_copy->data); |
98 packets_to_resend.push_back(std::make_pair(packet_key, packet_copy)); | |
99 } | 99 } |
100 } | 100 } |
101 transport_->ResendPackets(packets_to_resend); | 101 transport_->ResendPackets(packets_to_resend); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 void RtpSender::UpdateSequenceNumber(Packet* packet) { | 105 void RtpSender::UpdateSequenceNumber(Packet* packet) { |
106 uint16 new_sequence_number = packetizer_->NextSequenceNumber(); | 106 uint16 new_sequence_number = packetizer_->NextSequenceNumber(); |
107 int index = 2; | 107 int index = 2; |
108 (*packet)[index] = (static_cast<uint8>(new_sequence_number)); | 108 (*packet)[index] = (static_cast<uint8>(new_sequence_number)); |
109 (*packet)[index + 1] = (static_cast<uint8>(new_sequence_number >> 8)); | 109 (*packet)[index + 1] = (static_cast<uint8>(new_sequence_number >> 8)); |
110 } | 110 } |
111 | 111 |
112 } // namespace transport | 112 } // namespace transport |
113 } // namespace cast | 113 } // namespace cast |
114 } // namespace media | 114 } // namespace media |
OLD | NEW |