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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 packetizer_.reset(new RtpPacketizer(transport_, storage_.get(), config_)); | 67 packetizer_.reset(new RtpPacketizer(transport_, storage_.get(), config_)); |
68 return true; | 68 return true; |
69 } | 69 } |
70 | 70 |
71 void RtpSender::SendFrame(const EncodedFrame& frame) { | 71 void RtpSender::SendFrame(const EncodedFrame& frame) { |
72 DCHECK(packetizer_); | 72 DCHECK(packetizer_); |
73 packetizer_->SendFrameAsPackets(frame); | 73 packetizer_->SendFrameAsPackets(frame); |
74 } | 74 } |
75 | 75 |
76 void RtpSender::ResendPackets( | 76 void RtpSender::ResendPackets( |
77 const MissingFramesAndPacketsMap& missing_frames_and_packets) { | 77 const MissingFramesAndPacketsMap& missing_frames_and_packets, |
| 78 bool cancel_rtx_if_not_in_list) { |
78 DCHECK(storage_); | 79 DCHECK(storage_); |
79 // Iterate over all frames in the list. | 80 // Iterate over all frames in the list. |
80 for (MissingFramesAndPacketsMap::const_iterator it = | 81 for (MissingFramesAndPacketsMap::const_iterator it = |
81 missing_frames_and_packets.begin(); | 82 missing_frames_and_packets.begin(); |
82 it != missing_frames_and_packets.end(); | 83 it != missing_frames_and_packets.end(); |
83 ++it) { | 84 ++it) { |
84 SendPacketVector packets_to_resend; | 85 SendPacketVector packets_to_resend; |
85 uint8 frame_id = it->first; | 86 uint8 frame_id = it->first; |
86 // Set of packets that the receiver wants us to re-send. | 87 // Set of packets that the receiver wants us to re-send. |
87 // If empty, we need to re-send all packets for this frame. | 88 // If empty, we need to re-send all packets for this frame. |
88 const PacketIdSet& missing_packet_set = it->second; | 89 const PacketIdSet& missing_packet_set = it->second; |
89 | 90 |
90 const SendPacketVector* stored_packets = storage_->GetFrame8(frame_id); | 91 const SendPacketVector* stored_packets = storage_->GetFrame8(frame_id); |
91 if (!stored_packets) | 92 if (!stored_packets) |
92 continue; | 93 continue; |
93 | 94 |
94 for (SendPacketVector::const_iterator it = stored_packets->begin(); | 95 for (SendPacketVector::const_iterator it = stored_packets->begin(); |
95 it != stored_packets->end(); ++it) { | 96 it != stored_packets->end(); ++it) { |
96 const PacketKey& packet_key = it->first; | 97 const PacketKey& packet_key = it->first; |
97 const uint16 packet_id = packet_key.second.second; | 98 const uint16 packet_id = packet_key.second.second; |
98 | 99 |
99 // If the resend request doesn't include this packet then cancel | 100 // If the resend request doesn't include this packet then cancel |
100 // re-transmission already in queue. | 101 // re-transmission already in queue. |
101 if (!missing_packet_set.empty() && | 102 if (cancel_rtx_if_not_in_list && |
| 103 !missing_packet_set.empty() && |
102 missing_packet_set.find(packet_id) == missing_packet_set.end()) { | 104 missing_packet_set.find(packet_id) == missing_packet_set.end()) { |
103 transport_->CancelSendingPacket(it->first); | 105 transport_->CancelSendingPacket(it->first); |
104 } else { | 106 } else { |
105 // Resend packet to the network. | 107 // Resend packet to the network. |
106 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" | 108 VLOG(3) << "Resend " << static_cast<int>(frame_id) << ":" |
107 << packet_id; | 109 << packet_id; |
108 // Set a unique incremental sequence number for every packet. | 110 // Set a unique incremental sequence number for every packet. |
109 PacketRef packet_copy = FastCopyPacket(it->second); | 111 PacketRef packet_copy = FastCopyPacket(it->second); |
110 UpdateSequenceNumber(&packet_copy->data); | 112 UpdateSequenceNumber(&packet_copy->data); |
111 packets_to_resend.push_back(std::make_pair(packet_key, packet_copy)); | 113 packets_to_resend.push_back(std::make_pair(packet_key, packet_copy)); |
112 } | 114 } |
113 } | 115 } |
114 transport_->ResendPackets(packets_to_resend); | 116 transport_->ResendPackets(packets_to_resend); |
115 } | 117 } |
116 } | 118 } |
117 | 119 |
118 void RtpSender::UpdateSequenceNumber(Packet* packet) { | 120 void RtpSender::UpdateSequenceNumber(Packet* packet) { |
119 uint16 new_sequence_number = packetizer_->NextSequenceNumber(); | 121 uint16 new_sequence_number = packetizer_->NextSequenceNumber(); |
120 int index = 2; | 122 int index = 2; |
121 (*packet)[index] = (static_cast<uint8>(new_sequence_number)); | 123 (*packet)[index] = (static_cast<uint8>(new_sequence_number)); |
122 (*packet)[index + 1] = (static_cast<uint8>(new_sequence_number >> 8)); | 124 (*packet)[index + 1] = (static_cast<uint8>(new_sequence_number >> 8)); |
123 } | 125 } |
124 | 126 |
125 } // namespace transport | 127 } // namespace transport |
126 } // namespace cast | 128 } // namespace cast |
127 } // namespace media | 129 } // namespace media |
OLD | NEW |