📄 osip_negotiation.c
字号:
}static __payload_t *osip_negotiation_find_audio_payload (osip_negotiation_t * config, char *payload){ __payload_t *my; size_t length = strlen (payload); int pos = 0; if (payload == NULL) return NULL; while (!osip_list_eol (config->audio_codec, pos)) { my = (__payload_t *) osip_list_get (config->audio_codec, pos); if (strlen (my->payload) == length) if (0 == strncmp (my->payload, payload, length)) return my; pos++; } return NULL;}static __payload_t *osip_negotiation_find_video_payload (osip_negotiation_t * config, char *payload){ __payload_t *my; size_t length = strlen (payload); int pos = 0; if (payload == NULL) return NULL; while (!osip_list_eol (config->video_codec, pos)) { my = (__payload_t *) osip_list_get (config->video_codec, pos); if (strlen (my->payload) == length) if (0 == strncmp (my->payload, payload, length)) return my; pos++; } return NULL;}static __payload_t *osip_negotiation_find_other_payload (osip_negotiation_t * config, char *payload){ __payload_t *my; size_t length = strlen (payload); int pos = 0; if (payload == NULL) return NULL; while (!osip_list_eol (config->other_codec, pos)) { my = (__payload_t *) osip_list_get (config->other_codec, pos); if (strlen (my->payload) == length) if (0 == strncmp (my->payload, payload, length)) return my; pos++; } return NULL;}intosip_negotiation_set_fcn_set_info (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, sdp_message_t *)){ if (config == NULL) return -1; config->fcn_set_info = (int (*)(void *, sdp_message_t *)) fcn; return 0;}intosip_negotiation_set_fcn_set_uri (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, sdp_message_t *)){ if (config == NULL) return -1; config->fcn_set_uri = (int (*)(void *, sdp_message_t *)) fcn; return 0;}intosip_negotiation_set_fcn_set_emails (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, sdp_message_t *)){ if (config == NULL) return -1; config->fcn_set_emails = (int (*)(void *, sdp_message_t *)) fcn; return 0;}intosip_negotiation_set_fcn_set_phones (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, sdp_message_t *)){ if (config == NULL) return -1; config->fcn_set_phones = (int (*)(void *, sdp_message_t *)) fcn; return 0;}intosip_negotiation_set_fcn_set_attributes (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, sdp_message_t *, int)){ if (config == NULL) return -1; config->fcn_set_attributes = (int (*)(void *, sdp_message_t *, int)) fcn; return 0;}intosip_negotiation_set_fcn_accept_audio_codec (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, char *, char *, int, char *)){ if (config == NULL) return -1; config->fcn_accept_audio_codec = (int (*)(void *, char *, char *, int, char *)) fcn; return 0;}intosip_negotiation_set_fcn_accept_video_codec (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, char *, char *, int, char *)){ if (config == NULL) return -1; config->fcn_accept_video_codec = (int (*)(void *, char *, char *, int, char *)) fcn; return 0;}intosip_negotiation_set_fcn_accept_other_codec (osip_negotiation_t * config, int (*fcn) (osip_negotiation_ctx_t *, char *, char *, char *, char *)){ if (config == NULL) return -1; config->fcn_accept_other_codec = (int (*)(void *, char *, char *, char *, char *)) fcn; return 0;}intosip_negotiation_set_fcn_get_audio_port (osip_negotiation_t * config, char *(*fcn) (osip_negotiation_ctx_t *, int)){ if (config == NULL) return -1; config->fcn_get_audio_port = (char *(*)(void *, int)) fcn; return 0;}intosip_negotiation_set_fcn_get_video_port (osip_negotiation_t * config, char *(*fcn) (osip_negotiation_ctx_t *, int)){ if (config == NULL) return -1; config->fcn_get_video_port = (char *(*)(void *, int)) fcn; return 0;}intosip_negotiation_set_fcn_get_other_port (osip_negotiation_t * config, char *(*fcn) (osip_negotiation_ctx_t *, int)){ if (config == NULL) return -1; config->fcn_get_other_port = (char *(*)(void *, int)) fcn; return 0;}static intsdp_partial_clone (osip_negotiation_t * config, osip_negotiation_ctx_t * con, sdp_message_t * remote, sdp_message_t ** dest){ int i; sdp_message_v_version_set (*dest, osip_strdup ("0")); /* those fields MUST be set */ sdp_message_o_origin_set (*dest, osip_strdup (config->o_username), osip_strdup (config->o_session_id), osip_strdup (config->o_session_version), osip_strdup (config->o_nettype), osip_strdup (config->o_addrtype), osip_strdup (config->o_addr)); sdp_message_s_name_set (*dest, osip_strdup (remote->s_name)); if (config->fcn_set_info != NULL) config->fcn_set_info (con, *dest); if (config->fcn_set_uri != NULL) config->fcn_set_uri (con, *dest); if (config->fcn_set_emails != NULL) config->fcn_set_emails (con, *dest); if (config->fcn_set_phones != NULL) config->fcn_set_phones (con, *dest); if (config->c_nettype != NULL) sdp_message_c_connection_add (*dest, -1, osip_strdup (config->c_nettype), osip_strdup (config->c_addrtype), osip_strdup (config->c_addr), osip_strdup (config->c_addr_multicast_ttl), osip_strdup (config->c_addr_multicast_int)); { /* offer-answer draft says we must copy the "t=" line */ char *tmp = sdp_message_t_start_time_get (remote, 0); char *tmp2 = sdp_message_t_stop_time_get (remote, 0); if (tmp == NULL || tmp2 == NULL) return -1; /* no t line?? */ i = sdp_message_t_time_descr_add (*dest, osip_strdup (tmp), osip_strdup (tmp2)); if (i != 0) return -1; } if (config->fcn_set_attributes != NULL) config->fcn_set_attributes (con, *dest, -1); return 0;}static intsdp_confirm_media (osip_negotiation_t * config, osip_negotiation_ctx_t * context, sdp_message_t * remote, sdp_message_t ** dest){ char *payload; char *tmp, *tmp2, *tmp3, *tmp4; int ret; int i; int k; int audio_qty = 0; /* accepted audio line: do not accept more than one */ int video_qty = 0; i = 0; while (!sdp_message_endof_media (remote, i)) { tmp = sdp_message_m_media_get (remote, i); tmp2 = sdp_message_m_port_get (remote, i); tmp3 = sdp_message_m_number_of_port_get (remote, i); tmp4 = sdp_message_m_proto_get (remote, i); if (tmp == NULL) return -1; sdp_message_m_media_add (*dest, osip_strdup (tmp), osip_strdup ("0"), NULL, osip_strdup (tmp4)); k = 0; if (0 == strncmp (tmp, "audio", 5)) { do { payload = sdp_message_m_payload_get (remote, i, k); if (payload != NULL) { __payload_t *my_payload = osip_negotiation_find_audio_payload (config, payload); if (my_payload != NULL) /* payload is supported */ { ret = -1; /* somtimes, codec can be refused even if supported */ if (config->fcn_accept_audio_codec != NULL) ret = config->fcn_accept_audio_codec (context, tmp2, tmp3, audio_qty, payload); if (0 == ret) { sdp_message_m_payload_add (*dest, i, osip_strdup (payload)); if (my_payload->a_rtpmap != NULL) sdp_message_a_attribute_add (*dest, i, osip_strdup ("rtpmap"), osip_strdup (my_payload-> a_rtpmap)); if (my_payload->c_nettype != NULL) { sdp_media_t *med = osip_list_get ((*dest)->m_medias, i); if (osip_list_eol (med->c_connections, 0)) sdp_message_c_connection_add (*dest, i, osip_strdup (my_payload-> c_nettype), osip_strdup (my_payload-> c_addrtype), osip_strdup (my_payload-> c_addr), osip_strdup (my_payload-> c_addr_multicast_ttl), osip_strdup (my_payload-> c_addr_multicast_int)); } } } } k++; } while (payload != NULL); if (NULL != sdp_message_m_payload_get (*dest, i, 0)) audio_qty = 1; } else if (0 == strncmp (tmp, "video", 5)) { do { payload = sdp_message_m_payload_get (remote, i, k); if (payload != NULL) { __payload_t *my_payload = osip_negotiation_find_video_payload (config, payload); if (my_payload != NULL) /* payload is supported */ { ret = -1; if (config->fcn_accept_video_codec != NULL) ret = config->fcn_accept_video_codec (context, tmp2, tmp3, video_qty, payload); if (0 == ret) { sdp_message_m_payload_add (*dest, i, osip_strdup (payload)); /* TODO set the attribute list (rtpmap..) */ if (my_payload->a_rtpmap != NULL) sdp_message_a_attribute_add (*dest, i, osip_strdup ("rtpmap"), osip_strdup (my_payload-> a_rtpmap)); if (my_payload->c_nettype != NULL) { sdp_media_t *med = osip_list_get ((*dest)->m_medias, i); if (osip_list_eol (med->c_connections, 0)) sdp_message_c_connection_add (*dest, i, osip_strdup (my_payload-> c_nettype), osip_strdup (my_payload-> c_addrtype), osip_strdup (my_payload-> c_addr), osip_strdup (my_payload-> c_addr_multicast_ttl), osip_strdup (my_payload-> c_addr_multicast_int)); } } } } k++; } while (payload != NULL); if (NULL != sdp_message_m_payload_get (*dest, i, 0)) video_qty = 1; } else { do { payload = sdp_message_m_payload_get (remote, i, k); if (payload != NULL) { __payload_t *my_payload = osip_negotiation_find_other_payload (config, payload); if (my_payload != NULL) /* payload is supported */ { ret = -1; if (config->fcn_accept_other_codec != NULL) ret = config->fcn_accept_other_codec (context, tmp, tmp2, tmp3, payload); if (0 == ret) { sdp_message_m_payload_add (*dest, i, osip_strdup (payload)); /* rtpmap has no meaning here! */ if (my_payload->c_nettype != NULL) { sdp_media_t *med = osip_list_get ((*dest)->m_medias, i); if (osip_list_eol (med->c_connections, 0)) sdp_message_c_connection_add (*dest, i, osip_strdup (my_payload-> c_nettype), osip_strdup (my_payload-> c_addrtype), osip_strdup (my_payload-> c_addr), osip_strdup (my_payload-> c_addr_multicast_ttl), osip_strdup (my_payload-> c_addr_multicast_int)); } } } } k++; } while (payload != NULL); } i++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -