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 | |
87 } // namespace | 88 } // namespace |
88 | 89 |
89 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, | 90 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, |
90 int payload_type) | 91 int payload_type) |
91 : active_(false), | 92 : active_(false), |
92 num_sending_modules_(1), | 93 num_sending_modules_(1), |
93 rtp_modules_(rtp_modules), | 94 rtp_modules_(rtp_modules), |
94 payload_type_(payload_type) { | 95 payload_type_(payload_type) { |
95 UpdateModuleSendingState(); | 96 UpdateModuleSendingState(); |
96 } | 97 } |
(...skipping 11 matching lines...) Expand all Loading... | |
108 return; | 109 return; |
109 active_ = active; | 110 active_ = active; |
110 UpdateModuleSendingState(); | 111 UpdateModuleSendingState(); |
111 } | 112 } |
112 | 113 |
113 bool PayloadRouter::active() { | 114 bool PayloadRouter::active() { |
114 rtc::CritScope lock(&crit_); | 115 rtc::CritScope lock(&crit_); |
115 return active_ && !rtp_modules_.empty(); | 116 return active_ && !rtp_modules_.empty(); |
116 } | 117 } |
117 | 118 |
118 void PayloadRouter::SetSendingRtpModules(size_t num_sending_modules) { | 119 void PayloadRouter::SetSendStreams(const std::vector<VideoStream>& streams) { |
119 RTC_DCHECK_LE(num_sending_modules, rtp_modules_.size()); | 120 RTC_DCHECK_LE(streams.size(), rtp_modules_.size()); |
120 rtc::CritScope lock(&crit_); | 121 rtc::CritScope lock(&crit_); |
121 num_sending_modules_ = num_sending_modules; | 122 num_sending_modules_ = streams.size(); |
123 streams_ = streams; | |
pbos-webrtc
2016/05/02 00:45:44
Perhaps this one should also reallocate bitrates,
perkj_webrtc
2016/05/02 12:33:19
Done.
| |
122 UpdateModuleSendingState(); | 124 UpdateModuleSendingState(); |
123 } | 125 } |
124 | 126 |
125 void PayloadRouter::UpdateModuleSendingState() { | 127 void PayloadRouter::UpdateModuleSendingState() { |
126 for (size_t i = 0; i < num_sending_modules_; ++i) { | 128 for (size_t i = 0; i < num_sending_modules_; ++i) { |
127 rtp_modules_[i]->SetSendingStatus(active_); | 129 rtp_modules_[i]->SetSendingStatus(active_); |
128 rtp_modules_[i]->SetSendingMediaStatus(active_); | 130 rtp_modules_[i]->SetSendingMediaStatus(active_); |
129 } | 131 } |
130 // Disable inactive modules. | 132 // Disable inactive modules. |
131 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) { | 133 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_) | 158 if (rtp_video_header.simulcastIdx >= num_sending_modules_) |
157 return -1; | 159 return -1; |
158 stream_idx = rtp_video_header.simulcastIdx; | 160 stream_idx = rtp_video_header.simulcastIdx; |
159 | 161 |
160 return rtp_modules_[stream_idx]->SendOutgoingData( | 162 return rtp_modules_[stream_idx]->SendOutgoingData( |
161 encoded_image._frameType, payload_type_, encoded_image._timeStamp, | 163 encoded_image._frameType, payload_type_, encoded_image._timeStamp, |
162 encoded_image.capture_time_ms_, encoded_image._buffer, | 164 encoded_image.capture_time_ms_, encoded_image._buffer, |
163 encoded_image._length, fragmentation, &rtp_video_header); | 165 encoded_image._length, fragmentation, &rtp_video_header); |
164 } | 166 } |
165 | 167 |
166 void PayloadRouter::SetTargetSendBitrates( | 168 void PayloadRouter::SetTargetSendBitrate(uint32_t bitrate_bps) { |
167 const std::vector<uint32_t>& stream_bitrates) { | |
168 rtc::CritScope lock(&crit_); | 169 rtc::CritScope lock(&crit_); |
169 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size()); | 170 RTC_DCHECK_LE(streams_.size(), rtp_modules_.size()); |
170 for (size_t i = 0; i < stream_bitrates.size(); ++i) { | 171 |
171 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]); | 172 // Allocate the bandwidth between the streams. |
pbos-webrtc
2016/05/02 00:45:44
I think this should be target_bitrate_bps for all
perkj_webrtc
2016/05/02 12:33:19
Done.
| |
173 // TODO(perkj): Why are we allocating bitrates here as well as in the | |
174 // VCM. It should be done once, in the BitrateAllocator? | |
175 int bitrate_remainder = bitrate_bps; | |
176 for (size_t i = 0; i < streams_.size() && bitrate_remainder > 0; ++i) { | |
177 int stream_bitrate = 0; | |
178 if (streams_[i].max_bitrate_bps > bitrate_remainder) { | |
179 stream_bitrate = bitrate_remainder; | |
180 } else { | |
181 stream_bitrate = streams_[i].max_bitrate_bps; | |
182 } | |
183 bitrate_remainder -= stream_bitrate; | |
184 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrate); | |
172 } | 185 } |
173 } | 186 } |
174 | 187 |
175 size_t PayloadRouter::MaxPayloadLength() const { | 188 size_t PayloadRouter::MaxPayloadLength() const { |
176 size_t min_payload_length = DefaultMaxPayloadLength(); | 189 size_t min_payload_length = DefaultMaxPayloadLength(); |
177 rtc::CritScope lock(&crit_); | 190 rtc::CritScope lock(&crit_); |
178 for (size_t i = 0; i < num_sending_modules_; ++i) { | 191 for (size_t i = 0; i < num_sending_modules_; ++i) { |
179 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); | 192 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); |
180 if (module_payload_length < min_payload_length) | 193 if (module_payload_length < min_payload_length) |
181 min_payload_length = module_payload_length; | 194 min_payload_length = module_payload_length; |
182 } | 195 } |
183 return min_payload_length; | 196 return min_payload_length; |
184 } | 197 } |
185 | 198 |
186 } // namespace webrtc | 199 } // namespace webrtc |
OLD | NEW |