Exemplo n.º 1
0
void ast_pbx_hangup_handler_init(struct ast_channel *chan)
{
	struct ast_hangup_handler_list *handlers;

	handlers = ast_channel_hangup_handlers(chan);
	AST_LIST_HEAD_INIT_NOLOCK(handlers);
}
Exemplo n.º 2
0
struct varshead *ast_var_list_create(void)
{
	struct varshead *head;

	head = ast_calloc(1, sizeof(*head));
	if (!head) {
		return NULL;
	}
	AST_LIST_HEAD_INIT_NOLOCK(head);
	return head;
}
Exemplo n.º 3
0
static char *loopback_helper(char *buf, int buflen, const char *exten, const char *context, int priority, const char *data)
{
	struct ast_var_t *newvariable;
	struct varshead headp;
	char tmp[80];

	snprintf(tmp, sizeof(tmp), "%d", priority);
	memset(buf, 0, buflen);
	AST_LIST_HEAD_INIT_NOLOCK(&headp);
	AST_LIST_INSERT_HEAD(&headp, ast_var_assign("EXTEN", exten), entries);
	AST_LIST_INSERT_HEAD(&headp, ast_var_assign("CONTEXT", context), entries);
	AST_LIST_INSERT_HEAD(&headp, ast_var_assign("PRIORITY", tmp), entries);
	/* Substitute variables */
	pbx_substitute_variables_varshead(&headp, data, buf, buflen);
	/* free the list */
	while ((newvariable = AST_LIST_REMOVE_HEAD(&headp, entries)))
                ast_var_delete(newvariable);
	return buf;
}
/** \brief Build ast_speech_result based on the NLSML result */
static struct ast_speech_result* uni_recog_speech_result_build(uni_speech_t *uni_speech, const apt_str_t *nlsml_result, mrcp_version_e mrcp_version)
{
	float confidence;
	const char *grammar;
	const char *text;
	struct ast_speech_result *speech_result;
	struct ast_speech_result *first_speech_result;
	nlsml_interpretation_t *interpretation;
	nlsml_instance_t *instance;
	nlsml_input_t *input;
	int interpretation_count;
	int instance_count;

	apr_pool_t *pool = mrcp_application_session_pool_get(uni_speech->session);
	nlsml_result_t *result = nlsml_result_parse(nlsml_result->buf, nlsml_result->length, pool);
	if(!result) {
		ast_log(LOG_WARNING, "(%s) Failed to parse NLSML result: %s\n",uni_speech->name,nlsml_result->buf);
		return NULL;
	}

#if 1 /* enable/disable debug output of parsed results */
	nlsml_result_trace(result, pool);
#endif

	first_speech_result = NULL;
#if AST_VERSION_AT_LEAST(1,6,0)
	AST_LIST_HEAD_NOLOCK(, ast_speech_result) speech_results;
	AST_LIST_HEAD_INIT_NOLOCK(&speech_results);
#else
	struct ast_speech_result *last_speech_result = NULL;
#endif

	interpretation_count = 0;
	interpretation = nlsml_first_interpretation_get(result);
	while(interpretation) {
		input = nlsml_interpretation_input_get(interpretation);
		if(!input) {
			ast_log(LOG_WARNING, "(%s) Failed to get NLSML input\n",uni_speech->name);
			continue;
		}

		instance_count = 0;
		instance = nlsml_interpretation_first_instance_get(interpretation);
		if(!instance) {
			ast_log(LOG_WARNING, "(%s) Failed to get NLSML instance\n",uni_speech->name);
			continue;
		}

		confidence = nlsml_interpretation_confidence_get(interpretation);
		grammar = nlsml_interpretation_grammar_get(interpretation);

		if(grammar) {
			const char session_token[] = "session:";
			char *str = strstr(grammar,session_token);
			if(str) {
				grammar = str + sizeof(session_token) - 1;
			}
		}

		do {
			nlsml_instance_swi_suppress(instance);
			text = nlsml_instance_content_generate(instance, pool);

			speech_result = ast_calloc(sizeof(struct ast_speech_result), 1);
			if(text)
				speech_result->text = strdup(text);
			speech_result->score = confidence * 100;
			if(grammar)
				speech_result->grammar = strdup(grammar);
			speech_result->nbest_num = interpretation_count;
			if(!first_speech_result)
				first_speech_result = speech_result;
#if AST_VERSION_AT_LEAST(1,6,0)
			AST_LIST_INSERT_TAIL(&speech_results, speech_result, list);
#else
			speech_result->next = last_speech_result;
			last_speech_result = speech_result;
#endif
			ast_log(LOG_NOTICE, "(%s) Speech result[%d/%d]: %s, score: %d, grammar: %s\n",
					uni_speech->name,
					interpretation_count,
					instance_count,
					speech_result->text,
					speech_result->score,
					speech_result->grammar);

			instance_count++;
			instance = nlsml_interpretation_next_instance_get(interpretation, instance);
		}
		while(instance);

		interpretation_count++;
		interpretation = nlsml_next_interpretation_get(result, interpretation);
	}

	return first_speech_result;
}