Index: webrtc/media/engine/webrtcvoiceengine.cc |
diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc |
index b2933bb8db3eaf9e6aeb4256b2a3e6bbdf542821..f3f31cd32db01aa6ac46e28e223ddf65a4d333de 100644 |
--- a/webrtc/media/engine/webrtcvoiceengine.cc |
+++ b/webrtc/media/engine/webrtcvoiceengine.cc |
@@ -1274,10 +1274,12 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream |
return true; |
} |
- bool SendTelephoneEvent(int payload_type, int event, int duration_ms) { |
+ bool SendTelephoneEvent(int payload_type, int payload_freq, int event, |
+ int duration_ms) { |
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
RTC_DCHECK(stream_); |
- return stream_->SendTelephoneEvent(payload_type, event, duration_ms); |
+ return stream_->SendTelephoneEvent(payload_type, payload_freq, event, |
+ duration_ms); |
} |
void SetSend(bool send) { |
@@ -1867,22 +1869,37 @@ bool WebRtcVoiceMediaChannel::SetRecvCodecs( |
bool WebRtcVoiceMediaChannel::SetSendCodecs( |
const std::vector<AudioCodec>& codecs) { |
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
- // TODO(solenberg): Validate input - that payload types don't overlap, are |
- // within range, filter out codecs we don't support, |
- // redundant codecs etc - the same way it is done for |
- // RtpHeaderExtensions. |
- |
- // Find the DTMF telephone event "codec" payload type. |
dtmf_payload_type_ = rtc::Optional<int>(); |
+ |
+ // Validate supplied codecs list. |
+ for (const AudioCodec& codec : codecs) { |
+ // TODO(solenberg): Validate more aspects of input - that payload types |
+ // don't overlap, remove redundant/unsupported codecs etc - |
+ // the same way it is done for RtpHeaderExtensions. |
+ if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { |
+ LOG(LS_WARNING) << "Codec payload type out of range: " << ToString(codec); |
+ return false; |
+ } |
+ } |
+ |
+ // Find PT of telephone-event codec with lowest clockrate, as a fallback, in |
+ // case we don't have a DTMF codec with a rate matching the send codec's, or |
+ // if this function returns early. |
+ dtmf_payload_freq_ = -1; |
+ std::vector<AudioCodec> dtmf_codecs; |
for (const AudioCodec& codec : codecs) { |
if (IsCodec(codec, kDtmfCodecName)) { |
- if (codec.id < kMinPayloadType || codec.id > kMaxPayloadType) { |
- return false; |
- } |
- dtmf_payload_type_ = rtc::Optional<int>(codec.id); |
- break; |
+ dtmf_codecs.push_back(codec); |
} |
} |
+ if (!dtmf_codecs.empty()) { |
+ std::sort(dtmf_codecs.begin(), dtmf_codecs.end(), |
+ [](const AudioCodec& a, const AudioCodec& b) { |
+ return a.clockrate < b.clockrate; |
+ }); |
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.
|
+ dtmf_payload_type_ = rtc::Optional<int>(dtmf_codecs[0].id); |
+ dtmf_payload_freq_ = dtmf_codecs[0].clockrate; |
+ } |
// Scan through the list to figure out the codec to use for sending, along |
// with the proper configuration for VAD, CNG, NACK and Opus-specific |
@@ -1959,6 +1976,15 @@ bool WebRtcVoiceMediaChannel::SetSendCodecs( |
} |
} |
+ // Find the telephone-event PT exactly matching the preferred send codec. |
+ for (const AudioCodec& codec : dtmf_codecs) { |
+ if (codec.clockrate == send_codec_spec.codec_inst.plfreq) { |
+ dtmf_payload_type_ = rtc::Optional<int>(codec.id); |
+ dtmf_payload_freq_ = codec.clockrate; |
+ break; |
+ } |
+ } |
+ |
// Apply new settings to all streams. |
if (send_codec_spec_ != send_codec_spec) { |
send_codec_spec_ = std::move(send_codec_spec); |
@@ -2373,7 +2399,9 @@ bool WebRtcVoiceMediaChannel::InsertDtmf(uint32_t ssrc, int event, |
LOG(LS_WARNING) << "DTMF event duration " << duration << " out of range."; |
return false; |
} |
- return it->second->SendTelephoneEvent(*dtmf_payload_type_, event, duration); |
+ RTC_DCHECK_NE(-1, dtmf_payload_freq_); |
+ return it->second->SendTelephoneEvent(*dtmf_payload_type_, dtmf_payload_freq_, |
+ event, duration); |
} |
void WebRtcVoiceMediaChannel::OnPacketReceived( |