Ejemplo n.º 1
0
/* Create the audio queue. */
int audio_queue_create(audio_queue_t **audio_queue, const char *name)
{
	int status = 0;
	audio_queue_t *laudio_queue = NULL;
	char *lname = "";
	apr_pool_t *pool;

	if (audio_queue == NULL)
		return -1;
	else
		*audio_queue = NULL;

	if ((pool = apt_pool_create()) == NULL)
		return -1;

	if ((name == NULL) || (strlen(name) == 0))
		lname = "";
	else
		lname = apr_pstrdup(pool, name);
	if (lname == NULL)
		lname = "";

	if ((laudio_queue = (audio_queue_t *)apr_palloc(pool, sizeof(audio_queue_t))) == NULL) {
		ast_log(LOG_ERROR, "(%s) Unable to create audio queue\n", lname);
		return -1;
	} else {
		laudio_queue->buffer = NULL;
		laudio_queue->cond = NULL;
		laudio_queue->mutex = NULL;
		laudio_queue->name = lname;
		laudio_queue->pool = pool;
		laudio_queue->read_bytes = 0;
		laudio_queue->waiting = 0;
		laudio_queue->write_bytes = 0;

		if (audio_buffer_create(&laudio_queue->buffer, AUDIO_QUEUE_SIZE) != 0) {
			ast_log(LOG_ERROR, "(%s) Unable to create audio queue buffer\n", laudio_queue->name);
			status = -1;
		} else if (apr_thread_mutex_create(&laudio_queue->mutex, APR_THREAD_MUTEX_UNNESTED, pool) != APR_SUCCESS) {
			ast_log(LOG_ERROR, "(%s) Unable to create audio queue mutex\n", laudio_queue->name);
			status = -1;
		} else if (apr_thread_cond_create(&laudio_queue->cond, pool) != APR_SUCCESS) {
			ast_log(LOG_ERROR, "(%s) Unable to create audio queue condition variable\n", laudio_queue->name);
			status = -1;
		} else {
			*audio_queue = laudio_queue;
			ast_log(LOG_DEBUG, "(%s) Audio queue created\n", laudio_queue->name);
		}
	}

	if (status != 0)
		audio_queue_destroy(laudio_queue);

	return status;
}
Ejemplo n.º 2
0
int audio_engine_queue(struct audio_engine *e, const short *data, int length)
{
	struct audio_buffer *b;
	int rc;

	if (e->buffer == NULL) {
		rc = audio_buffer_create(e, NULL);
		if (rc)
			return rc;
	}

	b = e->buffer;
	while (b != NULL) {
		if (!b->isPlaying)
			return audio_buffer_queue(b, data, length);
		b = b->next;
	}

	// None not playing, enqueue in first
	return audio_buffer_queue(e->buffer, data, length);
}