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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // G722 should be advertised as 8000 Hz because of the RFC "bug". | 457 // G722 should be advertised as 8000 Hz because of the RFC "bug". |
458 {kG722CodecName, 8000, 1, 9, false, {10, 20, 30, 40, 50, 60}}, | 458 {kG722CodecName, 8000, 1, 9, false, {10, 20, 30, 40, 50, 60}}, |
459 {kIlbcCodecName, 8000, 1, 102, false, {20, 30, 40, 60}}, | 459 {kIlbcCodecName, 8000, 1, 102, false, {20, 30, 40, 60}}, |
460 {kPcmuCodecName, 8000, 1, 0, false, {10, 20, 30, 40, 50, 60}}, | 460 {kPcmuCodecName, 8000, 1, 0, false, {10, 20, 30, 40, 50, 60}}, |
461 {kPcmaCodecName, 8000, 1, 8, false, {10, 20, 30, 40, 50, 60}}, | 461 {kPcmaCodecName, 8000, 1, 8, false, {10, 20, 30, 40, 50, 60}}, |
462 {kCnCodecName, 32000, 1, 106, false, {}}, | 462 {kCnCodecName, 32000, 1, 106, false, {}}, |
463 {kCnCodecName, 16000, 1, 105, false, {}}, | 463 {kCnCodecName, 16000, 1, 105, false, {}}, |
464 {kCnCodecName, 8000, 1, 13, false, {}}, | 464 {kCnCodecName, 8000, 1, 13, false, {}}, |
465 {kDtmfCodecName, 8000, 1, 126, false, {}} | 465 {kDtmfCodecName, 8000, 1, 126, false, {}} |
466 }; | 466 }; |
| 467 |
| 468 void UpdateSendCodecSpecInConfig(const SendCodecSpec& spec, |
| 469 webrtc::AudioSendStream::Config* config) { |
| 470 config->send_codec_spec.nack_enabled = spec.nack_enabled; |
| 471 config->send_codec_spec.transport_cc_enabled = spec.transport_cc_enabled; |
| 472 config->send_codec_spec.enable_codec_fec = spec.enable_codec_fec; |
| 473 config->send_codec_spec.enable_opus_dtx = spec.enable_opus_dtx; |
| 474 config->send_codec_spec.opus_max_playback_rate = spec.opus_max_playback_rate; |
| 475 config->send_codec_spec.red_payload_type = spec.red_payload_type; |
| 476 config->send_codec_spec.cng_payload_type = spec.cng_payload_type; |
| 477 config->send_codec_spec.cng_plfreq = spec.cng_plfreq; |
| 478 config->send_codec_spec.codec_inst = spec.codec_inst; |
| 479 }; |
| 480 |
467 } // namespace { | 481 } // namespace { |
468 | 482 |
469 bool SendCodecSpec::operator==(const SendCodecSpec& rhs) const { | 483 bool SendCodecSpec::operator==(const SendCodecSpec& rhs) const { |
470 if (nack_enabled != rhs.nack_enabled) { | 484 if (nack_enabled != rhs.nack_enabled) { |
471 return false; | 485 return false; |
472 } | 486 } |
473 if (transport_cc_enabled != rhs.transport_cc_enabled) { | 487 if (transport_cc_enabled != rhs.transport_cc_enabled) { |
474 return false; | 488 return false; |
475 } | 489 } |
476 if (enable_codec_fec != rhs.enable_codec_fec) { | 490 if (enable_codec_fec != rhs.enable_codec_fec) { |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 } | 1184 } |
1171 | 1185 |
1172 void RecreateAudioSendStream(const SendCodecSpec& send_codec_spec) { | 1186 void RecreateAudioSendStream(const SendCodecSpec& send_codec_spec) { |
1173 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1187 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1174 if (stream_) { | 1188 if (stream_) { |
1175 call_->DestroyAudioSendStream(stream_); | 1189 call_->DestroyAudioSendStream(stream_); |
1176 stream_ = nullptr; | 1190 stream_ = nullptr; |
1177 } | 1191 } |
1178 config_.rtp.nack.rtp_history_ms = | 1192 config_.rtp.nack.rtp_history_ms = |
1179 send_codec_spec.nack_enabled ? kNackRtpHistoryMs : 0; | 1193 send_codec_spec.nack_enabled ? kNackRtpHistoryMs : 0; |
| 1194 UpdateSendCodecSpecInConfig(send_codec_spec, &config_); |
1180 RTC_DCHECK(!stream_); | 1195 RTC_DCHECK(!stream_); |
1181 stream_ = call_->CreateAudioSendStream(config_); | 1196 stream_ = call_->CreateAudioSendStream(config_); |
1182 RTC_CHECK(stream_); | 1197 RTC_CHECK(stream_); |
1183 UpdateSendState(); | 1198 UpdateSendState(); |
1184 } | 1199 } |
1185 | 1200 |
1186 void RecreateAudioSendStream( | 1201 void RecreateAudioSendStream( |
1187 const std::vector<webrtc::RtpExtension>& extensions) { | 1202 const std::vector<webrtc::RtpExtension>& extensions) { |
1188 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1203 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1189 if (stream_) { | 1204 if (stream_) { |
1190 call_->DestroyAudioSendStream(stream_); | 1205 call_->DestroyAudioSendStream(stream_); |
1191 stream_ = nullptr; | 1206 stream_ = nullptr; |
1192 } | 1207 } |
1193 config_.rtp.extensions = extensions; | 1208 config_.rtp.extensions = extensions; |
1194 if (webrtc::field_trial::FindFullName("WebRTC-AdaptAudioBitrate") == | 1209 if (webrtc::field_trial::FindFullName("WebRTC-AdaptAudioBitrate") == |
1195 "Enabled") { | 1210 "Enabled") { |
1196 // TODO(mflodman): Keep testing this and set proper values. | 1211 // TODO(mflodman): Keep testing this and set proper values. |
1197 // Note: This is an early experiment currently only supported by Opus. | 1212 // Note: This is an early experiment currently only supported by Opus. |
1198 config_.min_bitrate_kbps = kOpusMinBitrate; | 1213 config_.min_bitrate_kbps = kOpusMinBitrate; |
1199 config_.max_bitrate_kbps = kOpusBitrateFb; | 1214 config_.max_bitrate_kbps = kOpusBitrateFb; |
1200 } | 1215 } |
1201 | 1216 |
1202 RTC_DCHECK(!stream_); | 1217 RTC_DCHECK(!stream_); |
1203 stream_ = call_->CreateAudioSendStream(config_); | 1218 stream_ = call_->CreateAudioSendStream(config_); |
1204 RTC_CHECK(stream_); | 1219 RTC_CHECK(stream_); |
1205 UpdateSendState(); | 1220 UpdateSendState(); |
1206 } | 1221 } |
1207 | 1222 |
| 1223 void MaybeRecreateAudioSendStream(int bps) { |
| 1224 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1225 int new_max_send_bitrate_bps = |
| 1226 MinPositive(bps, rtp_parameters_.encodings[0].max_bitrate_bps); |
| 1227 |
| 1228 if (config_.max_send_bitrate_bps == new_max_send_bitrate_bps) |
| 1229 return; |
| 1230 |
| 1231 if (stream_) { |
| 1232 call_->DestroyAudioSendStream(stream_); |
| 1233 stream_ = nullptr; |
| 1234 } |
| 1235 RTC_DCHECK(!stream_); |
| 1236 config_.max_send_bitrate_bps = new_max_send_bitrate_bps; |
| 1237 stream_ = call_->CreateAudioSendStream(config_); |
| 1238 RTC_CHECK(stream_); |
| 1239 UpdateSendState(); |
| 1240 } |
| 1241 |
1208 bool SendTelephoneEvent(int payload_type, int event, int duration_ms) { | 1242 bool SendTelephoneEvent(int payload_type, int event, int duration_ms) { |
1209 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1243 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1210 RTC_DCHECK(stream_); | 1244 RTC_DCHECK(stream_); |
1211 return stream_->SendTelephoneEvent(payload_type, event, duration_ms); | 1245 return stream_->SendTelephoneEvent(payload_type, event, duration_ms); |
1212 } | 1246 } |
1213 | 1247 |
1214 void SetSend(bool send) { | 1248 void SetSend(bool send) { |
1215 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1249 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1216 send_ = send; | 1250 send_ = send; |
1217 UpdateSendState(); | 1251 UpdateSendState(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1293 return config_.voe_channel_id; | 1327 return config_.voe_channel_id; |
1294 } | 1328 } |
1295 | 1329 |
1296 const webrtc::RtpParameters& rtp_parameters() const { | 1330 const webrtc::RtpParameters& rtp_parameters() const { |
1297 return rtp_parameters_; | 1331 return rtp_parameters_; |
1298 } | 1332 } |
1299 | 1333 |
1300 void SetRtpParameters(const webrtc::RtpParameters& parameters) { | 1334 void SetRtpParameters(const webrtc::RtpParameters& parameters) { |
1301 RTC_CHECK_EQ(1UL, parameters.encodings.size()); | 1335 RTC_CHECK_EQ(1UL, parameters.encodings.size()); |
1302 rtp_parameters_ = parameters; | 1336 rtp_parameters_ = parameters; |
| 1337 |
| 1338 // parameters.encodings[0].max_bitrate_bps could have changed. |
| 1339 MaybeRecreateAudioSendStream(config_.max_send_bitrate_bps); |
| 1340 |
1303 // parameters.encodings[0].active could have changed. | 1341 // parameters.encodings[0].active could have changed. |
1304 UpdateSendState(); | 1342 UpdateSendState(); |
1305 } | 1343 } |
1306 | 1344 |
1307 private: | 1345 private: |
1308 void UpdateSendState() { | 1346 void UpdateSendState() { |
1309 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1347 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1310 RTC_DCHECK(stream_); | 1348 RTC_DCHECK(stream_); |
1311 RTC_DCHECK_EQ(1UL, rtp_parameters_.encodings.size()); | 1349 RTC_DCHECK_EQ(1UL, rtp_parameters_.encodings.size()); |
1312 if (send_ && source_ != nullptr && rtp_parameters_.encodings[0].active) { | 1350 if (send_ && source_ != nullptr && rtp_parameters_.encodings[0].active) { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 | 1622 |
1585 // TODO(deadbeef): Handle setting parameters with a list of codecs in a | 1623 // TODO(deadbeef): Handle setting parameters with a list of codecs in a |
1586 // different order (which should change the send codec). | 1624 // different order (which should change the send codec). |
1587 webrtc::RtpParameters current_parameters = GetRtpSendParameters(ssrc); | 1625 webrtc::RtpParameters current_parameters = GetRtpSendParameters(ssrc); |
1588 if (current_parameters.codecs != parameters.codecs) { | 1626 if (current_parameters.codecs != parameters.codecs) { |
1589 LOG(LS_ERROR) << "Using SetParameters to change the set of codecs " | 1627 LOG(LS_ERROR) << "Using SetParameters to change the set of codecs " |
1590 << "is not currently supported."; | 1628 << "is not currently supported."; |
1591 return false; | 1629 return false; |
1592 } | 1630 } |
1593 | 1631 |
1594 if (!SetChannelSendParameters(it->second->channel(), parameters)) { | 1632 // TODO(minyue): The following legacy actions go into |
1595 LOG(LS_WARNING) << "Failed to set send RtpParameters."; | 1633 // |WebRtcAudioSendStream::SetRtpParameters()| which is called at the end, |
1596 return false; | 1634 // though there is a difference: |
1597 } | 1635 // |WebRtcVoiceMediaChannel::SetChannelSendParameters()| only calls |
| 1636 // |SetSendCodec| while |WebRtcAudioSendStream::SetRtpParameters()| calls |
| 1637 // |SetSendCodecs|. The outcome should be the same. |
| 1638 |
| 1639 // if (!it->SetChannelSendParameters(it->second->channel(), parameters)) { |
| 1640 // LOG(LS_WARNING) << "Failed to set send RtpParameters."; |
| 1641 // return false; |
| 1642 // } |
| 1643 |
1598 // Codecs are handled at the WebRtcVoiceMediaChannel level. | 1644 // Codecs are handled at the WebRtcVoiceMediaChannel level. |
1599 webrtc::RtpParameters reduced_params = parameters; | 1645 webrtc::RtpParameters reduced_params = parameters; |
1600 reduced_params.codecs.clear(); | 1646 reduced_params.codecs.clear(); |
1601 it->second->SetRtpParameters(reduced_params); | 1647 it->second->SetRtpParameters(reduced_params); |
1602 return true; | 1648 return true; |
1603 } | 1649 } |
1604 | 1650 |
1605 webrtc::RtpParameters WebRtcVoiceMediaChannel::GetRtpReceiveParameters( | 1651 webrtc::RtpParameters WebRtcVoiceMediaChannel::GetRtpReceiveParameters( |
1606 uint32_t ssrc) const { | 1652 uint32_t ssrc) const { |
1607 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1653 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 break; | 1881 break; |
1836 } | 1882 } |
1837 } | 1883 } |
1838 } | 1884 } |
1839 | 1885 |
1840 // Apply new settings to all streams. | 1886 // Apply new settings to all streams. |
1841 if (send_codec_spec_ != send_codec_spec) { | 1887 if (send_codec_spec_ != send_codec_spec) { |
1842 send_codec_spec_ = std::move(send_codec_spec); | 1888 send_codec_spec_ = std::move(send_codec_spec); |
1843 for (const auto& kv : send_streams_) { | 1889 for (const auto& kv : send_streams_) { |
1844 kv.second->RecreateAudioSendStream(send_codec_spec_); | 1890 kv.second->RecreateAudioSendStream(send_codec_spec_); |
1845 if (!SetSendCodecs(kv.second->channel(), kv.second->rtp_parameters())) { | |
1846 return false; | |
1847 } | |
1848 } | 1891 } |
1849 } | 1892 } |
1850 | 1893 |
1851 // Check if the transport cc feedback or NACK status has changed on the | 1894 // Check if the transport cc feedback or NACK status has changed on the |
1852 // preferred send codec, and in that case reconfigure all receive streams. | 1895 // preferred send codec, and in that case reconfigure all receive streams. |
1853 if (recv_transport_cc_enabled_ != send_codec_spec_.transport_cc_enabled || | 1896 if (recv_transport_cc_enabled_ != send_codec_spec_.transport_cc_enabled || |
1854 recv_nack_enabled_ != send_codec_spec_.nack_enabled) { | 1897 recv_nack_enabled_ != send_codec_spec_.nack_enabled) { |
1855 LOG(LS_INFO) << "Recreate all the receive streams because the send " | 1898 LOG(LS_INFO) << "Recreate all the receive streams because the send " |
1856 "codec has changed."; | 1899 "codec has changed."; |
1857 recv_transport_cc_enabled_ = send_codec_spec_.transport_cc_enabled; | 1900 recv_transport_cc_enabled_ = send_codec_spec_.transport_cc_enabled; |
1858 recv_nack_enabled_ = send_codec_spec_.nack_enabled; | 1901 recv_nack_enabled_ = send_codec_spec_.nack_enabled; |
1859 for (auto& kv : recv_streams_) { | 1902 for (auto& kv : recv_streams_) { |
1860 kv.second->RecreateAudioReceiveStream(recv_transport_cc_enabled_, | 1903 kv.second->RecreateAudioReceiveStream(recv_transport_cc_enabled_, |
1861 recv_nack_enabled_); | 1904 recv_nack_enabled_); |
1862 } | 1905 } |
1863 } | 1906 } |
1864 | 1907 |
1865 send_codecs_ = codecs; | 1908 send_codecs_ = codecs; |
1866 return true; | 1909 return true; |
1867 } | 1910 } |
1868 | 1911 |
1869 // Apply current codec settings to a single voe::Channel used for sending. | |
1870 bool WebRtcVoiceMediaChannel::SetSendCodecs( | |
1871 int channel, | |
1872 const webrtc::RtpParameters& rtp_parameters) { | |
1873 // Disable VAD and FEC unless we know the other side wants them. | |
1874 engine()->voe()->codec()->SetVADStatus(channel, false); | |
1875 engine()->voe()->codec()->SetFECStatus(channel, false); | |
1876 | |
1877 // Set the codec immediately, since SetVADStatus() depends on whether | |
1878 // the current codec is mono or stereo. | |
1879 if (!SetSendCodec(channel, send_codec_spec_.codec_inst)) { | |
1880 return false; | |
1881 } | |
1882 | |
1883 // FEC should be enabled after SetSendCodec. | |
1884 if (send_codec_spec_.enable_codec_fec) { | |
1885 LOG(LS_INFO) << "Attempt to enable codec internal FEC on channel " | |
1886 << channel; | |
1887 if (engine()->voe()->codec()->SetFECStatus(channel, true) == -1) { | |
1888 // Enable codec internal FEC. Treat any failure as fatal internal error. | |
1889 LOG_RTCERR2(SetFECStatus, channel, true); | |
1890 return false; | |
1891 } | |
1892 } | |
1893 | |
1894 if (IsCodec(send_codec_spec_.codec_inst, kOpusCodecName)) { | |
1895 // DTX and maxplaybackrate should be set after SetSendCodec. Because current | |
1896 // send codec has to be Opus. | |
1897 | |
1898 // Set Opus internal DTX. | |
1899 LOG(LS_INFO) << "Attempt to " | |
1900 << (send_codec_spec_.enable_opus_dtx ? "enable" : "disable") | |
1901 << " Opus DTX on channel " | |
1902 << channel; | |
1903 if (engine()->voe()->codec()->SetOpusDtx(channel, | |
1904 send_codec_spec_.enable_opus_dtx)) { | |
1905 LOG_RTCERR2(SetOpusDtx, channel, send_codec_spec_.enable_opus_dtx); | |
1906 return false; | |
1907 } | |
1908 | |
1909 // If opus_max_playback_rate <= 0, the default maximum playback rate | |
1910 // (48 kHz) will be used. | |
1911 if (send_codec_spec_.opus_max_playback_rate > 0) { | |
1912 LOG(LS_INFO) << "Attempt to set maximum playback rate to " | |
1913 << send_codec_spec_.opus_max_playback_rate | |
1914 << " Hz on channel " | |
1915 << channel; | |
1916 if (engine()->voe()->codec()->SetOpusMaxPlaybackRate( | |
1917 channel, send_codec_spec_.opus_max_playback_rate) == -1) { | |
1918 LOG_RTCERR2(SetOpusMaxPlaybackRate, channel, | |
1919 send_codec_spec_.opus_max_playback_rate); | |
1920 return false; | |
1921 } | |
1922 } | |
1923 } | |
1924 // TODO(solenberg): SetMaxSendBitrate() yields another call to SetSendCodec(). | |
1925 // Check if it is possible to fuse with the previous call in this function. | |
1926 SetChannelSendParameters(channel, rtp_parameters); | |
1927 | |
1928 // Set the CN payloadtype and the VAD status. | |
1929 if (send_codec_spec_.cng_payload_type != -1) { | |
1930 // The CN payload type for 8000 Hz clockrate is fixed at 13. | |
1931 if (send_codec_spec_.cng_plfreq != 8000) { | |
1932 webrtc::PayloadFrequencies cn_freq; | |
1933 switch (send_codec_spec_.cng_plfreq) { | |
1934 case 16000: | |
1935 cn_freq = webrtc::kFreq16000Hz; | |
1936 break; | |
1937 case 32000: | |
1938 cn_freq = webrtc::kFreq32000Hz; | |
1939 break; | |
1940 default: | |
1941 RTC_NOTREACHED(); | |
1942 return false; | |
1943 } | |
1944 if (engine()->voe()->codec()->SetSendCNPayloadType( | |
1945 channel, send_codec_spec_.cng_payload_type, cn_freq) == -1) { | |
1946 LOG_RTCERR3(SetSendCNPayloadType, channel, | |
1947 send_codec_spec_.cng_payload_type, cn_freq); | |
1948 // TODO(ajm): This failure condition will be removed from VoE. | |
1949 // Restore the return here when we update to a new enough webrtc. | |
1950 // | |
1951 // Not returning false because the SetSendCNPayloadType will fail if | |
1952 // the channel is already sending. | |
1953 // This can happen if the remote description is applied twice, for | |
1954 // example in the case of ROAP on top of JSEP, where both side will | |
1955 // send the offer. | |
1956 } | |
1957 } | |
1958 | |
1959 // Only turn on VAD if we have a CN payload type that matches the | |
1960 // clockrate for the codec we are going to use. | |
1961 if (send_codec_spec_.cng_plfreq == send_codec_spec_.codec_inst.plfreq && | |
1962 send_codec_spec_.codec_inst.channels == 1) { | |
1963 // TODO(minyue): If CN frequency == 48000 Hz is allowed, consider the | |
1964 // interaction between VAD and Opus FEC. | |
1965 LOG(LS_INFO) << "Enabling VAD"; | |
1966 if (engine()->voe()->codec()->SetVADStatus(channel, true) == -1) { | |
1967 LOG_RTCERR2(SetVADStatus, channel, true); | |
1968 return false; | |
1969 } | |
1970 } | |
1971 } | |
1972 return true; | |
1973 } | |
1974 | |
1975 bool WebRtcVoiceMediaChannel::SetSendCodec( | |
1976 int channel, const webrtc::CodecInst& send_codec) { | |
1977 LOG(LS_INFO) << "Send channel " << channel << " selected voice codec " | |
1978 << ToString(send_codec) << ", bitrate=" << send_codec.rate; | |
1979 | |
1980 webrtc::CodecInst current_codec = {0}; | |
1981 if (engine()->voe()->codec()->GetSendCodec(channel, current_codec) == 0 && | |
1982 (send_codec == current_codec)) { | |
1983 // Codec is already configured, we can return without setting it again. | |
1984 return true; | |
1985 } | |
1986 | |
1987 if (engine()->voe()->codec()->SetSendCodec(channel, send_codec) == -1) { | |
1988 LOG_RTCERR2(SetSendCodec, channel, ToString(send_codec)); | |
1989 return false; | |
1990 } | |
1991 return true; | |
1992 } | |
1993 | |
1994 void WebRtcVoiceMediaChannel::SetPlayout(bool playout) { | 1912 void WebRtcVoiceMediaChannel::SetPlayout(bool playout) { |
1995 desired_playout_ = playout; | 1913 desired_playout_ = playout; |
1996 return ChangePlayout(desired_playout_); | 1914 return ChangePlayout(desired_playout_); |
1997 } | 1915 } |
1998 | 1916 |
1999 void WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { | 1917 void WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { |
2000 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::ChangePlayout"); | 1918 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::ChangePlayout"); |
2001 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1919 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2002 if (playout_ == playout) { | 1920 if (playout_ == playout) { |
2003 return; | 1921 return; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2096 // Save the channel to send_streams_, so that RemoveSendStream() can still | 2014 // Save the channel to send_streams_, so that RemoveSendStream() can still |
2097 // delete the channel in case failure happens below. | 2015 // delete the channel in case failure happens below. |
2098 webrtc::AudioTransport* audio_transport = | 2016 webrtc::AudioTransport* audio_transport = |
2099 engine()->voe()->base()->audio_transport(); | 2017 engine()->voe()->base()->audio_transport(); |
2100 | 2018 |
2101 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( | 2019 WebRtcAudioSendStream* stream = new WebRtcAudioSendStream( |
2102 channel, audio_transport, ssrc, sp.cname, send_codec_spec_, | 2020 channel, audio_transport, ssrc, sp.cname, send_codec_spec_, |
2103 send_rtp_extensions_, call_, this); | 2021 send_rtp_extensions_, call_, this); |
2104 send_streams_.insert(std::make_pair(ssrc, stream)); | 2022 send_streams_.insert(std::make_pair(ssrc, stream)); |
2105 | 2023 |
2106 // Set the current codecs to be used for the new channel. We need to do this | |
2107 // after adding the channel to send_channels_, because of how max bitrate is | |
2108 // currently being configured by SetSendCodec(). | |
2109 if (HasSendCodec() && !SetSendCodecs(channel, stream->rtp_parameters())) { | |
2110 RemoveSendStream(ssrc); | |
2111 return false; | |
2112 } | |
2113 | |
2114 // At this point the stream's local SSRC has been updated. If it is the first | 2024 // At this point the stream's local SSRC has been updated. If it is the first |
2115 // send stream, make sure that all the receive streams are updated with the | 2025 // send stream, make sure that all the receive streams are updated with the |
2116 // same SSRC in order to send receiver reports. | 2026 // same SSRC in order to send receiver reports. |
2117 if (send_streams_.size() == 1) { | 2027 if (send_streams_.size() == 1) { |
2118 receiver_reports_ssrc_ = ssrc; | 2028 receiver_reports_ssrc_ = ssrc; |
2119 for (const auto& kv : recv_streams_) { | 2029 for (const auto& kv : recv_streams_) { |
2120 // TODO(solenberg): Allow applications to set the RTCP SSRC of receive | 2030 // TODO(solenberg): Allow applications to set the RTCP SSRC of receive |
2121 // streams instead, so we can avoid recreating the streams here. | 2031 // streams instead, so we can avoid recreating the streams here. |
2122 kv.second->RecreateAudioReceiveStream(ssrc); | 2032 kv.second->RecreateAudioReceiveStream(ssrc); |
2123 int recv_channel = kv.second->channel(); | 2033 int recv_channel = kv.second->channel(); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2477 webrtc::AudioProcessing* ap = engine()->voe()->base()->audio_processing(); | 2387 webrtc::AudioProcessing* ap = engine()->voe()->base()->audio_processing(); |
2478 if (ap) { | 2388 if (ap) { |
2479 ap->set_output_will_be_muted(all_muted); | 2389 ap->set_output_will_be_muted(all_muted); |
2480 } | 2390 } |
2481 return true; | 2391 return true; |
2482 } | 2392 } |
2483 | 2393 |
2484 bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int bps) { | 2394 bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int bps) { |
2485 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetMaxSendBitrate."; | 2395 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetMaxSendBitrate."; |
2486 max_send_bitrate_bps_ = bps; | 2396 max_send_bitrate_bps_ = bps; |
2487 | 2397 for (const auto& kv : send_streams_) |
2488 for (const auto& kv : send_streams_) { | 2398 kv.second->MaybeRecreateAudioSendStream(max_send_bitrate_bps_); |
2489 if (!SetChannelSendParameters(kv.second->channel(), | |
2490 kv.second->rtp_parameters())) { | |
2491 return false; | |
2492 } | |
2493 } | |
2494 return true; | 2399 return true; |
2495 } | 2400 } |
2496 | 2401 |
2497 bool WebRtcVoiceMediaChannel::SetChannelSendParameters( | |
2498 int channel, | |
2499 const webrtc::RtpParameters& parameters) { | |
2500 RTC_CHECK_EQ(1UL, parameters.encodings.size()); | |
2501 // TODO(deadbeef): Handle setting parameters with a list of codecs in a | |
2502 // different order (which should change the send codec). | |
2503 return SetMaxSendBitrate( | |
2504 channel, MinPositive(max_send_bitrate_bps_, | |
2505 parameters.encodings[0].max_bitrate_bps)); | |
2506 } | |
2507 | |
2508 bool WebRtcVoiceMediaChannel::SetMaxSendBitrate(int channel, int bps) { | |
2509 // Bitrate is auto by default. | |
2510 // TODO(bemasc): Fix this so that if SetMaxSendBandwidth(50) is followed by | |
2511 // SetMaxSendBandwith(0), the second call removes the previous limit. | |
2512 if (bps <= 0) { | |
2513 return true; | |
2514 } | |
2515 | |
2516 if (!HasSendCodec()) { | |
2517 LOG(LS_INFO) << "The send codec has not been set up yet. " | |
2518 << "The send bitrate setting will be applied later."; | |
2519 return true; | |
2520 } | |
2521 | |
2522 webrtc::CodecInst codec = send_codec_spec_.codec_inst; | |
2523 bool is_multi_rate = WebRtcVoiceCodecs::IsCodecMultiRate(codec); | |
2524 | |
2525 if (is_multi_rate) { | |
2526 // If codec is multi-rate then just set the bitrate. | |
2527 int max_bitrate_bps = WebRtcVoiceCodecs::MaxBitrateBps(codec); | |
2528 codec.rate = std::min(bps, max_bitrate_bps); | |
2529 LOG(LS_INFO) << "Setting codec " << codec.plname << " to bitrate " << bps | |
2530 << " bps."; | |
2531 if (!SetSendCodec(channel, codec)) { | |
2532 LOG(LS_ERROR) << "Failed to set codec " << codec.plname << " to bitrate " | |
2533 << bps << " bps."; | |
2534 return false; | |
2535 } | |
2536 return true; | |
2537 } else { | |
2538 // If codec is not multi-rate and |bps| is less than the fixed bitrate | |
2539 // then fail. If codec is not multi-rate and |bps| exceeds or equal the | |
2540 // fixed bitrate then ignore. | |
2541 if (bps < codec.rate) { | |
2542 LOG(LS_ERROR) << "Failed to set codec " << codec.plname << " to bitrate " | |
2543 << bps << " bps" | |
2544 << ", requires at least " << codec.rate << " bps."; | |
2545 return false; | |
2546 } | |
2547 return true; | |
2548 } | |
2549 } | |
2550 | |
2551 void WebRtcVoiceMediaChannel::OnReadyToSend(bool ready) { | 2402 void WebRtcVoiceMediaChannel::OnReadyToSend(bool ready) { |
2552 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2403 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2553 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); | 2404 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); |
2554 call_->SignalChannelNetworkState( | 2405 call_->SignalChannelNetworkState( |
2555 webrtc::MediaType::AUDIO, | 2406 webrtc::MediaType::AUDIO, |
2556 ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); | 2407 ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); |
2557 } | 2408 } |
2558 | 2409 |
2559 bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { | 2410 bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { |
2560 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::GetStats"); | 2411 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::GetStats"); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2664 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2515 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2665 const auto it = send_streams_.find(ssrc); | 2516 const auto it = send_streams_.find(ssrc); |
2666 if (it != send_streams_.end()) { | 2517 if (it != send_streams_.end()) { |
2667 return it->second->channel(); | 2518 return it->second->channel(); |
2668 } | 2519 } |
2669 return -1; | 2520 return -1; |
2670 } | 2521 } |
2671 } // namespace cricket | 2522 } // namespace cricket |
2672 | 2523 |
2673 #endif // HAVE_WEBRTC_VOICE | 2524 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |