Exemple #1
0
int aac_open(auds_t *auds, char *fname)
{
	aac_t *aac=malloc(sizeof(aac_t));
	if(!aac) return -1;
	memset(aac,0,sizeof(aac_t));
	auds->stream=(aac_t*)aac;
	aac->fname=(char *)malloc(strlen(fname)+1);
	if(!aac->fname) goto erexit;
	strcpy(aac->fname,fname);
	aac->buffer=(u_int8_t *)malloc(MAX_SAMPLES_IN_CHUNK*4+16);
	if(!aac->buffer) goto erexit;
	auds->sigchld_cb=sigchld_callback;
	auds->sample_rate=DEFAULT_SAMPLE_RATE;
	read_header(auds, fname);
	if(access(FIFO_NAME,F_OK) && mkfifo(FIFO_NAME,0600)<0){
		ERRMSG("can't make a named fifo:%s\n",FIFO_NAME);
		goto erexit;
	}
	run_decoder(aac);
	auds->chunk_size=aud_clac_chunk_size(auds->sample_rate);
	return 0;
 erexit:
	aac_close(auds);
	return -1;
}
Exemple #2
0
/* Fill info structure with data from aac comments */
static void aac_info (const char *file_name,
		struct file_tags *info,
		const int tags_sel)
{
	if (tags_sel & TAGS_COMMENTS) {
		struct id3_tag *tag;
		struct id3_file *id3file;
		char *track = NULL;

		id3file = id3_file_open (file_name, ID3_FILE_MODE_READONLY);
		if (!id3file)
			return;
		tag = id3_file_tag (id3file);
		if (tag) {
			info->artist = get_tag (tag, ID3_FRAME_ARTIST);
			info->title = get_tag (tag, ID3_FRAME_TITLE);
			info->album = get_tag (tag, ID3_FRAME_ALBUM);
			track = get_tag (tag, ID3_FRAME_TRACK);

			if (track) {
				char *end;

				info->track = strtol (track, &end, 10);
				if (end == track)
					info->track = -1;
				free (track);
			}
		}
		id3_file_close (id3file);
	}

	if (tags_sel & TAGS_TIME) {
		struct aac_data *data;

		data = aac_open_internal (NULL, file_name);

		if (data->ok)
			info->time = aac_count_time (data);
		else
			logit ("%s", decoder_error_text (&data->error));

		aac_close (data);
	}
}
Exemple #3
0
static void *aac_open (const char *file)
{
	struct aac_data *data;

	data = aac_open_internal (NULL, file);

	if (data->ok) {
		int duration = -1;
		int avg_bitrate = -1;
		off_t file_size;

		duration = aac_count_time (data);
		file_size = io_file_size (data->stream);
		if (duration > 0 && file_size != -1)
			avg_bitrate = file_size / duration * 8;
		aac_close (data);
		data = aac_open_internal (NULL, file);
		data->duration = duration;
		data->avg_bitrate = avg_bitrate;
	}

	return data;
}
Exemple #4
0
void* record(void *arg){
	struct argStruct *pArg = (struct argStruct*)arg;
	FILE* fin = fopen(pArg->fin,"rb");
	FILE* fout = fopen(pArg->fout,"wb");
	int ret;
	int cnt;
	char* bufferIn;
	char* bufferOut;
	faacEncHandle handle;
	unsigned long maxOut=1, maxIn=1;
	handle = aac_init(44100,2,16,&bufferIn, &bufferOut, &maxOut, &maxIn);
	printf("record---%ld %ld-----\n", maxOut, maxIn);
	while(1){
		ret = fread(bufferIn,1,maxIn, fin);
		printf("read %d |||||||||\n",ret);
		if(ret <=0)break;
		cnt = aac_encode(handle,ret,16,bufferIn, bufferOut,maxOut);
		fwrite(bufferOut,1,cnt,fout);
	}
	aac_close( bufferIn, bufferOut);
	fclose(fin);
	fclose(fout);
}