Skip to content

Commit

Permalink
No longer grabs non-MP3 streams. Added init() and quit() methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Sep 22, 2001
1 parent 3d43a2a commit 7396bee
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions decoders/mp3.c
Expand Up @@ -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);
Expand All @@ -59,11 +61,26 @@ const Sound_DecoderFunctions __Sound_DecoderFunctions_MP3 =
"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;
Expand All @@ -86,9 +103,26 @@ static int MP3_open(Sound_Sample *sample, const char *ext)
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)
{
Expand Down

0 comments on commit 7396bee

Please sign in to comment.