Example #1
0
static mpf_object_t* mpf_linear_bridge_create(mpf_audio_stream_t *source, mpf_audio_stream_t *sink, const mpf_codec_manager_t *codec_manager, const char *name, apr_pool_t *pool)
{
	mpf_codec_descriptor_t *descriptor;
	apr_size_t frame_size;
	mpf_bridge_t *bridge;
	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Create Linear Audio Bridge %s",name);
	bridge = mpf_bridge_base_create(source,sink,name,pool);
	if(!bridge) {
		return NULL;
	}

	descriptor = source->rx_descriptor;
	frame_size = mpf_codec_linear_frame_size_calculate(descriptor->sampling_rate,descriptor->channel_count);
	bridge->frame.codec_frame.size = frame_size;
	bridge->frame.codec_frame.buffer = apr_palloc(pool,frame_size);
	
	if(mpf_audio_stream_rx_open(source,NULL) == FALSE) {
		return NULL;
	}
	if(mpf_audio_stream_tx_open(sink,NULL) == FALSE) {
		mpf_audio_stream_rx_close(source);
		return NULL;
	}
	return &bridge->base;
}
Example #2
0
/** \brief Set up the speech structure within the engine */
static int uni_recog_create_internal(struct ast_speech *speech, ast_format_compat *format)
{
	uni_speech_t *uni_speech;
	mrcp_session_t *session;
	apr_pool_t *pool;
	const mpf_codec_descriptor_t *descriptor;

	/* Create session instance */
	session = mrcp_application_session_create(uni_engine.application,uni_engine.profile,speech);
	if(!session) {
		ast_log(LOG_ERROR, "Failed to create session\n");
		return -1;
	}
	pool = mrcp_application_session_pool_get(session);
	uni_speech = apr_palloc(pool,sizeof(uni_speech_t));
	uni_speech->session = session;
	uni_speech->channel = NULL;
	uni_speech->wait_object = NULL;
	uni_speech->mutex = NULL;
	uni_speech->media_buffer = NULL;
	uni_speech->active_grammars = apr_hash_make(pool);
	uni_speech->is_sm_request = FALSE;
	uni_speech->is_inprogress = FALSE;
	uni_speech->sm_request = 0;
	uni_speech->sm_response = MRCP_SIG_STATUS_CODE_SUCCESS;
	uni_speech->mrcp_request = NULL;
	uni_speech->mrcp_response = NULL;
	uni_speech->mrcp_event = NULL;

	uni_speech->speech_base = speech;
	speech->data = uni_speech;

	/* Create cond wait object and mutex */
	apr_thread_mutex_create(&uni_speech->mutex,APR_THREAD_MUTEX_DEFAULT,pool);
	apr_thread_cond_create(&uni_speech->wait_object,pool);

	/* Create recognition channel instance */
	if(uni_recog_channel_create(uni_speech,format) != TRUE) {
		ast_log(LOG_ERROR, "Failed to create channel\n");
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	/* Send add channel request and wait for response */
	if(uni_recog_sm_request_send(uni_speech,MRCP_SIG_COMMAND_CHANNEL_ADD) != TRUE) {
		ast_log(LOG_WARNING, "Failed to send add channel request\n");
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	/* Check received response */
	if(uni_speech->sm_response != MRCP_SIG_STATUS_CODE_SUCCESS) {
		ast_log(LOG_WARNING, "Failed to add channel\n");
		uni_recog_sm_request_send(uni_speech,MRCP_SIG_COMMAND_SESSION_TERMINATE);
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	descriptor = mrcp_application_source_descriptor_get(uni_speech->channel);
	if(descriptor) {
		mpf_frame_buffer_t *media_buffer;
		apr_size_t frame_size = mpf_codec_linear_frame_size_calculate(descriptor->sampling_rate,descriptor->channel_count);
		/* Create media buffer */
		ast_log(LOG_DEBUG, "Create media buffer frame_size:%"APR_SIZE_T_FMT"\n",frame_size);
		media_buffer = mpf_frame_buffer_create(frame_size,20,pool);
		uni_speech->media_buffer = media_buffer;
	}
	
	if(!uni_speech->media_buffer) {
		ast_log(LOG_WARNING, "Failed to create media buffer\n");
		uni_recog_sm_request_send(uni_speech,MRCP_SIG_COMMAND_SESSION_TERMINATE);
		uni_recog_cleanup(uni_speech);
		return -1;
	}

	ast_log(LOG_NOTICE, "Created speech instance '%s'\n",uni_speech_id_get(uni_speech));

	/* Set properties for session */
	uni_recog_properties_set(uni_speech);
	/* Preload grammars */
	uni_recog_grammars_preload(uni_speech);
	return 0;
}
Example #3
0
MPF_DECLARE(mpf_object_t*) mpf_mixer_create(
								mpf_audio_stream_t **source_arr, 
								apr_size_t source_count, 
								mpf_audio_stream_t *sink, 
								const mpf_codec_manager_t *codec_manager, 
								const char *name,
								apr_pool_t *pool)
{
	apr_size_t i;
	apr_size_t frame_size;
	mpf_codec_descriptor_t *descriptor;
	mpf_audio_stream_t *source;
	mpf_mixer_t *mixer;
	if(!source_arr || !source_count || !sink) {
		return NULL;
	}

	apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Create Mixer %s",name);
	mixer = apr_palloc(pool,sizeof(mpf_mixer_t));
	mixer->source_arr = NULL;
	mixer->source_count = 0;
	mixer->sink = NULL;
	mpf_object_init(&mixer->base,name);
	mixer->base.process = mpf_mixer_process;
	mixer->base.destroy = mpf_mixer_destroy;
	mixer->base.trace = mpf_mixer_trace;

	if(mpf_audio_stream_tx_validate(sink,NULL,NULL,pool) == FALSE) {
		return NULL;
	}

	descriptor = sink->tx_descriptor;
	if(descriptor && mpf_codec_lpcm_descriptor_match(descriptor) == FALSE) {
		mpf_codec_t *codec = mpf_codec_manager_codec_get(codec_manager,descriptor,pool);
		if(codec) {
			/* set encoder after mixer */
			mpf_audio_stream_t *encoder = mpf_encoder_create(sink,codec,pool);
			sink = encoder;
		}
	}
	mixer->sink = sink;
	mpf_audio_stream_tx_open(sink,NULL);

	for(i=0; i<source_count; i++)	{
		source = source_arr[i];
		if(!source) continue;

		if(mpf_audio_stream_rx_validate(source,NULL,NULL,pool) == FALSE) {
			continue;
		}

		descriptor = source->rx_descriptor;
		if(descriptor && mpf_codec_lpcm_descriptor_match(descriptor) == FALSE) {
			mpf_codec_t *codec = mpf_codec_manager_codec_get(codec_manager,descriptor,pool);
			if(codec) {
				/* set decoder before mixer */
				mpf_audio_stream_t *decoder = mpf_decoder_create(source,codec,pool);
				source = decoder;
			}
		}
		source_arr[i] = source;
		mpf_audio_stream_rx_open(source,NULL);
	}
	mixer->source_arr = source_arr;
	mixer->source_count = source_count;

	descriptor = sink->tx_descriptor;
	frame_size = mpf_codec_linear_frame_size_calculate(descriptor->sampling_rate,descriptor->channel_count);
	mixer->frame.codec_frame.size = frame_size;
	mixer->frame.codec_frame.buffer = apr_palloc(pool,frame_size);
	mixer->mix_frame.codec_frame.size = frame_size;
	mixer->mix_frame.codec_frame.buffer = apr_palloc(pool,frame_size);
	return &mixer->base;
}