Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 const webrtc::RtpParameters& rtp_parameters() const { | |
| 1205 return rtp_parameters_; | |
| 1206 } | |
| 1207 | |
| 1208 void set_rtp_parameters(const webrtc::RtpParameters& parameters) { | |
| 1209 RTC_CHECK_EQ(1UL, parameters.encodings.size()); | |
| 1210 rtp_parameters_ = parameters; | |
| 1211 } | |
| 1212 | |
| 1201 private: | 1213 private: | 
| 1202 void UpdateSendState() { | 1214 void UpdateSendState() { | 
| 1203 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1215 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| 1204 RTC_DCHECK(stream_); | 1216 RTC_DCHECK(stream_); | 
| 1205 if (send_ && source_ != nullptr) { | 1217 if (send_ && source_ != nullptr) { | 
| 1206 stream_->Start(); | 1218 stream_->Start(); | 
| 1207 } else { // !send || source_ = nullptr | 1219 } else { // !send || source_ = nullptr | 
| 1208 stream_->Stop(); | 1220 stream_->Stop(); | 
| 1209 } | 1221 } | 
| 1210 } | 1222 } | 
| 1211 | 1223 | 
| 1212 rtc::ThreadChecker worker_thread_checker_; | 1224 rtc::ThreadChecker worker_thread_checker_; | 
| 1213 rtc::ThreadChecker audio_capture_thread_checker_; | 1225 rtc::ThreadChecker audio_capture_thread_checker_; | 
| 1214 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; | 1226 webrtc::AudioTransport* const voe_audio_transport_ = nullptr; | 
| 1215 webrtc::Call* call_ = nullptr; | 1227 webrtc::Call* call_ = nullptr; | 
| 1216 webrtc::AudioSendStream::Config config_; | 1228 webrtc::AudioSendStream::Config config_; | 
| 1217 // The stream is owned by WebRtcAudioSendStream and may be reallocated if | 1229 // The stream is owned by WebRtcAudioSendStream and may be reallocated if | 
| 1218 // configuration changes. | 1230 // configuration changes. | 
| 1219 webrtc::AudioSendStream* stream_ = nullptr; | 1231 webrtc::AudioSendStream* stream_ = nullptr; | 
| 1220 | 1232 | 
| 1221 // Raw pointer to AudioSource owned by LocalAudioTrackHandler. | 1233 // Raw pointer to AudioSource owned by LocalAudioTrackHandler. | 
| 1222 // PeerConnection will make sure invalidating the pointer before the object | 1234 // PeerConnection will make sure invalidating the pointer before the object | 
| 1223 // goes away. | 1235 // goes away. | 
| 1224 AudioSource* source_ = nullptr; | 1236 AudioSource* source_ = nullptr; | 
| 1225 bool send_ = false; | 1237 bool send_ = false; | 
| 1238 webrtc::RtpParameters rtp_parameters_; | |
| 1226 | 1239 | 
| 1227 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream); | 1240 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WebRtcAudioSendStream); | 
| 1228 }; | 1241 }; | 
| 1229 | 1242 | 
| 1230 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream { | 1243 class WebRtcVoiceMediaChannel::WebRtcAudioReceiveStream { | 
| 1231 public: | 1244 public: | 
| 1232 WebRtcAudioReceiveStream(int ch, | 1245 WebRtcAudioReceiveStream(int ch, | 
| 1233 uint32_t remote_ssrc, | 1246 uint32_t remote_ssrc, | 
| 1234 uint32_t local_ssrc, | 1247 uint32_t local_ssrc, | 
| 1235 bool use_transport_cc, | 1248 bool use_transport_cc, | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1352 std::vector<webrtc::RtpExtension> filtered_extensions = | 1365 std::vector<webrtc::RtpExtension> filtered_extensions = | 
| 1353 FilterRtpExtensions(params.extensions, | 1366 FilterRtpExtensions(params.extensions, | 
| 1354 webrtc::RtpExtension::IsSupportedForAudio, true); | 1367 webrtc::RtpExtension::IsSupportedForAudio, true); | 
| 1355 if (send_rtp_extensions_ != filtered_extensions) { | 1368 if (send_rtp_extensions_ != filtered_extensions) { | 
| 1356 send_rtp_extensions_.swap(filtered_extensions); | 1369 send_rtp_extensions_.swap(filtered_extensions); | 
| 1357 for (auto& it : send_streams_) { | 1370 for (auto& it : send_streams_) { | 
| 1358 it.second->RecreateAudioSendStream(send_rtp_extensions_); | 1371 it.second->RecreateAudioSendStream(send_rtp_extensions_); | 
| 1359 } | 1372 } | 
| 1360 } | 1373 } | 
| 1361 | 1374 | 
| 1362 if (!SetMaxSendBandwidth(params.max_bandwidth_bps)) { | 1375 if (!SetSendBitrate(params.max_bandwidth_bps)) { | 
| 1363 return false; | 1376 return false; | 
| 1364 } | 1377 } | 
| 1365 return SetOptions(params.options); | 1378 return SetOptions(params.options); | 
| 1366 } | 1379 } | 
| 1367 | 1380 | 
| 1368 bool WebRtcVoiceMediaChannel::SetRecvParameters( | 1381 bool WebRtcVoiceMediaChannel::SetRecvParameters( | 
| 1369 const AudioRecvParameters& params) { | 1382 const AudioRecvParameters& params) { | 
| 1370 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetRecvParameters"); | 1383 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetRecvParameters"); | 
| 1371 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1384 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| 1372 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetRecvParameters: " | 1385 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetRecvParameters: " | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1386 webrtc::RtpExtension::IsSupportedForAudio, false); | 1399 webrtc::RtpExtension::IsSupportedForAudio, false); | 
| 1387 if (recv_rtp_extensions_ != filtered_extensions) { | 1400 if (recv_rtp_extensions_ != filtered_extensions) { | 
| 1388 recv_rtp_extensions_.swap(filtered_extensions); | 1401 recv_rtp_extensions_.swap(filtered_extensions); | 
| 1389 for (auto& it : recv_streams_) { | 1402 for (auto& it : recv_streams_) { | 
| 1390 it.second->RecreateAudioReceiveStream(recv_rtp_extensions_); | 1403 it.second->RecreateAudioReceiveStream(recv_rtp_extensions_); | 
| 1391 } | 1404 } | 
| 1392 } | 1405 } | 
| 1393 return true; | 1406 return true; | 
| 1394 } | 1407 } | 
| 1395 | 1408 | 
| 1409 webrtc::RtpParameters WebRtcVoiceMediaChannel::GetRtpParameters( | |
| 1410 uint32_t ssrc) const { | |
| 1411 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | |
| 1412 auto it = send_streams_.find(ssrc); | |
| 1413 if (it == send_streams_.end()) { | |
| 1414 LOG(LS_WARNING) << "Attempting to get RTP parameters for stream with ssrc " | |
| 1415 << ssrc << " which doesn't exist."; | |
| 1416 return webrtc::RtpParameters(); | |
| 1417 } | |
| 1418 | |
| 1419 return it->second->rtp_parameters(); | |
| 1420 } | |
| 1421 | |
| 1422 bool WebRtcVoiceMediaChannel::SetRtpParameters( | |
| 1423 uint32_t ssrc, | |
| 1424 const webrtc::RtpParameters& parameters) { | |
| 1425 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | |
| 1426 if (!ValidateRtpParameters(parameters)) { | |
| 1427 return false; | |
| 1428 } | |
| 1429 auto it = send_streams_.find(ssrc); | |
| 1430 if (it == send_streams_.end()) { | |
| 1431 LOG(LS_WARNING) << "Attempting to set RTP parameters for stream with ssrc " | |
| 1432 << ssrc << " which doesn't exist."; | |
| 1433 return false; | |
| 1434 } | |
| 1435 | |
| 1436 if (!SetChannelParameters(it->second->channel(), parameters)) { | |
| 1437 LOG(LS_WARNING) << "Failed to set RtpParameters."; | |
| 1438 return false; | |
| 1439 } | |
| 1440 it->second->set_rtp_parameters(parameters); | |
| 1441 return true; | |
| 1442 } | |
| 1443 | |
| 1444 bool WebRtcVoiceMediaChannel::ValidateRtpParameters( | |
| 1445 const webrtc::RtpParameters& rtp_parameters) { | |
| 1446 if (rtp_parameters.encodings.size() != 1) { | |
| 1447 LOG(LS_ERROR) | |
| 1448 << "Attempted to set RtpParameters without exactly one encoding"; | |
| 1449 return false; | |
| 1450 } | |
| 1451 return true; | |
| 1452 } | |
| 1453 | |
| 1396 bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { | 1454 bool WebRtcVoiceMediaChannel::SetOptions(const AudioOptions& options) { | 
| 1397 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1455 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 
| 1398 LOG(LS_INFO) << "Setting voice channel options: " | 1456 LOG(LS_INFO) << "Setting voice channel options: " | 
| 1399 << options.ToString(); | 1457 << options.ToString(); | 
| 1400 | 1458 | 
| 1401 // We retain all of the existing options, and apply the given ones | 1459 // 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 | 1460 // on top. This means there is no way to "clear" options such that | 
| 1403 // they go back to the engine default. | 1461 // they go back to the engine default. | 
| 1404 options_.SetAll(options); | 1462 options_.SetAll(options); | 
| 1405 if (!engine()->ApplyOptions(options_)) { | 1463 if (!engine()->ApplyOptions(options_)) { | 
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1580 break; | 1638 break; | 
| 1581 } | 1639 } | 
| 1582 } | 1640 } | 
| 1583 | 1641 | 
| 1584 // Latch in the new state. | 1642 // Latch in the new state. | 
| 1585 send_codec_spec_ = std::move(send_codec_spec); | 1643 send_codec_spec_ = std::move(send_codec_spec); | 
| 1586 } | 1644 } | 
| 1587 | 1645 | 
| 1588 // Cache the codecs in order to configure the channel created later. | 1646 // Cache the codecs in order to configure the channel created later. | 
| 1589 for (const auto& ch : send_streams_) { | 1647 for (const auto& ch : send_streams_) { | 
| 1590 if (!SetSendCodecs(ch.second->channel())) { | 1648 if (!SetSendCodecs(ch.second->channel(), ch.second->rtp_parameters())) { | 
| 1591 return false; | 1649 return false; | 
| 1592 } | 1650 } | 
| 1593 } | 1651 } | 
| 1594 | 1652 | 
| 1595 // Set nack status on receive channels. | 1653 // Set nack status on receive channels. | 
| 1596 if (!send_streams_.empty()) { | 1654 if (!send_streams_.empty()) { | 
| 1597 for (const auto& kv : recv_streams_) { | 1655 for (const auto& kv : recv_streams_) { | 
| 1598 SetNack(kv.second->channel(), send_codec_spec_.nack_enabled); | 1656 SetNack(kv.second->channel(), send_codec_spec_.nack_enabled); | 
| 1599 } | 1657 } | 
| 1600 } | 1658 } | 
| 1601 | 1659 | 
| 1602 // Check if the transport cc feedback has changed on the preferred send codec, | 1660 // Check if the transport cc feedback has changed on the preferred send codec, | 
| 1603 // and in that case reconfigure all receive streams. | 1661 // and in that case reconfigure all receive streams. | 
| 1604 if (recv_transport_cc_enabled_ != send_codec_spec_.transport_cc_enabled) { | 1662 if (recv_transport_cc_enabled_ != send_codec_spec_.transport_cc_enabled) { | 
| 1605 LOG(LS_INFO) << "Recreate all the receive streams because the send " | 1663 LOG(LS_INFO) << "Recreate all the receive streams because the send " | 
| 1606 "codec has changed."; | 1664 "codec has changed."; | 
| 1607 recv_transport_cc_enabled_ = send_codec_spec_.transport_cc_enabled; | 1665 recv_transport_cc_enabled_ = send_codec_spec_.transport_cc_enabled; | 
| 1608 for (auto& kv : recv_streams_) { | 1666 for (auto& kv : recv_streams_) { | 
| 1609 kv.second->RecreateAudioReceiveStream(recv_transport_cc_enabled_); | 1667 kv.second->RecreateAudioReceiveStream(recv_transport_cc_enabled_); | 
| 1610 } | 1668 } | 
| 1611 } | 1669 } | 
| 1612 | 1670 | 
| 1613 return true; | 1671 return true; | 
| 1614 } | 1672 } | 
| 1615 | 1673 | 
| 1616 // Apply current codec settings to a single voe::Channel used for sending. | 1674 // Apply current codec settings to a single voe::Channel used for sending. | 
| 1617 bool WebRtcVoiceMediaChannel::SetSendCodecs(int channel) { | 1675 bool WebRtcVoiceMediaChannel::SetSendCodecs( | 
| 1676 int channel, | |
| 1677 const webrtc::RtpParameters& rtp_parameters) { | |
| 1618 // Disable VAD, FEC, and RED unless we know the other side wants them. | 1678 // Disable VAD, FEC, and RED unless we know the other side wants them. | 
| 1619 engine()->voe()->codec()->SetVADStatus(channel, false); | 1679 engine()->voe()->codec()->SetVADStatus(channel, false); | 
| 1620 engine()->voe()->rtp()->SetNACKStatus(channel, false, 0); | 1680 engine()->voe()->rtp()->SetNACKStatus(channel, false, 0); | 
| 1621 engine()->voe()->rtp()->SetREDStatus(channel, false); | 1681 engine()->voe()->rtp()->SetREDStatus(channel, false); | 
| 1622 engine()->voe()->codec()->SetFECStatus(channel, false); | 1682 engine()->voe()->codec()->SetFECStatus(channel, false); | 
| 1623 | 1683 | 
| 1624 if (send_codec_spec_.red_payload_type != -1) { | 1684 if (send_codec_spec_.red_payload_type != -1) { | 
| 1625 // Enable redundant encoding of the specified codec. Treat any | 1685 // Enable redundant encoding of the specified codec. Treat any | 
| 1626 // failure as a fatal internal error. | 1686 // failure as a fatal internal error. | 
| 1627 LOG(LS_INFO) << "Enabling RED on channel " << channel; | 1687 LOG(LS_INFO) << "Enabling RED on channel " << channel; | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1675 << " Hz on channel " | 1735 << " Hz on channel " | 
| 1676 << channel; | 1736 << channel; | 
| 1677 if (engine()->voe()->codec()->SetOpusMaxPlaybackRate( | 1737 if (engine()->voe()->codec()->SetOpusMaxPlaybackRate( | 
| 1678 channel, send_codec_spec_.opus_max_playback_rate) == -1) { | 1738 channel, send_codec_spec_.opus_max_playback_rate) == -1) { | 
| 1679 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel, | 1739 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel, | 
| 1680 send_codec_spec_.opus_max_playback_rate); | 1740 send_codec_spec_.opus_max_playback_rate); | 
| 1681 return false; | 1741 return false; | 
| 1682 } | 1742 } | 
| 1683 } | 1743 } | 
| 1684 } | 1744 } | 
| 1685 | 1745 // TODO(solenberg): SetSendBitrate() yields another call to SetSendCodec(). | 
| 1686 if (send_bitrate_setting_) { | 1746 // Check if it is possible to fuse with the previous call in this function. | 
| 1687 SetSendBitrateInternal(send_bitrate_bps_); | 1747 SetChannelParameters(channel, rtp_parameters); | 
| 1688 } | |
| 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 Loading... | |
| 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 Loading... | |
| 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& kv : send_streams_) { | 
| 2378 if (!SetChannelParameters(kv.second->channel(), | |
| 2379 kv.second->rtp_parameters())) { | |
| 2380 return false; | |
| 2381 } | |
| 2382 } | |
| 2383 return true; | |
| 2318 } | 2384 } | 
| 2319 | 2385 | 
| 2320 bool WebRtcVoiceMediaChannel::SetSendBitrateInternal(int bps) { | 2386 bool WebRtcVoiceMediaChannel::SetChannelParameters( | 
| 2321 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendBitrateInternal."; | 2387 int channel, | 
| 2388 const webrtc::RtpParameters& parameters) { | |
| 2389 RTC_CHECK_EQ(1UL, parameters.encodings.size()); | |
| 2390 return SetSendBitrate( | |
| 2391 channel, | |
| 2392 MinPositive(send_bitrate_bps_, parameters.encodings[0].max_bitrate_bps)); | |
| 2393 } | |
| 2322 | 2394 | 
| 2323 send_bitrate_setting_ = true; | 2395 bool WebRtcVoiceMediaChannel::SetSendBitrate(int channel, int bps) { | 
| 2324 send_bitrate_bps_ = bps; | 2396 // Bitrate is auto by default. | 
| 2397 // TODO(bemasc): Fix this so that if SetMaxSendBandwidth(50) is followed by | |
| 2398 // SetMaxSendBandwith(0), the second call removes the previous limit. | |
| 2399 if (bps <= 0) | |
| 2400 return true; | |
| 
 
pthatcher1
2016/04/12 18:04:23
{}s please
 
 | |
| 2325 | 2401 | 
| 2326 if (!HasSendCodec()) { | 2402 if (!HasSendCodec()) { | 
| 2327 LOG(LS_INFO) << "The send codec has not been set up yet. " | 2403 LOG(LS_INFO) << "The send codec has not been set up yet. " | 
| 2328 << "The send bitrate setting will be applied later."; | 2404 << "The send bitrate setting will be applied later."; | 
| 2329 return true; | 2405 return true; | 
| 2330 } | 2406 } | 
| 2331 | 2407 | 
| 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; | 2408 webrtc::CodecInst codec = send_codec_spec_.codec_inst; | 
| 2339 bool is_multi_rate = WebRtcVoiceCodecs::IsCodecMultiRate(codec); | 2409 bool is_multi_rate = WebRtcVoiceCodecs::IsCodecMultiRate(codec); | 
| 2340 | 2410 | 
| 2341 if (is_multi_rate) { | 2411 if (is_multi_rate) { | 
| 2342 // If codec is multi-rate then just set the bitrate. | 2412 // If codec is multi-rate then just set the bitrate. | 
| 2343 codec.rate = bps; | 2413 codec.rate = bps; | 
| 2344 for (const auto& ch : send_streams_) { | 2414 if (!SetSendCodec(channel, codec)) { | 
| 2345 if (!SetSendCodec(ch.second->channel(), codec)) { | 2415 LOG(LS_INFO) << "Failed to set codec " << codec.plname << " to bitrate " | 
| 2346 LOG(LS_INFO) << "Failed to set codec " << codec.plname | 2416 << bps << " bps."; | 
| 2347 << " to bitrate " << bps << " bps."; | 2417 return false; | 
| 2348 return false; | |
| 2349 } | |
| 2350 } | 2418 } | 
| 2351 return true; | 2419 return true; | 
| 2352 } else { | 2420 } else { | 
| 2353 // If codec is not multi-rate and |bps| is less than the fixed bitrate | 2421 // 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 | 2422 // then fail. If codec is not multi-rate and |bps| exceeds or equal the | 
| 2355 // fixed bitrate then ignore. | 2423 // fixed bitrate then ignore. | 
| 2356 if (bps < codec.rate) { | 2424 if (bps < codec.rate) { | 
| 2357 LOG(LS_INFO) << "Failed to set codec " << codec.plname | 2425 LOG(LS_INFO) << "Failed to set codec " << codec.plname | 
| 2358 << " to bitrate " << bps << " bps" | 2426 << " to bitrate " << bps << " bps" | 
| 2359 << ", requires at least " << codec.rate << " bps."; | 2427 << ", requires at least " << codec.rate << " bps."; | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2492 } | 2560 } | 
| 2493 } else { | 2561 } else { | 
| 2494 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2562 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 
| 2495 engine()->voe()->base()->StopPlayout(channel); | 2563 engine()->voe()->base()->StopPlayout(channel); | 
| 2496 } | 2564 } | 
| 2497 return true; | 2565 return true; | 
| 2498 } | 2566 } | 
| 2499 } // namespace cricket | 2567 } // namespace cricket | 
| 2500 | 2568 | 
| 2501 #endif // HAVE_WEBRTC_VOICE | 2569 #endif // HAVE_WEBRTC_VOICE | 
| OLD | NEW |