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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void TMMBRSet::SwapEntries(uint32_t i, uint32_t j) { | 60 void TMMBRSet::SwapEntries(uint32_t i, uint32_t j) { |
61 using std::swap; | 61 using std::swap; |
62 swap((*this)[i], (*this)[j]); | 62 swap((*this)[i], (*this)[j]); |
63 } | 63 } |
64 | 64 |
65 void TMMBRSet::ClearEntry(uint32_t idx) { | 65 void TMMBRSet::ClearEntry(uint32_t idx) { |
66 SetEntry(idx, 0, 0, 0); | 66 SetEntry(idx, 0, 0, 0); |
67 } | 67 } |
68 | 68 |
69 TMMBRHelp::TMMBRHelp() | 69 TMMBRHelp::TMMBRHelp() |
70 : _criticalSection(CriticalSectionWrapper::CreateCriticalSection()), | 70 : _candidateSet(), |
71 _candidateSet(), | |
72 _boundingSet(), | 71 _boundingSet(), |
73 _boundingSetToSend(), | 72 _boundingSetToSend(), |
74 _ptrIntersectionBoundingSet(NULL), | 73 _ptrIntersectionBoundingSet(NULL), |
75 _ptrMaxPRBoundingSet(NULL) { | 74 _ptrMaxPRBoundingSet(NULL) { |
76 } | 75 } |
77 | 76 |
78 TMMBRHelp::~TMMBRHelp() { | 77 TMMBRHelp::~TMMBRHelp() { |
79 delete [] _ptrIntersectionBoundingSet; | 78 delete [] _ptrIntersectionBoundingSet; |
80 delete [] _ptrMaxPRBoundingSet; | 79 delete [] _ptrMaxPRBoundingSet; |
81 _ptrIntersectionBoundingSet = 0; | 80 _ptrIntersectionBoundingSet = 0; |
82 _ptrMaxPRBoundingSet = 0; | 81 _ptrMaxPRBoundingSet = 0; |
83 delete _criticalSection; | |
84 } | 82 } |
85 | 83 |
86 TMMBRSet* | 84 TMMBRSet* |
87 TMMBRHelp::VerifyAndAllocateBoundingSet(uint32_t minimumSize) | 85 TMMBRHelp::VerifyAndAllocateBoundingSet(uint32_t minimumSize) |
88 { | 86 { |
89 CriticalSectionScoped lock(_criticalSection); | 87 rtc::CritScope lock(&_criticalSection); |
90 | 88 |
91 if(minimumSize > _boundingSet.capacity()) | 89 if(minimumSize > _boundingSet.capacity()) |
92 { | 90 { |
93 // make sure that our buffers are big enough | 91 // make sure that our buffers are big enough |
94 if(_ptrIntersectionBoundingSet) | 92 if(_ptrIntersectionBoundingSet) |
95 { | 93 { |
96 delete [] _ptrIntersectionBoundingSet; | 94 delete [] _ptrIntersectionBoundingSet; |
97 delete [] _ptrMaxPRBoundingSet; | 95 delete [] _ptrMaxPRBoundingSet; |
98 } | 96 } |
99 _ptrIntersectionBoundingSet = new float[minimumSize]; | 97 _ptrIntersectionBoundingSet = new float[minimumSize]; |
100 _ptrMaxPRBoundingSet = new float[minimumSize]; | 98 _ptrMaxPRBoundingSet = new float[minimumSize]; |
101 } | 99 } |
102 _boundingSet.VerifyAndAllocateSet(minimumSize); | 100 _boundingSet.VerifyAndAllocateSet(minimumSize); |
103 return &_boundingSet; | 101 return &_boundingSet; |
104 } | 102 } |
105 | 103 |
106 TMMBRSet* TMMBRHelp::BoundingSet() { | 104 TMMBRSet* TMMBRHelp::BoundingSet() { |
107 return &_boundingSet; | 105 return &_boundingSet; |
108 } | 106 } |
109 | 107 |
110 int32_t | 108 int32_t |
111 TMMBRHelp::SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend) | 109 TMMBRHelp::SetTMMBRBoundingSetToSend(const TMMBRSet* boundingSetToSend) |
112 { | 110 { |
113 CriticalSectionScoped lock(_criticalSection); | 111 rtc::CritScope lock(&_criticalSection); |
114 | 112 |
115 if (boundingSetToSend == NULL) | 113 if (boundingSetToSend == NULL) |
116 { | 114 { |
117 _boundingSetToSend.clearSet(); | 115 _boundingSetToSend.clearSet(); |
118 return 0; | 116 return 0; |
119 } | 117 } |
120 | 118 |
121 VerifyAndAllocateBoundingSetToSend(boundingSetToSend->lengthOfSet()); | 119 VerifyAndAllocateBoundingSetToSend(boundingSetToSend->lengthOfSet()); |
122 _boundingSetToSend.clearSet(); | 120 _boundingSetToSend.clearSet(); |
123 for (uint32_t i = 0; i < boundingSetToSend->lengthOfSet(); i++) | 121 for (uint32_t i = 0; i < boundingSetToSend->lengthOfSet(); i++) |
124 { | 122 { |
125 // cap at our configured max bitrate | 123 // cap at our configured max bitrate |
126 uint32_t bitrate = boundingSetToSend->Tmmbr(i); | 124 uint32_t bitrate = boundingSetToSend->Tmmbr(i); |
127 _boundingSetToSend.SetEntry(i, bitrate, | 125 _boundingSetToSend.SetEntry(i, bitrate, |
128 boundingSetToSend->PacketOH(i), | 126 boundingSetToSend->PacketOH(i), |
129 boundingSetToSend->Ssrc(i)); | 127 boundingSetToSend->Ssrc(i)); |
130 } | 128 } |
131 return 0; | 129 return 0; |
132 } | 130 } |
133 | 131 |
134 int32_t | 132 int32_t |
135 TMMBRHelp::VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize) | 133 TMMBRHelp::VerifyAndAllocateBoundingSetToSend(uint32_t minimumSize) |
136 { | 134 { |
137 CriticalSectionScoped lock(_criticalSection); | 135 rtc::CritScope lock(&_criticalSection); |
138 | 136 |
139 _boundingSetToSend.VerifyAndAllocateSet(minimumSize); | 137 _boundingSetToSend.VerifyAndAllocateSet(minimumSize); |
140 return 0; | 138 return 0; |
141 } | 139 } |
142 | 140 |
143 TMMBRSet* | 141 TMMBRSet* |
144 TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize) | 142 TMMBRHelp::VerifyAndAllocateCandidateSet(uint32_t minimumSize) |
145 { | 143 { |
146 CriticalSectionScoped lock(_criticalSection); | 144 rtc::CritScope lock(&_criticalSection); |
147 | 145 |
148 _candidateSet.VerifyAndAllocateSet(minimumSize); | 146 _candidateSet.VerifyAndAllocateSet(minimumSize); |
149 return &_candidateSet; | 147 return &_candidateSet; |
150 } | 148 } |
151 | 149 |
152 TMMBRSet* | 150 TMMBRSet* |
153 TMMBRHelp::CandidateSet() | 151 TMMBRHelp::CandidateSet() |
154 { | 152 { |
155 return &_candidateSet; | 153 return &_candidateSet; |
156 } | 154 } |
157 | 155 |
158 TMMBRSet* | 156 TMMBRSet* |
159 TMMBRHelp::BoundingSetToSend() | 157 TMMBRHelp::BoundingSetToSend() |
160 { | 158 { |
161 return &_boundingSetToSend; | 159 return &_boundingSetToSend; |
162 } | 160 } |
163 | 161 |
164 int32_t | 162 int32_t |
165 TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet) | 163 TMMBRHelp::FindTMMBRBoundingSet(TMMBRSet*& boundingSet) |
166 { | 164 { |
167 CriticalSectionScoped lock(_criticalSection); | 165 rtc::CritScope lock(&_criticalSection); |
168 | 166 |
169 // Work on local variable, will be modified | 167 // Work on local variable, will be modified |
170 TMMBRSet candidateSet; | 168 TMMBRSet candidateSet; |
171 candidateSet.VerifyAndAllocateSet(_candidateSet.capacity()); | 169 candidateSet.VerifyAndAllocateSet(_candidateSet.capacity()); |
172 | 170 |
173 for (uint32_t i = 0; i < _candidateSet.size(); i++) | 171 for (uint32_t i = 0; i < _candidateSet.size(); i++) |
174 { | 172 { |
175 if(_candidateSet.Tmmbr(i)) | 173 if(_candidateSet.Tmmbr(i)) |
176 { | 174 { |
177 candidateSet.AddEntry(_candidateSet.Tmmbr(i), | 175 candidateSet.AddEntry(_candidateSet.Tmmbr(i), |
(...skipping 22 matching lines...) Expand all Loading... |
200 } | 198 } |
201 boundingSet = &_boundingSet; | 199 boundingSet = &_boundingSet; |
202 } | 200 } |
203 return numBoundingSet; | 201 return numBoundingSet; |
204 } | 202 } |
205 | 203 |
206 | 204 |
207 int32_t | 205 int32_t |
208 TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet) | 206 TMMBRHelp::FindTMMBRBoundingSet(int32_t numCandidates, TMMBRSet& candidateSet) |
209 { | 207 { |
210 CriticalSectionScoped lock(_criticalSection); | 208 rtc::CritScope lock(&_criticalSection); |
211 | 209 |
212 uint32_t numBoundingSet = 0; | 210 uint32_t numBoundingSet = 0; |
213 VerifyAndAllocateBoundingSet(candidateSet.capacity()); | 211 VerifyAndAllocateBoundingSet(candidateSet.capacity()); |
214 | 212 |
215 if (numCandidates == 1) | 213 if (numCandidates == 1) |
216 { | 214 { |
217 for (uint32_t i = 0; i < candidateSet.size(); i++) | 215 for (uint32_t i = 0; i < candidateSet.size(); i++) |
218 { | 216 { |
219 if (candidateSet.Tmmbr(i) > 0) | 217 if (candidateSet.Tmmbr(i) > 0) |
220 { | 218 { |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 403 } |
406 | 404 |
407 // 9. Go back to step 5 if any tuple remains in candidate list | 405 // 9. Go back to step 5 if any tuple remains in candidate list |
408 } while (numCandidates > 0); | 406 } while (numCandidates > 0); |
409 | 407 |
410 return numBoundingSet; | 408 return numBoundingSet; |
411 } | 409 } |
412 | 410 |
413 bool TMMBRHelp::IsOwner(const uint32_t ssrc, | 411 bool TMMBRHelp::IsOwner(const uint32_t ssrc, |
414 const uint32_t length) const { | 412 const uint32_t length) const { |
415 CriticalSectionScoped lock(_criticalSection); | 413 rtc::CritScope lock(&_criticalSection); |
416 | 414 |
417 if (length == 0) { | 415 if (length == 0) { |
418 // Empty bounding set. | 416 // Empty bounding set. |
419 return false; | 417 return false; |
420 } | 418 } |
421 for(uint32_t i = 0; | 419 for(uint32_t i = 0; |
422 (i < length) && (i < _boundingSet.size()); ++i) { | 420 (i < length) && (i < _boundingSet.size()); ++i) { |
423 if(_boundingSet.Ssrc(i) == ssrc) { | 421 if(_boundingSet.Ssrc(i) == ssrc) { |
424 return true; | 422 return true; |
425 } | 423 } |
426 } | 424 } |
427 return false; | 425 return false; |
428 } | 426 } |
429 | 427 |
430 bool TMMBRHelp::CalcMinBitRate( uint32_t* minBitrateKbit) const { | 428 bool TMMBRHelp::CalcMinBitRate( uint32_t* minBitrateKbit) const { |
431 CriticalSectionScoped lock(_criticalSection); | 429 rtc::CritScope lock(&_criticalSection); |
432 | 430 |
433 if (_candidateSet.size() == 0) { | 431 if (_candidateSet.size() == 0) { |
434 // Empty bounding set. | 432 // Empty bounding set. |
435 return false; | 433 return false; |
436 } | 434 } |
437 *minBitrateKbit = std::numeric_limits<uint32_t>::max(); | 435 *minBitrateKbit = std::numeric_limits<uint32_t>::max(); |
438 | 436 |
439 for (uint32_t i = 0; i < _candidateSet.lengthOfSet(); ++i) { | 437 for (uint32_t i = 0; i < _candidateSet.lengthOfSet(); ++i) { |
440 uint32_t curNetBitRateKbit = _candidateSet.Tmmbr(i); | 438 uint32_t curNetBitRateKbit = _candidateSet.Tmmbr(i); |
441 if (curNetBitRateKbit < MIN_VIDEO_BW_MANAGEMENT_BITRATE) { | 439 if (curNetBitRateKbit < MIN_VIDEO_BW_MANAGEMENT_BITRATE) { |
442 curNetBitRateKbit = MIN_VIDEO_BW_MANAGEMENT_BITRATE; | 440 curNetBitRateKbit = MIN_VIDEO_BW_MANAGEMENT_BITRATE; |
443 } | 441 } |
444 *minBitrateKbit = curNetBitRateKbit < *minBitrateKbit ? | 442 *minBitrateKbit = curNetBitRateKbit < *minBitrateKbit ? |
445 curNetBitRateKbit : *minBitrateKbit; | 443 curNetBitRateKbit : *minBitrateKbit; |
446 } | 444 } |
447 return true; | 445 return true; |
448 } | 446 } |
449 } // namespace webrtc | 447 } // namespace webrtc |
OLD | NEW |