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/pacing/paced_sender.h" | 5 #include "media/cast/net/pacing/paced_sender.h" |
6 | 6 |
7 #include "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "media/cast/logging/logging_impl.h" | 10 #include "media/cast/logging/logging_impl.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 PacedSender::~PacedSender() {} | 53 PacedSender::~PacedSender() {} |
54 | 54 |
55 void PacedSender::RegisterAudioSsrc(uint32 audio_ssrc) { | 55 void PacedSender::RegisterAudioSsrc(uint32 audio_ssrc) { |
56 audio_ssrc_ = audio_ssrc; | 56 audio_ssrc_ = audio_ssrc; |
57 } | 57 } |
58 | 58 |
59 void PacedSender::RegisterVideoSsrc(uint32 video_ssrc) { | 59 void PacedSender::RegisterVideoSsrc(uint32 video_ssrc) { |
60 video_ssrc_ = video_ssrc; | 60 video_ssrc_ = video_ssrc; |
61 } | 61 } |
62 | 62 |
63 void PacedSender::RegisterPrioritySsrc(uint32 ssrc) { | |
64 priority_ssrcs_.push_back(ssrc); | |
65 } | |
66 | |
63 bool PacedSender::SendPackets(const SendPacketVector& packets) { | 67 bool PacedSender::SendPackets(const SendPacketVector& packets) { |
64 if (packets.empty()) { | 68 if (packets.empty()) { |
65 return true; | 69 return true; |
66 } | 70 } |
67 for (size_t i = 0; i < packets.size(); i++) { | 71 for (size_t i = 0; i < packets.size(); i++) { |
68 packet_list_[packets[i].first] = | 72 if (IsHighPriority(packets[i].first)) { |
miu
2014/07/16 22:55:55
Will a SendPacketVector ever contain packets from
Alpha Left Google
2014/07/17 00:12:56
Done.
| |
69 make_pair(PacketType_Normal, packets[i].second); | 73 priority_packet_list_[packets[i].first] = |
74 make_pair(PacketType_Normal, packets[i].second); | |
75 } else { | |
76 packet_list_[packets[i].first] = | |
77 make_pair(PacketType_Normal, packets[i].second); | |
78 } | |
70 } | 79 } |
71 if (state_ == State_Unblocked) { | 80 if (state_ == State_Unblocked) { |
72 SendStoredPackets(); | 81 SendStoredPackets(); |
73 } | 82 } |
74 return true; | 83 return true; |
75 } | 84 } |
76 | 85 |
77 bool PacedSender::ResendPackets(const SendPacketVector& packets, | 86 bool PacedSender::ResendPackets(const SendPacketVector& packets, |
78 base::TimeDelta dedupe_window) { | 87 base::TimeDelta dedupe_window) { |
79 if (packets.empty()) { | 88 if (packets.empty()) { |
80 return true; | 89 return true; |
81 } | 90 } |
82 base::TimeTicks now = clock_->NowTicks(); | 91 base::TimeTicks now = clock_->NowTicks(); |
83 for (size_t i = 0; i < packets.size(); i++) { | 92 for (size_t i = 0; i < packets.size(); i++) { |
84 std::map<PacketKey, base::TimeTicks>::const_iterator j = | 93 std::map<PacketKey, base::TimeTicks>::const_iterator j = |
85 sent_time_.find(packets[i].first); | 94 sent_time_.find(packets[i].first); |
86 | 95 |
87 if (j != sent_time_.end() && now - j->second < dedupe_window) { | 96 if (j != sent_time_.end() && now - j->second < dedupe_window) { |
88 LogPacketEvent(packets[i].second->data, PACKET_RTX_REJECTED); | 97 LogPacketEvent(packets[i].second->data, PACKET_RTX_REJECTED); |
89 continue; | 98 continue; |
90 } | 99 } |
91 | 100 |
92 packet_list_[packets[i].first] = | 101 if (IsHighPriority(packets[i].first)) { |
miu
2014/07/16 22:55:55
ditto re: redundant IsHighPriority() calls.
Alpha Left Google
2014/07/17 00:12:56
Done.
| |
93 make_pair(PacketType_Resend, packets[i].second); | 102 priority_packet_list_[packets[i].first] = |
103 make_pair(PacketType_Resend, packets[i].second); | |
104 } else { | |
105 packet_list_[packets[i].first] = | |
106 make_pair(PacketType_Resend, packets[i].second); | |
107 } | |
94 } | 108 } |
95 if (state_ == State_Unblocked) { | 109 if (state_ == State_Unblocked) { |
96 SendStoredPackets(); | 110 SendStoredPackets(); |
97 } | 111 } |
98 return true; | 112 return true; |
99 } | 113 } |
100 | 114 |
101 bool PacedSender::SendRtcpPacket(uint32 ssrc, PacketRef packet) { | 115 bool PacedSender::SendRtcpPacket(uint32 ssrc, PacketRef packet) { |
102 if (state_ == State_TransportBlocked) { | 116 if (state_ == State_TransportBlocked) { |
103 packet_list_[PacedPacketSender::MakePacketKey(base::TimeTicks(), ssrc, 0)] = | 117 priority_packet_list_[ |
118 PacedPacketSender::MakePacketKey(base::TimeTicks(), ssrc, 0)] = | |
104 make_pair(PacketType_RTCP, packet); | 119 make_pair(PacketType_RTCP, packet); |
105 } else { | 120 } else { |
106 // We pass the RTCP packets straight through. | 121 // We pass the RTCP packets straight through. |
107 if (!transport_->SendPacket( | 122 if (!transport_->SendPacket( |
108 packet, | 123 packet, |
109 base::Bind(&PacedSender::SendStoredPackets, | 124 base::Bind(&PacedSender::SendStoredPackets, |
110 weak_factory_.GetWeakPtr()))) { | 125 weak_factory_.GetWeakPtr()))) { |
111 state_ = State_TransportBlocked; | 126 state_ = State_TransportBlocked; |
112 } | 127 } |
113 | |
114 } | 128 } |
115 return true; | 129 return true; |
116 } | 130 } |
117 | 131 |
118 void PacedSender::CancelSendingPacket(const PacketKey& packet_key) { | 132 void PacedSender::CancelSendingPacket(const PacketKey& packet_key) { |
119 packet_list_.erase(packet_key); | 133 packet_list_.erase(packet_key); |
134 priority_packet_list_.erase(packet_key); | |
120 } | 135 } |
121 | 136 |
122 PacketRef PacedSender::GetNextPacket(PacketType* packet_type, | 137 PacketRef PacedSender::GetNextPacket(PacketType* packet_type, |
miu
2014/07/16 22:55:56
naming: This method should be called PopNextPacket
Alpha Left Google
2014/07/17 00:12:56
Done.
| |
123 PacketKey* packet_key) { | 138 PacketKey* packet_key) { |
124 std::map<PacketKey, std::pair<PacketType, PacketRef> >::iterator i; | 139 DCHECK(!priority_packet_list_.empty() || |
miu
2014/07/16 22:55:56
Don't need this DCHECK, since the one a few lines
Alpha Left Google
2014/07/17 00:12:56
Done.
| |
125 i = packet_list_.begin(); | 140 !packet_list_.empty()); |
126 DCHECK(i != packet_list_.end()); | 141 PacketList* list = !priority_packet_list_.empty() ? |
142 &priority_packet_list_ : &packet_list_; | |
143 DCHECK(!list->empty()); | |
144 PacketList::iterator i; | |
145 i = list->begin(); | |
miu
2014/07/16 22:55:55
Please merge this with the line above.
Alpha Left Google
2014/07/17 00:12:56
Done.
| |
127 *packet_type = i->second.first; | 146 *packet_type = i->second.first; |
128 *packet_key = i->first; | 147 *packet_key = i->first; |
129 PacketRef ret = i->second.second; | 148 PacketRef ret = i->second.second; |
130 packet_list_.erase(i); | 149 list->erase(i); |
131 return ret; | 150 return ret; |
132 } | 151 } |
133 | 152 |
153 bool PacedSender::IsHighPriority(const PacketKey& packet_key) const { | |
154 return std::find(priority_ssrcs_.begin(), priority_ssrcs_.end(), | |
155 packet_key.second.first) != priority_ssrcs_.end(); | |
156 } | |
157 | |
134 bool PacedSender::empty() const { | 158 bool PacedSender::empty() const { |
135 return packet_list_.empty(); | 159 return packet_list_.empty() && priority_packet_list_.empty(); |
136 } | 160 } |
137 | 161 |
138 size_t PacedSender::size() const { | 162 size_t PacedSender::size() const { |
139 return packet_list_.size(); | 163 return packet_list_.size() + priority_packet_list_.size(); |
140 } | 164 } |
141 | 165 |
142 // This function can be called from three places: | 166 // This function can be called from three places: |
143 // 1. User called one of the Send* functions and we were in an unblocked state. | 167 // 1. User called one of the Send* functions and we were in an unblocked state. |
144 // 2. state_ == State_TransportBlocked and the transport is calling us to | 168 // 2. state_ == State_TransportBlocked and the transport is calling us to |
145 // let us know that it's ok to send again. | 169 // let us know that it's ok to send again. |
146 // 3. state_ == State_BurstFull and there are still packets to send. In this | 170 // 3. state_ == State_BurstFull and there are still packets to send. In this |
147 // case we called PostDelayedTask on this function to start a new burst. | 171 // case we called PostDelayedTask on this function to start a new burst. |
148 void PacedSender::SendStoredPackets() { | 172 void PacedSender::SendStoredPackets() { |
149 State previous_state = state_; | 173 State previous_state = state_; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 return; | 274 return; |
251 } | 275 } |
252 | 276 |
253 EventMediaType media_type = is_audio ? AUDIO_EVENT : VIDEO_EVENT; | 277 EventMediaType media_type = is_audio ? AUDIO_EVENT : VIDEO_EVENT; |
254 logging_->InsertSinglePacketEvent(clock_->NowTicks(), event, media_type, | 278 logging_->InsertSinglePacketEvent(clock_->NowTicks(), event, media_type, |
255 packet); | 279 packet); |
256 } | 280 } |
257 | 281 |
258 } // namespace cast | 282 } // namespace cast |
259 } // namespace media | 283 } // namespace media |
OLD | NEW |