| 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/debug/dump_without_crashing.h" | 9 #include "base/debug/dump_without_crashing.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 namespace cast { | 13 namespace cast { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 static const int64 kPacingIntervalMs = 10; | 17 static const int64_t kPacingIntervalMs = 10; |
| 18 // Each frame will be split into no more than kPacingMaxBurstsPerFrame | 18 // Each frame will be split into no more than kPacingMaxBurstsPerFrame |
| 19 // bursts of packets. | 19 // bursts of packets. |
| 20 static const size_t kPacingMaxBurstsPerFrame = 3; | 20 static const size_t kPacingMaxBurstsPerFrame = 3; |
| 21 static const size_t kMaxDedupeWindowMs = 500; | 21 static const size_t kMaxDedupeWindowMs = 500; |
| 22 | 22 |
| 23 // "Impossible" upper-bound on the maximum number of packets that should ever be | 23 // "Impossible" upper-bound on the maximum number of packets that should ever be |
| 24 // enqueued in the pacer. This is used to detect bugs, reported as crash dumps. | 24 // enqueued in the pacer. This is used to detect bugs, reported as crash dumps. |
| 25 static const size_t kHugeQueueLengthSeconds = 10; | 25 static const size_t kHugeQueueLengthSeconds = 10; |
| 26 static const size_t kRidiculousNumberOfPackets = | 26 static const size_t kRidiculousNumberOfPackets = |
| 27 kHugeQueueLengthSeconds * (kMaxBurstSize * 1000 / kPacingIntervalMs); | 27 kHugeQueueLengthSeconds * (kMaxBurstSize * 1000 / kPacingIntervalMs); |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 DedupInfo::DedupInfo() : last_byte_acked_for_audio(0) {} | 31 DedupInfo::DedupInfo() : last_byte_acked_for_audio(0) {} |
| 32 | 32 |
| 33 // static | 33 // static |
| 34 PacketKey PacedPacketSender::MakePacketKey(PacketKey::PacketType packet_type, | 34 PacketKey PacedPacketSender::MakePacketKey(PacketKey::PacketType packet_type, |
| 35 uint32 frame_id, | 35 uint32_t frame_id, |
| 36 uint32 ssrc, | 36 uint32_t ssrc, |
| 37 uint16 packet_id) { | 37 uint16_t packet_id) { |
| 38 PacketKey key{packet_type, frame_id, ssrc, packet_id}; | 38 PacketKey key{packet_type, frame_id, ssrc, packet_id}; |
| 39 return key; | 39 return key; |
| 40 } | 40 } |
| 41 | 41 |
| 42 PacedSender::PacketSendRecord::PacketSendRecord() | 42 PacedSender::PacketSendRecord::PacketSendRecord() |
| 43 : last_byte_sent(0), last_byte_sent_for_audio(0) {} | 43 : last_byte_sent(0), last_byte_sent_for_audio(0) {} |
| 44 | 44 |
| 45 PacedSender::PacedSender( | 45 PacedSender::PacedSender( |
| 46 size_t target_burst_size, | 46 size_t target_burst_size, |
| 47 size_t max_burst_size, | 47 size_t max_burst_size, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 current_max_burst_size_(target_burst_size_), | 60 current_max_burst_size_(target_burst_size_), |
| 61 next_max_burst_size_(target_burst_size_), | 61 next_max_burst_size_(target_burst_size_), |
| 62 next_next_max_burst_size_(target_burst_size_), | 62 next_next_max_burst_size_(target_burst_size_), |
| 63 current_burst_size_(0), | 63 current_burst_size_(0), |
| 64 state_(State_Unblocked), | 64 state_(State_Unblocked), |
| 65 has_reached_upper_bound_once_(false), | 65 has_reached_upper_bound_once_(false), |
| 66 weak_factory_(this) {} | 66 weak_factory_(this) {} |
| 67 | 67 |
| 68 PacedSender::~PacedSender() {} | 68 PacedSender::~PacedSender() {} |
| 69 | 69 |
| 70 void PacedSender::RegisterAudioSsrc(uint32 audio_ssrc) { | 70 void PacedSender::RegisterAudioSsrc(uint32_t audio_ssrc) { |
| 71 audio_ssrc_ = audio_ssrc; | 71 audio_ssrc_ = audio_ssrc; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void PacedSender::RegisterVideoSsrc(uint32 video_ssrc) { | 74 void PacedSender::RegisterVideoSsrc(uint32_t video_ssrc) { |
| 75 video_ssrc_ = video_ssrc; | 75 video_ssrc_ = video_ssrc; |
| 76 } | 76 } |
| 77 | 77 |
| 78 void PacedSender::RegisterPrioritySsrc(uint32 ssrc) { | 78 void PacedSender::RegisterPrioritySsrc(uint32_t ssrc) { |
| 79 priority_ssrcs_.push_back(ssrc); | 79 priority_ssrcs_.push_back(ssrc); |
| 80 } | 80 } |
| 81 | 81 |
| 82 int64 PacedSender::GetLastByteSentForPacket(const PacketKey& packet_key) { | 82 int64_t PacedSender::GetLastByteSentForPacket(const PacketKey& packet_key) { |
| 83 PacketSendHistory::const_iterator it = send_history_.find(packet_key); | 83 PacketSendHistory::const_iterator it = send_history_.find(packet_key); |
| 84 if (it == send_history_.end()) | 84 if (it == send_history_.end()) |
| 85 return 0; | 85 return 0; |
| 86 return it->second.last_byte_sent; | 86 return it->second.last_byte_sent; |
| 87 } | 87 } |
| 88 | 88 |
| 89 int64 PacedSender::GetLastByteSentForSsrc(uint32 ssrc) { | 89 int64_t PacedSender::GetLastByteSentForSsrc(uint32_t ssrc) { |
| 90 std::map<uint32, int64>::const_iterator it = last_byte_sent_.find(ssrc); | 90 std::map<uint32_t, int64_t>::const_iterator it = last_byte_sent_.find(ssrc); |
| 91 if (it == last_byte_sent_.end()) | 91 if (it == last_byte_sent_.end()) |
| 92 return 0; | 92 return 0; |
| 93 return it->second; | 93 return it->second; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool PacedSender::SendPackets(const SendPacketVector& packets) { | 96 bool PacedSender::SendPackets(const SendPacketVector& packets) { |
| 97 if (packets.empty()) { | 97 if (packets.empty()) { |
| 98 return true; | 98 return true; |
| 99 } | 99 } |
| 100 const bool high_priority = IsHighPriority(packets.begin()->first); | 100 const bool high_priority = IsHighPriority(packets.begin()->first); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 packet_list_[packets[i].first] = | 162 packet_list_[packets[i].first] = |
| 163 make_pair(PacketType_Resend, packets[i].second); | 163 make_pair(PacketType_Resend, packets[i].second); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 if (state_ == State_Unblocked) { | 166 if (state_ == State_Unblocked) { |
| 167 SendStoredPackets(); | 167 SendStoredPackets(); |
| 168 } | 168 } |
| 169 return true; | 169 return true; |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool PacedSender::SendRtcpPacket(uint32 ssrc, PacketRef packet) { | 172 bool PacedSender::SendRtcpPacket(uint32_t ssrc, PacketRef packet) { |
| 173 if (state_ == State_TransportBlocked) { | 173 if (state_ == State_TransportBlocked) { |
| 174 PacketKey key = | 174 PacketKey key = |
| 175 PacedPacketSender::MakePacketKey(PacketKey::RTCP, 0, ssrc, 0); | 175 PacedPacketSender::MakePacketKey(PacketKey::RTCP, 0, ssrc, 0); |
| 176 priority_packet_list_[key] = make_pair(PacketType_RTCP, packet); | 176 priority_packet_list_[key] = make_pair(PacketType_RTCP, packet); |
| 177 } else { | 177 } else { |
| 178 // We pass the RTCP packets straight through. | 178 // We pass the RTCP packets straight through. |
| 179 if (!transport_->SendPacket( | 179 if (!transport_->SendPacket( |
| 180 packet, | 180 packet, |
| 181 base::Bind(&PacedSender::SendStoredPackets, | 181 base::Bind(&PacedSender::SendStoredPackets, |
| 182 weak_factory_.GetWeakPtr()))) { | 182 weak_factory_.GetWeakPtr()))) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 // Populate the new PacketEvent by parsing the wire-format |packet|. | 330 // Populate the new PacketEvent by parsing the wire-format |packet|. |
| 331 // | 331 // |
| 332 // TODO(miu): This parsing logic belongs in RtpParser. | 332 // TODO(miu): This parsing logic belongs in RtpParser. |
| 333 event.timestamp = clock_->NowTicks(); | 333 event.timestamp = clock_->NowTicks(); |
| 334 event.type = type; | 334 event.type = type; |
| 335 base::BigEndianReader reader(reinterpret_cast<const char*>(&packet[0]), | 335 base::BigEndianReader reader(reinterpret_cast<const char*>(&packet[0]), |
| 336 packet.size()); | 336 packet.size()); |
| 337 bool success = reader.Skip(4); | 337 bool success = reader.Skip(4); |
| 338 success &= reader.ReadU32(&event.rtp_timestamp); | 338 success &= reader.ReadU32(&event.rtp_timestamp); |
| 339 uint32 ssrc; | 339 uint32_t ssrc; |
| 340 success &= reader.ReadU32(&ssrc); | 340 success &= reader.ReadU32(&ssrc); |
| 341 if (ssrc == audio_ssrc_) { | 341 if (ssrc == audio_ssrc_) { |
| 342 event.media_type = AUDIO_EVENT; | 342 event.media_type = AUDIO_EVENT; |
| 343 } else if (ssrc == video_ssrc_) { | 343 } else if (ssrc == video_ssrc_) { |
| 344 event.media_type = VIDEO_EVENT; | 344 event.media_type = VIDEO_EVENT; |
| 345 } else { | 345 } else { |
| 346 DVLOG(3) << "Got unknown ssrc " << ssrc << " when logging packet event"; | 346 DVLOG(3) << "Got unknown ssrc " << ssrc << " when logging packet event"; |
| 347 return; | 347 return; |
| 348 } | 348 } |
| 349 success &= reader.Skip(2); | 349 success &= reader.Skip(2); |
| 350 success &= reader.ReadU16(&event.packet_id); | 350 success &= reader.ReadU16(&event.packet_id); |
| 351 success &= reader.ReadU16(&event.max_packet_id); | 351 success &= reader.ReadU16(&event.max_packet_id); |
| 352 event.size = packet.size(); | 352 event.size = packet.size(); |
| 353 DCHECK(success); | 353 DCHECK(success); |
| 354 } | 354 } |
| 355 | 355 |
| 356 } // namespace cast | 356 } // namespace cast |
| 357 } // namespace media | 357 } // namespace media |
| OLD | NEW |