OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... | |
40 namespace webrtc { | 40 namespace webrtc { |
41 namespace paced_sender { | 41 namespace paced_sender { |
42 struct Packet { | 42 struct Packet { |
43 Packet(RtpPacketSender::Priority priority, | 43 Packet(RtpPacketSender::Priority priority, |
44 uint32_t ssrc, | 44 uint32_t ssrc, |
45 uint16_t seq_number, | 45 uint16_t seq_number, |
46 int64_t capture_time_ms, | 46 int64_t capture_time_ms, |
47 int64_t enqueue_time_ms, | 47 int64_t enqueue_time_ms, |
48 size_t length_in_bytes, | 48 size_t length_in_bytes, |
49 bool retransmission, | 49 bool retransmission, |
50 uint64_t enqueue_order) | 50 uint64_t enqueue_order, |
51 int cluster_id = -1) | |
danilchap
2016/05/10 15:31:39
try to avoid default arguments. Here it is easy: c
philipel
2016/05/11 09:39:16
Removed default argument, |cluster_id| is not init
| |
51 : priority(priority), | 52 : priority(priority), |
52 ssrc(ssrc), | 53 ssrc(ssrc), |
53 sequence_number(seq_number), | 54 sequence_number(seq_number), |
54 capture_time_ms(capture_time_ms), | 55 capture_time_ms(capture_time_ms), |
55 enqueue_time_ms(enqueue_time_ms), | 56 enqueue_time_ms(enqueue_time_ms), |
56 bytes(length_in_bytes), | 57 bytes(length_in_bytes), |
57 retransmission(retransmission), | 58 retransmission(retransmission), |
58 enqueue_order(enqueue_order) {} | 59 enqueue_order(enqueue_order), |
60 cluster_id(cluster_id) {} | |
59 | 61 |
60 RtpPacketSender::Priority priority; | 62 RtpPacketSender::Priority priority; |
61 uint32_t ssrc; | 63 uint32_t ssrc; |
62 uint16_t sequence_number; | 64 uint16_t sequence_number; |
63 int64_t capture_time_ms; | 65 int64_t capture_time_ms; |
64 int64_t enqueue_time_ms; | 66 int64_t enqueue_time_ms; |
65 size_t bytes; | 67 size_t bytes; |
66 bool retransmission; | 68 bool retransmission; |
67 uint64_t enqueue_order; | 69 uint64_t enqueue_order; |
68 std::list<Packet>::iterator this_it; | 70 std::list<Packet>::iterator this_it; |
71 int cluster_id; | |
danilchap
2016/05/10 15:31:39
may be instead of modifying Packet structure, usin
philipel
2016/05/11 09:39:16
I agree, removed |cluster_id| From Packet class.
| |
69 }; | 72 }; |
70 | 73 |
71 // Used by priority queue to sort packets. | 74 // Used by priority queue to sort packets. |
72 struct Comparator { | 75 struct Comparator { |
73 bool operator()(const Packet* first, const Packet* second) { | 76 bool operator()(const Packet* first, const Packet* second) { |
74 // Highest prio = 0. | 77 // Highest prio = 0. |
75 if (first->priority != second->priority) | 78 if (first->priority != second->priority) |
76 return first->priority > second->priority; | 79 return first->priority > second->priority; |
77 | 80 |
78 // Retransmissions go first. | 81 // Retransmissions go first. |
(...skipping 27 matching lines...) Expand all Loading... | |
106 // Store packet in list, use pointers in priority queue for cheaper moves. | 109 // Store packet in list, use pointers in priority queue for cheaper moves. |
107 // Packets have a handle to its own iterator in the list, for easy removal | 110 // Packets have a handle to its own iterator in the list, for easy removal |
108 // when popping from queue. | 111 // when popping from queue. |
109 packet_list_.push_front(packet); | 112 packet_list_.push_front(packet); |
110 std::list<Packet>::iterator it = packet_list_.begin(); | 113 std::list<Packet>::iterator it = packet_list_.begin(); |
111 it->this_it = it; // Handle for direct removal from list. | 114 it->this_it = it; // Handle for direct removal from list. |
112 prio_queue_.push(&(*it)); // Pointer into list. | 115 prio_queue_.push(&(*it)); // Pointer into list. |
113 bytes_ += packet.bytes; | 116 bytes_ += packet.bytes; |
114 } | 117 } |
115 | 118 |
116 const Packet& BeginPop() { | 119 Packet& BeginPop() { |
danilchap
2016/05/10 15:31:39
If you want return a non-const object, return a po
philipel
2016/05/11 09:39:16
True, but now it's const again :)
| |
117 const Packet& packet = *prio_queue_.top(); | 120 Packet& packet = *prio_queue_.top(); |
118 prio_queue_.pop(); | 121 prio_queue_.pop(); |
119 return packet; | 122 return packet; |
120 } | 123 } |
121 | 124 |
122 void CancelPop(const Packet& packet) { prio_queue_.push(&(*packet.this_it)); } | 125 void CancelPop(const Packet& packet) { prio_queue_.push(&(*packet.this_it)); } |
123 | 126 |
124 void FinalizePop(const Packet& packet) { | 127 void FinalizePop(const Packet& packet) { |
125 RemoveFromDupeSet(packet); | 128 RemoveFromDupeSet(packet); |
126 bytes_ -= packet.bytes; | 129 bytes_ -= packet.bytes; |
127 queue_time_sum_ -= (time_last_updated_ - packet.enqueue_time_ms); | 130 queue_time_sum_ -= (time_last_updated_ - packet.enqueue_time_ms); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); | 385 int64_t delta_time_ms = std::min(kMaxIntervalTimeMs, elapsed_time_ms); |
383 UpdateBytesPerInterval(delta_time_ms); | 386 UpdateBytesPerInterval(delta_time_ms); |
384 } | 387 } |
385 while (!packets_->Empty()) { | 388 while (!packets_->Empty()) { |
386 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) | 389 if (media_budget_->bytes_remaining() == 0 && !prober_->IsProbing()) |
387 return; | 390 return; |
388 | 391 |
389 // Since we need to release the lock in order to send, we first pop the | 392 // Since we need to release the lock in order to send, we first pop the |
390 // element from the priority queue but keep it in storage, so that we can | 393 // element from the priority queue but keep it in storage, so that we can |
391 // reinsert it if send fails. | 394 // reinsert it if send fails. |
392 const paced_sender::Packet& packet = packets_->BeginPop(); | 395 paced_sender::Packet& packet = packets_->BeginPop(); |
396 if (prober_->IsProbing()) | |
397 packet.cluster_id = prober_->CurrentClusterId(); | |
danilchap
2016/05/10 15:31:39
should you clear cluster_id if not probing? Either
| |
393 | 398 |
394 if (SendPacket(packet)) { | 399 if (SendPacket(packet)) { |
395 // Send succeeded, remove it from the queue. | 400 // Send succeeded, remove it from the queue. |
396 packets_->FinalizePop(packet); | 401 packets_->FinalizePop(packet); |
397 if (prober_->IsProbing()) | 402 if (prober_->IsProbing()) |
398 return; | 403 return; |
399 } else { | 404 } else { |
400 // Send failed, put it back into the queue. | 405 // Send failed, put it back into the queue. |
401 packets_->CancelPop(packet); | 406 packets_->CancelPop(packet); |
402 return; | 407 return; |
(...skipping 15 matching lines...) Expand all Loading... | |
418 SendPadding(static_cast<size_t>(padding_needed)); | 423 SendPadding(static_cast<size_t>(padding_needed)); |
419 } | 424 } |
420 | 425 |
421 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { | 426 bool PacedSender::SendPacket(const paced_sender::Packet& packet) { |
422 // TODO(holmer): Because of this bug issue 5307 we have to send audio | 427 // TODO(holmer): Because of this bug issue 5307 we have to send audio |
423 // packets even when the pacer is paused. Here we assume audio packets are | 428 // packets even when the pacer is paused. Here we assume audio packets are |
424 // always high priority and that they are the only high priority packets. | 429 // always high priority and that they are the only high priority packets. |
425 if (paused_ && packet.priority != kHighPriority) | 430 if (paused_ && packet.priority != kHighPriority) |
426 return false; | 431 return false; |
427 critsect_->Leave(); | 432 critsect_->Leave(); |
428 const bool success = callback_->TimeToSendPacket(packet.ssrc, | 433 const bool success = callback_->TimeToSendPacket( |
429 packet.sequence_number, | 434 packet.ssrc, packet.sequence_number, packet.capture_time_ms, |
430 packet.capture_time_ms, | 435 packet.retransmission, packet.cluster_id); |
431 packet.retransmission); | |
432 critsect_->Enter(); | 436 critsect_->Enter(); |
433 | 437 |
434 if (success) { | 438 if (success) { |
435 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); | 439 prober_->PacketSent(clock_->TimeInMilliseconds(), packet.bytes); |
436 // TODO(holmer): High priority packets should only be accounted for if we | 440 // TODO(holmer): High priority packets should only be accounted for if we |
437 // are allocating bandwidth for audio. | 441 // are allocating bandwidth for audio. |
438 if (packet.priority != kHighPriority) { | 442 if (packet.priority != kHighPriority) { |
439 // Update media bytes sent. | 443 // Update media bytes sent. |
440 media_budget_->UseBudget(packet.bytes); | 444 media_budget_->UseBudget(packet.bytes); |
441 padding_budget_->UseBudget(packet.bytes); | 445 padding_budget_->UseBudget(packet.bytes); |
(...skipping 13 matching lines...) Expand all Loading... | |
455 media_budget_->UseBudget(bytes_sent); | 459 media_budget_->UseBudget(bytes_sent); |
456 padding_budget_->UseBudget(bytes_sent); | 460 padding_budget_->UseBudget(bytes_sent); |
457 } | 461 } |
458 } | 462 } |
459 | 463 |
460 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { | 464 void PacedSender::UpdateBytesPerInterval(int64_t delta_time_ms) { |
461 media_budget_->IncreaseBudget(delta_time_ms); | 465 media_budget_->IncreaseBudget(delta_time_ms); |
462 padding_budget_->IncreaseBudget(delta_time_ms); | 466 padding_budget_->IncreaseBudget(delta_time_ms); |
463 } | 467 } |
464 } // namespace webrtc | 468 } // namespace webrtc |
OLD | NEW |