PJSIP学习笔记11 -- SIP模块

关于模块的博文原文在这里: https://blog.csdn.net/smllyy/article/details/40820721

1) PJSIP模块结构体
        struct pjsip_module
        {
            PJ_DECL_LIST_MEMBER(struct pjsip_module);          //链表指针

            pj_str_t name;
            int id;                 //Application must initialize this field with -1 before registering the module to PJSIP
            int priority;              //模块ID在模块注册到Endpoint时决定


            pj_status_t (*load)(pjsip_endpoint *endpt);    //Module should return PJ_SUCCESS to indicate success
            pj_status_t (*start)(void);            //return zero to indicate success
            pj_status_t (*stop)(void);
            pj_status_t (*unload)(void);

            pj_bool_t (*on_rx_request)(pjsip_rx_data *rdata);
            pj_bool_t (*on_rx_response)(pjsip_rx_data *rdata);
            pj_status_t (*on_tx_request)(pjsip_tx_data *tdata);
            pj_status_t (*on_tx_response)(pjsip_tx_data *tdata);
            void (*on_tsx_state)(pjsip_transaction *tsx, pjsip_event *event);  //on_tsx_state()在接收到请求或响应重传时,不会被调用
                                                          //传送或接收临时响应并不属于重传,因此传送或接收临时响应将会引起该回调函数
        };


    某些PJSIP组件(结构体)有一个容器(一个void指针数组),可用来存放针对特定模块的特定数据,这个容器叫做mod_data,用模块ID作为索引

      例如,事务层会将匹配的事务实例存放到mod_data中,UA层也会将匹配的dialog实例存放到mod_data中。应用可以调用pjsip_rdata_get_tsx()或者pjsip_rdata_get_dlg()来获取这些数据

        如果模块的回调函数缺省为NULL,则该接口函数会被当作PJ_SUCCESS

参考博文有几张图帮助我们理解消息处理流程,摘录如下:

1)模块状态机, 涉及模块结构体前4个接口函数, 若接口指针为NULL, 则sip_endpoint默认为对该接口调用结果是SUCCESS

PJSIP学习笔记11 -- SIP模块

2)incoming 消息处理,模块调用示意图

PJSIP学习笔记11 -- SIP模块

3)新会话+新事务 incoming消息处理流程

PJSIP学习笔记11 -- SIP模块

4)事务内incoming消息处理流程

PJSIP学习笔记11 -- SIP模块


5) 会话内新事务incoming消息处理

PJSIP学习笔记11 -- SIP模块