diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..7d065c9 Binary files /dev/null and b/.DS_Store differ diff --git "a/img/make_call\346\265\201\347\250\213.png" "b/img/make_call\346\265\201\347\250\213.png" new file mode 100644 index 0000000..3c0234e Binary files /dev/null and "b/img/make_call\346\265\201\347\250\213.png" differ diff --git a/img/pjsua_call_make_call.png b/img/pjsua_call_make_call.png new file mode 100644 index 0000000..85173c5 Binary files /dev/null and b/img/pjsua_call_make_call.png differ diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 52a9957..8e5eedf 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -2,3 +2,7 @@ - [sip协议概述](./SIP.md) - [pjsip log](./PJSIP_log.md) +- [常见数据结构与工具] + - [pjsua_call](./pjsua_call.md) + - [pjsua_acc](./pjsua_acc.md) + - [pjsua_data](./pjsua_data.md) \ No newline at end of file diff --git "a/src/make_call\345\255\246\344\271\240.md" "b/src/make_call\345\255\246\344\271\240.md" new file mode 100644 index 0000000..9853fee --- /dev/null +++ "b/src/make_call\345\255\246\344\271\240.md" @@ -0,0 +1,26 @@ +## simple_pjsua.c流程 + +img + +## pjsua_call_make_call + +img + +```c +status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL); +``` + +### 1、参数详解 + +**acc_id ** 获得 + +``` +pjsua_acc_add(&cfg, PJ_TRUE, &acc_id); +``` + +**uri** 用户传入 + +``` +pj_str_t uri = pj_str(argv[1]); +``` + diff --git a/src/pjsua_acc.md b/src/pjsua_acc.md new file mode 100644 index 0000000..8ac16f9 --- /dev/null +++ b/src/pjsua_acc.md @@ -0,0 +1,80 @@ +## pjsua_acc + +``` +/** + * Account + */ +typedef struct pjsua_acc +{ + pj_pool_t *pool; /**< Pool for this account. */ + pjsua_acc_config cfg; /**< Account configuration. */ + pj_bool_t valid; /**< Is this account valid? */ + + int index; /**< Index in accounts array. */ + pj_str_t display; /**< Display name, if any. */ + pj_str_t user_part; /**< User part of local URI. */ + pj_bool_t is_sips; /**< Local URI uses "sips"? */ + pj_str_t contact; /**< Our Contact header. */ + pj_str_t reg_contact; /**< Contact header for REGISTER. + It may be different than acc + contact if outbound is used */ + pj_bool_t contact_rewritten; + /**< Contact rewrite has been done? */ + pjsip_host_port via_addr; /**< Address for Via header */ + pjsip_transport *via_tp; /**< Transport associated with + the Via address */ + + pj_str_t srv_domain; /**< Host part of reg server. */ + int srv_port; /**< Port number of reg server. */ + + pjsip_regc *regc; /**< Client registration session. */ + pj_status_t reg_last_err; /**< Last registration error. */ + int reg_last_code; /**< Last status last register. */ + + pj_str_t reg_mapped_addr;/**< Our addr as seen by reg srv. + Only if allow_sdp_nat_rewrite + is set */ + + struct { + pj_bool_t active; /**< Flag of reregister status. */ + pj_timer_entry timer; /**< Timer for reregistration. */ + void *reg_tp; /**< Transport for registration. */ + unsigned attempt_cnt; /**< Attempt counter. */ + } auto_rereg; /**< Reregister/reconnect data. */ + + pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */ + pjsip_transport *ka_transport; /**< Transport for keep-alive. */ + pj_sockaddr ka_target; /**< Destination address for K-A */ + unsigned ka_target_len; /**< Length of ka_target. */ + + pjsip_route_hdr route_set; /**< Complete route set inc. outbnd.*/ + pj_uint32_t global_route_crc; /** CRC of global route setting. */ + pj_uint32_t local_route_crc; /** CRC of account route setting.*/ + + unsigned rfc5626_status;/**< SIP outbound status: + 0: not used + 1: requested + 2: acknowledged by servers */ + pj_str_t rfc5626_instprm;/**< SIP outbound instance param. */ + pj_str_t rfc5626_regprm;/**< SIP outbound reg param. */ + unsigned rfc5626_flowtmr;/**< SIP outbound flow timer. */ + + unsigned cred_cnt; /**< Number of credentials. */ + pjsip_cred_info cred[PJSUA_ACC_MAX_PROXIES]; /**< Complete creds. */ + + pj_bool_t online_status; /**< Our online status. */ + pjrpid_element rpid; /**< RPID element information. */ + pjsua_srv_pres pres_srv_list; /**< Server subscription list. */ + pjsip_publishc *publish_sess; /**< Client publication session. */ + pj_bool_t publish_state; /**< Last published online status */ + + pjsip_evsub *mwi_sub; /**< MWI client subscription */ + pjsip_dialog *mwi_dlg; /**< Dialog for MWI sub. */ + + pj_uint16_t next_rtp_port; /**< Next RTP port to be used. */ + pjsip_transport_type_e tp_type; /**< Transport type (for local acc or + transport binding) */ + pjsua_ip_change_op ip_change_op;/**< IP change process progress. */ +} pjsua_acc; +``` + diff --git a/src/pjsua_call.md b/src/pjsua_call.md new file mode 100644 index 0000000..89553fb --- /dev/null +++ b/src/pjsua_call.md @@ -0,0 +1,141 @@ +## pjsua_call + +```c +/** + * Structure to be attached to invite dialog. + * Given a dialog "dlg", application can retrieve this structure + * by accessing dlg->mod_data[pjsua.mod.id]. + */ +struct pjsua_call +{ + unsigned index; /**< Index in pjsua array. */ + pjsua_call_setting opt; /**< Call setting. */ + pj_bool_t opt_inited;/**< Initial call setting has been set, + to avoid different opt in answer. */ + pjsip_inv_session *inv; /**< The invite session. */ + void *user_data; /**< User/application data. */ + pjsip_status_code last_code; /**< Last status code seen. */ + pj_str_t last_text; /**< Last status text seen. */ + pj_time_val start_time;/**< First INVITE sent/received. */ + pj_time_val res_time; /**< First response sent/received. */ + pj_time_val conn_time; /**< Connected/confirmed time. */ + pj_time_val dis_time; /**< Disconnect time. */ + pjsua_acc_id acc_id; /**< Account index being used. */ + int secure_level;/**< Signaling security level. */ + pjsua_call_hold_type call_hold_type; /**< How to do call hold. */ + pj_bool_t local_hold;/**< Flag for call-hold by local. */ + void *hold_msg; /**< Outgoing hold tx_data. */ + pj_str_t cname; /**< RTCP CNAME. */ + char cname_buf[16];/**< cname buffer. */ + + unsigned med_cnt; /**< Number of media in SDP. */ + pjsua_call_media media[PJSUA_MAX_CALL_MEDIA]; /**< Array of media */ + unsigned med_prov_cnt;/**< Number of provisional media. */ + pjsua_call_media media_prov[PJSUA_MAX_CALL_MEDIA]; + /**< Array of provisional media. */ + pj_bool_t med_update_success; + /**< Is media update successful? */ + pj_bool_t hanging_up;/**< Is call in the process of hangup? */ + + int audio_idx; /**< First active audio media. */ + pj_mutex_t *med_ch_mutex;/**< Media channel callback's mutex. */ + pjsua_med_tp_state_cb med_ch_cb;/**< Media channel callback. */ + pjsua_med_tp_state_info med_ch_info;/**< Media channel info. */ + + pjsip_evsub *xfer_sub; /**< Xfer server subscription, if this + call was triggered by xfer. */ + pj_stun_nat_type rem_nat_type; /**< NAT type of remote endpoint. */ + + char last_text_buf_[128]; /**< Buffer for last_text. */ + + struct { + int retry_cnt; /**< Retry count. */ + } lock_codec; /**< Data for codec locking when answer + contains multiple codecs. */ + + struct { + pjsip_dialog *dlg; /**< Call dialog. */ + pjmedia_sdp_session *rem_sdp;/**< Remote SDP. */ + pj_pool_t *pool_prov;/**< Provisional pool. */ + pj_bool_t med_ch_deinit;/**< Media channel de-init-ed? */ + union { + struct { + pjsua_msg_data *msg_data;/**< Headers for outgoing INVITE. */ + pj_bool_t hangup; /**< Call is hangup? */ + } out_call; + struct { + call_answer answers;/**< A list of call answers. */ + pj_bool_t hangup;/**< Call is hangup? */ + pjsip_dialog *replaced_dlg; /**< Replaced dialog. */ + } inc_call; + } call_var; + } async_call; /**< Temporary storage for async + outgoing/incoming call. */ + + pj_bool_t rem_offerer; /**< Was remote SDP offerer? */ + unsigned rem_aud_cnt; /**< No of active audio in last remote + offer. */ + unsigned rem_vid_cnt; /**< No of active video in last remote + offer. */ + + pj_bool_t rx_reinv_async;/**< on_call_rx_reinvite() async. */ + pj_timer_entry reinv_timer; /**< Reinvite retry timer. */ + pj_bool_t reinv_pending;/**< Pending until CONFIRMED state. */ + pj_bool_t reinv_ice_sent;/**< Has reinvite for ICE upd sent? */ + pjsip_rx_data *incoming_data;/**< Cloned incoming call rdata. + On pjsua2, when handling incoming + call, onCreateMediaTransport() will + not be called since the call isn't + created yet. This temporary + variable is used to handle such + case, see ticket #1916. */ + + struct { + pj_bool_t enabled; + pj_bool_t remote_sup; + pj_bool_t remote_dlg_est; + pjsua_op_state trickling; + int retrans18x_count; + pj_bool_t pending_info; + pj_timer_entry timer; + } trickle_ice; + + pj_timer_entry hangup_timer; /**< Hangup retry timer. */ + unsigned hangup_retry; /**< Number of hangup retries. */ + unsigned hangup_code; /**< Hangup code. */ + pj_str_t hangup_reason; /**< Hangup reason. */ + pjsua_msg_data *hangup_msg_data;/**< Hangup message data. */ +}; +``` + +### pjsua_call_hold_type + +```c +/** + * This enumeration specifies how we should offer call hold request to + * remote peer. The default value is set by compile time constant + * PJSUA_CALL_HOLD_TYPE_DEFAULT, and application may control the setting + * on per-account basis by manipulating \a call_hold_type field in + * #pjsua_acc_config. + */ +typedef enum pjsua_call_hold_type +{ + /** + * This will follow RFC 3264 recommendation to use a=sendonly, + * a=recvonly, and a=inactive attribute as means to signal call + * hold status. This is the correct value to use. + */ + PJSUA_CALL_HOLD_TYPE_RFC3264, + + /** + * This will use the old and deprecated method as specified in RFC 2543, + * and will offer c=0.0.0.0 in the SDP instead. Using this has many + * drawbacks such as inability to keep the media transport alive while + * the call is being put on hold, and should only be used if remote + * does not understand RFC 3264 style call hold offer. + */ + PJSUA_CALL_HOLD_TYPE_RFC2543 + +} pjsua_call_hold_type; +``` + diff --git a/src/pjsua_data.md b/src/pjsua_data.md new file mode 100644 index 0000000..d974918 --- /dev/null +++ b/src/pjsua_data.md @@ -0,0 +1,126 @@ +## pjsua_data pjsua_var + +```c +/** + * Global pjsua application data. + */ +struct pjsua_data +{ + + /* Control: */ + pj_caching_pool cp; /**< Global pool factory. */ + pj_pool_t *pool; /**< pjsua's private pool. */ + pj_pool_t *timer_pool;/**< pjsua's timer pool. */ + pj_mutex_t *mutex; /**< Mutex protection for this data */ + unsigned mutex_nesting_level; /**< Mutex nesting level. */ + pj_thread_t *mutex_owner; /**< Mutex owner. */ + pjsua_state state; /**< Library state. */ + + /* Logging: */ + pjsua_logging_config log_cfg; /**< Current logging config. */ + pj_oshandle_t log_file; /**