engine: soundlib: added proper errors reporting to Ogg Vorbis sound routines
This commit is contained in:
parent
960a3a1483
commit
7c23b6473c
1 changed files with 51 additions and 8 deletions
|
@ -66,6 +66,41 @@ static const ov_callbacks ov_callbacks_fs = {
|
||||||
|
|
||||||
=================================================================
|
=================================================================
|
||||||
*/
|
*/
|
||||||
|
static const char* Vorbis_GetErrorDesc( int errorCode )
|
||||||
|
{
|
||||||
|
switch( errorCode )
|
||||||
|
{
|
||||||
|
case OV_EOF:
|
||||||
|
return "end of file";
|
||||||
|
case OV_HOLE:
|
||||||
|
return "compressed data sync lost";
|
||||||
|
case OV_EBADHEADER:
|
||||||
|
return "invalid header";
|
||||||
|
case OV_EINVAL:
|
||||||
|
return "invalid argument";
|
||||||
|
case OV_ENOTVORBIS:
|
||||||
|
return "not a Vorbis data";
|
||||||
|
case OV_EBADLINK:
|
||||||
|
return "link corrupted";
|
||||||
|
case OV_EFAULT:
|
||||||
|
return "internal error";
|
||||||
|
case OV_EIMPL:
|
||||||
|
return "not implemented";
|
||||||
|
case OV_EBADPACKET:
|
||||||
|
return "invalid packet";
|
||||||
|
case OV_EVERSION:
|
||||||
|
return "version mismatch";
|
||||||
|
case OV_ENOSEEK:
|
||||||
|
return "bitstream not seekable";
|
||||||
|
case OV_ENOTAUDIO:
|
||||||
|
return "not an audio data";
|
||||||
|
case OV_EREAD:
|
||||||
|
return "read error";
|
||||||
|
default:
|
||||||
|
return "unknown error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Sound_ScanVorbisComments( OggVorbis_File *vf )
|
static void Sound_ScanVorbisComments( OggVorbis_File *vf )
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
|
@ -96,8 +131,8 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
OggFilestream_Init( &file, name, buffer, filesize );
|
OggFilestream_Init( &file, name, buffer, filesize );
|
||||||
if( ov_open_callbacks( &file, &vorbisFile, NULL, 0, ov_callbacks_membuf ) < 0 ) {
|
if(( ret = ov_open_callbacks( &file, &vorbisFile, NULL, 0, ov_callbacks_membuf )) < 0 ) {
|
||||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): file reading error\n", __func__, file.name );
|
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +156,7 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
|
||||||
while(( ret = ov_read( &vorbisFile, (char*)sound.wav + written, sound.size - written, 0, sound.width, 1, §ion )) != 0 )
|
while(( ret = ov_read( &vorbisFile, (char*)sound.wav + written, sound.size - written, 0, sound.width, 1, §ion )) != 0 )
|
||||||
{
|
{
|
||||||
if( ret < 0 ) {
|
if( ret < 0 ) {
|
||||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): compressed data decoding error\n", __func__, file.name );
|
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, file.name, Vorbis_GetErrorDesc( ret ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
written += ret;
|
written += ret;
|
||||||
|
@ -133,6 +168,7 @@ qboolean Sound_LoadOggVorbis( const char *name, const byte *buffer, fs_offset_t
|
||||||
|
|
||||||
stream_t *Stream_OpenOggVorbis( const char *filename )
|
stream_t *Stream_OpenOggVorbis( const char *filename )
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
stream_t *stream;
|
stream_t *stream;
|
||||||
vorbis_info *info;
|
vorbis_info *info;
|
||||||
vorbis_streaming_ctx_t *ctx;
|
vorbis_streaming_ctx_t *ctx;
|
||||||
|
@ -148,9 +184,9 @@ stream_t *Stream_OpenOggVorbis( const char *filename )
|
||||||
stream->file = ctx->file;
|
stream->file = ctx->file;
|
||||||
stream->pos = 0;
|
stream->pos = 0;
|
||||||
|
|
||||||
if( ov_open_callbacks( ctx, &ctx->vf, NULL, 0, ov_callbacks_fs ) < 0 )
|
if(( ret = ov_open_callbacks( ctx, &ctx->vf, NULL, 0, ov_callbacks_fs )) < 0 )
|
||||||
{
|
{
|
||||||
Con_DPrintf( S_ERROR "%s: failed to load (%s): file openning error\n", __func__, filename );
|
Con_DPrintf( S_ERROR "%s: failed to load (%s): %s\n", __func__, filename, Vorbis_GetErrorDesc( ret ));
|
||||||
FS_Close( ctx->file );
|
FS_Close( ctx->file );
|
||||||
Mem_Free( stream );
|
Mem_Free( stream );
|
||||||
Mem_Free( ctx );
|
Mem_Free( ctx );
|
||||||
|
@ -189,8 +225,13 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
|
||||||
|
|
||||||
if( !stream->buffsize )
|
if( !stream->buffsize )
|
||||||
{
|
{
|
||||||
if(( stream->pos = ov_read( &ctx->vf, (char*)stream->temp, OUTBUF_SIZE, 0, stream->width, 1, §ion )) <= 0 )
|
stream->pos = ov_read( &ctx->vf, (char*)stream->temp, OUTBUF_SIZE, 0, stream->width, 1, §ion );
|
||||||
break; // there was EoF or error
|
if( stream->pos == 0 ) {
|
||||||
|
break; // end of file
|
||||||
|
}
|
||||||
|
else if( stream->pos < 0 ) {
|
||||||
|
Con_DPrintf( S_ERROR "%s: error during read: %s\n", __func__, Vorbis_GetErrorDesc( stream->pos ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check remaining size
|
// check remaining size
|
||||||
|
@ -217,11 +258,13 @@ int Stream_ReadOggVorbis( stream_t *stream, int needBytes, void *buffer )
|
||||||
|
|
||||||
int Stream_SetPosOggVorbis( stream_t *stream, int newpos )
|
int Stream_SetPosOggVorbis( stream_t *stream, int newpos )
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr;
|
vorbis_streaming_ctx_t *ctx = (vorbis_streaming_ctx_t*)stream->ptr;
|
||||||
if( ov_raw_seek_lap( &ctx->vf, newpos ) == 0 ) {
|
if(( ret = ov_raw_seek_lap( &ctx->vf, newpos )) == 0 ) {
|
||||||
stream->buffsize = 0; // flush any previous data
|
stream->buffsize = 0; // flush any previous data
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Con_DPrintf( S_ERROR "%s: error during seek: %s\n", __func__, Vorbis_GetErrorDesc( ret ));
|
||||||
return false; // failed to seek
|
return false; // failed to seek
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue