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

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

Issue 2392883002: Multi frequency DTMF support - sender side (Closed)
Patch Set: WVoMC unittests for multi rate DTMF send Created 4 years, 2 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 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 max_send_bitrate_bps_ = bps; 1233 max_send_bitrate_bps_ = bps;
1234 1234
1235 if (config_.send_codec_spec.codec_inst.rate != *send_rate) { 1235 if (config_.send_codec_spec.codec_inst.rate != *send_rate) {
1236 // Recreate AudioSendStream with new bit rate. 1236 // Recreate AudioSendStream with new bit rate.
1237 config_.send_codec_spec.codec_inst.rate = *send_rate; 1237 config_.send_codec_spec.codec_inst.rate = *send_rate;
1238 RecreateAudioSendStream(); 1238 RecreateAudioSendStream();
1239 } 1239 }
1240 return true; 1240 return true;
1241 } 1241 }
1242 1242
1243 bool SendTelephoneEvent(int payload_type, int event, int duration_ms) { 1243 bool SendTelephoneEvent(int payload_type, int payload_freq, int event,
1244 int duration_ms) {
1244 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1245 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1245 RTC_DCHECK(stream_); 1246 RTC_DCHECK(stream_);
1246 return stream_->SendTelephoneEvent(payload_type, event, duration_ms); 1247 return stream_->SendTelephoneEvent(payload_type, payload_freq, event,
1248 duration_ms);
1247 } 1249 }
1248 1250
1249 void SetSend(bool send) { 1251 void SetSend(bool send) {
1250 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1252 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1251 send_ = send; 1253 send_ = send;
1252 UpdateSendState(); 1254 UpdateSendState();
1253 } 1255 }
1254 1256
1255 void SetMuted(bool muted) { 1257 void SetMuted(bool muted) {
1256 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1258 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 // codec settings from the given list of codecs (originally from SDP). Both send 1817 // codec settings from the given list of codecs (originally from SDP). Both send
1816 // and receive streams may be reconfigured based on the new settings. 1818 // and receive streams may be reconfigured based on the new settings.
1817 bool WebRtcVoiceMediaChannel::SetSendCodecs( 1819 bool WebRtcVoiceMediaChannel::SetSendCodecs(
1818 const std::vector<AudioCodec>& codecs) { 1820 const std::vector<AudioCodec>& codecs) {
1819 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 1821 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
1820 // TODO(solenberg): Validate input - that payload types don't overlap, are 1822 // TODO(solenberg): Validate input - that payload types don't overlap, are
1821 // within range, filter out codecs we don't support, 1823 // within range, filter out codecs we don't support,
1822 // redundant codecs etc - the same way it is done for 1824 // redundant codecs etc - the same way it is done for
1823 // RtpHeaderExtensions. 1825 // RtpHeaderExtensions.
1824 1826
1825 // Find the DTMF telephone event "codec" payload type. 1827 // Find PT of telephone-event codec with lowest clockrate, as a fallback, in
1828 // case we don't have a DTMF codec with a rate matching the send codec's, or
1829 // if this function returns early.
1826 dtmf_payload_type_ = rtc::Optional<int>(); 1830 dtmf_payload_type_ = rtc::Optional<int>();
1831 dtmf_payload_freq_ = -1;
1832 std::vector<AudioCodec> dtmf_codecs;
1827 for (const AudioCodec& codec : codecs) { 1833 for (const AudioCodec& codec : codecs) {
1834 if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) {
1835 // Note that we return if *any* codec's PT is out of range.
hlundin-webrtc 2016/10/28 08:12:36 This is more like an overall sanity check of the i
the sun 2016/11/07 13:33:31 Done.
1836 return false;
1837 }
1828 if (IsCodec(codec, kDtmfCodecName)) { 1838 if (IsCodec(codec, kDtmfCodecName)) {
1829 if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { 1839 dtmf_codecs.push_back(codec);
1830 return false;
1831 }
1832 dtmf_payload_type_ = rtc::Optional<int>(codec.id);
1833 break;
1834 } 1840 }
1835 } 1841 }
1842 if (!dtmf_codecs.empty()) {
1843 std::sort(dtmf_codecs.begin(), dtmf_codecs.end(),
1844 [](const AudioCodec& a, const AudioCodec& b) {
1845 return a.clockrate < b.clockrate;
1846 });
1847 dtmf_payload_type_ = rtc::Optional<int>(dtmf_codecs[0].id);
1848 dtmf_payload_freq_ = dtmf_codecs[0].clockrate;
1849 }
1836 1850
1837 // Scan through the list to figure out the codec to use for sending, along 1851 // Scan through the list to figure out the codec to use for sending, along
1838 // with the proper configuration for VAD, CNG, NACK and Opus-specific 1852 // with the proper configuration for VAD, CNG, NACK and Opus-specific
1839 // parameters. 1853 // parameters.
1840 // TODO(solenberg): Refactor this logic once we create AudioEncoders here. 1854 // TODO(solenberg): Refactor this logic once we create AudioEncoders here.
1841 webrtc::AudioSendStream::Config::SendCodecSpec send_codec_spec; 1855 webrtc::AudioSendStream::Config::SendCodecSpec send_codec_spec;
1842 { 1856 {
1843 send_codec_spec.nack_enabled = send_codec_spec_.nack_enabled; 1857 send_codec_spec.nack_enabled = send_codec_spec_.nack_enabled;
1844 1858
1845 // Find send codec (the first non-telephone-event/CN codec). 1859 // Find send codec (the first non-telephone-event/CN codec).
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 << " not supported."; 1914 << " not supported.";
1901 continue; 1915 continue;
1902 } 1916 }
1903 send_codec_spec.cng_payload_type = codec.id; 1917 send_codec_spec.cng_payload_type = codec.id;
1904 send_codec_spec.cng_plfreq = cng_plfreq; 1918 send_codec_spec.cng_plfreq = cng_plfreq;
1905 break; 1919 break;
1906 } 1920 }
1907 } 1921 }
1908 } 1922 }
1909 1923
1924 // Find the telephone-event PT exactly matching the preferred send codec.
1925 for (const AudioCodec& codec : dtmf_codecs) {
1926 if (codec.clockrate == send_codec_spec.codec_inst.plfreq) {
1927 dtmf_payload_type_ = rtc::Optional<int>(codec.id);
1928 dtmf_payload_freq_ = codec.clockrate;
hlundin-webrtc 2016/10/28 08:12:36 Is there any reason to continue the for loop after
the sun 2016/11/07 13:33:31 Added a simple "break" instead.
1929 }
1930 }
1931
1910 // Apply new settings to all streams. 1932 // Apply new settings to all streams.
1911 if (send_codec_spec_ != send_codec_spec) { 1933 if (send_codec_spec_ != send_codec_spec) {
1912 send_codec_spec_ = std::move(send_codec_spec); 1934 send_codec_spec_ = std::move(send_codec_spec);
1913 for (const auto& kv : send_streams_) { 1935 for (const auto& kv : send_streams_) {
1914 kv.second->RecreateAudioSendStream(send_codec_spec_); 1936 kv.second->RecreateAudioSendStream(send_codec_spec_);
1915 } 1937 }
1916 } 1938 }
1917 1939
1918 // Check if the transport cc feedback or NACK status has changed on the 1940 // Check if the transport cc feedback or NACK status has changed on the
1919 // preferred send codec, and in that case reconfigure all receive streams. 1941 // preferred send codec, and in that case reconfigure all receive streams.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 if (event < kMinTelephoneEventCode || 2328 if (event < kMinTelephoneEventCode ||
2307 event > kMaxTelephoneEventCode) { 2329 event > kMaxTelephoneEventCode) {
2308 LOG(LS_WARNING) << "DTMF event code " << event << " out of range."; 2330 LOG(LS_WARNING) << "DTMF event code " << event << " out of range.";
2309 return false; 2331 return false;
2310 } 2332 }
2311 if (duration < kMinTelephoneEventDuration || 2333 if (duration < kMinTelephoneEventDuration ||
2312 duration > kMaxTelephoneEventDuration) { 2334 duration > kMaxTelephoneEventDuration) {
2313 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; 2335 LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range.";
2314 return false; 2336 return false;
2315 } 2337 }
2316 return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); 2338 RTC_DCHECK_NE(-1, dtmf_payload_freq_);
2339 return it->second->SendTelephoneEvent(*dtmf_payload_type_, dtmf_payload_freq_,
2340 event, duration);
2317 } 2341 }
2318 2342
2319 void WebRtcVoiceMediaChannel::OnPacketReceived( 2343 void WebRtcVoiceMediaChannel::OnPacketReceived(
2320 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) { 2344 rtc::CopyOnWriteBuffer* packet, const rtc::PacketTime& packet_time) {
2321 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2345 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2322 2346
2323 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 2347 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
2324 packet_time.not_before); 2348 packet_time.not_before);
2325 webrtc::PacketReceiver::DeliveryStatus delivery_result = 2349 webrtc::PacketReceiver::DeliveryStatus delivery_result =
2326 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, 2350 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 2562 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
2539 const auto it = send_streams_.find(ssrc); 2563 const auto it = send_streams_.find(ssrc);
2540 if (it != send_streams_.end()) { 2564 if (it != send_streams_.end()) {
2541 return it->second->channel(); 2565 return it->second->channel();
2542 } 2566 }
2543 return -1; 2567 return -1;
2544 } 2568 }
2545 } // namespace cricket 2569 } // namespace cricket
2546 2570
2547 #endif // HAVE_WEBRTC_VOICE 2571 #endif // HAVE_WEBRTC_VOICE
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698