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 |
11 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" | 11 #include "webrtc/modules/video_coding/codecs/test/packet_manipulator.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 | 15 |
16 #include "webrtc/base/format_macros.h" | 16 #include "webrtc/base/format_macros.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 namespace test { | 19 namespace test { |
20 | 20 |
21 PacketManipulatorImpl::PacketManipulatorImpl(PacketReader* packet_reader, | 21 PacketManipulatorImpl::PacketManipulatorImpl(PacketReader* packet_reader, |
22 const NetworkingConfig& config, | 22 const NetworkingConfig& config, |
23 bool verbose) | 23 bool verbose) |
24 : packet_reader_(packet_reader), | 24 : packet_reader_(packet_reader), |
25 config_(config), | 25 config_(config), |
26 active_burst_packets_(0), | 26 active_burst_packets_(0), |
27 critsect_(CriticalSectionWrapper::CreateCriticalSection()), | |
28 random_seed_(1), | 27 random_seed_(1), |
29 verbose_(verbose) { | 28 verbose_(verbose) { |
30 assert(packet_reader); | 29 assert(packet_reader); |
31 } | 30 } |
32 | 31 |
33 PacketManipulatorImpl::~PacketManipulatorImpl() { | |
34 delete critsect_; | |
35 } | |
36 | |
37 int PacketManipulatorImpl::ManipulatePackets( | 32 int PacketManipulatorImpl::ManipulatePackets( |
38 webrtc::EncodedImage* encoded_image) { | 33 webrtc::EncodedImage* encoded_image) { |
39 int nbr_packets_dropped = 0; | 34 int nbr_packets_dropped = 0; |
40 // There's no need to build a copy of the image data since viewing an | 35 // There's no need to build a copy of the image data since viewing an |
41 // EncodedImage object, setting the length to a new lower value represents | 36 // EncodedImage object, setting the length to a new lower value represents |
42 // that everything is dropped after that position in the byte array. | 37 // that everything is dropped after that position in the byte array. |
43 // EncodedImage._size is the allocated bytes. | 38 // EncodedImage._size is the allocated bytes. |
44 // EncodedImage._length is how many that are filled with data. | 39 // EncodedImage._length is how many that are filled with data. |
45 int new_length = 0; | 40 int new_length = 0; |
46 packet_reader_->InitializeReading(encoded_image->_buffer, | 41 packet_reader_->InitializeReading(encoded_image->_buffer, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 77 } |
83 | 78 |
84 void PacketManipulatorImpl::InitializeRandomSeed(unsigned int seed) { | 79 void PacketManipulatorImpl::InitializeRandomSeed(unsigned int seed) { |
85 random_seed_ = seed; | 80 random_seed_ = seed; |
86 } | 81 } |
87 | 82 |
88 inline double PacketManipulatorImpl::RandomUniform() { | 83 inline double PacketManipulatorImpl::RandomUniform() { |
89 // Use the previous result as new seed before each rand() call. Doing this | 84 // 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 | 85 // 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. | 86 // get the same behavior as long as we're using a fixed initial seed. |
92 critsect_->Enter(); | 87 critsect_.Enter(); |
93 srand(random_seed_); | 88 srand(random_seed_); |
94 random_seed_ = rand(); // NOLINT (rand_r instead of rand) | 89 random_seed_ = rand(); // NOLINT (rand_r instead of rand) |
95 critsect_->Leave(); | 90 critsect_.Leave(); |
96 return (random_seed_ + 1.0) / (RAND_MAX + 1.0); | 91 return (random_seed_ + 1.0) / (RAND_MAX + 1.0); |
97 } | 92 } |
98 | 93 |
99 const char* PacketLossModeToStr(PacketLossMode e) { | 94 const char* PacketLossModeToStr(PacketLossMode e) { |
100 switch (e) { | 95 switch (e) { |
101 case kUniform: | 96 case kUniform: |
102 return "Uniform"; | 97 return "Uniform"; |
103 case kBurst: | 98 case kBurst: |
104 return "Burst"; | 99 return "Burst"; |
105 default: | 100 default: |
106 assert(false); | 101 assert(false); |
107 return "Unknown"; | 102 return "Unknown"; |
108 } | 103 } |
109 } | 104 } |
110 | 105 |
111 } // namespace test | 106 } // namespace test |
112 } // namespace webrtc | 107 } // namespace webrtc |
OLD | NEW |