Skip to content

Commit b72cec1

Browse files
committed
Allow Vorbis Read Size to be set by user
* Hooking up Vorbis read callbacks to an HTTP data provider currently yields a lot of overhead due to many read requests at 2kB * Allowing the user to set the vorbis read size lets backend reads become more efficient by reading greater chunks at any given time
1 parent 143caf4 commit b72cec1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/vorbis/vorbisfile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ typedef struct OggVorbis_File {
143143

144144
ov_callbacks callbacks;
145145

146+
/* The read size of the vorbis file */
147+
int read_size;
148+
146149
} OggVorbis_File;
147150

148151

@@ -185,6 +188,7 @@ extern double ov_time_tell(OggVorbis_File *vf);
185188

186189
extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
187190
extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
191+
extern void ov_set_read_size(OggVorbis_File *vf,int read_size);
188192

189193
extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
190194
int *bitstream);

lib/vorbisfile.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static long _get_data(OggVorbis_File *vf){
6868
errno=0;
6969
if(!(vf->callbacks.read_func))return(-1);
7070
if(vf->datasource){
71-
char *buffer=ogg_sync_buffer(&vf->oy,READSIZE);
72-
long bytes=(vf->callbacks.read_func)(buffer,1,READSIZE,vf->datasource);
71+
char *buffer=ogg_sync_buffer(&vf->oy,vf->read_size);
72+
long bytes=(vf->callbacks.read_func)(buffer,1,vf->read_size,vf->datasource);
7373
if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
7474
if(bytes==0 && errno)return(-1);
7575
return(bytes);
@@ -884,6 +884,7 @@ static int _ov_open1(void *f,OggVorbis_File *vf,const char *initial,
884884
memset(vf,0,sizeof(*vf));
885885
vf->datasource=f;
886886
vf->callbacks = callbacks;
887+
vf->read_size = READSIZE;
887888

888889
/* init the framing state */
889890
ogg_sync_init(&vf->oy);
@@ -1911,6 +1912,10 @@ vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
19111912
}
19121913
}
19131914

1915+
void ov_set_read_size(OggVorbis_File *vf,int read_size) {
1916+
vf->read_size = read_size;
1917+
}
1918+
19141919
static int host_is_big_endian() {
19151920
ogg_int32_t pattern = 0xfeedface; /* deadbeef */
19161921
unsigned char *bytewise = (unsigned char *)&pattern;

0 commit comments

Comments
 (0)