| 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 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 max_send_bitrate_bps_ = bps; | 1276 max_send_bitrate_bps_ = bps; |
| 1277 | 1277 |
| 1278 if (config_.send_codec_spec.codec_inst.rate != *send_rate) { | 1278 if (config_.send_codec_spec.codec_inst.rate != *send_rate) { |
| 1279 // Recreate AudioSendStream with new bit rate. | 1279 // Recreate AudioSendStream with new bit rate. |
| 1280 config_.send_codec_spec.codec_inst.rate = *send_rate; | 1280 config_.send_codec_spec.codec_inst.rate = *send_rate; |
| 1281 RecreateAudioSendStream(); | 1281 RecreateAudioSendStream(); |
| 1282 } | 1282 } |
| 1283 return true; | 1283 return true; |
| 1284 } | 1284 } |
| 1285 | 1285 |
| 1286 bool SendTelephoneEvent(int payload_type, int event, int duration_ms) { | 1286 bool SendTelephoneEvent(int payload_type, int payload_freq, int event, |
| 1287 int duration_ms) { |
| 1287 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1288 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1288 RTC_DCHECK(stream_); | 1289 RTC_DCHECK(stream_); |
| 1289 return stream_->SendTelephoneEvent(payload_type, event, duration_ms); | 1290 return stream_->SendTelephoneEvent(payload_type, payload_freq, event, |
| 1291 duration_ms); |
| 1290 } | 1292 } |
| 1291 | 1293 |
| 1292 void SetSend(bool send) { | 1294 void SetSend(bool send) { |
| 1293 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1295 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1294 send_ = send; | 1296 send_ = send; |
| 1295 UpdateSendState(); | 1297 UpdateSendState(); |
| 1296 } | 1298 } |
| 1297 | 1299 |
| 1298 void SetMuted(bool muted) { | 1300 void SetMuted(bool muted) { |
| 1299 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1301 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 } | 1871 } |
| 1870 return result; | 1872 return result; |
| 1871 } | 1873 } |
| 1872 | 1874 |
| 1873 // Utility function called from SetSendParameters() to extract current send | 1875 // Utility function called from SetSendParameters() to extract current send |
| 1874 // codec settings from the given list of codecs (originally from SDP). Both send | 1876 // codec settings from the given list of codecs (originally from SDP). Both send |
| 1875 // and receive streams may be reconfigured based on the new settings. | 1877 // and receive streams may be reconfigured based on the new settings. |
| 1876 bool WebRtcVoiceMediaChannel::SetSendCodecs( | 1878 bool WebRtcVoiceMediaChannel::SetSendCodecs( |
| 1877 const std::vector<AudioCodec>& codecs) { | 1879 const std::vector<AudioCodec>& codecs) { |
| 1878 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1880 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1879 // TODO(solenberg): Validate input - that payload types don't overlap, are | 1881 dtmf_payload_type_ = rtc::Optional<int>(); |
| 1880 // within range, filter out codecs we don't support, | 1882 dtmf_payload_freq_ = -1; |
| 1881 // redundant codecs etc - the same way it is done for | |
| 1882 // RtpHeaderExtensions. | |
| 1883 | 1883 |
| 1884 // Find the DTMF telephone event "codec" payload type. | 1884 // Validate supplied codecs list. |
| 1885 dtmf_payload_type_ = rtc::Optional<int>(); | |
| 1886 for (const AudioCodec& codec : codecs) { | 1885 for (const AudioCodec& codec : codecs) { |
| 1887 if (IsCodec(codec, kDtmfCodecName)) { | 1886 // TODO(solenberg): Validate more aspects of input - that payload types |
| 1888 if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { | 1887 // don't overlap, remove redundant/unsupported codecs etc - |
| 1889 return false; | 1888 // the same way it is done for RtpHeaderExtensions. |
| 1890 } | 1889 if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { |
| 1891 dtmf_payload_type_ = rtc::Optional<int>(codec.id); | 1890 LOG(LS_WARNING) << "Codec payload type out of range: " << ToString(codec); |
| 1892 break; | 1891 return false; |
| 1893 } | 1892 } |
| 1894 } | 1893 } |
| 1895 | 1894 |
| 1895 // Find PT of telephone-event codec with lowest clockrate, as a fallback, in |
| 1896 // case we don't have a DTMF codec with a rate matching the send codec's, or |
| 1897 // if this function returns early. |
| 1898 std::vector<AudioCodec> dtmf_codecs; |
| 1899 for (const AudioCodec& codec : codecs) { |
| 1900 if (IsCodec(codec, kDtmfCodecName)) { |
| 1901 dtmf_codecs.push_back(codec); |
| 1902 if (!dtmf_payload_type_ || codec.clockrate < dtmf_payload_freq_) { |
| 1903 dtmf_payload_type_ = rtc::Optional<int>(codec.id); |
| 1904 dtmf_payload_freq_ = codec.clockrate; |
| 1905 } |
| 1906 } |
| 1907 } |
| 1908 |
| 1896 // Scan through the list to figure out the codec to use for sending, along | 1909 // Scan through the list to figure out the codec to use for sending, along |
| 1897 // with the proper configuration for VAD, CNG, NACK and Opus-specific | 1910 // with the proper configuration for VAD, CNG, NACK and Opus-specific |
| 1898 // parameters. | 1911 // parameters. |
| 1899 // TODO(solenberg): Refactor this logic once we create AudioEncoders here. | 1912 // TODO(solenberg): Refactor this logic once we create AudioEncoders here. |
| 1900 webrtc::AudioSendStream::Config::SendCodecSpec send_codec_spec; | 1913 webrtc::AudioSendStream::Config::SendCodecSpec send_codec_spec; |
| 1901 { | 1914 { |
| 1902 send_codec_spec.nack_enabled = send_codec_spec_.nack_enabled; | 1915 send_codec_spec.nack_enabled = send_codec_spec_.nack_enabled; |
| 1903 | 1916 |
| 1904 // Find send codec (the first non-telephone-event/CN codec). | 1917 // Find send codec (the first non-telephone-event/CN codec). |
| 1905 const AudioCodec* codec = WebRtcVoiceCodecs::GetPreferredCodec( | 1918 const AudioCodec* codec = WebRtcVoiceCodecs::GetPreferredCodec( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 default: | 1972 default: |
| 1960 LOG(LS_WARNING) << "CN frequency " << codec.clockrate | 1973 LOG(LS_WARNING) << "CN frequency " << codec.clockrate |
| 1961 << " not supported."; | 1974 << " not supported."; |
| 1962 continue; | 1975 continue; |
| 1963 } | 1976 } |
| 1964 send_codec_spec.cng_payload_type = codec.id; | 1977 send_codec_spec.cng_payload_type = codec.id; |
| 1965 send_codec_spec.cng_plfreq = cng_plfreq; | 1978 send_codec_spec.cng_plfreq = cng_plfreq; |
| 1966 break; | 1979 break; |
| 1967 } | 1980 } |
| 1968 } | 1981 } |
| 1982 |
| 1983 // Find the telephone-event PT exactly matching the preferred send codec. |
| 1984 for (const AudioCodec& dtmf_codec : dtmf_codecs) { |
| 1985 if (dtmf_codec.clockrate == codec->clockrate) { |
| 1986 dtmf_payload_type_ = rtc::Optional<int>(dtmf_codec.id); |
| 1987 dtmf_payload_freq_ = dtmf_codec.clockrate; |
| 1988 break; |
| 1989 } |
| 1990 } |
| 1969 } | 1991 } |
| 1970 | 1992 |
| 1971 // Apply new settings to all streams. | 1993 // Apply new settings to all streams. |
| 1972 if (send_codec_spec_ != send_codec_spec) { | 1994 if (send_codec_spec_ != send_codec_spec) { |
| 1973 send_codec_spec_ = std::move(send_codec_spec); | 1995 send_codec_spec_ = std::move(send_codec_spec); |
| 1974 for (const auto& kv : send_streams_) { | 1996 for (const auto& kv : send_streams_) { |
| 1975 kv.second->RecreateAudioSendStream(send_codec_spec_); | 1997 kv.second->RecreateAudioSendStream(send_codec_spec_); |
| 1976 } | 1998 } |
| 1977 } | 1999 } |
| 1978 | 2000 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2366 if (event < kMinTelephoneEventCode || | 2388 if (event < kMinTelephoneEventCode || |
| 2367 event > kMaxTelephoneEventCode) { | 2389 event > kMaxTelephoneEventCode) { |
| 2368 LOG(LS_WARNING) << "DTMF event code " << event << " out of range."; | 2390 LOG(LS_WARNING) << "DTMF event code " << event << " out of range."; |
| 2369 return false; | 2391 return false; |
| 2370 } | 2392 } |
| 2371 if (duration < kMinTelephoneEventDuration || | 2393 if (duration < kMinTelephoneEventDuration || |
| 2372 duration > kMaxTelephoneEventDuration) { | 2394 duration > kMaxTelephoneEventDuration) { |
| 2373 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; | 2395 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; |
| 2374 return false; | 2396 return false; |
| 2375 } | 2397 } |
| 2376 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); | 2398 RTC_DCHECK_NE(-1, dtmf_payload_freq_); |
| 2399 return it->second->SendTelephoneEvent(*dtmf_payload_type_, dtmf_payload_freq_, |
| 2400 event, duration); |
| 2377 } | 2401 } |
| 2378 | 2402 |
| 2379 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2403 void WebRtcVoiceMediaChannel::OnPacketReceived( |
| 2380 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { | 2404 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { |
| 2381 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2405 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 2382 | 2406 |
| 2383 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2407 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
| 2384 packet_time.not_before); | 2408 packet_time.not_before); |
| 2385 webrtc::PacketReceiver::DeliveryStatus delivery_result = | 2409 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
| 2386 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2410 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2603 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2627 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 2604 const auto it = send_streams_.find(ssrc); | 2628 const auto it = send_streams_.find(ssrc); |
| 2605 if (it != send_streams_.end()) { | 2629 if (it != send_streams_.end()) { |
| 2606 return it->second->channel(); | 2630 return it->second->channel(); |
| 2607 } | 2631 } |
| 2608 return -1; | 2632 return -1; |
| 2609 } | 2633 } |
| 2610 } // namespace cricket | 2634 } // namespace cricket |
| 2611 | 2635 |
| 2612 #endif // HAVE_WEBRTC_VOICE | 2636 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |