mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
snd_mp3.c, snd_vorbis.c, snd_wave.c: Make _sure_ that the number
of channels in the music file is supported, i.e. either stereo or mono. Minor tidy up of the error return paths. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@661 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
c66cadc05a
commit
6651858aff
4 changed files with 43 additions and 20 deletions
|
@ -499,6 +499,7 @@ static void S_MP3_CodecShutdown (void)
|
||||||
static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
|
static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
|
||||||
{
|
{
|
||||||
snd_stream_t *stream;
|
snd_stream_t *stream;
|
||||||
|
int err;
|
||||||
|
|
||||||
stream = S_CodecUtilOpen(filename, &mp3_codec);
|
stream = S_CodecUtilOpen(filename, &mp3_codec);
|
||||||
if (!stream)
|
if (!stream)
|
||||||
|
@ -516,10 +517,21 @@ static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mp3_startread(stream) == 0)
|
err = mp3_startread(stream);
|
||||||
return stream;
|
if (err != 0)
|
||||||
|
{
|
||||||
Con_Printf("%s is not a valid mp3 file\n", filename);
|
Con_Printf("%s is not a valid mp3 file\n", filename);
|
||||||
|
}
|
||||||
|
else if (stream->info.channels != 1 && stream->info.channels != 2)
|
||||||
|
{
|
||||||
|
Con_Printf("Unsupported number of channels %d in %s\n",
|
||||||
|
stream->info.channels, filename);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0 /*defined(CODECS_USE_ZONE)*/
|
#if 0 /*defined(CODECS_USE_ZONE)*/
|
||||||
Z_Free(stream->priv);
|
Z_Free(stream->priv);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -132,7 +132,7 @@ static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
|
||||||
stream->info.channels = 2;
|
stream->info.channels = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Con_Printf("Unsupported channel count in %s\n", filename);
|
Con_Printf("Unsupported number of channels %d in %s\n", channels, filename);
|
||||||
goto _fail;
|
goto _fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,12 +85,11 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
|
||||||
|
|
||||||
ovFile = (OggVorbis_File *) Z_Malloc(sizeof(OggVorbis_File));
|
ovFile = (OggVorbis_File *) Z_Malloc(sizeof(OggVorbis_File));
|
||||||
res = ov_open_callbacks(&stream->fh, ovFile, NULL, 0, ovc_qfs);
|
res = ov_open_callbacks(&stream->fh, ovFile, NULL, 0, ovc_qfs);
|
||||||
if (res < 0)
|
if (res != 0)
|
||||||
{
|
{
|
||||||
Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n", filename, res);
|
Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n",
|
||||||
Z_Free(ovFile);
|
filename, res);
|
||||||
S_CodecUtilClose(&stream);
|
goto _fail;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->priv = ovFile;
|
stream->priv = ovFile;
|
||||||
|
@ -98,20 +97,21 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
|
||||||
if (!ov_seekable(ovFile))
|
if (!ov_seekable(ovFile))
|
||||||
{
|
{
|
||||||
Con_Printf("OGG_Open: stream %s not seekable.\n", filename);
|
Con_Printf("OGG_Open: stream %s not seekable.\n", filename);
|
||||||
ov_clear(ovFile);
|
goto _fail;
|
||||||
Z_Free(ovFile);
|
|
||||||
S_CodecUtilClose(&stream);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ogg_info = ov_info(ovFile, 0);
|
ogg_info = ov_info(ovFile, 0);
|
||||||
if (!ogg_info)
|
if (!ogg_info)
|
||||||
{
|
{
|
||||||
Con_Printf("Unable to get stream information for %s.\n", filename);
|
Con_Printf("Unable to get stream information for %s.\n", filename);
|
||||||
ov_clear(ovFile);
|
goto _fail;
|
||||||
Z_Free(ovFile);
|
}
|
||||||
S_CodecUtilClose(&stream);
|
|
||||||
return NULL;
|
if (ogg_info->channels != 1 && ogg_info->channels != 2)
|
||||||
|
{
|
||||||
|
Con_Printf("Unsupported number of channels %d in %s\n",
|
||||||
|
ogg_info->channels, filename);
|
||||||
|
goto _fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->info.rate = ogg_info->rate;
|
stream->info.rate = ogg_info->rate;
|
||||||
|
@ -119,6 +119,12 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
|
||||||
stream->info.width = OGG_SAMPLEWIDTH;
|
stream->info.width = OGG_SAMPLEWIDTH;
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
_fail:
|
||||||
|
if (res == 0)
|
||||||
|
ov_clear(ovFile);
|
||||||
|
Z_Free(ovFile);
|
||||||
|
S_CodecUtilClose(&stream);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer)
|
static int S_OGG_CodecReadStream (snd_stream_t *stream, int bytes, void *buffer)
|
||||||
|
|
|
@ -203,20 +203,25 @@ snd_stream_t *S_WAV_CodecOpenStream(const char *filename)
|
||||||
* for the FS_*() functions: We will manipulate the
|
* for the FS_*() functions: We will manipulate the
|
||||||
* file by ourselves from now on. */
|
* file by ourselves from now on. */
|
||||||
if (!WAV_ReadRIFFHeader(filename, stream->fh.file, &stream->info))
|
if (!WAV_ReadRIFFHeader(filename, stream->fh.file, &stream->info))
|
||||||
|
goto _fail;
|
||||||
|
if (stream->info.channels != 1 && stream->info.channels != 2)
|
||||||
{
|
{
|
||||||
S_CodecUtilClose(&stream);
|
Con_Printf("Unsupported number of channels %d in %s\n",
|
||||||
return NULL;
|
stream->info.channels, filename);
|
||||||
|
goto _fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream->fh.start = ftell(stream->fh.file); /* reset to data position */
|
stream->fh.start = ftell(stream->fh.file); /* reset to data position */
|
||||||
if (stream->fh.start - start + stream->info.size > stream->fh.length)
|
if (stream->fh.start - start + stream->info.size > stream->fh.length)
|
||||||
{
|
{
|
||||||
Con_Printf("%s data size mismatch\n", filename);
|
Con_Printf("%s data size mismatch\n", filename);
|
||||||
S_CodecUtilClose(&stream);
|
goto _fail;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
_fail:
|
||||||
|
S_CodecUtilClose(&stream);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue