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/rtp_rtcp/source/tmmbr_help.h" | 11 #include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
16 #include <limits> | 16 #include <limits> |
17 | 17 |
18 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" | 18 #include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
21 TMMBRSet::TMMBRSet() : | 21 TMMBRSet::TMMBRSet() : |
22 _sizeOfSet(0), | |
23 _lengthOfSet(0) | 22 _lengthOfSet(0) |
24 { | 23 { |
25 } | 24 } |
26 | 25 |
27 TMMBRSet::~TMMBRSet() | 26 TMMBRSet::~TMMBRSet() |
28 { | 27 { |
29 _sizeOfSet = 0; | |
30 _lengthOfSet = 0; | 28 _lengthOfSet = 0; |
31 } | 29 } |
32 | 30 |
33 void | 31 void |
34 TMMBRSet::VerifyAndAllocateSet(uint32_t minimumSize) | 32 TMMBRSet::VerifyAndAllocateSet(uint32_t minimumSize) |
35 { | 33 { |
36 if(minimumSize > _sizeOfSet) | 34 if(minimumSize > size()) |
37 { | 35 { |
38 // make sure that our buffers are big enough | 36 // make sure that our buffers are big enough |
39 _data.resize(minimumSize); | 37 resize(minimumSize); |
40 _sizeOfSet = minimumSize; | |
41 } | 38 } |
42 // reset memory | 39 // reset memory |
43 for(uint32_t i = 0; i < _sizeOfSet; i++) | 40 for(uint32_t i = 0; i < size(); i++) |
44 { | 41 { |
45 _data.at(i).tmmbr = 0; | 42 at(i).set_bitrate_bps(0); |
philipel
2016/02/23 13:46:39
replace at() with operator[] since at() does bound
danilchap
2016/02/23 14:39:47
exception is not a problem, still better avoid unn
| |
46 _data.at(i).packet_oh = 0; | 43 at(i).set_packet_overhead(0); |
47 _data.at(i).ssrc = 0; | 44 at(i).set_ssrc(0); |
48 } | 45 } |
49 _lengthOfSet = 0; | 46 _lengthOfSet = 0; |
50 } | 47 } |
51 | 48 |
52 void | 49 void |
53 TMMBRSet::VerifyAndAllocateSetKeepingData(uint32_t minimumSize) | 50 TMMBRSet::VerifyAndAllocateSetKeepingData(uint32_t minimumSize) |
54 { | 51 { |
55 if(minimumSize > _sizeOfSet) | 52 if(minimumSize > size()) |
56 { | 53 { |
57 { | 54 resize(minimumSize); |
58 _data.resize(minimumSize); | |
59 } | |
60 _sizeOfSet = minimumSize; | |
61 } | 55 } |
62 } | 56 } |
63 | 57 |
64 void TMMBRSet::SetEntry(unsigned int i, | 58 void TMMBRSet::SetEntry(unsigned int i, |
65 uint32_t tmmbrSet, | 59 uint32_t tmmbrSet, |
66 uint32_t packetOHSet, | 60 uint32_t packetOHSet, |
67 uint32_t ssrcSet) { | 61 uint32_t ssrcSet) { |
68 assert(i < _sizeOfSet); | 62 assert(i < size()); |
philipel
2016/02/23 13:46:39
Use RTC_DCHECK instead of assert.
danilchap
2016/02/23 14:39:47
Done.
| |
69 _data.at(i).tmmbr = tmmbrSet; | 63 at(i).set_bitrate_bps(tmmbrSet * 1000); |
philipel
2016/02/23 13:46:39
Again, replace at() with operator[].
danilchap
2016/02/23 14:39:47
Done.
| |
70 _data.at(i).packet_oh = packetOHSet; | 64 at(i).set_packet_overhead(packetOHSet); |
71 _data.at(i).ssrc = ssrcSet; | 65 at(i).set_ssrc(ssrcSet); |
72 if (i >= _lengthOfSet) { | 66 if (i >= _lengthOfSet) { |
73 _lengthOfSet = i + 1; | 67 _lengthOfSet = i + 1; |
74 } | 68 } |
75 } | 69 } |
76 | 70 |
77 void TMMBRSet::AddEntry(uint32_t tmmbrSet, | 71 void TMMBRSet::AddEntry(uint32_t tmmbrSet, |
78 uint32_t packetOHSet, | 72 uint32_t packetOHSet, |
79 uint32_t ssrcSet) { | 73 uint32_t ssrcSet) { |
80 assert(_lengthOfSet < _sizeOfSet); | 74 assert(_lengthOfSet < size()); |
philipel
2016/02/23 13:46:38
Use RTC_DCHECK.
danilchap
2016/02/23 14:39:47
Done.
| |
81 SetEntry(_lengthOfSet, tmmbrSet, packetOHSet, ssrcSet); | 75 SetEntry(_lengthOfSet, tmmbrSet, packetOHSet, ssrcSet); |
82 } | 76 } |
83 | 77 |
84 void TMMBRSet::RemoveEntry(uint32_t sourceIdx) { | 78 void TMMBRSet::RemoveEntry(uint32_t sourceIdx) { |
85 assert(sourceIdx < _lengthOfSet); | 79 assert(sourceIdx < _lengthOfSet); |
philipel
2016/02/23 13:46:38
RTC_DCHECK :)
danilchap
2016/02/23 14:39:47
Done.
| |
86 _data.erase(_data.begin() + sourceIdx); | 80 erase(begin() + sourceIdx); |
87 _lengthOfSet--; | 81 _lengthOfSet--; |
88 _data.resize(_sizeOfSet); // Ensure that size remains the same. | 82 resize(size()+1); // Ensure that size remains the same. |
89 } | 83 } |
90 | 84 |
91 void TMMBRSet::SwapEntries(uint32_t i, uint32_t j) { | 85 void TMMBRSet::SwapEntries(uint32_t i, uint32_t j) { |
92 SetElement temp; | 86 using std::swap; |
93 temp = _data[i]; | 87 swap(at(i), at(j)); |
philipel
2016/02/23 13:46:38
Remove line 86 and just go for std::swap instead.
danilchap
2016/02/23 14:39:47
But that is not recommended way to use swap functi
| |
94 _data[i] = _data[j]; | |
95 _data[j] = temp; | |
96 } | 88 } |
97 | 89 |
98 void TMMBRSet::ClearEntry(uint32_t idx) { | 90 void TMMBRSet::ClearEntry(uint32_t idx) { |
99 SetEntry(idx, 0, 0, 0); | 91 SetEntry(idx, 0, 0, 0); |
100 } | 92 } |
101 | 93 |
102 TMMBRHelp::TMMBRHelp() | 94 TMMBRHelp::TMMBRHelp() |
103 : _criticalSection(CriticalSectionWrapper::CreateCriticalSection()), | 95 : _criticalSection(CriticalSectionWrapper::CreateCriticalSection()), |
104 _candidateSet(), | 96 _candidateSet(), |
105 _boundingSet(), | 97 _boundingSet(), |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 uint32_t curNetBitRateKbit = _candidateSet.Tmmbr(i); | 464 uint32_t curNetBitRateKbit = _candidateSet.Tmmbr(i); |
473 if (curNetBitRateKbit < MIN_VIDEO_BW_MANAGEMENT_BITRATE) { | 465 if (curNetBitRateKbit < MIN_VIDEO_BW_MANAGEMENT_BITRATE) { |
474 curNetBitRateKbit = MIN_VIDEO_BW_MANAGEMENT_BITRATE; | 466 curNetBitRateKbit = MIN_VIDEO_BW_MANAGEMENT_BITRATE; |
475 } | 467 } |
476 *minBitrateKbit = curNetBitRateKbit < *minBitrateKbit ? | 468 *minBitrateKbit = curNetBitRateKbit < *minBitrateKbit ? |
477 curNetBitRateKbit : *minBitrateKbit; | 469 curNetBitRateKbit : *minBitrateKbit; |
478 } | 470 } |
479 return true; | 471 return true; |
480 } | 472 } |
481 } // namespace webrtc | 473 } // namespace webrtc |
OLD | NEW |