diff options
-rw-r--r-- | apps/lang/english.lang | 10 | ||||
-rw-r--r-- | apps/onplay.c | 102 |
2 files changed, 58 insertions, 54 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 8257435503..4b1320793a 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -1447,3 +1447,13 @@ id: LANG_SETTINGS_SAVED2 | |||
1447 | desc: Feedback shown when a .cfg file is saved | 1447 | desc: Feedback shown when a .cfg file is saved |
1448 | eng: "Saved" | 1448 | eng: "Saved" |
1449 | new: | 1449 | new: |
1450 | |||
1451 | id: LANG_VBRFIX_STOP_PLAY | ||
1452 | desc: Tells the user to stop the playback | ||
1453 | eng: "Stop the playback first" | ||
1454 | new: | ||
1455 | |||
1456 | id: LANG_VBRFIX_NOT_VBR | ||
1457 | desc: Tells the user that the selected file is not a VBR file | ||
1458 | eng: "Not a VBR file" | ||
1459 | new: | ||
diff --git a/apps/onplay.c b/apps/onplay.c index 90f6db78b0..54aefb8e92 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -127,32 +127,27 @@ static int insert_space_in_file(char *fname, int fpos, int num_bytes) | |||
127 | snprintf(tmpname, MAX_PATH, "%s.tmp", fname); | 127 | snprintf(tmpname, MAX_PATH, "%s.tmp", fname); |
128 | 128 | ||
129 | orig_fd = open(fname, O_RDONLY); | 129 | orig_fd = open(fname, O_RDONLY); |
130 | if(orig_fd < 0) | 130 | if(orig_fd < 0) { |
131 | { | ||
132 | return 10*orig_fd - 1; | 131 | return 10*orig_fd - 1; |
133 | } | 132 | } |
134 | 133 | ||
135 | fd = creat(tmpname, O_WRONLY); | 134 | fd = creat(tmpname, O_WRONLY); |
136 | if(fd < 0) | 135 | if(fd < 0) { |
137 | { | ||
138 | close(orig_fd); | 136 | close(orig_fd); |
139 | return 10*fd - 2; | 137 | return 10*fd - 2; |
140 | } | 138 | } |
141 | 139 | ||
142 | /* First, copy the initial portion (the ID3 tag) */ | 140 | /* First, copy the initial portion (the ID3 tag) */ |
143 | if(fpos) | 141 | if(fpos) { |
144 | { | ||
145 | readlen = read(orig_fd, mp3buf, fpos); | 142 | readlen = read(orig_fd, mp3buf, fpos); |
146 | if(readlen < 0) | 143 | if(readlen < 0) { |
147 | { | ||
148 | close(fd); | 144 | close(fd); |
149 | close(orig_fd); | 145 | close(orig_fd); |
150 | return 10*readlen - 3; | 146 | return 10*readlen - 3; |
151 | } | 147 | } |
152 | 148 | ||
153 | rc = write(fd, mp3buf, readlen); | 149 | rc = write(fd, mp3buf, readlen); |
154 | if(rc < 0) | 150 | if(rc < 0) { |
155 | { | ||
156 | close(fd); | 151 | close(fd); |
157 | close(orig_fd); | 152 | close(orig_fd); |
158 | return 10*rc - 4; | 153 | return 10*rc - 4; |
@@ -163,35 +158,30 @@ static int insert_space_in_file(char *fname, int fpos, int num_bytes) | |||
163 | memset(mp3buf, 0, num_bytes); | 158 | memset(mp3buf, 0, num_bytes); |
164 | 159 | ||
165 | rc = write(fd, mp3buf, num_bytes); | 160 | rc = write(fd, mp3buf, num_bytes); |
166 | if(rc < 0) | 161 | if(rc < 0) { |
167 | { | ||
168 | close(orig_fd); | 162 | close(orig_fd); |
169 | close(fd); | 163 | close(fd); |
170 | return 10*rc - 5; | 164 | return 10*rc - 5; |
171 | } | 165 | } |
172 | 166 | ||
173 | rc = lseek(orig_fd, 0, SEEK_SET); | 167 | rc = lseek(orig_fd, 0, SEEK_SET); |
174 | if(rc < 0) | 168 | if(rc < 0) { |
175 | { | ||
176 | close(orig_fd); | 169 | close(orig_fd); |
177 | close(fd); | 170 | close(fd); |
178 | return 10*rc - 6; | 171 | return 10*rc - 6; |
179 | } | 172 | } |
180 | 173 | ||
181 | /* Copy the file */ | 174 | /* Copy the file */ |
182 | do | 175 | do { |
183 | { | ||
184 | readlen = read(orig_fd, mp3buf, mp3end - mp3buf); | 176 | readlen = read(orig_fd, mp3buf, mp3end - mp3buf); |
185 | if(readlen < 0) | 177 | if(readlen < 0) { |
186 | { | ||
187 | close(fd); | 178 | close(fd); |
188 | close(orig_fd); | 179 | close(orig_fd); |
189 | return 10*readlen - 7; | 180 | return 10*readlen - 7; |
190 | } | 181 | } |
191 | 182 | ||
192 | rc = write(fd, mp3buf, readlen); | 183 | rc = write(fd, mp3buf, readlen); |
193 | if(rc < 0) | 184 | if(rc < 0) { |
194 | { | ||
195 | close(fd); | 185 | close(fd); |
196 | close(orig_fd); | 186 | close(orig_fd); |
197 | return 10*rc - 8; | 187 | return 10*rc - 8; |
@@ -203,21 +193,24 @@ static int insert_space_in_file(char *fname, int fpos, int num_bytes) | |||
203 | 193 | ||
204 | /* Remove the old file */ | 194 | /* Remove the old file */ |
205 | rc = remove(fname); | 195 | rc = remove(fname); |
206 | if(rc < 0) | 196 | if(rc < 0) { |
207 | { | ||
208 | return 10*rc - 9; | 197 | return 10*rc - 9; |
209 | } | 198 | } |
210 | 199 | ||
211 | /* Replace the old file with the new */ | 200 | /* Replace the old file with the new */ |
212 | rc = rename(tmpname, fname); | 201 | rc = rename(tmpname, fname); |
213 | if(rc < 0) | 202 | if(rc < 0) { |
214 | { | ||
215 | return 10*rc - 9; | 203 | return 10*rc - 9; |
216 | } | 204 | } |
217 | 205 | ||
218 | return 0; | 206 | return 0; |
219 | } | 207 | } |
220 | 208 | ||
209 | static void fileerror(int rc) | ||
210 | { | ||
211 | splash(HZ*2, 0, true, "File error: %d", rc); | ||
212 | } | ||
213 | |||
221 | static bool vbr_fix(void) | 214 | static bool vbr_fix(void) |
222 | { | 215 | { |
223 | unsigned char xingbuf[417]; | 216 | unsigned char xingbuf[417]; |
@@ -229,9 +222,8 @@ static bool vbr_fix(void) | |||
229 | int fpos; | 222 | int fpos; |
230 | int numbytes; | 223 | int numbytes; |
231 | 224 | ||
232 | if(mpeg_status()) | 225 | if(mpeg_status()) { |
233 | { | 226 | splash(HZ*2, 0, true, str(LANG_VBRFIX_STOP_PLAY)); |
234 | splash(HZ*2, 0, true, "Stop the playback"); | ||
235 | return reload_dir; | 227 | return reload_dir; |
236 | } | 228 | } |
237 | 229 | ||
@@ -242,16 +234,14 @@ static bool vbr_fix(void) | |||
242 | xingupdate(0); | 234 | xingupdate(0); |
243 | 235 | ||
244 | rc = mp3info(&entry, selected_file); | 236 | rc = mp3info(&entry, selected_file); |
245 | if(rc < 0) | 237 | if(rc < 0) { |
246 | { | 238 | fileerror(rc); |
247 | splash(HZ*2, 0, true, "File error: %d", rc); | ||
248 | return true; | 239 | return true; |
249 | } | 240 | } |
250 | 241 | ||
251 | fd = open(selected_file, O_RDWR); | 242 | fd = open(selected_file, O_RDWR); |
252 | if(fd < 0) | 243 | if(fd < 0) { |
253 | { | 244 | fileerror(fd); |
254 | splash(HZ*2, 0, true, "File error: %d", fd); | ||
255 | return true; | 245 | return true; |
256 | } | 246 | } |
257 | 247 | ||
@@ -262,30 +252,23 @@ static bool vbr_fix(void) | |||
262 | num_frames = count_mp3_frames(fd, entry.first_frame_offset, | 252 | num_frames = count_mp3_frames(fd, entry.first_frame_offset, |
263 | flen, xingupdate); | 253 | flen, xingupdate); |
264 | 254 | ||
265 | if(num_frames) | 255 | if(num_frames) { |
266 | { | ||
267 | create_xing_header(fd, entry.first_frame_offset, | 256 | create_xing_header(fd, entry.first_frame_offset, |
268 | flen, xingbuf, num_frames, xingupdate, true); | 257 | flen, xingbuf, num_frames, xingupdate, true); |
269 | 258 | ||
270 | /* Try to fit the Xing header first in the stream. Replace the existing | 259 | /* Try to fit the Xing header first in the stream. Replace the existing |
271 | Xing header if there is one, else see if there is room between the | 260 | Xing header if there is one, else see if there is room between the |
272 | ID3 tag and the first MP3 frame. */ | 261 | ID3 tag and the first MP3 frame. */ |
273 | if(entry.vbr_header_pos) | 262 | if(entry.vbr_header_pos) { |
274 | { | ||
275 | /* Reuse existing Xing header */ | 263 | /* Reuse existing Xing header */ |
276 | fpos = entry.vbr_header_pos; | 264 | fpos = entry.vbr_header_pos; |
277 | 265 | ||
278 | DEBUGF("Reusing Xing header at %d\n", fpos); | 266 | DEBUGF("Reusing Xing header at %d\n", fpos); |
279 | } | 267 | } else { |
280 | else | ||
281 | { | ||
282 | /* Any room between ID3 tag and first MP3 frame? */ | 268 | /* Any room between ID3 tag and first MP3 frame? */ |
283 | if(entry.first_frame_offset - entry.id3v2len > 417) | 269 | if(entry.first_frame_offset - entry.id3v2len > 417) { |
284 | { | ||
285 | fpos = entry.first_frame_offset - 417; | 270 | fpos = entry.first_frame_offset - 417; |
286 | } | 271 | } else { |
287 | else | ||
288 | { | ||
289 | /* If not, insert some space. If there is an ID3 tag in the | 272 | /* If not, insert some space. If there is an ID3 tag in the |
290 | file we only insert just enough to squeeze the Xing header | 273 | file we only insert just enough to squeeze the Xing header |
291 | in. If not, we insert 4K. */ | 274 | in. If not, we insert 4K. */ |
@@ -298,16 +281,14 @@ static bool vbr_fix(void) | |||
298 | rc = insert_space_in_file(selected_file, | 281 | rc = insert_space_in_file(selected_file, |
299 | entry.first_frame_offset, numbytes); | 282 | entry.first_frame_offset, numbytes); |
300 | 283 | ||
301 | if(rc < 0) | 284 | if(rc < 0) { |
302 | { | 285 | fileerror(rc); |
303 | splash(HZ*2, 0, true, "File error: %d", rc); | ||
304 | return true; | 286 | return true; |
305 | } | 287 | } |
306 | 288 | ||
307 | /* Reopen the file */ | 289 | /* Reopen the file */ |
308 | fd = open(selected_file, O_RDWR); | 290 | fd = open(selected_file, O_RDWR); |
309 | if(fd < 0) | 291 | if(fd < 0) { |
310 | { | ||
311 | splash(HZ*2, 0, true, "File reopen error: %d", fd); | 292 | splash(HZ*2, 0, true, "File reopen error: %d", fd); |
312 | return true; | 293 | return true; |
313 | } | 294 | } |
@@ -316,8 +297,20 @@ static bool vbr_fix(void) | |||
316 | } | 297 | } |
317 | } | 298 | } |
318 | 299 | ||
319 | lseek(fd, fpos, SEEK_SET); | 300 | rc = lseek(fd, fpos, SEEK_SET); |
320 | write(fd, xingbuf, 417); | 301 | if(rc < 0) { |
302 | close(fd); | ||
303 | fileerror(rc); | ||
304 | return true; | ||
305 | } | ||
306 | |||
307 | rc = write(fd, xingbuf, 417); | ||
308 | if(rc < 0) { | ||
309 | close(fd); | ||
310 | fileerror(rc); | ||
311 | return true; | ||
312 | } | ||
313 | |||
321 | close(fd); | 314 | close(fd); |
322 | 315 | ||
323 | xingupdate(100); | 316 | xingupdate(100); |
@@ -326,11 +319,12 @@ static bool vbr_fix(void) | |||
326 | { | 319 | { |
327 | /* Not a VBR file */ | 320 | /* Not a VBR file */ |
328 | DEBUGF("Not a VBR file\n"); | 321 | DEBUGF("Not a VBR file\n"); |
329 | splash(HZ*2, 0, true, "Not a VBR file"); | 322 | splash(HZ*2, 0, true, str(LANG_VBRFIX_NOT_VBR)); |
330 | } | 323 | } |
331 | 324 | ||
332 | return false; | 325 | return false; |
333 | } | 326 | } |
327 | |||
334 | int onplay(char* file, int attr) | 328 | int onplay(char* file, int attr) |
335 | { | 329 | { |
336 | struct menu_items menu[5]; /* increase this if you add entries! */ | 330 | struct menu_items menu[5]; /* increase this if you add entries! */ |