MPF_DECLARE(apt_bool_t) mpf_codec_manager_codec_list_get(const mpf_codec_manager_t *codec_manager, mpf_codec_list_t *codec_list, apr_pool_t *pool) { const mpf_codec_descriptor_t *static_descriptor; mpf_codec_descriptor_t *descriptor; int i; mpf_codec_t *codec; mpf_codec_list_init(codec_list,codec_manager->codec_arr->nelts,pool); for(i=0; i<codec_manager->codec_arr->nelts; i++) { codec = APR_ARRAY_IDX(codec_manager->codec_arr,i,mpf_codec_t*); static_descriptor = codec->static_descriptor; if(static_descriptor) { descriptor = mpf_codec_list_add(codec_list); if(descriptor) { *descriptor = *static_descriptor; } } } if(codec_manager->event_descriptor) { descriptor = mpf_codec_list_add(codec_list); if(descriptor) { *descriptor = *codec_manager->event_descriptor; } } return TRUE; }
/** Create demo RTP termination descriptor */ mpf_rtp_termination_descriptor_t* demo_rtp_descriptor_create(apr_pool_t *pool) { mpf_codec_descriptor_t *codec_descriptor; mpf_rtp_media_descriptor_t *media; /* create rtp descriptor */ mpf_rtp_termination_descriptor_t *rtp_descriptor = apr_palloc(pool,sizeof(mpf_rtp_termination_descriptor_t)); mpf_rtp_termination_descriptor_init(rtp_descriptor); /* create rtp local media */ media = apr_palloc(pool,sizeof(mpf_rtp_media_descriptor_t)); mpf_rtp_media_descriptor_init(media); apt_string_assign(&media->ip,"127.0.0.1",pool); media->port = 6000; media->state = MPF_MEDIA_ENABLED; media->direction = STREAM_DIRECTION_RECEIVE; /* initialize codec list */ mpf_codec_list_init(&media->codec_list,2,pool); /* set codec descriptor */ codec_descriptor = mpf_codec_list_add(&media->codec_list); if(codec_descriptor) { codec_descriptor->payload_type = 0; } /* set another codec descriptor */ codec_descriptor = mpf_codec_list_add(&media->codec_list); if(codec_descriptor) { codec_descriptor->payload_type = 96; apt_string_set(&codec_descriptor->name,"PCMU"); codec_descriptor->sampling_rate = 16000; codec_descriptor->channel_count = 1; } rtp_descriptor->audio.local = media; return rtp_descriptor; }
/** Create sample RTP remote descriptor */ static mpf_rtp_stream_descriptor_t* mpf_rtp_remote_descriptor_create(mpf_suite_session_t *session) { mpf_codec_list_t *codec_list; mpf_codec_descriptor_t *codec_descriptor; mpf_rtp_stream_descriptor_t *descriptor = apr_palloc(session->pool,sizeof(mpf_rtp_stream_descriptor_t)); mpf_rtp_stream_descriptor_init(descriptor); descriptor->remote = apr_palloc(session->pool,sizeof(mpf_rtp_media_descriptor_t)); mpf_rtp_media_descriptor_init(descriptor->remote); descriptor->remote->direction = STREAM_DIRECTION_DUPLEX; apt_string_set(&descriptor->remote->ip,"127.0.0.1"); descriptor->remote->port = 5002; codec_list = &descriptor->remote->codec_list; mpf_codec_list_init(codec_list,2,session->pool); codec_descriptor = mpf_codec_list_add(codec_list); if(codec_descriptor) { codec_descriptor->payload_type = 0; } codec_descriptor = mpf_codec_list_add(codec_list); if(codec_descriptor) { codec_descriptor->payload_type = 96; apt_string_set(&codec_descriptor->name,"PCMU"); codec_descriptor->sampling_rate = 16000; codec_descriptor->channel_count = 1; } return descriptor; }
/** Generate RTP media descriptor by SDP media */ static apt_bool_t mpf_rtp_media_generate(mpf_rtp_media_descriptor_t *rtp_media, const sdp_media_t *sdp_media, const apt_str_t *ip, apr_pool_t *pool) { mpf_rtp_attrib_e id; apt_str_t name; sdp_attribute_t *attrib = NULL; sdp_rtpmap_t *map; mpf_codec_descriptor_t *codec; for(attrib = sdp_media->m_attributes; attrib; attrib=attrib->a_next) { apt_string_set(&name,attrib->a_name); id = mpf_rtp_attrib_id_find(&name); switch(id) { case RTP_ATTRIB_PTIME: rtp_media->ptime = (apr_uint16_t)atoi(attrib->a_value); break; default: break; } } mpf_codec_list_init(&rtp_media->codec_list,5,pool); for(map = sdp_media->m_rtpmaps; map; map = map->rm_next) { codec = mpf_codec_list_add(&rtp_media->codec_list); if(codec) { codec->payload_type = (apr_byte_t)map->rm_pt; apt_string_assign(&codec->name,map->rm_encoding,pool); codec->sampling_rate = (apr_uint16_t)map->rm_rate; codec->channel_count = 1; } } switch(sdp_media->m_mode) { case sdp_inactive: rtp_media->direction = STREAM_DIRECTION_NONE; break; case sdp_sendonly: rtp_media->direction = STREAM_DIRECTION_SEND; break; case sdp_recvonly: rtp_media->direction = STREAM_DIRECTION_RECEIVE; break; case sdp_sendrecv: rtp_media->direction = STREAM_DIRECTION_DUPLEX; break; } if(sdp_media->m_connections) { apt_string_assign(&rtp_media->ip,sdp_media->m_connections->c_address,pool); } else { rtp_media->ip = *ip; } if(sdp_media->m_port) { rtp_media->port = (apr_port_t)sdp_media->m_port; rtp_media->state = MPF_MEDIA_ENABLED; } else { rtp_media->state = MPF_MEDIA_DISABLED; } return TRUE; }
/** Create RTP tx remote descriptor */ static mpf_rtp_stream_descriptor_t* mpf_rtp_tx_remote_descriptor_create(const mpf_suite_agent_t *agent, const mpf_suite_session_t *session) { mpf_codec_list_t *codec_list; mpf_codec_descriptor_t *codec_descriptor; mpf_rtp_media_descriptor_t *media_descriptor; mpf_rtp_stream_descriptor_t *stream_descriptor; media_descriptor = mpf_rtp_media_descriptor_alloc(session->pool); media_descriptor->state = MPF_MEDIA_ENABLED; media_descriptor->direction = STREAM_DIRECTION_RECEIVE; apt_string_set(&media_descriptor->ip,"127.0.0.1"); media_descriptor->port = 5000; codec_list = &media_descriptor->codec_list; mpf_codec_list_init(codec_list,1,session->pool); codec_descriptor = mpf_codec_list_add(codec_list); if(codec_descriptor) { codec_descriptor->payload_type = 0; apt_string_set(&codec_descriptor->name,"PCMU"); codec_descriptor->sampling_rate = 8000; codec_descriptor->channel_count = 1; } stream_descriptor = apr_palloc(session->pool,sizeof(mpf_rtp_stream_descriptor_t)); mpf_rtp_stream_descriptor_init(stream_descriptor); stream_descriptor->remote = media_descriptor; stream_descriptor->settings = agent->rtp_settings; return stream_descriptor; }
static apt_bool_t mpf_codec_manager_codec_parse(const mpf_codec_manager_t *codec_manager, mpf_codec_list_t *codec_list, char *codec_desc_str, apr_pool_t *pool) { const mpf_codec_t *codec; mpf_codec_descriptor_t *descriptor; const char *separator = "/"; char *state; /* parse codec name */ char *str = apr_strtok(codec_desc_str, separator, &state); codec_desc_str = NULL; /* make sure we pass NULL on subsequent calls of apr_strtok() */ if(str) { apt_str_t name; apt_string_assign(&name,str,pool); /* find codec by name */ codec = mpf_codec_manager_codec_find(codec_manager,&name); if(!codec) { apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"No Such Codec [%s]",str); return FALSE; } descriptor = mpf_codec_list_add(codec_list); descriptor->name = name; /* set defualt attributes */ if(codec->static_descriptor) { descriptor->payload_type = codec->static_descriptor->payload_type; descriptor->sampling_rate = codec->static_descriptor->sampling_rate; descriptor->channel_count = codec->static_descriptor->channel_count; } else { descriptor->payload_type = 96; descriptor->sampling_rate = 8000; descriptor->channel_count = 1; } /* parse optional payload type */ str = apr_strtok(codec_desc_str, separator, &state); if(str) { descriptor->payload_type = (apr_byte_t)atol(str); /* parse optional sampling rate */ str = apr_strtok(codec_desc_str, separator, &state); if(str) { descriptor->sampling_rate = (apr_uint16_t)atol(str); /* parse optional channel count */ str = apr_strtok(codec_desc_str, separator, &state); if(str) { descriptor->channel_count = (apr_byte_t)atol(str); } } } } return TRUE; }