Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: webrtc/video/payload_router.cc

Issue 1913073002: Extract common simulcast logic from VP8 wrapper and simulcast adapter (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address comments, added tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
88 VideoCodec DefaultCodec() {
89 VideoCodec codec;
90 memset(&codec, 0, sizeof(VideoCodec));
91 return codec;
92 }
93
88 } // namespace 94 } // namespace
89 95
90 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules, 96 PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
91 int payload_type) 97 int payload_type)
92 : active_(false), 98 : active_(false),
93 num_sending_modules_(1), 99 num_sending_modules_(1),
100 simulcast_state_(DefaultCodec()),
94 rtp_modules_(rtp_modules), 101 rtp_modules_(rtp_modules),
95 payload_type_(payload_type) { 102 payload_type_(payload_type) {
96 UpdateModuleSendingState(); 103 UpdateModuleSendingState();
97 } 104 }
98 105
99 PayloadRouter::~PayloadRouter() {} 106 PayloadRouter::~PayloadRouter() {}
100 107
101 size_t PayloadRouter::DefaultMaxPayloadLength() { 108 size_t PayloadRouter::DefaultMaxPayloadLength() {
102 const size_t kIpUdpSrtpLength = 44; 109 const size_t kIpUdpSrtpLength = 44;
103 return IP_PACKET_SIZE - kIpUdpSrtpLength; 110 return IP_PACKET_SIZE - kIpUdpSrtpLength;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 return rtp_modules_[stream_idx]->SendOutgoingData( 170 return rtp_modules_[stream_idx]->SendOutgoingData(
164 encoded_image._frameType, payload_type_, encoded_image._timeStamp, 171 encoded_image._frameType, payload_type_, encoded_image._timeStamp,
165 encoded_image.capture_time_ms_, encoded_image._buffer, 172 encoded_image.capture_time_ms_, encoded_image._buffer,
166 encoded_image._length, fragmentation, &rtp_video_header); 173 encoded_image._length, fragmentation, &rtp_video_header);
167 } 174 }
168 175
169 void PayloadRouter::SetTargetSendBitrate(uint32_t bitrate_bps) { 176 void PayloadRouter::SetTargetSendBitrate(uint32_t bitrate_bps) {
170 rtc::CritScope lock(&crit_); 177 rtc::CritScope lock(&crit_);
171 RTC_DCHECK_LE(streams_.size(), rtp_modules_.size()); 178 RTC_DCHECK_LE(streams_.size(), rtp_modules_.size());
172 179
173 // TODO(sprang): Rebase https://codereview.webrtc.org/1913073002/ on top of 180 if (simulcast_state_.NumStreams() > 0) {
174 // this. 181 simulcast_state_.AllocateBitrate(bitrate_bps);
175 int bitrate_remainder = bitrate_bps; 182 for (auto& stream : simulcast_state_.Streams())
176 for (size_t i = 0; i < streams_.size() && bitrate_remainder > 0; ++i) { 183 rtp_modules_[stream.idx]->SetTargetSendBitrate(stream.allocated_rate_bps);
177 int stream_bitrate = 0; 184 } else {
178 if (streams_[i].max_bitrate_bps > bitrate_remainder) { 185 rtp_modules_[0]->SetTargetSendBitrate(bitrate_bps);
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);
185 } 186 }
186 } 187 }
187 188
189 void PayloadRouter::UpdateSimulcastState(const SimulcastState& state) {
190 rtc::CritScope lock(&crit_);
191 simulcast_state_ = state;
192 }
193
188 size_t PayloadRouter::MaxPayloadLength() const { 194 size_t PayloadRouter::MaxPayloadLength() const {
189 size_t min_payload_length = DefaultMaxPayloadLength(); 195 size_t min_payload_length = DefaultMaxPayloadLength();
190 rtc::CritScope lock(&crit_); 196 rtc::CritScope lock(&crit_);
191 for (size_t i = 0; i < num_sending_modules_; ++i) { 197 for (size_t i = 0; i < num_sending_modules_; ++i) {
192 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength(); 198 size_t module_payload_length = rtp_modules_[i]->MaxDataPayloadLength();
193 if (module_payload_length < min_payload_length) 199 if (module_payload_length < min_payload_length)
194 min_payload_length = module_payload_length; 200 min_payload_length = module_payload_length;
195 } 201 }
196 return min_payload_length; 202 return min_payload_length;
197 } 203 }
198 204
199 } // namespace webrtc 205 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698