背景
在应用linphone-sdk-android过程中,发现当有一起呼叫在通话中时,又收到一起呼叫,会莫名其妙的播报振铃声音,问题是曾经调用linphone-sdk-android提供的接口敞开了振铃声音
// 敞开RingmCore.setRing(null);mCore.setRingback(null);mCore.setRemoteRingbackTone(null);mCore.setNativeRingingEnabled(false);mCore.setRingDuringIncomingEarlyMedia(false);mCore.setVibrationOnIncomingCallEnabled(false);// 敞开CallErrorToneReason[] reasons = Reason.values();for (Reason reason : reasons) { mCore.setCallErrorTone(reason, null);}// 敞开ToneIdToneID[] toneIds = ToneID.values();for (ToneID toneId : toneIds) { mCore.setTone(toneId, "");}
剖析
查看Logcat输入的日志,剖析发现有ToneManager
、doStartRingtone
等关键词
13056-13056/com.guodong.android.linphone I/liblinphone: [ToneManager] [0x934e70ac] state changed : [None, LinphoneCallIncomingReceived]13056-13056/com.guodong.android.linphone I/liblinphone: [ToneManager] add new session [0x934e70ac]13056-13056/com.guodong.android.linphone I/liblinphone: [ToneManager] doStopToneToPlaySomethingElse13056-13056/com.guodong.android.linphone I/liblinphone: [ToneManager] doStartRingtone13056-13056/com.guodong.android.linphone I/liblinphone: [ToneManager] doStartNamedTone [2]
关上IDE去源码中搜寻一番,发现tone-manager.cpp
,在其中找到doStopToneToPlaySomethingElse
、doStartRingtone
、doStartNamedTone
办法,与Logcat日志输入吻合
void ToneManager::doStopToneToPlaySomethingElse(const std::shared_ptr<CallSession> &session) { lInfo() << "[ToneManager] " << __func__; if (isAnotherSessionInState(session, State::Tone)) { doStopTone(); }}void ToneManager::doStartRingtone(const std::shared_ptr<CallSession> &session) { lInfo() << "[ToneManager] " << __func__; LinphoneCore *lc = getCore()->getCCore(); // 如果有一个正在通话的呼叫就调用`doStartNamedTone` if (isAnotherSessionInState(session, State::Call)) { /* play a tone within the context of the current call */ doStartNamedTone(session, LinphoneToneCallWaiting); } else { MSSndCard *ringcard = lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; if (ringcard && !linphone_core_is_native_ringing_enabled(lc)) { if (!linphone_core_callkit_enabled(lc)){ ms_snd_card_set_stream_type(ringcard, MS_SND_CARD_STREAM_RING); linphone_ringtoneplayer_start(lc->factory, lc->ringtoneplayer, ringcard, lc->sound_conf.local_ring, 2000); }else{ ms_message("Callkit is enabled, not playing ringtone."); } } }}void ToneManager::doStartNamedTone(const std::shared_ptr<CallSession> &session, LinphoneToneID toneId) { lInfo() << "[ToneManager] " << __func__ << " [" << Utils::toString(toneId) << "]"; LinphoneToneDescription *tone = getToneFromId(toneId); // 在Java中已将audiofile置为"",所以会走else分支 if (tone && tone->audiofile) { playFile(tone->audiofile); } else { // 此处生成振铃声音 MSDtmfGenCustomTone dtmfTone = generateToneFromId(toneId); playTone(session, dtmfTone); }}
好的,当初先找到调用doStopToneToPlaySomethingElse
的办法,在IDE中查找,发现startRingtone
办法
void ToneManager::printDebugInfo(const std::shared_ptr<CallSession> &session) { auto callState = session->getState(); auto toneState = getState(session); lInfo() << "[ToneManager] [" << session << "] state changed : [" << stateToString(toneState) << ", " << Utils::toString(callState) << "]";}void ToneManager::startRingtone(const std::shared_ptr<CallSession> &session) { printDebugInfo(session); // 对应Logcat第一行输入日志 setState(session, State::Ringtone); // 对应Logcat第二行输入日志 // 如果另外一个呼叫不在Ringtone且不在Ringback状态 if (!isAnotherSessionInState(session, State::Ringtone) && !isAnotherSessionInState(session, State::Ringback)) { doStopToneToPlaySomethingElse(session); doStartRingtone(session); mStats->number_of_startRingtone++; }}
查看ToneManager::startRingtone
上面的startErrorTone
办法,发现此办法是调用linphone_core_tone_indications_enabled
判断是否能够播报Tone,猜测能够在startRingtone
办法中也减少此判断逻辑
void ToneManager::startErrorTone(const std::shared_ptr<CallSession> &session, LinphoneReason reason) { LinphoneCore *lc = getCore()->getCCore(); // 此处判断是否能够播报Tone if (linphone_core_tone_indications_enabled(lc)) { printDebugInfo(session); doStopToneToPlaySomethingElse(session); doStartErrorTone(session, reason); mStats->number_of_startErrorTone++; }}
不过须要先理解下linphone_core_tone_indications_enabled
办法的实现,此办法位于msic.c
中,办法外部从linphone_config
中读取sound
section下tone_indications
key的值转换为bool_t
类型,大于0为Ture,小于等于0为Flase,其中linphone_config
能够从Java层配置
bool_t linphone_core_tone_indications_enabled(LinphoneCore*lc){ return !!linphone_config_get_int(lc->config,"sound","tone_indications",1);}
好的,问题剖析结束,能够在startRingtone
办法中也减少此判断逻辑了
void ToneManager::startRingtone(const std::shared_ptr<CallSession> &session) { printDebugInfo(session); setState(session, State::Ringtone); // modified by guodongAndroid on 2022/04/24 批改有正在通话的呼叫时,又收到一起呼叫播报Ringtone问题 // 减少tone_indications是否开启判断 LinphoneCore *lc = getCore()->getCCore(); if (!linphone_core_tone_indications_enabled(lc)) { return; } if (!isAnotherSessionInState(session, State::Ringtone) && !isAnotherSessionInState(session, State::Ringback)) { doStopToneToPlaySomethingElse(session); doStartRingtone(session); mStats->number_of_startRingtone++; }}
保留从新编译,期待编译实现拷贝至AS中,当初只需在Java层初始化时配置Config,批改tone_indications
的值即可
// modified by guodongAndroid on 2022/04/24 批改有正在通话的呼叫时,又收到一起呼叫播报Ringtone问题// 敞开ToneIndicationsmCore.getConfig().setInt("sound", "tone_indications", 0);
happy~