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; |
| 124 // TODO(perkj): Should SetSendStreams also call SetTargetSendBitrate? |
122 UpdateModuleSendingState(); | 125 UpdateModuleSendingState(); |
123 } | 126 } |
124 | 127 |
125 void PayloadRouter::UpdateModuleSendingState() { | 128 void PayloadRouter::UpdateModuleSendingState() { |
126 for (size_t i = 0; i < num_sending_modules_; ++i) { | 129 for (size_t i = 0; i < num_sending_modules_; ++i) { |
127 rtp_modules_[i]->SetSendingStatus(active_); | 130 rtp_modules_[i]->SetSendingStatus(active_); |
128 rtp_modules_[i]->SetSendingMediaStatus(active_); | 131 rtp_modules_[i]->SetSendingMediaStatus(active_); |
129 } | 132 } |
130 // Disable inactive modules. | 133 // Disable inactive modules. |
131 for (size_t i = num_sending_modules_; i < rtp_modules_.size(); ++i) { | 134 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_) | 159 if (rtp_video_header.simulcastIdx >= num_sending_modules_) |
157 return -1; | 160 return -1; |
158 stream_idx = rtp_video_header.simulcastIdx; | 161 stream_idx = rtp_video_header.simulcastIdx; |
159 | 162 |
160 return rtp_modules_[stream_idx]->SendOutgoingData( | 163 return rtp_modules_[stream_idx]->SendOutgoingData( |
161 encoded_image._frameType, payload_type_, encoded_image._timeStamp, | 164 encoded_image._frameType, payload_type_, encoded_image._timeStamp, |
162 encoded_image.capture_time_ms_, encoded_image._buffer, | 165 encoded_image.capture_time_ms_, encoded_image._buffer, |
163 encoded_image._length, fragmentation, &rtp_video_header); | 166 encoded_image._length, fragmentation, &rtp_video_header); |
164 } | 167 } |
165 | 168 |
166 void PayloadRouter::SetTargetSendBitrates( | 169 void PayloadRouter::SetTargetSendBitrate(uint32_t bitrate_bps) { |
167 const std::vector<uint32_t>& stream_bitrates) { | |
168 rtc::CritScope lock(&crit_); | 170 rtc::CritScope lock(&crit_); |
169 RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size()); | 171 RTC_DCHECK_LE(streams_.size(), rtp_modules_.size()); |
170 for (size_t i = 0; i < stream_bitrates.size(); ++i) { | 172 |
171 rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]); | 173 // TODO(sprang): Rebase https://codereview.webrtc.org/1913073002/ on top of |
| 174 // this. |
| 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 |