Exemplo n.º 1
0
static void do_test_amr_xx(const char *file, int line,
		char *fmtp_s, char *data_s, int data_len, char *expect_s, int expect_len,
		char *codec, int clockrate)
{
	printf("running test %s:%i\n", file, line);
	str codec_name;
	str_init(&codec_name, codec);
	const codec_def_t *def = codec_find(&codec_name, MT_AUDIO);
	assert(def);
	if (!def->support_encoding || !def->support_decoding) {
		printf("AMR not fully supported - skipping test\n");
		exit(0);
	}
	const format_t fmt = { .clockrate = clockrate, .channels = 1, .format = AV_SAMPLE_FMT_S16};
	str fmtp_str, *fmtp = NULL;
	if (fmtp_s) {
		str_init(&fmtp_str, fmtp_s);
		fmtp = &fmtp_str;
	}
	decoder_t *d = decoder_new_fmtp(def, clockrate, 1, &fmt, fmtp);
	assert(d);
	const str data = { data_s, data_len };
	int ret = decoder_input_data(d, &data, 1, frame_cb, &expect_s, &expect_len);
	assert(!ret);
	assert(expect_s == NULL);
	decoder_close(d);
	printf("test ok: %s:%i\n", file, line);
}

static void do_test_amr_wb(const char *file, int line,
		char *fmtp_s, char *data_s, int data_len, char *expect_s, int expect_len)
{
	do_test_amr_xx(file, line, fmtp_s, data_s, data_len, expect_s, expect_len,
			"AMR-WB", 16000);
}
Exemplo n.º 2
0
long
spu_aac_decode_stop (void)
{
	long err = RSACPDS_RTN_GOOD;
	if (state.open != 0) {
		err = decoder_close (1);
		state.open = 0;
	}
	return err;
}
Exemplo n.º 3
0
int file_close(struct file_handle *h)
{
	/* Close decoder */
	decoder_close(h->dec);

	/* Close file */
	fclose(h->fp);

	free(h);

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[])
{
	float *buffer;
	unsigned int len;
	unsigned int frate;
	FILE *f;
	decoder_handle handle;
	if(argc != 3) {
		printf("USAGE: %s <MP3 File> <Output file>\n", argv[0]);
		exit(-1);
	}
	f = fopen(argv[2], "w");
	if(!f) {
		printf("Cannot create %s\n", argv[2]);
		exit(-1);
	}

	if(decoder_init(&handle)) {
		printf("Cound not initialize decoder\n");
		goto init_failed;
	}
	if(decoder_open(handle, argv[1])) {
		printf("Could not open %s to decode\n", argv[1]);
		goto open_failed;
	}
	if(decoder_start(handle)) {
		printf("Could not start decoding\n");
		goto start_failed;
	}
	while(1) {
		decoder_data_pull(handle, &buffer, &len, &frate);
		if(len == 0)
			break;
		if(write(fileno(f), buffer, len * sizeof(float)) != len * sizeof(float)) {
			printf("Write failed\n");
		}

		free(buffer);
	}
init_failed:
	fclose(f);
start_failed:
	if(decoder_close(handle)) {
		printf("Closing decoder handle failed\n");
	}
open_failed:
	decoder_exit(handle);

	return 0;

}
Exemplo n.º 5
0
int spectgen_close(spectgen_handle _handle)
{
	struct spectgen_struct *handle = (struct spectgen_struct *)_handle;

	if(!handle)
	      return -1;

	/* Will block till decoder is still active */
	decoder_close(handle->session->d_handle);

	/* Will block if the session is still in working state */
	spectgen_session_put(handle->session);

	q_destroy(&handle->queue);
	free(handle->leftover);
	free(handle->barkband_table);

	free(handle);
	return 0;
}
Exemplo n.º 6
0
/*
 * unload stream.
 */
int callc fennec_plugin_close(unsigned long id)
{
	if(id >= pstreams_count)return 0;
	if(!pstreams[id].initialized)return 0;

	while(plugin_busy)sys_pass();
	plugin_busy = 1;

	if(plugin_error)
	{
		plugin_busy = 0;
		return 0;
	}


	decoder_close(id);

	pstreams[id].initialized = 0;
	plugin_busy = 0;
	return 1;
}
Exemplo n.º 7
0
long
spu_aac_decode (void **destbuf, void *destend, void **srcbuf, void *srcend,
		struct spu_aac_decode_fmt *format, void *dataout,
		void *datain, int datalen)
{
	long status;
	int need_input, need_output;
	int inbuf_added;
	int endflag;
	int state_decode;
	int state_decode_end, state_decode_really_end;
	int incopy, outcopy;
	unsigned long nblk;
	long err = RSACPDS_RTN_GOOD;
	void *_dataout;
	int _dataoutlen;

once_again:
	need_input = 0;
	need_output = 0;
	inbuf_added = 0;
	if (state.init == 0) {
		if (init2 () < 0)
			return -1;
		state.init = 1;
	}
	pthread_mutex_lock (&transfer_lock);
	while (output_remain <= 0 && outlendata.head != NULL) {
		int *outlen;
		struct spu_aac_decode_fmt *outfmt;
		void *p;
		int tmp;

		datalist_sub (&outlendata, &p, &tmp, 1);
		outlen = p;
		datalist_sub (&outfmtdata, &p, &tmp, 1);
		outfmt = p;
		output_remain += *outlen;
		format_next = *outfmt;
		free (outlen);
		free (outfmt);
	}
	endflag = outbuf_end;
	state_decode_end = state.decode_end;
	state_decode_really_end = state.decode_really_end;
	transfer_flag = 1;
	pthread_mutex_unlock (&transfer_lock);

	outcopy = copy_output_buffer (destbuf, destend, &need_output,
				      &_dataout, &_dataoutlen);
	incopy = copy_input_buffer (srcbuf, srcend, &need_input, &inbuf_added,
				    datain, datalen);
	if (_dataoutlen != 0) {
		if (_dataoutlen > datalen)
			_dataoutlen = datalen;
		memcpy (dataout, _dataout, _dataoutlen);
		free (_dataout);
	}
	*format = format_current;

	if (state.open == 0) {
		state_decode = 0;
		state.decode_end = 0;
		state.decode_really_end = 0;
		state_decode_end = 0;
		state_decode_really_end = 0;
		callbk_err = 0;
		inbuf_end = 0;
		pthread_mutex_lock (&transfer_lock);
		outbuf_end = 0;
		pthread_mutex_unlock (&transfer_lock);
		if (inbuf_added == 0)
			goto unlock_ret;
		if ((err = middleware_open ()) < 0)
			goto ret;
		if ((err = RSACPDS_SetDecOpt(paac, 0)) < RSACPDS_RTN_GOOD) {
			ERR ("RSACPDS_SetDecOpt error");
			goto close_and_ret;
		}
		err = RSACPDS_RTN_GOOD;
		state.first_block = 1;
		state.open = 1;
		need_input = 1;
		need_output = 0;
		output_remain = 0;
	} else {
		state_decode = 1;
		if (state_decode_really_end != 0)
			state_decode = 0;
	}
	status = 0;
	if (state_decode_end != 0) {
		if (state.first_block != 0) {
			state.first_block = 0;
			need_output = 1;
		}
		if (output_remain <= 0) {
			state_decode = 0;
			state.decode_end = 0;
			err = RSACPDS_DecodeStatus (paac, &status);
			if (err < RSACPDS_RTN_GOOD) {
				ERR ("RSACPDS_DecodeStatus error");
				goto close_and_ret;
			}
		}
	}
	if (need_input != 0)
		stream_input_end_cb (0);
	if (need_output != 0)
		pcm_output_end_cb (0, 0);
	if (state_decode == 0 && state_decode_really_end == 0) {
		err = get_header_and_pce (status);
		if (err < 0)
			goto close_and_ret;
		nblk = 0;
		if (format_type == SPU_AAC_DECODE_SETFMT_TYPE_RAW_AAC ||
		    format_type == SPU_AAC_DECODE_SETFMT_TYPE_RAW_AACPLUS)
			nblk = 1;
		if (state.first_block != 0)
			nblk = 1;
		if (RSACPDS_Decode (paac, nblk) < RSACPDS_RTN_GOOD) {
			err = RSACPDS_GetStatusCode (paac);
			ERR ("RSACPDS_Decode error");
			goto close_and_ret;
		}
		state_decode = 1;
	}
	if (inbuf_end == 2 && endflag != 0 && outbuf_copying == NULL &&
	    buflist_poll (&outbuf_used) == NULL) {
		if (decode_end_status != RSACPDS_ERR_DATA_EMPTY)
			ERR ("strange statusCode; ignored");
		err = decoder_close (0);
		state.open = 0;
		goto ret;
	}
	if (callbk_err != 0) {
		err = -1;
		goto close_and_ret;
	}
	if ((inbuf_end != 0 || incopy == 0) && outcopy == 0) {
		pthread_mutex_lock (&transfer_done);
		goto once_again;
	}
	goto unlock_ret;
close_and_ret:
	if (state.decode_end != 0 || state.decode_really_end != 0)
		state_decode = 0;
	decoder_close (state_decode);
	state.open = 0;
ret:
	if (inbuf_copying != NULL) {
		buflist_add (&inbuf_free, inbuf_copying);
		inbuf_copying = NULL;
	}
	if (outbuf_current != NULL) {
		buflist_add (&outbuf_free, outbuf_current);
		outbuf_current = NULL;
	}
	do {
		if (inbuf_current != NULL)
			buflist_add (&inbuf_free, inbuf_current);
		inbuf_current = buflist_pop (&inbuf_used);
	} while (inbuf_current != NULL);
	do {
		if (outbuf_copying != NULL)
			buflist_add (&outbuf_free, outbuf_copying);
		outbuf_copying = buflist_pop (&outbuf_used);
	} while (outbuf_copying != NULL);
	while (indata.head != NULL)
		datalist_sub (&indata, NULL, NULL, indata.head->len);
	while (outdata.head != NULL)
		datalist_sub (&outdata, NULL, NULL, outdata.head->len);
	while (delaydata.head != NULL)
		datalist_sub (&delaydata, NULL, NULL, delaydata.head->len);
unlock_ret:
	pthread_mutex_lock (&transfer_lock);
	if (transfer_flag == 0) {
		pthread_mutex_unlock (&transfer_lock);
		pthread_mutex_lock (&transfer_done);
	} else {
		transfer_flag = 0;
		pthread_mutex_unlock (&transfer_lock);
	}
	return err;
}