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

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine.cc

Issue 1847353004: Allow applications to control audio send bitrate through RtpParameters. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Redesigned to keep the logic inside WebRtcVoiceMediaChannel Created 4 years, 8 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) 2004 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2004 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 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 } 1074 }
1075 1075
1076 int WebRtcVoiceEngine::CreateVoEChannel() { 1076 int WebRtcVoiceEngine::CreateVoEChannel() {
1077 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1077 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1078 return voe_wrapper_->base()->CreateChannel(voe_config_); 1078 return voe_wrapper_->base()->CreateChannel(voe_config_);
1079 } 1079 }
1080 1080
1081 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream 1081 class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
1082 : public AudioSource::Sink { 1082 : public AudioSource::Sink {
1083 public: 1083 public:
1084 WebRtcAudioSendStream(int ch, webrtc::AudioTransport* voe_audio_transport, 1084 WebRtcAudioSendStream(int ch,
1085 uint32_t ssrc, const std::string& c_name, 1085 webrtc::AudioTransport* voe_audio_transport,
1086 uint32_t ssrc,
1087 const std::string& c_name,
1086 const std::vector<webrtc::RtpExtension>& extensions, 1088 const std::vector<webrtc::RtpExtension>& extensions,
1087 webrtc::Call* call) 1089 webrtc::Call* call)
1088 : voe_audio_transport_(voe_audio_transport), 1090 : voe_audio_transport_(voe_audio_transport),
1089 call_(call), 1091 call_(call),
1090 config_(nullptr) { 1092 config_(nullptr),
1093 rtp_parameters_(CreateRtpParametersWithOneEncoding()) {
1091 RTC_DCHECK_GE(ch, 0); 1094 RTC_DCHECK_GE(ch, 0);
1092 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore: 1095 // TODO(solenberg): Once we're not using FakeWebRtcVoiceEngine anymore:
1093 // RTC_DCHECK(voe_audio_transport); 1096 // RTC_DCHECK(voe_audio_transport);
1094 RTC_DCHECK(call); 1097 RTC_DCHECK(call);
1095 audio_capture_thread_checker_.DetachFromThread(); 1098 audio_capture_thread_checker_.DetachFromThread();
1096 config_.rtp.ssrc = ssrc; 1099 config_.rtp.ssrc = ssrc;
1097 config_.rtp.c_name = c_name; 1100 config_.rtp.c_name = c_name;
1098 config_.voe_channel_id = ch; 1101 config_.voe_channel_id = ch;
1099 RecreateAudioSendStream(extensions); 1102 RecreateAudioSendStream(extensions);
1100 } 1103 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 source_ = nullptr; 1194 source_ = nullptr;
1192 UpdateSendState(); 1195 UpdateSendState();
1193 } 1196 }
1194 1197
1195 // Accessor to the VoE channel ID. 1198 // Accessor to the VoE channel ID.
1196 int channel() const { 1199 int channel() const {
1197 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1200 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1198 return config_.voe_channel_id; 1201 return config_.voe_channel_id;
1199 } 1202 }
1200 1203
1204 webrtc::RtpParameters rtp_parameters() const { return rtp_parameters_; }
the sun 2016/04/06 09:27:41 Return a const &
skvlad 2016/04/07 00:50:49 Done. It's a bit dangerous though - if the caller
the sun 2016/04/07 08:22:21 True, which is why I didn't comment on WVoMC::GetR
1205
1206 void set_rtp_parameters(const webrtc::RtpParameters& parameters) {
the sun 2016/04/06 09:27:41 RTC_DCHECK_EQ(1, parameters.encodings.size()); or
skvlad 2016/04/07 00:50:50 It's supposed to be exactly 1 at the moment. Added
1207 rtp_parameters_ = parameters;
1208 }
1209
1201 private: 1210 private:
1202 void UpdateSendState() { 1211 void UpdateSendState() {
1203 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1212 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1204 RTC_DCHECK(stream_); 1213 RTC_DCHECK(stream_);
1205 if (send_ && source_ != nullptr) { 1214 if (send_ && source_ != nullptr) {
1206 stream_->Start(); 1215 stream_->Start();
1207 } else { // !send || source_ = nullptr 1216 } else { // !send || source_ = nullptr
1208 stream_->Stop(); 1217 stream_->Stop();
1209 } 1218 }
1210 } 1219 }
1211 1220
1212 rtc::ThreadChecker worker_thread_checker_; 1221 rtc::ThreadChecker worker_thread_checker_;
1213 rtc::ThreadChecker audio_capture_thread_checker_; 1222 rtc::ThreadChecker audio_capture_thread_checker_;
1214 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; 1223 webrtc::AudioTransport* const voe_audio_transport_ = nullptr;
1215 webrtc::Call* call_ = nullptr; 1224 webrtc::Call* call_ = nullptr;
1216 webrtc::AudioSendStream::Config config_; 1225 webrtc::AudioSendStream::Config config_;
1217 // The stream is owned by WebRtcAudioSendStream and may be reallocated if 1226 // The stream is owned by WebRtcAudioSendStream and may be reallocated if
1218 // configuration changes. 1227 // configuration changes.
1219 webrtc::AudioSendStream* stream_ = nullptr; 1228 webrtc::AudioSendStream* stream_ = nullptr;
1220 1229
1221 // Raw pointer to AudioSource owned by LocalAudioTrackHandler. 1230 // Raw pointer to AudioSource owned by LocalAudioTrackHandler.
1222 // PeerConnection will make sure invalidating the pointer before the object 1231 // PeerConnection will make sure invalidating the pointer before the object
1223 // goes away. 1232 // goes away.
1224 AudioSource* source_ = nullptr; 1233 AudioSource* source_ = nullptr;
1225 bool send_ = false; 1234 bool send_ = false;
1235 webrtc::RtpParameters rtp_parameters_;
1226 1236
1227 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream); 1237 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream);
1228 }; 1238 };
1229 1239
1230 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream { 1240 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream {
1231 public: 1241 public:
1232 WebRtcAudioReceiveStream(int ch, 1242 WebRtcAudioReceiveStream(int ch,
1233 uint32_t remote_ssrc, 1243 uint32_t remote_ssrc,
1234 uint32_t local_ssrc, 1244 uint32_t local_ssrc,
1235 bool use_transport_cc, 1245 bool use_transport_cc,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 std::vector<webrtc::RtpExtension> filtered_extensions = 1362 std::vector<webrtc::RtpExtension> filtered_extensions =
1353 FilterRtpExtensions(params.extensions, 1363 FilterRtpExtensions(params.extensions,
1354 webrtc::RtpExtension::IsSupportedForAudio, true); 1364 webrtc::RtpExtension::IsSupportedForAudio, true);
1355 if (send_rtp_extensions_ != filtered_extensions) { 1365 if (send_rtp_extensions_ != filtered_extensions) {
1356 send_rtp_extensions_.swap(filtered_extensions); 1366 send_rtp_extensions_.swap(filtered_extensions);
1357 for (auto& it : send_streams_) { 1367 for (auto& it : send_streams_) {
1358 it.second->RecreateAudioSendStream(send_rtp_extensions_); 1368 it.second->RecreateAudioSendStream(send_rtp_extensions_);
1359 } 1369 }
1360 } 1370 }
1361 1371
1362 if (!SetMaxSendBandwidth(params.max_bandwidth_bps)) { 1372 if (!SetSendBitrate(params.max_bandwidth_bps)) {
1363 return false; 1373 return false;
1364 } 1374 }
1365 return SetOptions(params.options); 1375 return SetOptions(params.options);
1366 } 1376 }
1367 1377
1368 bool WebRtcVoiceMediaChannel::SetRecvParameters( 1378 bool WebRtcVoiceMediaChannel::SetRecvParameters(
1369 const AudioRecvParameters& params) { 1379 const AudioRecvParameters& params) {
1370 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetRecvParameters"); 1380 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetRecvParameters");
1371 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1381 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1372 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetRecvParameters: " 1382 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetRecvParameters: "
(...skipping 13 matching lines...) Expand all
1386 webrtc::RtpExtension::IsSupportedForAudio, false); 1396 webrtc::RtpExtension::IsSupportedForAudio, false);
1387 if (recv_rtp_extensions_ != filtered_extensions) { 1397 if (recv_rtp_extensions_ != filtered_extensions) {
1388 recv_rtp_extensions_.swap(filtered_extensions); 1398 recv_rtp_extensions_.swap(filtered_extensions);
1389 for (auto& it : recv_streams_) { 1399 for (auto& it : recv_streams_) {
1390 it.second->RecreateAudioReceiveStream(recv_rtp_extensions_); 1400 it.second->RecreateAudioReceiveStream(recv_rtp_extensions_);
1391 } 1401 }
1392 } 1402 }
1393 return true; 1403 return true;
1394 } 1404 }
1395 1405
1406 webrtc::RtpParameters WebRtcVoiceMediaChannel::GetRtpParameters(
1407 uint32_t ssrc) const {
1408 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1409 auto it = send_streams_.find(ssrc);
1410 if (it == send_streams_.end()) {
1411 LOG(LS_WARNING) << "Attempting to get RTP parameters for stream with ssrc "
1412 << ssrc << " which doesn't exist.";
1413 return webrtc::RtpParameters();
1414 }
1415
1416 return it->second->rtp_parameters();
1417 }
1418
1419 bool WebRtcVoiceMediaChannel::SetRtpParameters(
1420 uint32_t ssrc,
1421 const webrtc::RtpParameters& parameters) {
1422 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1423 if (!ValidateRtpParameters(parameters)) {
1424 return false;
1425 }
1426 auto it = send_streams_.find(ssrc);
1427 if (it == send_streams_.end()) {
1428 LOG(LS_WARNING) << "Attempting to set RTP parameters for stream with ssrc "
1429 << ssrc << " which doesn't exist.";
1430 return false;
1431 }
1432
1433 int combined_bitrate_limit =
1434 MinPositive(parameters.encodings[0].max_bitrate_bps, send_bitrate_bps_);
1435 if (!SetSendBitrate(it->second->channel(), combined_bitrate_limit)) {
1436 LOG(LS_WARNING) << "Failed to apply the bitrate limit.";
1437 return false;
1438 }
1439 it->second->set_rtp_parameters(parameters);
1440 return true;
1441 }
1442
1443 bool WebRtcVoiceMediaChannel::ValidateRtpParameters(
1444 const webrtc::RtpParameters& rtp_parameters) {
1445 if (rtp_parameters.encodings.size() != 1) {
1446 LOG(LS_ERROR)
1447 << "Attempted to set RtpParameters without exactly one encoding";
1448 return false;
1449 }
1450 return true;
1451 }
1452
1396 bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { 1453 bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) {
1397 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1454 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1398 LOG(LS_INFO) << "Setting voice channel options: " 1455 LOG(LS_INFO) << "Setting voice channel options: "
1399 << options.ToString(); 1456 << options.ToString();
1400 1457
1401 // We retain all of the existing options, and apply the given ones 1458 // We retain all of the existing options, and apply the given ones
1402 // on top. This means there is no way to "clear" options such that 1459 // on top. This means there is no way to "clear" options such that
1403 // they go back to the engine default. 1460 // they go back to the engine default.
1404 options_.SetAll(options); 1461 options_.SetAll(options);
1405 if (!engine()->ApplyOptions(options_)) { 1462 if (!engine()->ApplyOptions(options_)) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 break; 1637 break;
1581 } 1638 }
1582 } 1639 }
1583 1640
1584 // Latch in the new state. 1641 // Latch in the new state.
1585 send_codec_spec_ = std::move(send_codec_spec); 1642 send_codec_spec_ = std::move(send_codec_spec);
1586 } 1643 }
1587 1644
1588 // Cache the codecs in order to configure the channel created later. 1645 // Cache the codecs in order to configure the channel created later.
1589 for (const auto& ch : send_streams_) { 1646 for (const auto& ch : send_streams_) {
1590 if (!SetSendCodecs(ch.second->channel())) { 1647 if (!SetSendCodecs(ch.second->channel(), ch.second->rtp_parameters())) {
1591 return false; 1648 return false;
1592 } 1649 }
1593 } 1650 }
1594 1651
1595 // Set nack status on receive channels. 1652 // Set nack status on receive channels.
1596 if (!send_streams_.empty()) { 1653 if (!send_streams_.empty()) {
1597 for (const auto& kv : recv_streams_) { 1654 for (const auto& kv : recv_streams_) {
1598 SetNack(kv.second->channel(), send_codec_spec_.nack_enabled); 1655 SetNack(kv.second->channel(), send_codec_spec_.nack_enabled);
1599 } 1656 }
1600 } 1657 }
1601 1658
1602 // Check if the transport cc feedback has changed on the preferred send codec, 1659 // Check if the transport cc feedback has changed on the preferred send codec,
1603 // and in that case reconfigure all receive streams. 1660 // and in that case reconfigure all receive streams.
1604 if (recv_transport_cc_enabled_ != send_codec_spec_.transport_cc_enabled) { 1661 if (recv_transport_cc_enabled_ != send_codec_spec_.transport_cc_enabled) {
1605 LOG(LS_INFO) << "Recreate all the receive streams because the send " 1662 LOG(LS_INFO) << "Recreate all the receive streams because the send "
1606 "codec has changed."; 1663 "codec has changed.";
1607 recv_transport_cc_enabled_ = send_codec_spec_.transport_cc_enabled; 1664 recv_transport_cc_enabled_ = send_codec_spec_.transport_cc_enabled;
1608 for (auto& kv : recv_streams_) { 1665 for (auto& kv : recv_streams_) {
1609 kv.second->RecreateAudioReceiveStream(recv_transport_cc_enabled_); 1666 kv.second->RecreateAudioReceiveStream(recv_transport_cc_enabled_);
1610 } 1667 }
1611 } 1668 }
1612 1669
1613 return true; 1670 return true;
1614 } 1671 }
1615 1672
1616 // Apply current codec settings to a single voe::Channel used for sending. 1673 // Apply current codec settings to a single voe::Channel used for sending.
1617 bool WebRtcVoiceMediaChannel::SetSendCodecs(int channel) { 1674 bool WebRtcVoiceMediaChannel::SetSendCodecs(
1675 int channel,
1676 const webrtc::RtpParameters& rtp_parameters) {
1618 // Disable VAD, FEC, and RED unless we know the other side wants them. 1677 // Disable VAD, FEC, and RED unless we know the other side wants them.
1619 engine()->voe()->codec()->SetVADStatus(channel, false); 1678 engine()->voe()->codec()->SetVADStatus(channel, false);
1620 engine()->voe()->rtp()->SetNACKStatus(channel, false, 0); 1679 engine()->voe()->rtp()->SetNACKStatus(channel, false, 0);
1621 engine()->voe()->rtp()->SetREDStatus(channel, false); 1680 engine()->voe()->rtp()->SetREDStatus(channel, false);
1622 engine()->voe()->codec()->SetFECStatus(channel, false); 1681 engine()->voe()->codec()->SetFECStatus(channel, false);
1623 1682
1624 if (send_codec_spec_.red_payload_type != -1) { 1683 if (send_codec_spec_.red_payload_type != -1) {
1625 // Enable redundant encoding of the specified codec. Treat any 1684 // Enable redundant encoding of the specified codec. Treat any
1626 // failure as a fatal internal error. 1685 // failure as a fatal internal error.
1627 LOG(LS_INFO) << "Enabling RED on channel " << channel; 1686 LOG(LS_INFO) << "Enabling RED on channel " << channel;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 << channel; 1735 << channel;
1677 if (engine()->voe()->codec()->SetOpusMaxPlaybackRate( 1736 if (engine()->voe()->codec()->SetOpusMaxPlaybackRate(
1678 channel, send_codec_spec_.opus_max_playback_rate) == -1) { 1737 channel, send_codec_spec_.opus_max_playback_rate) == -1) {
1679 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel, 1738 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel,
1680 send_codec_spec_.opus_max_playback_rate); 1739 send_codec_spec_.opus_max_playback_rate);
1681 return false; 1740 return false;
1682 } 1741 }
1683 } 1742 }
1684 } 1743 }
1685 1744
1686 if (send_bitrate_setting_) { 1745 SetSendBitrate(channel,
the sun 2016/04/06 09:27:41 Add: TODO(solenberg): SetSendBitrate() yields anot
skvlad 2016/04/07 00:50:50 Done.
1687 SetSendBitrateInternal(send_bitrate_bps_); 1746 MinPositive(send_bitrate_bps_,
1688 } 1747 rtp_parameters.encodings[0].max_bitrate_bps));
1689 1748
1690 // Set the CN payloadtype and the VAD status. 1749 // Set the CN payloadtype and the VAD status.
1691 if (send_codec_spec_.cng_payload_type != -1) { 1750 if (send_codec_spec_.cng_payload_type != -1) {
1692 // The CN payload type for 8000 Hz clockrate is fixed at 13. 1751 // The CN payload type for 8000 Hz clockrate is fixed at 13.
1693 if (send_codec_spec_.cng_plfreq != 8000) { 1752 if (send_codec_spec_.cng_plfreq != 8000) {
1694 webrtc::PayloadFrequencies cn_freq; 1753 webrtc::PayloadFrequencies cn_freq;
1695 switch (send_codec_spec_.cng_plfreq) { 1754 switch (send_codec_spec_.cng_plfreq) {
1696 case 16000: 1755 case 16000:
1697 cn_freq = webrtc::kFreq16000Hz; 1756 cn_freq = webrtc::kFreq16000Hz;
1698 break; 1757 break;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 // Create a new channel for sending audio data. 1932 // Create a new channel for sending audio data.
1874 int channel = CreateVoEChannel(); 1933 int channel = CreateVoEChannel();
1875 if (channel == -1) { 1934 if (channel == -1) {
1876 return false; 1935 return false;
1877 } 1936 }
1878 1937
1879 // Save the channel to send_streams_, so that RemoveSendStream() can still 1938 // Save the channel to send_streams_, so that RemoveSendStream() can still
1880 // delete the channel in case failure happens below. 1939 // delete the channel in case failure happens below.
1881 webrtc::AudioTransport* audio_transport = 1940 webrtc::AudioTransport* audio_transport =
1882 engine()->voe()->base()->audio_transport(); 1941 engine()->voe()->base()->audio_transport();
1883 send_streams_.insert(std::make_pair(ssrc, new WebRtcAudioSendStream( 1942 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream(
1884 channel, audio_transport, ssrc, sp.cname, send_rtp_extensions_, call_))); 1943 channel, audio_transport, ssrc, sp.cname, send_rtp_extensions_, call_);
1944 send_streams_.insert(std::make_pair(ssrc, stream));
1885 1945
1886 // Set the current codecs to be used for the new channel. We need to do this 1946 // Set the current codecs to be used for the new channel. We need to do this
1887 // after adding the channel to send_channels_, because of how max bitrate is 1947 // after adding the channel to send_channels_, because of how max bitrate is
1888 // currently being configured by SetSendCodec(). 1948 // currently being configured by SetSendCodec().
1889 if (HasSendCodec() && !SetSendCodecs(channel)) { 1949 if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) {
1890 RemoveSendStream(ssrc); 1950 RemoveSendStream(ssrc);
1891 return false; 1951 return false;
1892 } 1952 }
1893 1953
1894 // At this point the channel's local SSRC has been updated. If the channel is 1954 // At this point the channel's local SSRC has been updated. If the channel is
1895 // the first send channel make sure that all the receive channels are updated 1955 // the first send channel make sure that all the receive channels are updated
1896 // with the same SSRC in order to send receiver reports. 1956 // with the same SSRC in order to send receiver reports.
1897 if (send_streams_.size() == 1) { 1957 if (send_streams_.size() == 1) {
1898 receiver_reports_ssrc_ = ssrc; 1958 receiver_reports_ssrc_ = ssrc;
1899 for (const auto& stream : recv_streams_) { 1959 for (const auto& stream : recv_streams_) {
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
2303 } 2363 }
2304 } 2364 }
2305 2365
2306 webrtc::AudioProcessing* ap = engine()->voe()->base()->audio_processing(); 2366 webrtc::AudioProcessing* ap = engine()->voe()->base()->audio_processing();
2307 if (ap) { 2367 if (ap) {
2308 ap->set_output_will_be_muted(all_muted); 2368 ap->set_output_will_be_muted(all_muted);
2309 } 2369 }
2310 return true; 2370 return true;
2311 } 2371 }
2312 2372
2313 // TODO(minyue): SetMaxSendBandwidth() is subject to be renamed to 2373 bool WebRtcVoiceMediaChannel::SetSendBitrate(int bps) {
2314 // SetMaxSendBitrate() in future. 2374 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendBitrate.";
2315 bool WebRtcVoiceMediaChannel::SetMaxSendBandwidth(int bps) { 2375 send_bitrate_bps_ = bps;
2316 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetMaxSendBandwidth."; 2376
2317 return SetSendBitrateInternal(bps); 2377 for (const auto& ch : send_streams_) {
the sun 2016/04/06 09:27:41 super nit: use 'kv' for the variable instead (sorr
skvlad 2016/04/07 00:50:50 Done.
2378 int channel_bitrate =
2379 MinPositive(send_bitrate_bps_,
2380 ch.second->rtp_parameters().encodings[0].max_bitrate_bps);
2381
2382 if (!SetSendBitrate(ch.second->channel(), channel_bitrate)) {
2383 return false;
2384 }
2385 }
2386 return true;
2318 } 2387 }
2319 2388
2320 bool WebRtcVoiceMediaChannel::SetSendBitrateInternal(int bps) { 2389 bool WebRtcVoiceMediaChannel::SetSendBitrate(int channel, int bps) {
the sun 2016/04/06 09:27:41 How about you send in the const RtpParameters& her
skvlad 2016/04/07 00:50:49 Done.
2321 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendBitrateInternal."; 2390 // Bitrate is auto by default.
2322 2391 // TODO(bemasc): Fix this so that if SetMaxSendBandwidth(50) is followed by
2323 send_bitrate_setting_ = true; 2392 // SetMaxSendBandwith(0), the second call removes the previous limit.
2324 send_bitrate_bps_ = bps; 2393 if (bps <= 0)
2394 return true;
2325 2395
2326 if (!HasSendCodec()) { 2396 if (!HasSendCodec()) {
2327 LOG(LS_INFO) << "The send codec has not been set up yet. " 2397 LOG(LS_INFO) << "The send codec has not been set up yet. "
2328 << "The send bitrate setting will be applied later."; 2398 << "The send bitrate setting will be applied later.";
2329 return true; 2399 return true;
2330 } 2400 }
2331 2401
2332 // Bitrate is auto by default.
2333 // TODO(bemasc): Fix this so that if SetMaxSendBandwidth(50) is followed by
2334 // SetMaxSendBandwith(0), the second call removes the previous limit.
2335 if (bps <= 0)
2336 return true;
2337
2338 webrtc::CodecInst codec = send_codec_spec_.codec_inst; 2402 webrtc::CodecInst codec = send_codec_spec_.codec_inst;
2339 bool is_multi_rate = WebRtcVoiceCodecs::IsCodecMultiRate(codec); 2403 bool is_multi_rate = WebRtcVoiceCodecs::IsCodecMultiRate(codec);
2340 2404
2341 if (is_multi_rate) { 2405 if (is_multi_rate) {
2342 // If codec is multi-rate then just set the bitrate. 2406 // If codec is multi-rate then just set the bitrate.
2343 codec.rate = bps; 2407 codec.rate = bps;
2344 for (const auto& ch : send_streams_) { 2408 if (!SetSendCodec(channel, codec)) {
the sun 2016/04/06 09:27:41 Great to remove this!
2345 if (!SetSendCodec(ch.second->channel(), codec)) { 2409 LOG(LS_INFO) << "Failed to set codec " << codec.plname << " to bitrate "
2346 LOG(LS_INFO) << "Failed to set codec " << codec.plname 2410 << bps << " bps.";
2347 << " to bitrate " << bps << " bps."; 2411 return false;
2348 return false;
2349 }
2350 } 2412 }
2351 return true; 2413 return true;
2352 } else { 2414 } else {
2353 // If codec is not multi-rate and |bps| is less than the fixed bitrate 2415 // If codec is not multi-rate and |bps| is less than the fixed bitrate
2354 // then fail. If codec is not multi-rate and |bps| exceeds or equal the 2416 // then fail. If codec is not multi-rate and |bps| exceeds or equal the
2355 // fixed bitrate then ignore. 2417 // fixed bitrate then ignore.
2356 if (bps < codec.rate) { 2418 if (bps < codec.rate) {
2357 LOG(LS_INFO) << "Failed to set codec " << codec.plname 2419 LOG(LS_INFO) << "Failed to set codec " << codec.plname
2358 << " to bitrate " << bps << " bps" 2420 << " to bitrate " << bps << " bps"
2359 << ", requires at least " << codec.rate << " bps."; 2421 << ", requires at least " << codec.rate << " bps.";
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 } 2554 }
2493 } else { 2555 } else {
2494 LOG(LS_INFO) << "Stopping playout for channel #" << channel; 2556 LOG(LS_INFO) << "Stopping playout for channel #" << channel;
2495 engine()->voe()->base()->StopPlayout(channel); 2557 engine()->voe()->base()->StopPlayout(channel);
2496 } 2558 }
2497 return true; 2559 return true;
2498 } 2560 }
2499 } // namespace cricket 2561 } // namespace cricket
2500 2562
2501 #endif // HAVE_WEBRTC_VOICE 2563 #endif // HAVE_WEBRTC_VOICE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698