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 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1267 max_send_bitrate_bps_ = bps; | 1267 max_send_bitrate_bps_ = bps; |
1268 | 1268 |
1269 if (config_.send_codec_spec.codec_inst.rate != *send_rate) { | 1269 if (config_.send_codec_spec.codec_inst.rate != *send_rate) { |
1270 // Recreate AudioSendStream with new bit rate. | 1270 // Recreate AudioSendStream with new bit rate. |
1271 config_.send_codec_spec.codec_inst.rate = *send_rate; | 1271 config_.send_codec_spec.codec_inst.rate = *send_rate; |
1272 RecreateAudioSendStream(); | 1272 RecreateAudioSendStream(); |
1273 } | 1273 } |
1274 return true; | 1274 return true; |
1275 } | 1275 } |
1276 | 1276 |
1277 bool SendTelephoneEvent(int payload_type, int event, int duration_ms) { | 1277 bool SendTelephoneEvent(int payload_type, int payload_freq, int event, |
1278 int duration_ms) { | |
1278 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1279 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1279 RTC_DCHECK(stream_); | 1280 RTC_DCHECK(stream_); |
1280 return stream_->SendTelephoneEvent(payload_type, event, duration_ms); | 1281 return stream_->SendTelephoneEvent(payload_type, payload_freq, event, |
1282 duration_ms); | |
1281 } | 1283 } |
1282 | 1284 |
1283 void SetSend(bool send) { | 1285 void SetSend(bool send) { |
1284 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1286 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1285 send_ = send; | 1287 send_ = send; |
1286 UpdateSendState(); | 1288 UpdateSendState(); |
1287 } | 1289 } |
1288 | 1290 |
1289 void SetMuted(bool muted) { | 1291 void SetMuted(bool muted) { |
1290 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1292 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1860 } | 1862 } |
1861 return result; | 1863 return result; |
1862 } | 1864 } |
1863 | 1865 |
1864 // Utility function called from SetSendParameters() to extract current send | 1866 // Utility function called from SetSendParameters() to extract current send |
1865 // codec settings from the given list of codecs (originally from SDP). Both send | 1867 // codec settings from the given list of codecs (originally from SDP). Both send |
1866 // and receive streams may be reconfigured based on the new settings. | 1868 // and receive streams may be reconfigured based on the new settings. |
1867 bool WebRtcVoiceMediaChannel::SetSendCodecs( | 1869 bool WebRtcVoiceMediaChannel::SetSendCodecs( |
1868 const std::vector<AudioCodec>& codecs) { | 1870 const std::vector<AudioCodec>& codecs) { |
1869 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1871 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
1870 // TODO(solenberg): Validate input - that payload types don't overlap, are | 1872 dtmf_payload_type_ = rtc::Optional<int>(); |
1871 // within range, filter out codecs we don't support, | |
1872 // redundant codecs etc - the same way it is done for | |
1873 // RtpHeaderExtensions. | |
1874 | 1873 |
1875 // Find the DTMF telephone event "codec" payload type. | 1874 // Validate supplied codecs list. |
1876 dtmf_payload_type_ = rtc::Optional<int>(); | 1875 for (const AudioCodec& codec : codecs) { |
1876 // TODO(solenberg): Validate more aspects of input - that payload types | |
1877 // don't overlap, remove redundant/unsupported codecs etc - | |
1878 // the same way it is done for RtpHeaderExtensions. | |
1879 if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { | |
1880 LOG(LS_WARNING) << "Codec payload type out of range: " << ToString(codec); | |
1881 return false; | |
1882 } | |
1883 } | |
1884 | |
1885 // Find PT of telephone-event codec with lowest clockrate, as a fallback, in | |
1886 // case we don't have a DTMF codec with a rate matching the send codec's, or | |
1887 // if this function returns early. | |
1888 dtmf_payload_freq_ = -1; | |
1889 std::vector<AudioCodec> dtmf_codecs; | |
1877 for (const AudioCodec& codec : codecs) { | 1890 for (const AudioCodec& codec : codecs) { |
1878 if (IsCodec(codec, kDtmfCodecName)) { | 1891 if (IsCodec(codec, kDtmfCodecName)) { |
1879 if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { | 1892 dtmf_codecs.push_back(codec); |
1880 return false; | |
1881 } | |
1882 dtmf_payload_type_ = rtc::Optional<int>(codec.id); | |
1883 break; | |
1884 } | 1893 } |
1885 } | 1894 } |
1895 if (!dtmf_codecs.empty()) { | |
1896 std::sort(dtmf_codecs.begin(), dtmf_codecs.end(), | |
1897 [](const AudioCodec& a, const AudioCodec& b) { | |
1898 return a.clockrate < b.clockrate; | |
1899 }); | |
stefan-webrtc
2016/11/08 15:05:39
Sorting isn't necessary if you simply keep track o
the sun
2016/11/11 12:07:24
Yeah, thanks. That's more nicer.
| |
1900 dtmf_payload_type_ = rtc::Optional<int>(dtmf_codecs[0].id); | |
1901 dtmf_payload_freq_ = dtmf_codecs[0].clockrate; | |
1902 } | |
1886 | 1903 |
1887 // Scan through the list to figure out the codec to use for sending, along | 1904 // Scan through the list to figure out the codec to use for sending, along |
1888 // with the proper configuration for VAD, CNG, NACK and Opus-specific | 1905 // with the proper configuration for VAD, CNG, NACK and Opus-specific |
1889 // parameters. | 1906 // parameters. |
1890 // TODO(solenberg): Refactor this logic once we create AudioEncoders here. | 1907 // TODO(solenberg): Refactor this logic once we create AudioEncoders here. |
1891 webrtc::AudioSendStream::Config::SendCodecSpec send_codec_spec; | 1908 webrtc::AudioSendStream::Config::SendCodecSpec send_codec_spec; |
1892 { | 1909 { |
1893 send_codec_spec.nack_enabled = send_codec_spec_.nack_enabled; | 1910 send_codec_spec.nack_enabled = send_codec_spec_.nack_enabled; |
1894 | 1911 |
1895 // Find send codec (the first non-telephone-event/CN codec). | 1912 // Find send codec (the first non-telephone-event/CN codec). |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1952 << " not supported."; | 1969 << " not supported."; |
1953 continue; | 1970 continue; |
1954 } | 1971 } |
1955 send_codec_spec.cng_payload_type = codec.id; | 1972 send_codec_spec.cng_payload_type = codec.id; |
1956 send_codec_spec.cng_plfreq = cng_plfreq; | 1973 send_codec_spec.cng_plfreq = cng_plfreq; |
1957 break; | 1974 break; |
1958 } | 1975 } |
1959 } | 1976 } |
1960 } | 1977 } |
1961 | 1978 |
1979 // Find the telephone-event PT exactly matching the preferred send codec. | |
1980 for (const AudioCodec& codec : dtmf_codecs) { | |
1981 if (codec.clockrate == send_codec_spec.codec_inst.plfreq) { | |
1982 dtmf_payload_type_ = rtc::Optional<int>(codec.id); | |
1983 dtmf_payload_freq_ = codec.clockrate; | |
1984 break; | |
1985 } | |
1986 } | |
1987 | |
1962 // Apply new settings to all streams. | 1988 // Apply new settings to all streams. |
1963 if (send_codec_spec_ != send_codec_spec) { | 1989 if (send_codec_spec_ != send_codec_spec) { |
1964 send_codec_spec_ = std::move(send_codec_spec); | 1990 send_codec_spec_ = std::move(send_codec_spec); |
1965 for (const auto& kv : send_streams_) { | 1991 for (const auto& kv : send_streams_) { |
1966 kv.second->RecreateAudioSendStream(send_codec_spec_); | 1992 kv.second->RecreateAudioSendStream(send_codec_spec_); |
1967 } | 1993 } |
1968 } | 1994 } |
1969 | 1995 |
1970 // Check if the transport cc feedback or NACK status has changed on the | 1996 // Check if the transport cc feedback or NACK status has changed on the |
1971 // preferred send codec, and in that case reconfigure all receive streams. | 1997 // preferred send codec, and in that case reconfigure all receive streams. |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2366 if (event < kMinTelephoneEventCode || | 2392 if (event < kMinTelephoneEventCode || |
2367 event > kMaxTelephoneEventCode) { | 2393 event > kMaxTelephoneEventCode) { |
2368 LOG(LS_WARNING) << "DTMF event code " << event << " out of range."; | 2394 LOG(LS_WARNING) << "DTMF event code " << event << " out of range."; |
2369 return false; | 2395 return false; |
2370 } | 2396 } |
2371 if (duration < kMinTelephoneEventDuration || | 2397 if (duration < kMinTelephoneEventDuration || |
2372 duration > kMaxTelephoneEventDuration) { | 2398 duration > kMaxTelephoneEventDuration) { |
2373 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; | 2399 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; |
2374 return false; | 2400 return false; |
2375 } | 2401 } |
2376 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); | 2402 RTC_DCHECK_NE(-1, dtmf_payload_freq_); |
2403 return it->second->SendTelephoneEvent(*dtmf_payload_type_, dtmf_payload_freq_, | |
2404 event, duration); | |
2377 } | 2405 } |
2378 | 2406 |
2379 void WebRtcVoiceMediaChannel::OnPacketReceived( | 2407 void WebRtcVoiceMediaChannel::OnPacketReceived( |
2380 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { | 2408 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { |
2381 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2409 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2382 | 2410 |
2383 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2411 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2384 packet_time.not_before); | 2412 packet_time.not_before); |
2385 webrtc::PacketReceiver::DeliveryStatus delivery_result = | 2413 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
2386 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2414 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2596 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2624 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2597 const auto it = send_streams_.find(ssrc); | 2625 const auto it = send_streams_.find(ssrc); |
2598 if (it != send_streams_.end()) { | 2626 if (it != send_streams_.end()) { |
2599 return it->second->channel(); | 2627 return it->second->channel(); |
2600 } | 2628 } |
2601 return -1; | 2629 return -1; |
2602 } | 2630 } |
2603 } // namespace cricket | 2631 } // namespace cricket |
2604 | 2632 |
2605 #endif // HAVE_WEBRTC_VOICE | 2633 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |