static apt_bool_t mrcp_client_on_termination_modify(mrcp_client_session_t *session, const mpf_message_t *mpf_message) { rtp_termination_slot_t *termination_slot; if(!session) { return FALSE; } apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Media Termination Modified "APT_NAMESIDRES_FMT, MRCP_SESSION_NAMESID(session), mpf_termination_name_get(mpf_message->termination)); termination_slot = mrcp_client_rtp_termination_find(session,mpf_message->termination); if(termination_slot) { /* rtp termination */ if(termination_slot->waiting == FALSE) { return FALSE; } termination_slot->waiting = FALSE; termination_slot->descriptor = mpf_message->descriptor;; if(mrcp_client_session_subrequest_remove(session) == TRUE) { if(session->state == SESSION_STATE_GENERATING_OFFER) { /* send offer to server */ mrcp_client_session_offer_send(session); } else if(session->state == SESSION_STATE_PROCESSING_ANSWER) { /* raise app response */ mrcp_app_sig_response_raise(session,TRUE); } } } return TRUE; }
static apt_bool_t mrcp_client_on_termination_modify(mrcp_client_session_t *session, mpf_message_t *mpf_message) { rtp_termination_slot_t *termination_slot; if(!session) { return FALSE; } termination_slot = mrcp_client_rtp_termination_find(session,mpf_message->termination); if(termination_slot) { /* rtp termination */ if(termination_slot->waiting == FALSE) { return FALSE; } termination_slot->waiting = FALSE; termination_slot->descriptor = mpf_message->descriptor;; if(session->offer_flag_count) { session->offer_flag_count--; if(!session->offer_flag_count) { /* send offer to server */ mrcp_client_session_offer_send(session); } } if(session->answer_flag_count) { session->answer_flag_count--; if(!session->answer_flag_count) { /* raise app response */ mrcp_app_sig_response_raise(session,MRCP_SIG_STATUS_CODE_SUCCESS,TRUE); } } } return TRUE; }
static apt_bool_t mrcp_client_resource_discover(mrcp_client_session_t *session) { mrcp_session_descriptor_t *descriptor = NULL; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Discover Resources "APT_PTR_FMT, MRCP_SESSION_PTR(&session->base)); session->answer = NULL; mrcp_client_session_state_set(session,SESSION_STATE_DISCOVERING); if(mrcp_session_version_get(session) == MRCP_VERSION_1) { mrcp_resource_t *resource; mrcp_resource_id i; for(i=0; i<MRCP_RESOURCE_TYPE_COUNT; i++) { resource = mrcp_resource_get(session->profile->resource_factory,i); if(!resource) continue; descriptor = mrcp_session_descriptor_create(session->base.pool); apt_string_copy(&descriptor->resource_name,&resource->name,session->base.pool); if(mrcp_session_discover_request(&session->base,descriptor) == TRUE) { mrcp_client_session_subrequest_add(session); } } } else { if(mrcp_session_discover_request(&session->base,descriptor) == TRUE) { mrcp_client_session_subrequest_add(session); } } if(session->subrequest_count == 0) { session->status = MRCP_SIG_STATUS_CODE_FAILURE; mrcp_app_sig_response_raise(session,TRUE); } return TRUE; }
static apt_bool_t mrcp_client_on_termination_subtract(mrcp_client_session_t *session, const mpf_message_t *mpf_message) { rtp_termination_slot_t *termination_slot; if(!session) { return FALSE; } apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Media Termination Subtracted "APT_NAMESIDRES_FMT, MRCP_SESSION_NAMESID(session), mpf_termination_name_get(mpf_message->termination)); termination_slot = mrcp_client_rtp_termination_find(session,mpf_message->termination); if(termination_slot) { /* rtp termination */ if(termination_slot->waiting == FALSE) { return FALSE; } termination_slot->waiting = FALSE; if(mrcp_client_session_subrequest_remove(session) == TRUE) { mrcp_app_session_terminate_raise(session,MRCP_SIG_STATUS_CODE_SUCCESS); } } else { /* channel termination */ mrcp_channel_t *channel = mrcp_client_channel_termination_find(session,mpf_message->termination); if(channel && channel->waiting_for_termination == TRUE) { channel->waiting_for_termination = FALSE; if(mrcp_client_session_subrequest_remove(session) == TRUE) { /* raise app response */ mrcp_app_sig_response_raise(session,TRUE); } } } return TRUE; }
apt_bool_t mrcp_client_session_answer_process(mrcp_client_session_t *session, mrcp_session_descriptor_t *descriptor) { mrcp_sig_status_code_e status_code = MRCP_SIG_STATUS_CODE_SUCCESS; if(!session->offer) { return FALSE; } apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Receive Answer <%s> [c:%d a:%d v:%d]", mrcp_session_str(session), descriptor->control_media_arr->nelts, descriptor->audio_media_arr->nelts, descriptor->video_media_arr->nelts); if(session->base.signaling_agent->mrcp_version == MRCP_VERSION_1) { if(mrcp_client_resource_answer_process(session,descriptor) != TRUE) { status_code = MRCP_SIG_STATUS_CODE_FAILURE; } } else { mrcp_client_control_media_answer_process(session,descriptor); mrcp_client_av_media_answer_process(session,descriptor); } /* store received answer */ session->answer = descriptor; if(!session->answer_flag_count) { /* raise app response */ mrcp_app_sig_response_raise(session,status_code,TRUE); } return TRUE; }
static apt_bool_t mrcp_client_on_termination_subtract(mrcp_client_session_t *session, const mpf_message_t *mpf_message) { rtp_termination_slot_t *termination_slot; if(!session) { return FALSE; } termination_slot = mrcp_client_rtp_termination_find(session,mpf_message->termination); if(termination_slot) { /* rtp termination */ if(termination_slot->waiting == FALSE) { return FALSE; } termination_slot->waiting = FALSE; if(mrcp_client_session_subrequest_remove(session) == TRUE) { mrcp_app_session_terminate_raise(session,MRCP_SIG_STATUS_CODE_SUCCESS); } } else { /* channel termination */ mrcp_channel_t *channel = mrcp_client_channel_termination_find(session,mpf_message->termination); if(channel && channel->waiting_for_termination == TRUE) { channel->waiting_for_termination = FALSE; if(mrcp_client_session_subrequest_remove(session) == TRUE) { /* raise app response */ mrcp_app_sig_response_raise(session,TRUE); } } } return TRUE; }
static apt_bool_t mrcp_client_on_termination_modify(mrcp_client_session_t *session, const mpf_message_t *mpf_message) { rtp_termination_slot_t *termination_slot; if(!session) { return FALSE; } termination_slot = mrcp_client_rtp_termination_find(session,mpf_message->termination); if(termination_slot) { /* rtp termination */ if(termination_slot->waiting == FALSE) { return FALSE; } termination_slot->waiting = FALSE; termination_slot->descriptor = mpf_message->descriptor;; if(mrcp_client_session_subrequest_remove(session) == TRUE) { if(session->state == SESSION_STATE_GENERATING_OFFER) { /* send offer to server */ mrcp_client_session_offer_send(session); } else if(session->state == SESSION_STATE_PROCESSING_ANSWER) { /* raise app response */ mrcp_app_sig_response_raise(session,TRUE); } } } return TRUE; }
apt_bool_t mrcp_client_mpf_message_process(mpf_message_container_t *mpf_message_container) { apr_size_t i; mrcp_client_session_t *session; const mpf_message_t *mpf_message; for(i=0; i<mpf_message_container->count; i++) { mpf_message = &mpf_message_container->messages[i]; if(mpf_message->context) { session = mpf_engine_context_object_get(mpf_message->context); } else { session = NULL; } if(!session) { apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Received MPF Message: NULL session"); continue; } if(mpf_message->message_type == MPF_MESSAGE_TYPE_RESPONSE) { switch(mpf_message->command_id) { case MPF_ADD_TERMINATION: mrcp_client_on_termination_add(session,mpf_message); break; case MPF_MODIFY_TERMINATION: mrcp_client_on_termination_modify(session,mpf_message); break; case MPF_SUBTRACT_TERMINATION: mrcp_client_on_termination_subtract(session,mpf_message); break; case MPF_ADD_ASSOCIATION: case MPF_REMOVE_ASSOCIATION: case MPF_RESET_ASSOCIATIONS: case MPF_APPLY_TOPOLOGY: case MPF_DESTROY_TOPOLOGY: if(mrcp_client_session_subrequest_remove(session) == TRUE) { if(session->state == SESSION_STATE_GENERATING_OFFER) { /* send offer to server */ mrcp_client_session_offer_send(session); } else if(session->state == SESSION_STATE_PROCESSING_ANSWER) { /* raise app response */ mrcp_app_sig_response_raise(session,TRUE); } } break; default: break; } } else if(mpf_message->message_type == MPF_MESSAGE_TYPE_EVENT) { apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Process MPF Event " APT_NAMESID_FMT, MRCP_SESSION_NAMESID(session)); } } return TRUE; }
apt_bool_t mrcp_client_session_terminate_event_process(mrcp_client_session_t *session) { if(session->active_request) { /* raise app response */ mrcp_app_sig_response_raise(session,MRCP_SIG_STATUS_CODE_TERMINATE,FALSE); /* cancel remaing requests (if any) */ do { session->active_request = apt_list_pop_front(session->request_queue); if(session->active_request) { mrcp_app_sig_response_raise(session,MRCP_SIG_STATUS_CODE_CANCEL,FALSE); } } while(session->active_request); } else { /* raise app event */ mrcp_app_sig_event_raise(session,NULL); } return TRUE; }
apt_bool_t mrcp_client_on_channel_modify(mrcp_channel_t *channel, mrcp_control_descriptor_t *descriptor) { mrcp_client_session_t *session = (mrcp_client_session_t*)channel->session; apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"On Control Channel Modify"); if(!channel->waiting_for_channel) { return FALSE; } channel->waiting_for_channel = FALSE; if(session->answer_flag_count) { session->answer_flag_count--; if(!session->answer_flag_count) { /* raise app response */ mrcp_app_sig_response_raise(session,MRCP_SIG_STATUS_CODE_SUCCESS,TRUE); } } return TRUE; }
apt_bool_t mrcp_client_on_channel_modify(mrcp_channel_t *channel, mrcp_control_descriptor_t *descriptor, apt_bool_t status) { mrcp_client_session_t *session = (mrcp_client_session_t*)channel->session; apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"On Control Channel Modify "APT_PTRSID_FMT, MRCP_SESSION_PTRSID(&session->base)); if(!channel->waiting_for_channel) { return FALSE; } channel->waiting_for_channel = FALSE; if(mrcp_client_session_subrequest_remove(session) == TRUE) { /* raise app response */ if(status != TRUE) { session->status = MRCP_SIG_STATUS_CODE_FAILURE; } mrcp_app_sig_response_raise(session,TRUE); } return TRUE; }
static apt_bool_t mrcp_app_session_terminate_raise(mrcp_client_session_t *session, mrcp_sig_status_code_e status) { int i; mrcp_channel_t *channel; for(i=0; i<session->channels->nelts; i++) { channel = ((mrcp_channel_t**)session->channels->elts)[i]; if(!channel) continue; if(channel->control_channel) { mrcp_client_control_channel_destroy(channel->control_channel); channel->control_channel = NULL; } } mrcp_client_session_remove(session->application->client,session); /* raise app response */ return mrcp_app_sig_response_raise(session,status,TRUE); }
apt_bool_t mrcp_client_session_discover_response_process(mrcp_client_session_t *session, mrcp_session_descriptor_t *descriptor) { apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Resources Discovered %s", session->base.name); if(!session->active_request) { return FALSE; } if(!descriptor) { /* raise app response */ session->status = MRCP_SIG_STATUS_CODE_FAILURE; return mrcp_app_sig_response_raise(session,TRUE); } if(mrcp_session_version_get(session) == MRCP_VERSION_1) { if(descriptor->resource_state == TRUE) { mrcp_control_descriptor_t *control_media; if(!session->answer) { session->answer = descriptor; } control_media = mrcp_control_descriptor_create(session->base.pool); control_media->id = mrcp_session_control_media_add(session->answer,control_media); control_media->resource_name = descriptor->resource_name; } } else { session->answer = descriptor; } if(mrcp_client_session_subrequest_remove(session) == TRUE) { mrcp_app_message_t *response; response = mrcp_client_app_response_create(session->active_request,MRCP_SIG_STATUS_CODE_SUCCESS,session->base.pool); response->descriptor = session->answer; session->answer = NULL; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Raise App Resource Discovery Response %s", session->base.name); session->application->handler(response); session->active_request = apt_list_pop_front(session->request_queue); if(session->active_request) { mrcp_app_request_dispatch(session,session->active_request); } } return TRUE; }
static apt_bool_t mrcp_app_session_terminate_raise(mrcp_client_session_t *session, mrcp_sig_status_code_e status) { int i; mrcp_channel_t *channel; for(i=0; i<session->channels->nelts; i++) { channel = APR_ARRAY_IDX(session->channels,i,mrcp_channel_t*); if(!channel) continue; if(channel->control_channel) { mrcp_client_control_channel_destroy(channel->control_channel); channel->control_channel = NULL; } } mrcp_client_session_remove(session->application->client,session); /* raise app response */ if(status != MRCP_SIG_STATUS_CODE_SUCCESS) { session->status = status; } return mrcp_app_sig_response_raise(session,FALSE); }
apt_bool_t mrcp_client_session_answer_process(mrcp_client_session_t *session, mrcp_session_descriptor_t *descriptor) { if(!session->offer) { return FALSE; } if(!descriptor) { apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->base.log_obj,"Receive Answer "APT_NAMESID_FMT" [null descriptor]", MRCP_SESSION_NAMESID(session)); session->status = MRCP_SIG_STATUS_CODE_FAILURE; /* raise app response */ return mrcp_app_sig_response_raise(session,TRUE); } apt_obj_log(APT_LOG_MARK,APT_PRIO_INFO,session->base.log_obj,"Receive Answer "APT_NAMESID_FMT" [c:%d a:%d v:%d] Status %d", MRCP_SESSION_NAMESID(session), descriptor->control_media_arr->nelts, descriptor->audio_media_arr->nelts, descriptor->video_media_arr->nelts, descriptor->response_code); if(descriptor->response_code >=200 && descriptor->response_code < 300) { mrcp_client_session_state_set(session,SESSION_STATE_PROCESSING_ANSWER); if(session->context) { /* first, reset/destroy existing associations and topology */ if(mpf_engine_topology_message_add( session->profile->media_engine, MPF_RESET_ASSOCIATIONS,session->context, &session->mpf_task_msg) == TRUE){ mrcp_client_session_subrequest_add(session); } } if(mrcp_session_version_get(session) == MRCP_VERSION_1) { if(mrcp_client_resource_answer_process(session,descriptor) != TRUE) { session->status = MRCP_SIG_STATUS_CODE_FAILURE; } } else { mrcp_client_control_media_answer_process(session,descriptor); mrcp_client_av_media_answer_process(session,descriptor); } if(session->context) { /* apply topology based on assigned associations */ if(mpf_engine_topology_message_add( session->profile->media_engine, MPF_APPLY_TOPOLOGY,session->context, &session->mpf_task_msg) == TRUE) { mrcp_client_session_subrequest_add(session); } mpf_engine_message_send(session->profile->media_engine,&session->mpf_task_msg); } } else { session->status = MRCP_SIG_STATUS_CODE_TERMINATE; } /* store received answer */ session->answer = descriptor; if(!session->subrequest_count) { /* raise app response */ mrcp_app_sig_response_raise(session,TRUE); } return TRUE; }
static apt_bool_t mrcp_app_request_dispatch(mrcp_client_session_t *session, const mrcp_app_message_t *app_message) { if(session->state == SESSION_STATE_TERMINATING) { /* no more requests are allowed, as session is being terminated! just return, it is horribly wrong and can crash anytime here */ apt_obj_log(APT_LOG_MARK,APT_PRIO_ERROR,session->base.log_obj,"Inappropriate Application Request " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); return FALSE; } if(session->disconnected == TRUE) { /* cancel all the requests besides session termination one */ if(!IS_SESSION_TERMINATE(app_message)) { apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,session->base.log_obj,"Cancel App Request " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); session->status = MRCP_SIG_STATUS_CODE_CANCEL; return mrcp_app_failure_message_raise(session); } } if(session->registered == FALSE) { if(IS_SESSION_TERMINATE(app_message)) { /* if session is not registered, nothing to terminate, just respond with success */ session->status = MRCP_SIG_STATUS_CODE_SUCCESS; return mrcp_app_sig_response_raise(session,FALSE); } /* select signaling agent */ session->base.signaling_agent = mrcp_sa_factory_agent_select(session->profile->sa_factory); if(!session->base.signaling_agent) { apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,session->base.log_obj,"Failed to Select Signaling Agent " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); session->status = MRCP_SIG_STATUS_CODE_FAILURE; } if(session->profile->mrcp_version == MRCP_VERSION_2) { /* select connection agent */ session->base.connection_agent = mrcp_ca_factory_agent_select(session->profile->ca_factory); if(!session->base.connection_agent) { apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,session->base.log_obj,"Failed to Select Connection Agent " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); session->status = MRCP_SIG_STATUS_CODE_FAILURE; } } if(session->profile->mpf_factory) { /* select media engine */ session->base.media_engine = mpf_engine_factory_engine_select(session->profile->mpf_factory); if(!session->base.media_engine) { apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,session->base.log_obj,"Failed to Select Media Engine " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); session->status = MRCP_SIG_STATUS_CODE_FAILURE; } } /* set rtp termination factory */ session->base.rtp_factory = session->profile->rtp_termination_factory; if(session->status == MRCP_SIG_STATUS_CODE_FAILURE) { /* raise app response in case of failure */ return mrcp_app_failure_message_raise(session); } if(session->base.signaling_agent->create_client_session(&session->base,session->profile->signaling_settings) != TRUE) { /* raise app response */ apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,session->base.log_obj,"Failed to Create Session " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); session->status = MRCP_SIG_STATUS_CODE_FAILURE; return mrcp_app_failure_message_raise(session); } mrcp_client_session_add(session->application->client,session); session->registered = TRUE; } session->status = MRCP_SIG_STATUS_CODE_SUCCESS; switch(app_message->message_type) { case MRCP_APP_MESSAGE_TYPE_SIGNALING: { apt_obj_log(APT_LOG_MARK,APT_PRIO_DEBUG,session->base.log_obj,"Dispatch App Request " APT_NAMESID_FMT " [%d]", MRCP_SESSION_NAMESID(session), app_message->sig_message.command_id); switch(app_message->sig_message.command_id) { case MRCP_SIG_COMMAND_SESSION_UPDATE: mrcp_client_session_update(session); break; case MRCP_SIG_COMMAND_SESSION_TERMINATE: mrcp_client_session_terminate(session); break; case MRCP_SIG_COMMAND_CHANNEL_ADD: mrcp_client_channel_add(session,app_message->channel); break; case MRCP_SIG_COMMAND_CHANNEL_REMOVE: mrcp_client_channel_modify(session,app_message->channel,FALSE); break; case MRCP_SIG_COMMAND_RESOURCE_DISCOVER: mrcp_client_resource_discover(session); break; default: break; } break; } case MRCP_APP_MESSAGE_TYPE_CONTROL: { mrcp_client_message_send(session,app_message->channel,app_message->control_message); break; } } return TRUE; }