| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 int nbr_bytes_to_read; | 50 int nbr_bytes_to_read; |
| 51 // keep track of if we've lost any packets, since then we shall loose | 51 // keep track of if we've lost any packets, since then we shall loose |
| 52 // the remains of the current frame: | 52 // the remains of the current frame: |
| 53 bool packet_loss_has_occurred = false; | 53 bool packet_loss_has_occurred = false; |
| 54 while ((nbr_bytes_to_read = packet_reader_->NextPacket(&packet)) > 0) { | 54 while ((nbr_bytes_to_read = packet_reader_->NextPacket(&packet)) > 0) { |
| 55 // Check if we're currently in a packet loss burst that is not completed: | 55 // Check if we're currently in a packet loss burst that is not completed: |
| 56 if (active_burst_packets_ > 0) { | 56 if (active_burst_packets_ > 0) { |
| 57 active_burst_packets_--; | 57 active_burst_packets_--; |
| 58 nbr_packets_dropped++; | 58 nbr_packets_dropped++; |
| 59 } else if (RandomUniform() < config_.packet_loss_probability || | 59 } else if (RandomUniform() < config_.packet_loss_probability || |
| 60 packet_loss_has_occurred) { | 60 packet_loss_has_occurred) { |
| 61 packet_loss_has_occurred = true; | 61 packet_loss_has_occurred = true; |
| 62 nbr_packets_dropped++; | 62 nbr_packets_dropped++; |
| 63 if (config_.packet_loss_mode == kBurst) { | 63 if (config_.packet_loss_mode == kBurst) { |
| 64 // Initiate a new burst | 64 // Initiate a new burst |
| 65 active_burst_packets_ = config_.packet_loss_burst_length - 1; | 65 active_burst_packets_ = config_.packet_loss_burst_length - 1; |
| 66 } | 66 } |
| 67 } else { | 67 } else { |
| 68 new_length += nbr_bytes_to_read; | 68 new_length += nbr_bytes_to_read; |
| 69 } | 69 } |
| 70 } | 70 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 84 void PacketManipulatorImpl::InitializeRandomSeed(unsigned int seed) { | 84 void PacketManipulatorImpl::InitializeRandomSeed(unsigned int seed) { |
| 85 random_seed_ = seed; | 85 random_seed_ = seed; |
| 86 } | 86 } |
| 87 | 87 |
| 88 inline double PacketManipulatorImpl::RandomUniform() { | 88 inline double PacketManipulatorImpl::RandomUniform() { |
| 89 // Use the previous result as new seed before each rand() call. Doing this | 89 // Use the previous result as new seed before each rand() call. Doing this |
| 90 // it doesn't matter if other threads are calling rand() since we'll always | 90 // it doesn't matter if other threads are calling rand() since we'll always |
| 91 // get the same behavior as long as we're using a fixed initial seed. | 91 // get the same behavior as long as we're using a fixed initial seed. |
| 92 critsect_->Enter(); | 92 critsect_->Enter(); |
| 93 srand(random_seed_); | 93 srand(random_seed_); |
| 94 random_seed_ = rand(); | 94 random_seed_ = rand(); // NOLINT (rand_r instead of rand) |
| 95 critsect_->Leave(); | 95 critsect_->Leave(); |
| 96 return (random_seed_ + 1.0)/(RAND_MAX + 1.0); | 96 return (random_seed_ + 1.0) / (RAND_MAX + 1.0); |
| 97 } | 97 } |
| 98 | 98 |
| 99 const char* PacketLossModeToStr(PacketLossMode e) { | 99 const char* PacketLossModeToStr(PacketLossMode e) { |
| 100 switch (e) { | 100 switch (e) { |
| 101 case kUniform: | 101 case kUniform: |
| 102 return "Uniform"; | 102 return "Uniform"; |
| 103 case kBurst: | 103 case kBurst: |
| 104 return "Burst"; | 104 return "Burst"; |
| 105 default: | 105 default: |
| 106 assert(false); | 106 assert(false); |
| 107 return "Unknown"; | 107 return "Unknown"; |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace test | 111 } // namespace test |
| 112 } // namespace webrtcc | 112 } // namespace webrtc |
| OLD | NEW |