如何在 Android 上使用 pjsip 发送 dtmf?

How to send dtmf with pjsip on Android?

我正在尝试在 voip 通话期间发送 dtmf。 为此,我使用

mCall.dialDtmf(String.valueOf(dtmf));

mCall 是从 PjSip 调用的。 调用此函数时,我捕获异常:

04-25 16:03:57.867 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err: java.lang.Exception: Title:       pjsua_call_dial_dtmf(id, &pj_digits)
04-25 16:03:57.867 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err: Code:        70013
04-25 16:03:57.867 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err: Description: Invalid operation (PJ_EINVALIDOP)
04-25 16:03:57.867 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err: Location:    ../src/pjsua2/call.cpp:551
04-25 16:03:57.879 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at org.pjsip.pjsua2.pjsua2JNI.Call_dialDtmf(Native Method)
04-25 16:03:57.879 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at org.pjsip.pjsua2.Call.dialDtmf(Call.java:143)
04-25 16:03:57.879 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at com.kaymera.kphoneapp.voipEngine.PJCall.dialDtmf(PJCall.java:115)
04-25 16:03:57.879 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at com.kaymera.kphoneapp.voipEngine.calls.VoipCall.sendDTMF(VoipCall.java:149)
04-25 16:03:57.879 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at kphoneapp.kymera.kvoip.myapplication.MainActivity.generateDtmf(MainActivity.java:223)
04-25 16:03:57.880 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at kphoneapp.kymera.kvoip.myapplication.MainActivity$$ViewBinder.doClick(MainActivity$$ViewBinder.java:110)
04-25 16:03:57.880 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
04-25 16:03:57.880 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at android.view.View.performClick(View.java:4764)
04-25 16:03:57.880 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at android.view.View$PerformClick.run(View.java:19844)
04-25 16:03:57.880 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
04-25 16:03:57.880 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
04-25 16:03:57.881 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at android.os.Looper.loop(Looper.java:135)
04-25 16:03:57.881 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5349)
04-25 16:03:57.881 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
04-25 16:03:57.881 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at java.lang.reflect.Method.invoke(Method.java:372)
04-25 16:03:57.881 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
04-25 16:03:57.881 19670-19670/kphoneapp.kymera.kvoip.myapplication W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

我该如何解决?

我遇到了类似的问题,问题是服务器对 DTMF 使用了不同的方法。

dialDtmf 方法使用 RFC 2833,而我的服务器使用 SIP INFO 调用 DTMF。

这是适用于我的服务器的代码:

CallSendRequestParam prm = new CallSendRequestParam();
prm.setMethod("INFO");
SipTxOption txo = new SipTxOption();
txo.setContentType(" application/dtmf-relay");
txo.setMsgBody("Signal=" + String.valueOf(code) + "\n" + "Duration=160");
prm.setTxOption(txo);
call.sendRequest(prm);