android sip通话实现流程分析

sip协议的核心是SipManager,我在前篇博客中已经讲述了sip通话的代码建立过程,点击打开链接

会创建一个SipManager实例,它的构造代码如下:

public static SipManager newInstance(Context context) {
        return (isApiSupported(context) ? new SipManager(context) : null);
    }


private SipManager(Context context) {
        mContext = context;
        createSipService();
    }


private void createSipService() {
        IBinder b = ServiceManager.getService(Context.SIP_SERVICE); //获取sip服务的代理类,返回一个BinderProxy对象.
        mSipService = ISipService.Stub.asInterface(b);
    }

从上面代码可以看出,SipManager的构造过程中会去获取sip服务(实际就是SipService)的代理类对象,SipManager的很多方法最终是调用到这个服务端的相应方法来实现的.

那么下面我们先看看SipService是如何注册到ServiceManager中去的.

它的注册与一般服务的注册不同,绝大多数Service都是直接在SysetmServer进程中进行注册,而SipService是在TeleService apk中注册,也就是在phone进程中注册的(部分phone相关的服务也是在phone进程中注册的),虽然最终都是注册到ServiceManager中,但这个服务是运行在phone进程中的.

具体实现代码在PhoneGlobals.java中.

Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            PhoneConstants.State phoneState;
            switch (msg.what) {
                // Starts the SIP service. It's a no-op if SIP API is not supported
                // on the deivce.
                // TODO: Having the phone process host the SIP service is only
                // temporary. Will move it to a persistent communication process
                // later.
                case EVENT_START_SIP_SERVICE:
                    SipService.start(getApplicationContext());
                    break;

..//

}

在PhoneGlobals的onCreate()中

if (mCM == null) {

....//

 mHandler.sendEmptyMessage(EVENT_START_SIP_SERVICE);

}


SipService的start方法如下:

    public static void start(Context context) {
        if (SipManager.isApiSupported(context)) {
            ServiceManager.addService("sip", new SipService(context));
            context.sendBroadcast(new Intent(SipManager.ACTION_SIP_SERVICE_UP));
            if (DBG) slog("start:");
        }
    }

这样就将一个SipService注册到ServiceManager中了.

我在前面博客已分析过,拨打一个网络电话是调用SipManager的makeAudioCall()方法实现的.

下面我以拨打一个网络电话为例进行说明具体实现流程:

public SipAudioCall makeAudioCall(SipProfile localProfile,
       

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值