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:
Ozkan Sezer 2012-04-22 11:02:08 +00:00
parent c66cadc05a
commit 6651858aff
4 changed files with 43 additions and 20 deletions

View File

@ -499,6 +499,7 @@ static void S_MP3_CodecShutdown (void)
static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
{
snd_stream_t *stream;
int err;
stream = S_CodecUtilOpen(filename, &mp3_codec);
if (!stream)
@ -516,10 +517,21 @@ static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
}
#endif
if (mp3_startread(stream) == 0)
err = mp3_startread(stream);
if (err != 0)
{
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;
}
Con_Printf("%s is not a valid mp3 file\n", filename);
#if 0 /*defined(CODECS_USE_ZONE)*/
Z_Free(stream->priv);
#else

View File

@ -132,7 +132,7 @@ static snd_stream_t *S_MP3_CodecOpenStream (const char *filename)
stream->info.channels = 2;
break;
default:
Con_Printf("Unsupported channel count in %s\n", filename);
Con_Printf("Unsupported number of channels %d in %s\n", channels, filename);
goto _fail;
}

View File

@ -85,12 +85,11 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
ovFile = (OggVorbis_File *) Z_Malloc(sizeof(OggVorbis_File));
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);
Z_Free(ovFile);
S_CodecUtilClose(&stream);
return NULL;
Con_Printf("%s is not a valid Ogg Vorbis file (error %i).\n",
filename, res);
goto _fail;
}
stream->priv = ovFile;
@ -98,20 +97,21 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
if (!ov_seekable(ovFile))
{
Con_Printf("OGG_Open: stream %s not seekable.\n", filename);
ov_clear(ovFile);
Z_Free(ovFile);
S_CodecUtilClose(&stream);
return NULL;
goto _fail;
}
ogg_info = ov_info(ovFile, 0);
if (!ogg_info)
{
Con_Printf("Unable to get stream information for %s.\n", filename);
ov_clear(ovFile);
Z_Free(ovFile);
S_CodecUtilClose(&stream);
return NULL;
goto _fail;
}
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;
@ -119,6 +119,12 @@ static snd_stream_t *S_OGG_CodecOpenStream (const char *filename)
stream->info.width = OGG_SAMPLEWIDTH;
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)

View File

@ -203,20 +203,25 @@ snd_stream_t *S_WAV_CodecOpenStream(const char *filename)
* for the FS_*() functions: We will manipulate the
* file by ourselves from now on. */
if (!WAV_ReadRIFFHeader(filename, stream->fh.file, &stream->info))
goto _fail;
if (stream->info.channels != 1 && stream->info.channels != 2)
{
S_CodecUtilClose(&stream);
return NULL;
Con_Printf("Unsupported number of channels %d in %s\n",
stream->info.channels, filename);
goto _fail;
}
stream->fh.start = ftell(stream->fh.file); /* reset to data position */
if (stream->fh.start - start + stream->info.size > stream->fh.length)
{
Con_Printf("%s data size mismatch\n", filename);
S_CodecUtilClose(&stream);
return NULL;
goto _fail;
}
return stream;
_fail:
S_CodecUtilClose(&stream);
return NULL;
}
/*