Android pjsip:第一个传入视频呼叫提供 CallmediaInfo 状态 PJSUA_CALL_MEDIA_NONE
Android pjsip: First Incoming Video call gives CallmediaInfo status PJSUA_CALL_MEDIA_NONE
我正在使用 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)
}
谁能帮我解决这个问题?
提前致谢!
我找到了自己的答案。
这是因为我在接听电话时设置的 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)
}
...
}
我正在使用 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)
}
谁能帮我解决这个问题?
提前致谢!
我找到了自己的答案。 这是因为我在接听电话时设置的 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)
}
...
}