1

我正在使用 Pjsip(v2.6) 进行 VoIP 音频和视频通话。

我在第一个来电视频通话中遇到问题。当我注册用户并进行视频通话时,它总是失败。

当我调试我的代码时,我发现我收到的 CallMediaInfo 状态为PJSUA_CALL_MEDIA_NONE。当我第二次尝试时,我收到了PJSUA_CALL_MEDIA_ACTIVE并显示了预览。

这是我的makeCall代码:

fun makeCall(id: String, isVideo: Boolean) {
        video = isVideo
        val buddyUri = "sip:$CALLEE@$URI"

        val call = MyCall(account, -1)
        val prm = CallOpParam(true)
        val callSettings = prm.opt
        if (isVideo) {
            callSettings.videoCount = 1
            callSettings.audioCount = 1
        } else {
            callSettings.audioCount = 1
            callSettings.videoCount = 0
        }

        try {
            call.makeCall(buddyUri, prm)
        } catch (e: Exception) {
            call.delete()
        }
        currentCall = call
    }

这是我执行 Incoming_Call 通知的代码:

if (m?.what == Constants.MSGTYPE.INCOMING_CALL) {

            /* Incoming call */
            val call = m.obj as MyCall
            val prm = CallOpParam()

            /* Only one call at anytime */
            if (currentCall != null) {
                call.delete()
                return true
            }

            /* Answer with ringing */
            prm.statusCode = pjsip_status_code.PJSIP_SC_RINGING
            try {
                val callSetting = prm.opt
                callSetting?.audioCount = 1
                if (video) {
                    callSetting?.videoCount = 1
                } else callSetting?.videoCount = 0
                call.answer(prm)
            } catch (e: Exception) {
                println(e)
            }

            currentCall = call
            if (call.info.remOfferer && call.info.remVideoCount == 1L) {
                // start Video Activity
            } else {
                // start Audio Activity
            }
        }

当我接听电话时,我收到了 onCallMediaState 回调:

override fun onCallMediaState(prm: OnCallMediaStateParam) {
        val ci: CallInfo
        try {
            ci = info
        } catch (e: Exception) {
            return
        }

        val cmiv = ci.media

        for (i in 0 until cmiv!!.size()) {
            val cmi = cmiv.get(i.toInt())
            if (cmi.type == pjmedia_type.PJMEDIA_TYPE_AUDIO && (cmi.status == pjsua_call_media_status.PJSUA_CALL_MEDIA_ACTIVE || cmi.status == pjsua_call_media_status.PJSUA_CALL_MEDIA_REMOTE_HOLD)) {
                LogUtils.e("AANAL onCallMediaState  Audio")
                handleAudioMedia(getMedia(i))
            } else if (cmi.type == pjmedia_type.PJMEDIA_TYPE_VIDEO &&
//                    cmi.status == pjsua_call_media_status.PJSUA_CALL_MEDIA_ACTIVE &&
                    cmi.videoIncomingWindowId != pjsua2.INVALID_ID) {
                LogUtils.e("AANAL onCallMediaState  Video")
                handleVideoMedia(cmi)
            }
        }

        MyApp.observer.notifyCallMediaState(this)
    }

谁能帮我这个?

先感谢您!

4

1 回答 1

0

我找到了自己的答案。这是因为我在接听电话时设置的 videoCount 不正确。

确保在来电回调中调用 call.answer 方法时设置 videoCount = 1。

例如。

     if (m?.what == Constants.MSGTYPE.INCOMING_CALL) {
        ...
        try {
                        val callSetting = prm.opt
                        callSetting?.audioCount = 1
                        // I have corrected this videoCount
                        if (call.info.remOfferer && call.info.remVideoCount == 1L) { 
                            callSetting?.videoCount = 1
                        } else callSetting?.videoCount = 0
                        call.answer(prm)
                    } catch (e: Exception) {
                        println(e)
                    }

        ...
        }
于 2019-09-05T11:54:06.410 回答