# HG changeset patch # User Ryan C. Gordon # Date 1001169670 0 # Node ID 6e13fcc178da80040d8d91608a7a5955c10a66cf # Parent f7a792fdf7a49f870ced560fa7dd62bc6420f5f7 No longer grabs non-MP3 streams. Added init() and quit() methods. diff -r f7a792fdf7a4 -r 6e13fcc178da decoders/mp3.c --- a/decoders/mp3.c Sat Sep 22 14:40:15 2001 +0000 +++ b/decoders/mp3.c Sat Sep 22 14:41:10 2001 +0000 @@ -46,6 +46,8 @@ #endif +static int MP3_init(void); +static void MP3_quit(void); static int MP3_open(Sound_Sample *sample, const char *ext); static void MP3_close(Sound_Sample *sample); static Uint32 MP3_read(Sound_Sample *sample); @@ -59,11 +61,26 @@ "http://www.icculus.org/SDL_sound/" }, - MP3_open, /* open() method */ - MP3_close, /* close() method */ - MP3_read /* read() method */ + MP3_init, /* init() method */ + MP3_quit, /* quit() method */ + MP3_open, /* open() method */ + MP3_close, /* close() method */ + MP3_read /* read() method */ }; + +static int MP3_init(void) +{ + return(1); /* always succeeds. */ +} /* MP3_init */ + + +static void MP3_quit(void) +{ + /* it's a no-op. */ +} /* MP3_quit */ + + static __inline__ void output_version(void) { static int first_time = 1; @@ -86,9 +103,26 @@ SDL_AudioSpec spec; Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; SDL_RWops *refCounter; + Uint8 mp3_magic[2]; output_version(); + /* + * SMPEG appears to be far too greedy about what it accepts as input. + * This test was adapted from SDL_mixer. + */ + if (SDL_RWread(internal->rw, mp3_magic, sizeof (mp3_magic), 1) != 1) + { + Sound_SetError("MP3: Could not read MP3 magic."); + return(0); + } + if (mp3_magic[0] != 0xFF || (mp3_magic[1] & 0xF0) != 0xF0) + { + Sound_SetError("MP3: Not an MP3 stream."); + return(0); + } + SDL_RWseek(internal->rw, -sizeof (mp3_magic), SEEK_CUR); + refCounter = RWops_RWRefCounter_new(internal->rw); if (refCounter == NULL) {