Mercurial > SDL_sound_CoreAudio
comparison decoders/mpglib/interface.c @ 273:e1429f96aded
Replaced exit() calls with proper error reporting.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 10 Mar 2002 19:04:46 +0000 |
parents | 9b6e82f7c853 |
children | 9e7f9e09ea0e |
comparison
equal
deleted
inserted
replaced
272:0ac181b5adc6 | 273:e1429f96aded |
---|---|
1 | 1 |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <stdio.h> | 3 #include <stdio.h> |
4 | |
5 #include "SDL_sound.h" | |
6 | |
7 #define __SDL_SOUND_INTERNAL__ | |
8 #include "SDL_sound_internal.h" | |
4 | 9 |
5 #include "mpg123_sdlsound.h" | 10 #include "mpg123_sdlsound.h" |
6 #include "mpglib_sdlsound.h" | 11 #include "mpglib_sdlsound.h" |
7 | 12 |
8 /* Global mp .. it's a hack */ | 13 /* Global mp .. it's a hack */ |
93 free(buf->pnt); | 98 free(buf->pnt); |
94 free(buf); | 99 free(buf); |
95 | 100 |
96 } | 101 } |
97 | 102 |
98 static int read_buf_byte(struct mpstr *mp) | 103 static int read_buf_byte(struct mpstr *mp, unsigned long *retval) |
99 { | 104 { |
100 unsigned int b; | |
101 | |
102 int pos; | 105 int pos; |
103 | 106 |
104 pos = mp->tail->pos; | 107 pos = mp->tail->pos; |
105 while(pos >= mp->tail->size) { | 108 while(pos >= mp->tail->size) { |
106 remove_buf(mp); | 109 remove_buf(mp); |
107 pos = mp->tail->pos; | 110 pos = mp->tail->pos; |
108 if(!mp->tail) { | 111 if(!mp->tail) { |
109 fprintf(stderr,"Fatal error!\n"); | 112 Sound_SetError("MPGLIB: Fatal error! Short read in read_buf_byte()!"); |
110 exit(1); | 113 return 0; |
111 } | 114 } |
112 } | 115 } |
113 | 116 |
114 b = mp->tail->pnt[pos]; | 117 if (retval != NULL) |
118 *retval = mp->tail->pnt[pos]; | |
119 | |
115 mp->bsize--; | 120 mp->bsize--; |
116 mp->tail->pos++; | 121 mp->tail->pos++; |
117 | 122 |
118 | 123 return 1; |
119 return b; | 124 } |
120 } | 125 |
121 | 126 static int read_head(struct mpstr *mp) |
122 static void read_head(struct mpstr *mp) | 127 { |
123 { | 128 unsigned long val; |
124 unsigned long head; | 129 unsigned long head; |
125 | 130 |
126 head = read_buf_byte(mp); | 131 if (!read_buf_byte(mp, &val)) |
132 return 0; | |
133 | |
134 head = val << 8; | |
135 | |
136 if (!read_buf_byte(mp, &val)) | |
137 return 0; | |
138 | |
139 head |= val; | |
127 head <<= 8; | 140 head <<= 8; |
128 head |= read_buf_byte(mp); | 141 |
142 if (!read_buf_byte(mp, &val)) | |
143 return 0; | |
144 | |
145 head |= val; | |
129 head <<= 8; | 146 head <<= 8; |
130 head |= read_buf_byte(mp); | 147 |
131 head <<= 8; | 148 if (!read_buf_byte(mp, &val)) |
132 head |= read_buf_byte(mp); | 149 return 0; |
133 | 150 |
151 head |= val; | |
134 mp->header = head; | 152 mp->header = head; |
153 return 1; | |
135 } | 154 } |
136 | 155 |
137 int decodeMP3(struct mpstr *mp,char *in,int isize,char *out, | 156 int decodeMP3(struct mpstr *mp,char *in,int isize,char *out, |
138 int osize,int *done) | 157 int osize,int *done) |
139 { | 158 { |
155 /* First decode header */ | 174 /* First decode header */ |
156 if(mp->framesize == 0) { | 175 if(mp->framesize == 0) { |
157 if(mp->bsize < 4) { | 176 if(mp->bsize < 4) { |
158 return MP3_NEED_MORE; | 177 return MP3_NEED_MORE; |
159 } | 178 } |
160 read_head(mp); | 179 |
161 decode_header(&mp->fr,mp->header); | 180 if (!read_head(mp)) |
181 return MP3_ERR; | |
182 | |
183 if (!decode_header(&mp->fr,mp->header)) | |
184 return MP3_ERR; | |
185 | |
162 mp->framesize = mp->fr.framesize; | 186 mp->framesize = mp->fr.framesize; |
163 } | 187 } |
164 | 188 |
165 if(mp->fr.framesize > mp->bsize) | 189 if(mp->fr.framesize > mp->bsize) |
166 return MP3_NEED_MORE; | 190 return MP3_NEED_MORE; |