[FS-7578] Telephone-event codec clock-rate mismatch (leads to DTMF issue) Created: 26/May/15  Updated: 22/Oct/15  Resolved: 03/Jul/15

Status: Resolved
Project: FreeSWITCH
Component/s: freeswitch-core
Affects Version/s: 1.4.18, 1.4.19, 1.4.20
Fix Version/s: 1.6
Security Level: public

Type: Bug Priority: Minor
Reporter: Dragos Oancea Assignee: Anthony Minessale II
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment: Linux

CPU Architecture:
x86-64
Kernel:
Linux
Userland:
GNU/Linux
Distribution:
CentOS
Distribution Version:
CentOS Based (3.x kernel)
Compiler:
gcc
FreeSWITCH GIT Revision: 9eb887af478eb7615cfbb1f43055e5c1b73ee9ef
GIT Master Revision hash:: 9eb887af478eb7615cfbb1f43055e5c1b73ee9ef

 Description   
Telephone-event codec is used to send/receive DTMF.

Telephone-event codec clock rate should be the clock rate of the audio codec.

But when FS receives SDP as follows:

m=audio 7090 RTP/AVP 96 97 98 99 100 102 103 0 8 104 101 105 106 107 108
[...]
a=rtpmap:101 telephone-event/48000
a=rtpmap:105 telephone-event/16000
a=rtpmap:106 telephone-event/24000
a=rtpmap:107 telephone-event/12000
a=rtpmap:108 telephone-event/8000

FS replies as follows:
a=rtpmap:101 telephone-event/8000

The remote client will see that FS is changing the clock-rate of the 101 payload from 48000 to 8000 .

RFC4733 states ( https://tools.ietf.org/html/rfc4733#section-2.1 ) :

"Named telephone events are carried as part of the audio stream and
MUST use the same sequence number and timestamp base as the regular
audio channel to simplify the generation of audio waveforms at a
gateway"

For example, for Opus, the RTP clock rate is at 48000 , but the telephone-event clock rate offered by FS is 8000, so DTMF on RFC compliant clients would not work (sending telephone-event/8000 over a 48000 Hz audio stream is prohibited).

This situation is becoming more common, as Opus is becoming used more and more.

This patch addresses the issue,replacing the hardcoded clock rate (8000) with the clock rate of the offered audio codec..
Pull request here :
https://freeswitch.org/stash/projects/FS/repos/freeswitch/pull-requests/258/overview

Tested with <param name="inbound-codec-negotiation" value="greedy"/>

 Comments   
Comment by Brian West [ 26/May/15 ]
What does this do if you have 8k,16k,32k and 48k codecs in the offer?
Comment by Dragos Oancea [ 26/May/15 ]
The change impacts only replies generated by FS.
Now FS will always reply with telephone-event/8000 , but with the change it will reply with the clock rate of the chosen audio codec, and the remote client will send DTMF.
So if for example FS answers with SILK/16000, telephone event clock rate will be 16000 , if FS answers with OPUS/48000 , telephone-event clock rate will be 48000.

Example:
incoming INVITE SDP:

m=audio 30298 RTP/AVP 96 97 98 99 100 102 0 8 101 103 104 105 106
a=rtpmap:96 opus/48000/2
a=fmtp:96 useinbandfec=1; stereo=0; sprop-stereo=0
a=rtpmap:97 SILK/16000
a=rtpmap:98 SILK/24000
a=rtpmap:99 SILK/8000
a=rtpmap:100 SILK/12000
a=rtpmap:102 iLBC/8000
a=fmtp:102 mode=30
a=rtpmap:101 telephone-event/48000
a=rtpmap:103 telephone-event/16000
a=rtpmap:104 telephone-event/24000
a=rtpmap:105 telephone-event/12000
a=rtpmap:106 telephone-event/8000
a=rtcp:30299

reply SDP (before patch ):
2015-05-26 14:20:04.821039 [DEBUG] mod_sofia.c:780 Local SDP sofia/internal/99973251@voip.sipdomain.com:
v=0
o=FreeSWITCH 1432623041 1432623043 IN IP4 10.10.10.144
s=FreeSWITCH
c=IN IP4 10.10.10.144
t=0 0
m=audio 26956 RTP/AVP 96 101
a=rtpmap:96 opus/48000/2
a=fmtp:96 useinbandfec=1; maxaveragebitrate=12000; maxplaybackrate=8000
a=rtpmap:101 telephone-event/8000 <- the client will not send DTMF over this RTP stream
a=fmtp:101 0-16
a=ptime:20
a=sendrecv
a=rtcp:26957 IN IP4 10.10.10.144

reply SDP ( after patch ):
2015-05-26 14:20:04.821039 [DEBUG] mod_sofia.c:780 Local SDP sofia/internal/99973251@voip.sipdomain.com:
v=0
o=FreeSWITCH 1432623041 1432623043 IN IP4 10.10.10.144
s=FreeSWITCH
c=IN IP4 10.10.10.144
t=0 0
m=audio 26956 RTP/AVP 96 101
a=rtpmap:96 opus/48000/2
a=fmtp:96 useinbandfec=1; maxaveragebitrate=12000; maxplaybackrate=8000
a=rtpmap:101 telephone-event/48000 <- the clock rate of the telephone-event codec
a=fmtp:101 0-16
a=ptime:20
a=sendrecv
a=rtcp:26957 IN IP4 10.10.10.144

Comment by Daniel Sokolowski [ 22/Oct/15 ]
This bug is linked from a Linphone bug thread here: https://lists.gnu.org/archive/html/linphone-users/2015-05/msg00084.html .

I am posting a workarround here for the benefit of others which is to change Linphone's preferences to use 8000Hz codecs, see http://danielsokolowski.blogspot.ca/2015/10/linphone-keys-dtmf-not-working-with.html
Generated at Mon May 29 22:43:36 CDT 2017 using JIRA 7.3.3#73014-sha1:d5be8da522213be2ca9ad7b043c51da6e4cc9754.