| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 | 148 |
| 149 const uint32_t BitrateAllocation::kMaxBitrateBps = | 149 const uint32_t BitrateAllocation::kMaxBitrateBps = |
| 150 std::numeric_limits<uint32_t>::max(); | 150 std::numeric_limits<uint32_t>::max(); |
| 151 | 151 |
| 152 BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {} | 152 BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {} |
| 153 | 153 |
| 154 bool BitrateAllocation::SetBitrate(size_t spatial_index, | 154 bool BitrateAllocation::SetBitrate(size_t spatial_index, |
| 155 size_t temporal_index, | 155 size_t temporal_index, |
| 156 uint32_t bitrate_bps) { | 156 uint32_t bitrate_bps) { |
| 157 RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers); | 157 RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); |
| 158 RTC_DCHECK_LT(temporal_index, kMaxTemporalStreams); | 158 RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); |
| 159 RTC_DCHECK_LE(bitrates_[spatial_index][temporal_index], sum_); | 159 RTC_CHECK_LE(bitrates_[spatial_index][temporal_index], sum_); |
| 160 uint64_t new_bitrate_sum_bps = sum_; | 160 uint64_t new_bitrate_sum_bps = sum_; |
| 161 new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index]; | 161 new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index]; |
| 162 new_bitrate_sum_bps += bitrate_bps; | 162 new_bitrate_sum_bps += bitrate_bps; |
| 163 if (new_bitrate_sum_bps > kMaxBitrateBps) | 163 if (new_bitrate_sum_bps > kMaxBitrateBps) |
| 164 return false; | 164 return false; |
| 165 | 165 |
| 166 bitrates_[spatial_index][temporal_index] = bitrate_bps; | 166 bitrates_[spatial_index][temporal_index] = bitrate_bps; |
| 167 sum_ = static_cast<uint32_t>(new_bitrate_sum_bps); | 167 sum_ = static_cast<uint32_t>(new_bitrate_sum_bps); |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 | 170 |
| 171 uint32_t BitrateAllocation::GetBitrate(size_t spatial_index, | 171 uint32_t BitrateAllocation::GetBitrate(size_t spatial_index, |
| 172 size_t temporal_index) const { | 172 size_t temporal_index) const { |
| 173 RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers); | 173 RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); |
| 174 RTC_DCHECK_LT(temporal_index, kMaxTemporalStreams); | 174 RTC_CHECK_LT(temporal_index, kMaxTemporalStreams); |
| 175 return bitrates_[spatial_index][temporal_index]; | 175 return bitrates_[spatial_index][temporal_index]; |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Get the sum of all the temporal layer for a specific spatial layer. | 178 // Get the sum of all the temporal layer for a specific spatial layer. |
| 179 uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const { | 179 uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const { |
| 180 RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers); | 180 RTC_CHECK_LT(spatial_index, kMaxSpatialLayers); |
| 181 uint32_t sum = 0; | 181 uint32_t sum = 0; |
| 182 for (int i = 0; i < kMaxTemporalStreams; ++i) | 182 for (int i = 0; i < kMaxTemporalStreams; ++i) |
| 183 sum += bitrates_[spatial_index][i]; | 183 sum += bitrates_[spatial_index][i]; |
| 184 return sum; | 184 return sum; |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace webrtc | 187 } // namespace webrtc |
| OLD | NEW |