Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/vorbis/vorbisfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ typedef struct OggVorbis_File {

ov_callbacks callbacks;

/* The read size of the vorbis file */
int read_size;

} OggVorbis_File;


Expand Down Expand Up @@ -185,6 +188,8 @@ extern double ov_time_tell(OggVorbis_File *vf);

extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
extern void ov_set_read_size(OggVorbis_File *vf,int read_size);
extern int ov_get_read_size(OggVorbis_File *vf);

extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
int *bitstream);
Expand Down
15 changes: 13 additions & 2 deletions lib/vorbisfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ static long _get_data(OggVorbis_File *vf){
errno=0;
if(!(vf->callbacks.read_func))return(-1);
if(vf->datasource){
char *buffer=ogg_sync_buffer(&vf->oy,READSIZE);
long bytes=(vf->callbacks.read_func)(buffer,1,READSIZE,vf->datasource);
char *buffer=ogg_sync_buffer(&vf->oy,vf->read_size);
long bytes=(vf->callbacks.read_func)(buffer,1,vf->read_size,vf->datasource);
if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
if(bytes==0 && errno)return(-1);
return(bytes);
Expand Down Expand Up @@ -884,6 +884,7 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial,
memset(vf,0,sizeof(*vf));
vf->datasource=f;
vf->callbacks = callbacks;
vf->read_size = READSIZE;

/* init the framing state */
ogg_sync_init(&vf->oy);
Expand Down Expand Up @@ -1911,6 +1912,16 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
}
}

void ov_set_read_size(OggVorbis_File *vf,int read_size) {
read_size = read_size > CHUNKSIZE ? CHUNKSIZE : read_size;
read_size = read_size < 1 ? 1 : read_size;
vf->read_size = read_size;
}

int ov_get_read_size(OggVorbis_File *vf) {
return vf->read_size;
}

static int host_is_big_endian() {
ogg_int32_t pattern = 0xfeedface; /* deadbeef */
unsigned char *bytewise = (unsigned char *)&pattern;
Expand Down