VoiSmart / pjsip-android

SIP Service for Android based on PJSIP
http://www.pjsip.org/
Apache License 2.0
288 stars 140 forks source link

[Codec priority] Changing or Setting Codec priority does not work #204

Closed AAlier closed 4 months ago

AAlier commented 6 months ago

Describe the bug Disabling codec priorities does not take effect. Tested with clear application, shared pred does not contain any data and calling setAccountWithCodec does not take effect. By default all codecs are set

pjsua_core.c ....TX 2410 bytes Request msg INVITE/cseq=24638
v=0
s=pjmedia
b=AS:117
t=0 0
a=X-nat:0
m=audio 4000 RTP/AVP 8 0 9 18 96 97 3 98 99 100 101 102 103 104 105 106 107 120 121 122 123
c=IN IP4 212.112.118.89
b=TIAS:96000
a=rtcp:4001 IN IP4 212.112.118.89
a=sendrecv
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:9 G722/8000
a=rtpmap:18 G729/8000
a=rtpmap:96 speex/16000
a=rtpmap:97 speex/8000
a=rtpmap:3 GSM/8000
a=rtpmap:98 AMR/8000
a=rtpmap:97 speex/8000
a=rtpmap:3 GSM/8000
a=rtpmap:98 AMR/8000
a=fmtp:98 octet-align=1
a=rtpmap:99 speex/32000
a=rtpmap:100 AMR-WB/16000
a=fmtp:100 octet-align=1
a=rtpmap:101 G7221/16000
a=fmtp:101 bitrate=24000
a=rtpmap:102 G7221/16000
a=fmtp:102 bitrate=32000
a=rtpmap:103 G7221/32000
a=fmtp:103 bitrate=24000
a=rtpmap:104 G7221/32000
a=fmtp:104 bitrate=32000
a=rtpmap:105 G7221/32000
a=fmtp:105 bitrate=48000
a=rtpmap:106 opus/48000/2
a=fmtp:106 useinbandfec=1
a=rtpmap:107 iLBC/8000
a=fmtp:107 mode=30
a=rtpmap:120 telephone-event/8000
a=fmtp:120 0-16
a=rtpmap:121 telephone-event/16000
a=fmtp:121 0-16
a=rtpmap:122 telephone-event/32000
a=fmtp:122 0-16
a=rtpmap:123 telephone-event/48000
a=fmtp:123 0-16
a=ssrc:2146870234 cname:438ea5f4714f6b9a
a=crypto:1 AES_256_CM_HMAC_SHA1_80 inline:JIv1q+avh4CNQgffiSIXoMj7MTNXeZeZDbPLSECnEUjgt5X1n8hZNdRSLxfUtw==
a=crypto:2 AES_256_CM_HMAC_SHA1_32 inline:6MrvYGBfcX7icpDba+SGD/P3pybfpH3x3iYLWjXqomFo3P2OhexMxLTq1Pw7gg==
a=crypto:3 AES_CM_128_HMAC_SHA1_80 inline:93r0U3/Ux1qJkahKXU5aP8mbzxEB7BgKjzv+sLOc
a=crypto:4 AES_CM_128_HMAC_SHA1_32 inline:xy+fqx51ngHhmIhFwOF6oDjC6LlQWTpcsESqB3tH
m=video 0 RTP/AVP 31
c=IN IP4 127.0.0.1


**Lib version**
Latest

**Configuration*
NA

**Changes**
NA

**Smartphone (please complete the following information):**
 - Device: Samsung s8+
 - OS: Latest
aenonGit commented 6 months ago

can you show the code and logs?

AAlier commented 5 months ago

Here is the modification I have tried:

public static void setAudioCodecPriorities (
            ArrayList<CodecPriority> codecPriorities,
            SipEndpoint sipEndpoint
    ) throws Exception {
        if (codecPriorities != null) {
            Logger.debug(TAG, "Setting saved codec priorities...");
            StringBuilder log = new StringBuilder();
            log.append("Saved codec priorities set:\n");
            for (CodecPriority codecPriority : codecPriorities) {
                sipEndpoint.codecSetPriority(codecPriority.getCodecId(), (short) codecPriority.getPriority());
                log.append(codecPriority).append(",");
            }
            Logger.debug(TAG, log.toString());
        } else {
            sipEndpoint.codecSetPriority("PCMA/8000", (short) (CodecPriority.PRIORITY_MAX - 1));
            sipEndpoint.codecSetPriority("PCMU/8000", (short) (CodecPriority.PRIORITY_MAX - 2));
            sipEndpoint.codecSetPriority("G722/16000", (short) (CodecPriority.PRIORITY_MAX - 3));
            sipEndpoint.codecSetPriority("G729/8000", (short) (CodecPriority.PRIORITY_MAX - 4));

//            sipEndpoint.codecSetPriority("OPUS", (short) (CodecPriority.PRIORITY_MAX - 1));
//            sipEndpoint.codecSetPriority("PCMA/8000", (short) (CodecPriority.PRIORITY_MAX - 2));
//            sipEndpoint.codecSetPriority("PCMU/8000", (short) (CodecPriority.PRIORITY_MAX - 3));
//            sipEndpoint.codecSetPriority("G729/8000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("speex/8000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("speex/16000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("speex/32000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("GSM/8000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("G722/16000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("G7221/16000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("G7221/32000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("ilbc/8000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("AMR-WB/16000", (short) CodecPriority.PRIORITY_DISABLED);
//            sipEndpoint.codecSetPriority("AMR/8000", (short) CodecPriority.PRIORITY_DISABLED);
            Logger.debug(TAG, "Default codec priorities set!");
        }
    }

In addition, I have tried to setAccountWithCodecs with only supported codec types but still when making a call, all the codec types are listed.

Trying to list only 4 audio codec types and to remove m=video 0 RTP/AVP 31 in order to reduce data size

aenonGit commented 5 months ago

that part works, you should not try to change it. Instead, show me how you call setAccountWithCodec and how you set the codecs in there. Also show me the logs of the library during the account set , because they tell you what is being configured