Android Linphone 音视频呼进监听(二)

一、呼叫监听:LinphoneService
当我们启动程序的时候LinphoneLauncherActivity会执行LinphoneService这个标准的android后台服务,如下代码

    if (LinphoneService.isReady()) {
        onServiceReady();
    } else {
        // start linphone as background
        startService(new Intent(ACTION_MAIN).setClass(this, LinphoneService.class));
        mServiceThread = new ServiceWaitThread();
        mServiceThread.start();
    }

LinphoneService需要完成的工作包括以下几点:
1、加载APP需要使用的资源
2、启动LinphoneManager这个APP的全局管理器

LinphoneManager的职能有一下几点:
1、管理LinphoneService 的实例
2、管理LinphoneCore这个核心实例
3、生成目前需要处理的事件通知的LinphoneCoreListenerBase实例并注册到LinphoneCore这个核心实例的事件监听器中,LinphoneCoreListenerBase 实例只监听callState,globalState,registrationState这三个事件

(PS:实现了LinphoneCoreListener, LinphoneChatMessage.LinphoneChatMessageListener这两个接口的部分方法,负责系统需要使用的资源的管理与初始化,管理着LinphoneCore的实例,负责了LinphoneCore的初始化和它的整个生命周期,同时又响应接收到文件消息与文件消息的响应,感觉它的整体职责是有点混乱的,可能作者开始是把它作为全局的统一资源管理器的,可是后来开发着开发着就什么东西都往里面放,就成了这样了)

二、linphone内核基于JNI的封装接口:LinphoneCore
LinphoneCoreImpl是linphone内核针对JAVA开发语言的封装。所有linphone内核的相关方法都是通过它来向android系统暴露

从一中可知:LinphoneCoreListenerBase 实例只监听callState,globalState,registrationState这三个事件

1、callState:有电话呼入时,将会出发这个事件,callState事件当中state会是LinphoneCall.State.IncomingReceived,APP需要切换到电话呼入的操作界面

2、registrationState:registrationState这个事件反馈的是用户的SIP账号到SIP服务器的注册状态,是成功注册还是注册失败等。

3、globalState;linphone核心状态

三、音视频呼进监听流程

1、电话呼进

2、触发LinphoneService中已经启动的LinphoneCoreListenerBase监听实例callState事件,其中state会是LinphoneCall.State.IncomingReceived,同时跳转到LinphoneActivity

3、LinphoneActivity也监听了LinphoneCoreListenerBase,此时已经收到呼进请求,LinphoneCoreListenerBase中callState会判断当前的LinphoneCall.State,跳转到CallIncomingActivity

4、CallIncomingActivity声明LinphoneCall一个会话,并在会话列表中找到当前会话(lookupCurrentCall),拿到这个会话可以拿到联系呼进用的基本信息、接听(此方法:answer,跳转到CallActivity界面)、拒绝(LinphoneManager.getLc().terminateCall(mCall);结束当前界面)此会话

5、接听:

你可能感兴趣的:(Android Linphone 音视频呼进监听(二))