| Index: webrtc/video/payload_router.cc
|
| diff --git a/webrtc/video/payload_router.cc b/webrtc/video/payload_router.cc
|
| index abe476f276b8a83532446dab87be9f27a6ae7ceb..a1e11811ca62037eaa53c90725c166bfe42cc252 100644
|
| --- a/webrtc/video/payload_router.cc
|
| +++ b/webrtc/video/payload_router.cc
|
| @@ -84,11 +84,35 @@ void CopyCodecSpecific(const CodecSpecificInfo* info, RTPVideoHeader* rtp) {
|
| return;
|
| }
|
| }
|
| +
|
| +std::vector<uint32_t> AllocateStreamBitrates(
|
| + uint32_t total_bitrate,
|
| + const SimulcastStream* stream_configs,
|
| + size_t number_of_streams) {
|
| + if (number_of_streams == 0) {
|
| + std::vector<uint32_t> stream_bitrates(1, 0);
|
| + stream_bitrates[0] = total_bitrate;
|
| + return stream_bitrates;
|
| + }
|
| + std::vector<uint32_t> stream_bitrates(number_of_streams, 0);
|
| + uint32_t bitrate_remainder = total_bitrate;
|
| + for (size_t i = 0; i < stream_bitrates.size() && bitrate_remainder > 0; ++i) {
|
| + if (stream_configs[i].maxBitrate * 1000 > bitrate_remainder) {
|
| + stream_bitrates[i] = bitrate_remainder;
|
| + } else {
|
| + stream_bitrates[i] = stream_configs[i].maxBitrate * 1000;
|
| + }
|
| + bitrate_remainder -= stream_bitrates[i];
|
| + }
|
| + return stream_bitrates;
|
| +}
|
| +
|
| } // namespace
|
|
|
| PayloadRouter::PayloadRouter(const std::vector<RtpRtcp*>& rtp_modules,
|
| int payload_type)
|
| : active_(false),
|
| + codec_(),
|
| num_sending_modules_(1),
|
| rtp_modules_(rtp_modules),
|
| payload_type_(payload_type) {
|
| @@ -115,10 +139,11 @@ bool PayloadRouter::active() {
|
| return active_ && !rtp_modules_.empty();
|
| }
|
|
|
| -void PayloadRouter::SetSendingRtpModules(size_t num_sending_modules) {
|
| - RTC_DCHECK_LE(num_sending_modules, rtp_modules_.size());
|
| +void PayloadRouter::SetSendCodec(const VideoCodec& codec) {
|
| + RTC_DCHECK_LE(codec.numberOfSimulcastStreams, rtp_modules_.size());
|
| rtc::CritScope lock(&crit_);
|
| - num_sending_modules_ = num_sending_modules;
|
| + num_sending_modules_ = codec.numberOfSimulcastStreams;
|
| + codec_ = codec;
|
| UpdateModuleSendingState();
|
| }
|
|
|
| @@ -163,9 +188,12 @@ int32_t PayloadRouter::Encoded(const EncodedImage& encoded_image,
|
| encoded_image._length, fragmentation, &rtp_video_header);
|
| }
|
|
|
| -void PayloadRouter::SetTargetSendBitrates(
|
| - const std::vector<uint32_t>& stream_bitrates) {
|
| +void PayloadRouter::SetTargetSendBitrate(uint32_t bitrate_bps) {
|
| rtc::CritScope lock(&crit_);
|
| + // Allocate the bandwidth between the streams.
|
| + std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates(
|
| + bitrate_bps, codec_.simulcastStream, codec_.numberOfSimulcastStreams);
|
| +
|
| RTC_DCHECK_LE(stream_bitrates.size(), rtp_modules_.size());
|
| for (size_t i = 0; i < stream_bitrates.size(); ++i) {
|
| rtp_modules_[i]->SetTargetSendBitrate(stream_bitrates[i]);
|
|
|