Audio-Play-MPG123
view release on metacpan or search on metacpan
mpg123/readers.c view on Meta::CPAN
return TRUE;
}
static int mapped_head_shift(struct reader *rds,unsigned long *head)
{
if(mappnt + 1 > mapend)
return FALSE;
*head <<= 8;
*head |= *mappnt++;
*head &= 0xffffffff;
return TRUE;
}
static int mapped_skip_bytes(struct reader *rds,int len)
{
if(mappnt + len > mapend)
return FALSE;
mappnt += len;
if (param.usebuffer)
buffer_resync();
return TRUE;
}
static int mapped_read_frame_body(struct reader *rds,unsigned char *buf,
int size)
{
if(size <= 0) {
fprintf(stderr,"Ouch. Read_frame called with size <= 0\n");
return FALSE;
}
if(mappnt + size > mapend)
return FALSE;
memcpy(buf,mappnt,size);
mappnt += size;
return TRUE;
}
static int mapped_back_bytes(struct reader *rds,int bytes)
{
if( (mappnt - bytes) < mapbuf || (mappnt - bytes + 4) > mapend)
return -1;
mappnt -= bytes;
if(param.usebuffer)
buffer_resync();
return 0;
}
static int mapped_back_frame(struct reader *rds,struct frame *fr,int num)
{
long bytes;
unsigned long newhead;
if(!firsthead)
return 0;
bytes = (fr->framesize+8)*(num+2);
/* Buffered mode is a bit trickier. From the size of the buffered
* output audio stream we have to make a guess at the number of frames
* this corresponds to.
*/
if(param.usebuffer)
bytes += (long)(xfermem_get_usedspace(buffermem) /
(buffermem->buf[0] * buffermem->buf[1]
* (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
16.0 : 8.0 ))
* (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
/*
bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
*/
if( (mappnt - bytes) < mapbuf || (mappnt - bytes + 4) > mapend)
return -1;
mappnt -= bytes;
newhead = (mappnt[0]<<24) + (mappnt[1]<<16) + (mappnt[2]<<8) + mappnt[3];
mappnt += 4;
while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
if(mappnt + 1 > mapend)
return -1;
newhead <<= 8;
newhead |= *mappnt++;
newhead &= 0xffffffff;
}
mappnt -= 4;
read_frame(fr);
read_frame(fr);
if(fr->lay == 3)
set_pointer(fr->sideInfoSize,512);
if(param.usebuffer)
buffer_resync();
return 0;
}
static long mapped_tell(struct reader *rds)
{
return mappnt - mapbuf;
}
#endif
/*****************************************************************
* read frame helper
*/
struct reader *rd;
struct reader readers[] = {
#ifdef READ_SYSTEM
{ system_init,
NULL, /* filled in by system_init() */
NULL,
NULL,
NULL,
NULL,
( run in 2.152 seconds using v1.01-cache-2.11-cpan-800906f7e73 )