Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opus read size to be set by user #9

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 12 additions & 0 deletions include/opusfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,18 @@ OP_WARN_UNUSED_RESULT int op_read_stereo(OggOpusFile *_of,
OP_WARN_UNUSED_RESULT int op_read_float_stereo(OggOpusFile *_of,
float *_pcm,int _buf_size) OP_ARG_NONNULL(1);

/**Sets the read size for the \c OggOpusFile.
\param _of The \c OggOpusFile on which to set the read size.
\param _read_size The number of bytes that should be consumed each time the
\c OggOpusFile reads from its data source.*/
void op_set_read_size(OggOpusFile *_of, int _read_size);

/**Gets the current read size for the \c OggOpusFile.
\param _of The \c OggOpusFile on which to set the read size.
\return The number of bytes consumed each time the \c OggOpusFile
reads from its data source.*/
int op_get_read_size(OggOpusFile *_of);

/*@}*/
/*@}*/

Expand Down
2 changes: 2 additions & 0 deletions src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ struct OggOpusFile{
occurs (switching between the float/short APIs, or between the
stereo/multistream APIs).*/
int state_channel_count;
/*The read size for the opus file in bytes*/
int read_size;
#endif
};

Expand Down
15 changes: 13 additions & 2 deletions src/opusfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ static opus_int64 op_get_next_page(OggOpusFile *_of,ogg_page *_og,
int ret;
/*Send more paramedics.*/
if(!_boundary)return OP_FALSE;
if(_boundary<0)read_nbytes=OP_READ_SIZE;
if(_boundary<0)read_nbytes=_of->read_size;
else{
opus_int64 position;
position=op_position(_of);
if(position>=_boundary)return OP_FALSE;
read_nbytes=(int)OP_MIN(_boundary-position,OP_READ_SIZE);
read_nbytes=(int)OP_MIN(_boundary-position,_of->read_size);
}
ret=op_get_data(_of,read_nbytes);
if(OP_UNLIKELY(ret<0))return OP_EREAD;
Expand Down Expand Up @@ -1513,6 +1513,7 @@ static int op_open1(OggOpusFile *_of,
_of->end=-1;
_of->stream=_stream;
*&_of->callbacks=*_cb;
_of->read_size = OP_READ_SIZE;
/*At a minimum, we need to be able to read data.*/
if(OP_UNLIKELY(_of->callbacks.read==NULL))return OP_EREAD;
/*Initialize the framing state.*/
Expand Down Expand Up @@ -3323,4 +3324,14 @@ int op_read_float_stereo(OggOpusFile *_of,float *_pcm,int _buf_size){
return op_filter_read_native(_of,_pcm,_buf_size,op_stereo_filter,NULL);
}

void op_set_read_size(OggOpusFile *_of, int _read_size) {
_read_size = _read_size > OP_CHUNK_SIZE_MAX ? OP_CHUNK_SIZE_MAX : _read_size;
_read_size = _read_size < 1 ? OP_READ_SIZE : _read_size;
_of->read_size = _read_size;
}

int op_get_read_size(OggOpusFile *_of) {
return _of->read_size;
}

#endif