Chromium Code Reviews| 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 const PacketIdSet& packets_set = it->second; | 73 const PacketIdSet& packets_set = it->second; |
| 74 bool success = false; | 74 bool success = false; |
| 75 | 75 |
| 76 if (packets_set.empty()) { | 76 for (uint16 packet_id = 0; ; packet_id++) { |
| 77 VLOG(3) << "Missing all packets in frame " << static_cast<int>(frame_id); | 77 // Get packet from storage. |
| 78 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | |
| 78 | 79 |
| 79 uint16 packet_id = 0; | 80 // Check that we got at least one packet. |
| 80 do { | 81 DCHECK(packet_id != 0 || success) |
| 81 // Get packet from storage. | 82 << "Failed to resend frame " << static_cast<int>(frame_id); |
| 82 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | |
| 83 | 83 |
| 84 // Check that we got at least one packet. | 84 if (!success) break; |
| 85 DCHECK(packet_id != 0 || success) | |
| 86 << "Failed to resend frame " << static_cast<int>(frame_id); | |
| 87 | 85 |
| 86 if (!packets_set.empty() && | |
|
miu
2014/05/29 20:28:34
I'm a little confused about the semantics of |pack
hubbe
2014/05/29 20:46:22
Better?
| |
| 87 packets_set.find(packet_id) == packets_set.end()) { | |
| 88 transport_->CancelSendingPacket(packets_to_resend.back().first); | |
| 89 packets_to_resend.pop_back(); | |
| 90 } else { | |
| 88 // Resend packet to the network. | 91 // Resend packet to the network. |
| 89 if (success) { | 92 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" |
| 90 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" | 93 << packet_id; |
| 91 << packet_id; | 94 // Set a unique incremental sequence number for every packet. |
| 92 // Set a unique incremental sequence number for every packet. | 95 PacketRef packet = packets_to_resend.back().second; |
| 93 PacketRef packet = packets_to_resend.back().second; | 96 UpdateSequenceNumber(&packet->data); |
| 94 UpdateSequenceNumber(&packet->data); | |
| 95 // Set the size as correspond to each frame. | |
| 96 ++packet_id; | |
| 97 } | |
| 98 } while (success); | |
| 99 } else { | |
| 100 // Iterate over all of the packets in the frame. | |
| 101 for (PacketIdSet::const_iterator set_it = packets_set.begin(); | |
| 102 set_it != packets_set.end(); | |
| 103 ++set_it) { | |
| 104 uint16 packet_id = *set_it; | |
| 105 success = storage_->GetPacket(frame_id, packet_id, &packets_to_resend); | |
| 106 | |
| 107 // Check that we got at least one packet. | |
| 108 DCHECK(set_it != packets_set.begin() || success) | |
| 109 << "Failed to resend frame " << frame_id; | |
| 110 | |
| 111 // Resend packet to the network. | |
| 112 if (success) { | |
| 113 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" | |
| 114 << packet_id; | |
| 115 PacketRef packet = packets_to_resend.back().second; | |
| 116 UpdateSequenceNumber(&packet->data); | |
| 117 } | |
| 118 } | 97 } |
| 119 } | 98 } |
| 120 transport_->ResendPackets(packets_to_resend); | 99 transport_->ResendPackets(packets_to_resend); |
| 121 } | 100 } |
| 122 } | 101 } |
| 123 | 102 |
| 124 void RtpSender::UpdateSequenceNumber(Packet* packet) { | 103 void RtpSender::UpdateSequenceNumber(Packet* packet) { |
| 125 uint16 new_sequence_number = packetizer_->NextSequenceNumber(); | 104 uint16 new_sequence_number = packetizer_->NextSequenceNumber(); |
| 126 int index = 2; | 105 int index = 2; |
| 127 (*packet)[index] = (static_cast<uint8>(new_sequence_number)); | 106 (*packet)[index] = (static_cast<uint8>(new_sequence_number)); |
| 128 (*packet)[index + 1] = (static_cast<uint8>(new_sequence_number >> 8)); | 107 (*packet)[index + 1] = (static_cast<uint8>(new_sequence_number >> 8)); |
| 129 } | 108 } |
| 130 | 109 |
| 131 } // namespace transport | 110 } // namespace transport |
| 132 } // namespace cast | 111 } // namespace cast |
| 133 } // namespace media | 112 } // namespace media |
| OLD | NEW |