Index: webrtc/media/engine/webrtcvoiceengine.cc |
diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc |
index 8561aa2dc4fbcf2c238bef44cee9bcc838334d58..130cc950b0e6e36307dedce323f7edafa1b67e68 100644 |
--- a/webrtc/media/engine/webrtcvoiceengine.cc |
+++ b/webrtc/media/engine/webrtcvoiceengine.cc |
@@ -83,6 +83,9 @@ const int kOpusBitrateFb = 32000; |
const int kOpusMinBitrate = 6000; |
const int kOpusMaxBitrate = 510000; |
+// iSAC bitrate should be <= 56000. |
+const int kIsacMaxBitrate = 56000; |
+ |
// Default audio dscp value. |
// See http://tools.ietf.org/html/rfc2474 for details. |
// See also http://tools.ietf.org/html/draft-jennings-rtcweb-qos-00 |
@@ -305,7 +308,9 @@ class WebRtcVoiceCodecs final { |
MaybeFixupG722(&voe_codec, 8000); |
AudioCodec codec(voe_codec.pltype, voe_codec.plname, voe_codec.plfreq, |
voe_codec.rate, voe_codec.channels); |
- bool multi_rate = IsCodecMultiRate(voe_codec); |
+ // This function returns a nonempty value if the codec is multi-rate. |
+ bool multi_rate = |
+ bool(WebRtcVoiceCodecs::MaxBitrateBpsForMultiRateCodec(voe_codec)); |
// Allow arbitrary rates for ISAC to be specified. |
if (multi_rate) { |
// Set codec.bitrate to 0 so the check for codec.Matches() passes. |
@@ -338,14 +343,15 @@ class WebRtcVoiceCodecs final { |
return false; |
} |
- static bool IsCodecMultiRate(const webrtc::CodecInst& codec) { |
+ static rtc::Optional<int> MaxBitrateBpsForMultiRateCodec( |
+ const webrtc::CodecInst& codec) { |
for (size_t i = 0; i < arraysize(kCodecPrefs); ++i) { |
if (IsCodec(codec, kCodecPrefs[i].name) && |
kCodecPrefs[i].clockrate == codec.plfreq) { |
- return kCodecPrefs[i].is_multi_rate; |
+ return kCodecPrefs[i].max_bitrate_bps; |
} |
} |
- return false; |
+ return rtc::Optional<int>(); |
} |
// If the AudioCodec param kCodecParamPTime is set, then we will set it to |
@@ -416,8 +422,9 @@ class WebRtcVoiceCodecs final { |
int clockrate; |
size_t channels; |
int payload_type; |
- bool is_multi_rate; |
int packet_sizes_ms[kMaxNumPacketSize]; |
+ // Nonempty if it's a multirate codec. |
The Sun (google.com)
2016/04/26 22:18:08
Ah, what I had in mind was just to make the return
|
+ rtc::Optional<int> max_bitrate_bps; |
}; |
// Note: keep the supported packet sizes in ascending order. |
static const CodecPref kCodecPrefs[12]; |
@@ -484,19 +491,29 @@ class WebRtcVoiceCodecs final { |
}; |
const WebRtcVoiceCodecs::CodecPref WebRtcVoiceCodecs::kCodecPrefs[12] = { |
- { kOpusCodecName, 48000, 2, 111, true, { 10, 20, 40, 60 } }, |
- { kIsacCodecName, 16000, 1, 103, true, { 30, 60 } }, |
- { kIsacCodecName, 32000, 1, 104, true, { 30 } }, |
- // G722 should be advertised as 8000 Hz because of the RFC "bug". |
- { kG722CodecName, 8000, 1, 9, false, { 10, 20, 30, 40, 50, 60 } }, |
- { kIlbcCodecName, 8000, 1, 102, false, { 20, 30, 40, 60 } }, |
- { kPcmuCodecName, 8000, 1, 0, false, { 10, 20, 30, 40, 50, 60 } }, |
- { kPcmaCodecName, 8000, 1, 8, false, { 10, 20, 30, 40, 50, 60 } }, |
- { kCnCodecName, 32000, 1, 106, false, { } }, |
- { kCnCodecName, 16000, 1, 105, false, { } }, |
- { kCnCodecName, 8000, 1, 13, false, { } }, |
- { kRedCodecName, 8000, 1, 127, false, { } }, |
- { kDtmfCodecName, 8000, 1, 126, false, { } }, |
+ {kOpusCodecName, |
+ 48000, |
+ 2, |
+ 111, |
+ {10, 20, 40, 60}, |
+ rtc::Optional<int>(kOpusMaxBitrate)}, |
+ {kIsacCodecName, |
+ 16000, |
+ 1, |
+ 103, |
+ {30, 60}, |
+ rtc::Optional<int>(kIsacMaxBitrate)}, |
+ {kIsacCodecName, 32000, 1, 104, {30}, rtc::Optional<int>(kIsacMaxBitrate)}, |
+ // G722 should be advertised as 8000 Hz because of the RFC "bug". |
+ {kG722CodecName, 8000, 1, 9, {10, 20, 30, 40, 50, 60}}, |
+ {kIlbcCodecName, 8000, 1, 102, {20, 30, 40, 60}}, |
+ {kPcmuCodecName, 8000, 1, 0, {10, 20, 30, 40, 50, 60}}, |
+ {kPcmaCodecName, 8000, 1, 8, {10, 20, 30, 40, 50, 60}}, |
+ {kCnCodecName, 32000, 1, 106, {}}, |
+ {kCnCodecName, 16000, 1, 105, {}}, |
+ {kCnCodecName, 8000, 1, 13, {}}, |
+ {kRedCodecName, 8000, 1, 127, {}}, |
+ {kDtmfCodecName, 8000, 1, 126, {}}, |
}; |
} // namespace { |
@@ -1367,7 +1384,7 @@ bool WebRtcVoiceMediaChannel::SetSendParameters( |
} |
} |
- if (!SetSendBitrate(params.max_bandwidth_bps)) { |
+ if (!SetMaxSendBitrate(params.max_bandwidth_bps)) { |
return false; |
} |
return SetOptions(params.options); |
@@ -1747,7 +1764,7 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs( |
} |
} |
} |
- // TODO(solenberg): SetSendBitrate() yields another call to SetSendCodec(). |
+ // TODO(solenberg): SetMaxSendBitrate() yields another call to SetSendCodec(). |
// Check if it is possible to fuse with the previous call in this function. |
SetChannelParameters(channel, rtp_parameters); |
@@ -2383,9 +2400,9 @@ bool WebRtcVoiceMediaChannel::MuteStream(uint32_t ssrc, bool muted) { |
return true; |
} |
-bool WebRtcVoiceMediaChannel::SetSendBitrate(int bps) { |
- LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendBitrate."; |
- send_bitrate_bps_ = bps; |
+bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int bps) { |
+ LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetMaxSendBitrate."; |
+ max_send_bitrate_bps_ = bps; |
for (const auto& kv : send_streams_) { |
if (!SetChannelParameters(kv.second->channel(), |
@@ -2402,17 +2419,18 @@ bool WebRtcVoiceMediaChannel::SetChannelParameters( |
RTC_CHECK_EQ(1UL, parameters.encodings.size()); |
// TODO(deadbeef): Handle setting parameters with a list of codecs in a |
// different order (which should change the send codec). |
- return SetSendBitrate( |
- channel, |
- MinPositive(send_bitrate_bps_, parameters.encodings[0].max_bitrate_bps)); |
+ return SetMaxSendBitrate( |
+ channel, MinPositive(max_send_bitrate_bps_, |
+ parameters.encodings[0].max_bitrate_bps)); |
} |
-bool WebRtcVoiceMediaChannel::SetSendBitrate(int channel, int bps) { |
+bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int channel, int bps) { |
// Bitrate is auto by default. |
// TODO(bemasc): Fix this so that if SetMaxSendBandwidth(50) is followed by |
// SetMaxSendBandwith(0), the second call removes the previous limit. |
- if (bps <= 0) |
+ if (bps <= 0) { |
return true; |
+ } |
if (!HasSendCodec()) { |
LOG(LS_INFO) << "The send codec has not been set up yet. " |
@@ -2421,14 +2439,18 @@ bool WebRtcVoiceMediaChannel::SetSendBitrate(int channel, int bps) { |
} |
webrtc::CodecInst codec = send_codec_spec_.codec_inst; |
- bool is_multi_rate = WebRtcVoiceCodecs::IsCodecMultiRate(codec); |
+ // This function returns a nonempty value if the codec is multi-rate. |
+ rtc::Optional<int> max_bitrate_bps = |
+ WebRtcVoiceCodecs::MaxBitrateBpsForMultiRateCodec(codec); |
- if (is_multi_rate) { |
+ if (max_bitrate_bps) { |
// If codec is multi-rate then just set the bitrate. |
- codec.rate = bps; |
+ codec.rate = std::min(bps, *max_bitrate_bps); |
+ LOG(LS_INFO) << "Setting codec " << codec.plname << " to bitrate " << bps |
+ << " bps."; |
if (!SetSendCodec(channel, codec)) { |
- LOG(LS_INFO) << "Failed to set codec " << codec.plname << " to bitrate " |
- << bps << " bps."; |
+ LOG(LS_ERROR) << "Failed to set codec " << codec.plname << " to bitrate " |
+ << bps << " bps."; |
return false; |
} |
return true; |
@@ -2437,9 +2459,9 @@ bool WebRtcVoiceMediaChannel::SetSendBitrate(int channel, int bps) { |
// then fail. If codec is not multi-rate and |bps| exceeds or equal the |
// fixed bitrate then ignore. |
if (bps < codec.rate) { |
- LOG(LS_INFO) << "Failed to set codec " << codec.plname |
- << " to bitrate " << bps << " bps" |
- << ", requires at least " << codec.rate << " bps."; |
+ LOG(LS_ERROR) << "Failed to set codec " << codec.plname << " to bitrate " |
+ << bps << " bps" |
+ << ", requires at least " << codec.rate << " bps."; |
return false; |
} |
return true; |