Ejemplo n.º 1
0
raopcl_t *raopcl_open()
{
	raopcl_data_t *raopcld;
	int16_t sdata[MINIMUM_SAMPLE_SIZE*2];
	data_source_t ds={.type=MEMORY};
	u_int8_t *bp;

	raopcld=malloc(sizeof(raopcl_data_t));
	RAND_seed(raopcld,sizeof(raopcl_data_t));
	memset(raopcld, 0, sizeof(raopcl_data_t));
	if(!RAND_bytes(raopcld->iv, sizeof(raopcld->iv)) || !RAND_bytes(raopcld->key, sizeof(raopcld->key))){
		ERRMSG("%s:RAND_bytes error code=%ld\n",__func__,ERR_get_error());
		return NULL;
	}
	memcpy(raopcld->nv,raopcld->iv,sizeof(raopcld->nv));
	raopcld->volume=VOLUME_DEF;
        aes_set_key(&raopcld->ctx, raopcld->key, 128);
	// prepare a small silent data to send during pause period.
	ds.u.mem.size=MINIMUM_SAMPLE_SIZE*4;
	ds.u.mem.data=sdata;
	memset(sdata,0,sizeof(sdata));
	auds_write_pcm(NULL, raopcld->min_sdata, &bp, &raopcld->min_sdata_size,
		       MINIMUM_SAMPLE_SIZE, &ds);
	return (raopcl_t *)raopcld;
}
Ejemplo n.º 2
0
int pcm_get_next_sample(auds_t *auds, __u8 **data, int *size)
{
	int rval;
	pcm_t *pcm=(pcm_t *)auds->stream;
	int bsize=auds->chunk_size;
	data_source_t ds={.type=MEMORY};
	__u8 *rbuf=NULL;
	if(!(rbuf=(__u8*)malloc(bsize*4))) return -1;
	memset(rbuf,0,bsize*4);
	/* ds.u.mem.size, ds.u.mem.data */
	ds.u.mem.size=read(pcm->dfd,rbuf,bsize*4);
	if(ds.u.mem.size<0){
		ERRMSG("%s: data read error(%s)\n", __func__, strerror(errno));
		return -1;
	}
	if(ds.u.mem.size<MINIMUM_SAMPLE_SIZE*4){
		//INFMSG("%s: too small chunk of data(size=%d), add null data\n",__func__, ds.u.mem.size);
		ds.u.mem.size=MINIMUM_SAMPLE_SIZE*4;
	}
	ds.u.mem.data=(__s16*)rbuf;
	bsize=ds.u.mem.size/4;
	rval=auds_write_pcm(auds, pcm->buffer, data, size, bsize, &ds);
	free(rbuf);
	return rval;
}
Ejemplo n.º 3
0
int wav_get_next_sample(auds_t *auds, __u8 **data, int *size)
{
	wav_t *wav=(wav_t *)auds->stream;
	int bsize=(wav->subchunk2size - wav->playedbytes>=auds->chunk_size)?
		auds->chunk_size:wav->subchunk2size - wav->playedbytes;
	data_source_t ds={.type=STREAM, .u.inf=wav->inf};
	if(!bsize) return -1;
	wav->playedbytes+=bsize;
	return auds_write_pcm(auds, wav->buffer, data, size, bsize, &ds);
}


static int read_wave_header(wav_t *wav, int *sample_rate, int *channels)
{
	wave_header_t head;
	FILE *infile=wav->inf;
	
	if(fread(&head,1,sizeof(head),infile)<sizeof(head)) return -1;
	if(strncmp(head.charChunkID,"RIFF",4) || strncmp(head.Format,"WAVE",4)){
		ERRMSG("This is not a WAV file\n");
		return -1;
	}
	*channels=head.NumChannels;
	if(head.NumChannels!=2 && head.NumChannels!=1){
		ERRMSG("This is neither stereo nor mono, NumChannels=%d\n",head.NumChannels);
		return -1;
	}
	if(head.BitsPerSample!=16){
		ERRMSG("bits per sample = %d, we need 16 bits data\n", head.BitsPerSample);
		return -1;
	}
	*sample_rate=head.SampleRate;
#if 0	
	if(head.SampleRate!=DEFAULT_SAMPLE_RATE){
		ERRMSG("sample rate = %d, we need %d\n", head.SampleRate,DEFAULT_SAMPLE_RATE);
		return -1;
	}
#endif	
	if(strncmp(head.Subchunk2ID,"data",4)){
		ERRMSG("sub chunk is not \"data\"\n");
		//return -1;
	}
	wav->subchunk2size=head.Subchunk2Size;
	return 0;
}
Ejemplo n.º 4
0
int wav_get_next_sample(auds_t *auds, uint8_t **data, int *size)
{
	wav_t *wav=(wav_t *)auds->stream;
	int bsize=MAX_SAMPLES_IN_CHUNK;
	data_source_t ds={.type=STREAM, .inf=wav->inf, .inf2=wav->inf2 };

	if(!bsize) return -1;
	wav->playedbytes+=bsize;
        int posinbytes;
        if (csync>0.0)
        {
           posinbytes=ftell(wav->inf2);
        }
        else
        {
           posinbytes=ftell(wav->inf);
        }
        if ( posinbytes < 0 )
        {
           ERRMSG( "Couldn't get file position\n" );
        }
        else
        {
           // in secs
           fposition=(posinbytes-sizeof(wave_header_t))/(sizeof(short)*auds->channels*auds->sample_rate);
        }
        long enbbytes = sizeof(short)*auds->channels*auds->sample_rate;
        if ( endinms != -1 )
        {
          enbbytes *= endinms/1000;
          if ( posinbytes >= enbbytes )
          {
             DBGMSG( "marker end position reached\n" );
             return -1;
          }
        }
	return auds_write_pcm(auds, wav->buffer, data, size, bsize, &ds);
}


static int read_wave_header(wav_t *wav, int *sample_rate, int *channels)
{
	wave_header_t head;
	FILE *infile=wav->inf;
	
	if(fread(&head,1,sizeof(head),infile)<sizeof(head)) return -1;
	if(strncmp(head.charChunkID,"RIFF",4) || strncmp(head.Format,"WAVE",4)){
		ERRMSG("This is not a WAV file\n");
		return -1;
	}
	*channels=head.NumChannels;
	if(head.NumChannels!=2 && head.NumChannels!=1){
		ERRMSG("This is neither stereo nor mono, NumChannels=%d\n",head.NumChannels);
		return -1;
	}
	if(head.BitsPerSample!=16){
		ERRMSG("bits per sample = %d, we need 16 bits data\n", head.BitsPerSample);
		return -1;
	}
	*sample_rate=head.SampleRate;
#if 0	
	if(head.SampleRate!=DEFAULT_SAMPLE_RATE){
		ERRMSG("sample rate = %d, we need %d\n", head.SampleRate,DEFAULT_SAMPLE_RATE);
		return -1;
	}
#endif	
	// if(strncmp(head.Subchunk2ID,"data",4)){
	// 	ERRMSG("sub chunk is not \"data\"\n");
	//      return -1;
	// }
	wav->subchunk2size=head.Subchunk2Size;
	return 0;
}
Ejemplo n.º 5
0
int aac_get_next_sample(auds_t *auds, u_int8_t **data, int *size)
{
	aac_t *aac=(aac_t *)auds->stream;
	data_source_t ds={.type=STREAM, .u.inf=aac->inf};
	return auds_write_pcm(auds, aac->buffer, data, size, auds->chunk_size, &ds);
}