📄 ice_strans.h
字号:
/**
* This structure represents the ICE stream transport.
*/
struct pj_ice_strans
{
char obj_name[PJ_MAX_OBJ_NAME]; /**< Log ID. */
pj_pool_t *pool; /**< Pool used by this object. */
void *user_data; /**< Application data. */
pj_stun_config stun_cfg; /**< STUN settings. */
pj_ice_strans_cb cb; /**< Application callback. */
pj_ice_sess *ice; /**< ICE session. */
unsigned comp_cnt; /**< Number of components. */
pj_ice_strans_comp **comp; /**< Components array. */
pj_dns_resolver *resolver; /**< The resolver instance. */
pj_bool_t has_rjob; /**< Has pending resolve? */
pj_sockaddr_in stun_srv; /**< STUN server address. */
pj_sockaddr_in turn_srv; /**< TURN server address. */
pj_timer_entry ka_timer; /**< STUN keep-alive timer. */
};
/**
* Create the ICE stream transport containing the specified number of
* components. After the ICE stream transport is created, application
* may initialize the STUN server settings, and after that it has to
* initialize each components by calling #pj_ice_strans_create_comp()
* function.
*
* @param stun_cfg The STUN settings.
* @param name Optional name for logging identification.
* @param comp_cnt Number of components.
* @param user_data Arbitrary user data to be associated with this
* ICE stream transport.
* @param cb Callback.
* @param p_ice_st Pointer to receive the ICE stream transport
* instance.
*
* @return PJ_SUCCESS if ICE stream transport is created
* successfully.
*/
PJ_DECL(pj_status_t) pj_ice_strans_create(pj_stun_config *stun_cfg,
const char *name,
unsigned comp_cnt,
void *user_data,
const pj_ice_strans_cb *cb,
pj_ice_strans **p_ice_st);
/**
* Destroy the ICE stream transport. This will destroy the ICE session
* inside the ICE stream transport, close all sockets and release all
* other resources.
*
* @param ice_st The ICE stream transport.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ice_strans_destroy(pj_ice_strans *ice_st);
/**
* Set the domain to be used when resolving the STUN servers. If application
* wants to utillize STUN, then STUN server must be specified, either by
* calling this function or by calling #pj_ice_strans_set_stun_srv().
*
* If application calls this function, then the STUN/TURN servers will
* be resolved by querying DNS SRV records for the specified domain.
*
* @param ice_st The ICE stream transport.
* @param resolver The resolver instance that will be used to
* resolve the STUN/TURN servers.
* @param domain The target domain.
*
* @return PJ_SUCCESS if DNS SRV resolution job can be
* started. The resolution process itself will
* complete asynchronously.
*/
PJ_DECL(pj_status_t) pj_ice_strans_set_stun_domain(pj_ice_strans *ice_st,
pj_dns_resolver *resolver,
const pj_str_t *domain);
/**
* Set the STUN and TURN server addresses. If application
* wants to utillize STUN, then STUN server must be specified, either by
* calling this function or by calling #pj_ice_strans_set_stun_domain().
*
* With this function, the STUN and TURN server addresses will be
* assigned immediately, that is no DNS resolution will need to be
* performed.
*
* @param ice_st The ICE stream transport.
* @param stun_srv The STUN server address, or NULL if STUN
* reflexive candidate is not to be used.
* @param turn_srv The TURN server address, or NULL if STUN
* relay candidate is not to be used.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t)
pj_ice_strans_set_stun_srv( pj_ice_strans *ice_st,
const pj_sockaddr_in *stun_srv,
const pj_sockaddr_in *turn_srv);
/**
* Create and initialize the specified component. This function will
* instantiate the socket descriptor for this component, optionally
* bind the socket to the specified address (or bind to any address/port
* if the \a addr parameter is NULL), and start finding all alias
* addresses for this socket. For each alias addresses that if finds,
* it will add an ICE stream transport candidate for this component.
*
* After all components have been initialized, application should poll
* the #pj_ice_strans_get_comps_status() peridically to check if STUN
* server reflexive and relayed candidates have been obtained
* successfully.
*
* @param ice_st The ICE stream transport.
* @param comp_id The component ID, which value must be greater than
* zero and less than or equal to the number of
* components in this ICE stream transport.
* @param options Options, see #pj_ice_strans_option.
* @param addr Local address where socket will be bound to. This
* address will be used as follows:
* - if the value is NULL, then socket will be bound
* to any available port.
* - if the value is not NULL, then if the port number
* is not zero, it will used as the starting port
* where the socket will be bound to. If bind() to
* this port fails, this function will try to bind
* to port+2, repeatedly until it succeeded.
* If application doesn't want this function to
* retry binding the socket to other port, it can
* specify PJ_ICE_ST_OPT_NO_PORT_RETRY option.
* - if the value is not NULL, then if the address
* is not INADDR_ANY, this function will bind the
* socket to this particular interface only, and
* no other host candidates will be added for this
* socket.
*
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ice_strans_create_comp(pj_ice_strans *ice_st,
unsigned comp_id,
pj_uint32_t options,
const pj_sockaddr_in *addr);
/**
* Manually add a candidate (transport address alias) for the specified
* component. Normally application shouldn't need to use this function,
* as candidates will be added automatically when component is created
* with #pj_ice_strans_create_comp().
*
* @param ice_st ICE stream transport.
* @param comp_id The component ID.
* @param type The candidate type.
* @param local_pref The local preference for this candidate
* (typically the value is 65535).
* @param addr The candidate address.
* @param set_default Set to non-zero to make this candidate the
* default candidate for this component.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ice_strans_add_cand(pj_ice_strans *ice_st,
unsigned comp_id,
pj_ice_cand_type type,
pj_uint16_t local_pref,
const pj_sockaddr_in *addr,
pj_bool_t set_default);
/**
* Get the status of components in the ICE stream transports. Since
* some IP address candidates have to be obtained asynchronously (for
* example, the STUN reflexive or relay candidate), application can
* use this function to know whether the address resolution has
* completed.
*
* @param ice_st The ICE stream transport.
*
* @return PJ_SUCCESS if all candidates have been resolved
* successfully, PJ_EPENDING if transport resolution
* is still in progress, or other status on failure.
*/
PJ_DECL(pj_status_t) pj_ice_strans_get_comps_status(pj_ice_strans *ice_st);
/**
* Initialize the ICE session in the ICE stream transport.
*
* @param ice_st The ICE stream transport.
* @param role ICE role.
* @param local_ufrag Optional local username fragment.
* @param local_passwd Optional local password.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
pj_ice_sess_role role,
const pj_str_t *local_ufrag,
const pj_str_t *local_passwd);
/**
* Enumerate the local candidates. This function can only be called
* after the ICE session has been created in the ICE stream transport.
*
* @param ice_st The ICE stream transport.
* @param count On input, it specifies the maximum number of
* elements. On output, it will be filled with
* the number of candidates copied to the
* array.
* @param cand Array of candidates.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ice_strans_enum_cands(pj_ice_strans *ice_st,
unsigned *count,
pj_ice_sess_cand cand[]);
/**
* Start ICE connectivity checks. This function can only be called
* after the ICE session has been created in the ICE stream transport.
*
* This function will pair the local and remote candidates to create
* check list. Once the check list is created and sorted based on the
* priority, ICE periodic checks will be started. This function will
* return immediately, and application will be notified about the
* connectivity check status in the callback.
*
* @param ice_st The ICE stream transport.
* @param rem_ufrag Remote ufrag, as seen in the SDP received from
* the remote agent.
* @param rem_passwd Remote password, as seen in the SDP received from
* the remote agent.
* @param rem_cand_cnt Number of remote candidates.
* @param rem_cand Remote candidate array.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t)
pj_ice_strans_start_ice( pj_ice_strans *ice_st,
const pj_str_t *rem_ufrag,
const pj_str_t *rem_passwd,
unsigned rem_cand_cnt,
const pj_ice_sess_cand rem_cand[]);
/**
* Stop and destroy the ICE session inside this media transport.
*
* @param ice_st The ICE stream transport.
*
* @return PJ_SUCCESS, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pj_ice_strans_stop_ice(pj_ice_strans *ice_st);
/**
* Send outgoing packet using this transport. If ICE checks have not
* produced a valid check for the specified component ID, this function
* will return with failure. Otherwise it will send the packet to remote
* destination using the nominated local candidate as have been checked
* previously.
*
* @param ice_st The ICE stream transport.
* @param comp_id Component ID.
* @param data The data or packet to be sent.
* @param data_len Size of data or packet, in bytes.
* @param dst_addr The destination address.
* @param dst_addr_len Length of destination address.
*
* @return PJ_SUCCESS if data is sent successfully.
*/
PJ_DECL(pj_status_t) pj_ice_strans_sendto(pj_ice_strans *ice_st,
unsigned comp_id,
const void *data,
pj_size_t data_len,
const pj_sockaddr_t *dst_addr,
int dst_addr_len);
/**
* @}
*/
PJ_END_DECL
#endif /* __PJNATH_ICE_STRANS_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -