OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 ++simulcast_id) { | 95 ++simulcast_id) { |
96 auto tl_it = temporal_layers_.find(simulcast_id); | 96 auto tl_it = temporal_layers_.find(simulcast_id); |
97 if (tl_it == temporal_layers_.end()) | 97 if (tl_it == temporal_layers_.end()) |
98 continue; // TODO(sprang): If > 1 SS, assume default TL alloc? | 98 continue; // TODO(sprang): If > 1 SS, assume default TL alloc? |
99 | 99 |
100 uint32_t target_bitrate_kbps = | 100 uint32_t target_bitrate_kbps = |
101 allocated_bitrates_bps.GetBitrate(simulcast_id, 0) / 1000; | 101 allocated_bitrates_bps.GetBitrate(simulcast_id, 0) / 1000; |
102 RTC_DCHECK_EQ( | 102 RTC_DCHECK_EQ( |
103 target_bitrate_kbps, | 103 target_bitrate_kbps, |
104 allocated_bitrates_bps.GetSpatialLayerSum(simulcast_id) / 1000); | 104 allocated_bitrates_bps.GetSpatialLayerSum(simulcast_id) / 1000); |
105 const int num_temporal_streams = std::max<uint8_t>( | |
106 1, codec_.numberOfSimulcastStreams == 0 | |
107 ? codec_.VP8().numberOfTemporalLayers | |
108 : codec_.simulcastStream[0].numberOfTemporalLayers); | |
109 | |
105 uint32_t max_bitrate_kbps; | 110 uint32_t max_bitrate_kbps; |
106 if (num_spatial_streams == 1) { | 111 if (num_spatial_streams == 1) { |
107 max_bitrate_kbps = codec_.maxBitrate; | 112 max_bitrate_kbps = codec_.maxBitrate; |
108 const int num_temporal_streams = | |
109 codec_.numberOfSimulcastStreams == 0 | |
110 ? codec_.VP8().numberOfTemporalLayers | |
111 : codec_.simulcastStream[0].numberOfTemporalLayers; | |
112 | 113 |
113 // TODO(holmer): This is a temporary hack for screensharing, where we | 114 // TODO(holmer): This is a temporary hack for screensharing, where we |
114 // interpret the startBitrate as the encoder target bitrate. This is | 115 // interpret the startBitrate as the encoder target bitrate. This is |
115 // to allow for a different max bitrate, so if the codec can't meet | 116 // to allow for a different max bitrate, so if the codec can't meet |
116 // the target we still allow it to overshoot up to the max before dropping | 117 // the target we still allow it to overshoot up to the max before dropping |
117 // frames. This hack should be improved. | 118 // frames. This hack should be improved. |
118 if (codec_.mode == kScreensharing && codec_.targetBitrate > 0 && | 119 if (codec_.mode == kScreensharing && codec_.targetBitrate > 0 && |
119 num_temporal_streams == 2) { | 120 num_temporal_streams == 2) { |
120 int tl0_bitrate = std::min(codec_.targetBitrate, target_bitrate_kbps); | 121 int tl0_bitrate = std::min(codec_.targetBitrate, target_bitrate_kbps); |
121 max_bitrate_kbps = std::min(codec_.maxBitrate, target_bitrate_kbps); | 122 max_bitrate_kbps = std::min(codec_.maxBitrate, target_bitrate_kbps); |
122 target_bitrate_kbps = tl0_bitrate; | 123 target_bitrate_kbps = tl0_bitrate; |
123 } | 124 } |
124 } else { | 125 } else { |
125 max_bitrate_kbps = codec_.simulcastStream[simulcast_id].maxBitrate; | 126 max_bitrate_kbps = codec_.simulcastStream[simulcast_id].maxBitrate; |
126 } | 127 } |
127 | 128 |
128 std::vector<uint32_t> tl_allocation = tl_it->second->OnRatesUpdated( | 129 std::vector<uint32_t> tl_allocation = tl_it->second->OnRatesUpdated( |
129 target_bitrate_kbps, max_bitrate_kbps, framerate); | 130 target_bitrate_kbps, max_bitrate_kbps, framerate); |
131 RTC_DCHECK_GT(tl_allocation.size(), 0); | |
132 RTC_DCHECK_LE(tl_allocation.size(), num_temporal_streams); | |
130 | 133 |
134 uint64_t tl_allocation_sum_kbps = 0; | |
131 for (size_t tl_index = 0; tl_index < tl_allocation.size(); ++tl_index) { | 135 for (size_t tl_index = 0; tl_index < tl_allocation.size(); ++tl_index) { |
136 uint32_t layer_rate_kbps = tl_allocation[tl_index]; | |
137 RTC_DCHECK_LE(tl_allocation_sum_kbps, target_bitrate_kbps); | |
danilchap
2016/11/25 14:40:31
may be move this check after the loop, or at least
sprang_webrtc
2016/11/25 14:46:36
Done.
| |
132 allocated_bitrates_bps.SetBitrate(simulcast_id, tl_index, | 138 allocated_bitrates_bps.SetBitrate(simulcast_id, tl_index, |
133 tl_allocation[tl_index] * 1000); | 139 layer_rate_kbps * 1000); |
140 tl_allocation_sum_kbps += layer_rate_kbps; | |
134 } | 141 } |
135 } | 142 } |
136 | 143 |
137 return allocated_bitrates_bps; | 144 return allocated_bitrates_bps; |
138 } | 145 } |
139 | 146 |
140 uint32_t SimulcastRateAllocator::GetPreferredBitrateBps(uint32_t framerate) { | 147 uint32_t SimulcastRateAllocator::GetPreferredBitrateBps(uint32_t framerate) { |
148 // Create a temporary instance without temporal layers, as they may be | |
149 // stateful, and updating the bitrate to max here can cause side effects. | |
150 SimulcastRateAllocator temp_allocator(codec_, nullptr); | |
141 BitrateAllocation allocation = | 151 BitrateAllocation allocation = |
142 GetAllocation(codec_.maxBitrate * 1000, framerate); | 152 temp_allocator.GetAllocation(codec_.maxBitrate * 1000, framerate); |
143 return allocation.get_sum_bps(); | 153 return allocation.get_sum_bps(); |
144 } | 154 } |
145 | 155 |
146 const VideoCodec& webrtc::SimulcastRateAllocator::GetCodec() const { | 156 const VideoCodec& webrtc::SimulcastRateAllocator::GetCodec() const { |
147 return codec_; | 157 return codec_; |
148 } | 158 } |
149 | 159 |
150 } // namespace webrtc | 160 } // namespace webrtc |
OLD | NEW |