OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 rtp->codec = kRtpVideoH264; | 77 rtp->codec = kRtpVideoH264; |
78 return; | 78 return; |
79 case kVideoCodecGeneric: | 79 case kVideoCodecGeneric: |
80 rtp->codec = kRtpVideoGeneric; | 80 rtp->codec = kRtpVideoGeneric; |
81 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; | 81 rtp->simulcastIdx = info->codecSpecific.generic.simulcast_idx; |
82 return; | 82 return; |
83 default: | 83 default: |
84 return; | 84 return; |
85 } | 85 } |
86 } | 86 } |
| 87 |
| 88 std::vector<uint32_t> AllocateStreamBitrates( |
| 89 uint32_t total_bitrate, |
| 90 const SimulcastStream* stream_configs, |
| 91 size_t number_of_streams) { |
| 92 if (number_of_streams == 0) { |
| 93 std::vector<uint32_t> stream_bitrates(1, 0); |
| 94 stream_bitrates[0] = total_bitrate; |
| 95 return stream_bitrates; |
| 96 } |
| 97 std::vector<uint32_t> stream_bitrates(number_of_streams, 0); |
| 98 uint32_t bitrate_remainder = total_bitrate; |
| 99 for (size_t i = 0; i < stream_bitrates.size() && bitrate_remainder > 0; ++i) { |
| 100 if (stream_configs[i].maxBitrate * 1000 > bitrate_remainder) { |
| 101 stream_bitrates[i] = bitrate_remainder; |
| 102 } else { |
| 103 stream_bitrates[i] = stream_configs[i].maxBitrate * 1000; |
| 104 } |
| 105 bitrate_remainder -= stream_bitrates[i]; |
| 106 } |
| 107 return stream_bitrates; |
| 108 } |
| 109 |
87 } // namespace | 110 } // namespace |
88 | 111 |
89 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, | 112 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, |
90 int payload_type) | 113 int payload_type) |
91 : active_(false), | 114 : active_(false), |
| 115 codec_(), |
92 num_sending_modules_(1), | 116 num_sending_modules_(1), |
93 rtp_modules_(rtp_modules), | 117 rtp_modules_(rtp_modules), |
94 payload_type_(payload_type) { | 118 payload_type_(payload_type) { |
95 UpdateModuleSendingState(); | 119 UpdateModuleSendingState(); |
96 } | 120 } |
97 | 121 |
98 PayloadRouter::~PayloadRouter() {} | 122 PayloadRouter::~PayloadRouter() {} |
99 | 123 |
100 size_t PayloadRouter::DefaultMaxPayloadLength() { | 124 size_t PayloadRouter::DefaultMaxPayloadLength() { |
101 const size_t kIpUdpSrtpLength = 44; | 125 const size_t kIpUdpSrtpLength = 44; |
102 return IP_PACKET_SIZE - kIpUdpSrtpLength; | 126 return IP_PACKET_SIZE - kIpUdpSrtpLength; |
103 } | 127 } |
104 | 128 |
105 void PayloadRouter::set_active(bool active) { | 129 void PayloadRouter::set_active(bool active) { |
106 rtc::CritScope lock(&crit_); | 130 rtc::CritScope lock(&crit_); |
107 if (active_ == active) | 131 if (active_ == active) |
108 return; | 132 return; |
109 active_ = active; | 133 active_ = active; |
110 UpdateModuleSendingState(); | 134 UpdateModuleSendingState(); |
111 } | 135 } |
112 | 136 |
113 bool PayloadRouter::active() { | 137 bool PayloadRouter::active() { |
114 rtc::CritScope lock(&crit_); | 138 rtc::CritScope lock(&crit_); |
115 return active_ && !rtp_modules_.empty(); | 139 return active_ && !rtp_modules_.empty(); |
116 } | 140 } |
117 | 141 |
118 void PayloadRouter::SetSendingRtpModules(size_t num_sending_modules) { | 142 void PayloadRouter::SetSendCodec(const VideoCodec& codec) { |
119 RTC_DCHECK_LE(num_sending_modules, rtp_modules_.size()); | 143 RTC_DCHECK_LE(codec.numberOfSimulcastStreams, rtp_modules_.size()); |
120 rtc::CritScope lock(&crit_); | 144 rtc::CritScope lock(&crit_); |
121 num_sending_modules_ = num_sending_modules; | 145 num_sending_modules_ = codec.numberOfSimulcastStreams; |
| 146 codec_ = codec; |
122 UpdateModuleSendingState(); | 147 UpdateModuleSendingState(); |
123 } | 148 } |
124 | 149 |
125 void PayloadRouter::UpdateModuleSendingState() { | 150 void PayloadRouter::UpdateModuleSendingState() { |
126 for (size_t i = 0; i < num_sending_modules_; ++i) { | 151 for (size_t i = 0; i < num_sending_modules_; ++i) { |
127 rtp_modules_[i]->SetSendingStatus(active_); | 152 rtp_modules_[i]->SetSendingStatus(active_); |
128 rtp_modules_[i]->SetSendingMediaStatus(active_); | 153 rtp_modules_[i]->SetSendingMediaStatus(active_); |
129 } | 154 } |
130 // Disable inactive modules. | 155 // Disable inactive modules. |
131 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) { | 156 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) { |
(...skipping 24 matching lines...) Expand all Loading... |
156 if (rtp_video_header.simulcastIdx >= num_sending_modules_) | 181 if (rtp_video_header.simulcastIdx >= num_sending_modules_) |
157 return -1; | 182 return -1; |
158 stream_idx = rtp_video_header.simulcastIdx; | 183 stream_idx = rtp_video_header.simulcastIdx; |
159 | 184 |
160 return rtp_modules_[stream_idx]->SendOutgoingData( | 185 return rtp_modules_[stream_idx]->SendOutgoingData( |
161 encoded_image._frameType, payload_type_, encoded_image._timeStamp, | 186 encoded_image._frameType, payload_type_, encoded_image._timeStamp, |
162 encoded_image.capture_time_ms_, encoded_image._buffer, | 187 encoded_image.capture_time_ms_, encoded_image._buffer, |
163 encoded_image._length, fragmentation, &rtp_video_header); | 188 encoded_image._length, fragmentation, &rtp_video_header); |
164 } | 189 } |
165 | 190 |
166 void PayloadRouter::SetTargetSendBitrates( | 191 void PayloadRouter::SetTargetSendBitrate(uint32_t bitrate_bps) { |
167 const std::vector<uint32_t>& stream_bitrates) { | |
168 rtc::CritScope lock(&crit_); | 192 rtc::CritScope lock(&crit_); |
| 193 // Allocate the bandwidth between the streams. |
| 194 std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( |
| 195 bitrate_bps, codec_.simulcastStream, codec_.numberOfSimulcastStreams); |
| 196 |
169 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size()); | 197 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size()); |
170 for (size_t i = 0; i < stream_bitrates.size(); ++i) { | 198 for (size_t i = 0; i < stream_bitrates.size(); ++i) { |
171 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]); | 199 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]); |
172 } | 200 } |
173 } | 201 } |
174 | 202 |
175 size_t PayloadRouter::MaxPayloadLength() const { | 203 size_t PayloadRouter::MaxPayloadLength() const { |
176 size_t min_payload_length = DefaultMaxPayloadLength(); | 204 size_t min_payload_length = DefaultMaxPayloadLength(); |
177 rtc::CritScope lock(&crit_); | 205 rtc::CritScope lock(&crit_); |
178 for (size_t i = 0; i < num_sending_modules_; ++i) { | 206 for (size_t i = 0; i < num_sending_modules_; ++i) { |
179 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); | 207 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); |
180 if (module_payload_length < min_payload_length) | 208 if (module_payload_length < min_payload_length) |
181 min_payload_length = module_payload_length; | 209 min_payload_length = module_payload_length; |
182 } | 210 } |
183 return min_payload_length; | 211 return min_payload_length; |
184 } | 212 } |
185 | 213 |
186 } // namespace webrtc | 214 } // namespace webrtc |
OLD | NEW |