signalwire / freeswitch

FreeSWITCH is a Software Defined Telecom Stack enabling the digital transformation from proprietary telecom switches to a versatile software implementation that runs on any commodity hardware. From a Raspberry PI to a multi-core server, FreeSWITCH can unlock the telecommunications potential of any device.
https://freeswitch.com/#getting-started
Other
3.31k stars 1.37k forks source link

[mod_amr]RFC 4867/Bandwidth-Efficient Mode/ CMR mechanism does not work #537

Open olegans1972 opened 4 years ago

olegans1972 commented 4 years ago

freeswitch rel 1.10.2 I am trying to establish a media session with a remote side using the AMR codec :

Remote side sends Invite with: a=rtpmap:96 AMR/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=fmtp:96 mode-set=0,2,4,7; mode-change-period=2; mode-change-neighbor=1; max-red=0 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:97 AMR/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=fmtp:97 mode-set=0,2,4; mode-change-period=2; mode-change-neighbor=1; max-red=0 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:8 PCMA/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:98 AMR/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=fmtp:98 mode-change-period=2; mode-change-neighbor=1; max-red=0 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:13 CN/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:99 telephone-event/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=ptime:20 bb1a871a-328b-4f76-8057-ef3906f1886f a=maxptime:20

Freeswitch sends 183

bb1a871a-328b-4f76-8057-ef3906f1886f m=audio 31734 RTP/AVP 96 99 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:96 AMR/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=fmtp:96 mode-set=0,2,4,7;octet-align=0 bb1a871a-328b-4f76-8057-ef3906f1886f a=rtpmap:99 telephone-event/8000 bb1a871a-328b-4f76-8057-ef3906f1886f a=fmtp:99 0-16 bb1a871a-328b-4f76-8057-ef3906f1886f a=silenceSupp:off - - - - bb1a871a-328b-4f76-8057-ef3906f1886f a=ptime:20 bb1a871a-328b-4f76-8057-ef3906f1886f a=sendrecv

This mode assumes that the coding rate can vary from Frame Type = 0 to 7 [0,2,4,7]. According to the RFC4687 (https://tools.ietf.org/html/rfc4867#section-4.3), an any party can request the required coding rate through the CMR [codec mode request] mechanism. In my case, the remote side sends, for example CMR 2

But freeswitch ALWAYS only works frame type = 7. No matter what speed the remote side would ask. As a result of this, when CMR! = 7 , the subscriber listens to silence.

The speed of encoding is always the same:

2020-03-30 13:23:08.249125 [DEBUG] mod_amr.c:223 AMR encoder (BE): FT: [0x7] Q: [0x1] Frame flag: [0] 2020-03-30 13:23:08.249125 [DEBUG] mod_amr.c:225 AMR encoder (BE): AMR encoded voice payload sz: [31] : | encoded_data_len: [32] 2020-03-30 13:23:08.269147 [DEBUG] mod_amr.c:223 AMR encoder (BE): FT: [0x7] Q: [0x1] Frame flag: [0] 2020-03-30 13:23:08.269147 [DEBUG] mod_amr.c:225 AMR encoder (BE): AMR encoded voice payload sz: [31] : | encoded_data_len: [32] 2020-03-30 13:23:08.289127 [DEBUG] mod_amr.c:223 AMR encoder (BE): FT: [0x7] Q: [0x1] Frame flag: [0] 2020-03-30 13:23:08.289127 [DEBUG] mod_amr.c:225 AMR encoder (BE): AMR encoded voice payload sz: [31] : | encoded_data_len: [32] 2020-03-30 13:23:08.309125 [DEBUG] mod_amr.c:223 AMR encoder (BE): FT: [0x7] Q: [0x1] Frame flag: [0] 2020-03-30 13:23:08.309125 [DEBUG] mod_amr.c:225 AMR encoder (BE): AMR encoded voice payload sz: [31] : | encoded_data_len: [32] 2020-03-30 13:23:08.329150 [DEBUG] mod_amr.c:223 AMR encoder (BE): FT: [0x7] Q: [0x1] Frame flag: [0] 2020-03-30 13:23:08.329150 [DEBUG] mod_amr.c:225 AMR encoder (BE): AMR encoded voice payload sz: [31] : | encoded_data_len: [32]

dragos-oancea commented 4 years ago

it was probably not meant to work . this patch may touch the same issue: https://github.com/signalwire/freeswitch/pull/133 . could you try it ?

also see the config here (you could set the CMR): https://github.com/signalwire/freeswitch/blob/master/conf/testing/autoload_configs/amr.conf.xml

olegans1972 commented 4 years ago

This is not about it. The Offer-Answer is fine and at the config [amr.conf.xml] I can set only default-bitrate! But this is not the behavior that should actually be. The meaning of ARM codec is that it can dynamically change the encoding speed during the media session. And here you determine its speed in advance - which is not right.

Remote side sends rtp packet
Which says: I want you to send me your RTP stream at a speed of 7.40 kbit/s freeswitch ignores this request and continues to encode at the rate of 12.2...It is not right. Here I am talking about. RTP_from_remote_side

olegans1972 commented 4 years ago

RFC4867 (https://tools.ietf.org/html/rfc4867#section-4.3): The codec mode request received in the CMR field is valid until the next codec mode request is received, i.e., a newly received CMR value corresponding to a speech mode, or NO_DATA overrides the previously received CMR value corresponding to a speech mode or NO_DATA. Therefore, if a terminal continuously wishes to receive frames in the same mode X, it needs to set CMR=X for all its outbound payloads, and if a terminal has no preference in which mode to receive, it SHOULD set CMR=15 in all its outbound payloads.

olegans1972 commented 4 years ago

And we have already applied this patch(https://github.com/signalwire/freeswitch/pull/133)

dragos-oancea commented 4 years ago

The only way the encoder changes CMR currently is through the "adjust-bitrate" feature, it varies it according to packet loss. It does not change the CMR when the other side changes the CMR (no code for this), however as I see it, since you said "As a result of this, when CMR! = 7 , the subscriber listens to silence." your UE should keep decoding what it gets, even if it changed its CMR from 7 to 2 for example (FS does it). When the AMR modules were patched for transcoding I didn't have access to a device which was doing what you want hence some things remained untested. The devices it was tested successfully with are in the README file. A patch may be tricky because you'll need to update the encoding context (context->enc_mode) based on what CMR you see on the decoding context.

olegans1972 commented 4 years ago

I would like to explain. In my config, I had "param name= "default-bitrate" value= "7". When I wrote about "As a result of this, when CMR! = 7, the subscriber listens to silence." I meant the following: Due to the fact that the local side (FS) encoded voice transmission with the wrong bitrate (incoming RTP packet had CMR=4), but FS always encoded with "7", the subscriber of the remote side heard "silence" in the handset of the mobile phone, although in fact there was speech. Because the subscriber's UE tried to decode with 4.

olegans1972 commented 4 years ago

Hi! Here's our vision. How could it work. Please look at it https://github.com/SIfoxDevTeam/freeswitch/commits/amr_cmr

dragos-oancea commented 4 years ago

what are you using to test this ?

olegans1972 commented 4 years ago

We have a sip-trunk to MSC Nokia. It looks like: mobile phone --> MSC---->opensips--->freeswitch. Between MSC and freeswitch we use AMR.

russagit commented 4 years ago

Now we also have a version for v1.10.3 including AMR-WB here https://github.com/SIfoxDevTeam/freeswitch/tree/1.10.3_cmr

ticpu commented 3 weeks ago

Was this merged via another mean? I see the pull request is deleted as well as the 1.10.3 tree above.