diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2003-04-03 07:20:57 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2003-04-03 07:20:57 +0000 |
commit | 6edea74ea6deab4302fffa476d2b2dd724fa8f05 (patch) | |
tree | e3c0c0981ff670a566f7bbd742698167d5b52bd6 /apps/onplay.c | |
parent | 11edfa8d96a4a84af58663b0aa9cce55ed8d8798 (diff) | |
download | rockbox-6edea74ea6deab4302fffa476d2b2dd724fa8f05.tar.gz rockbox-6edea74ea6deab4302fffa476d2b2dd724fa8f05.zip |
Now VBRFix correctly handles all types of files, with or without ID3 tags
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3514 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/onplay.c')
-rw-r--r-- | apps/onplay.c | 93 |
1 files changed, 61 insertions, 32 deletions
diff --git a/apps/onplay.c b/apps/onplay.c index 74e7136738..90f6db78b0 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -117,16 +117,13 @@ static void xingupdate(int percent) | |||
117 | extern unsigned char mp3buf[]; | 117 | extern unsigned char mp3buf[]; |
118 | extern unsigned char mp3end[]; | 118 | extern unsigned char mp3end[]; |
119 | 119 | ||
120 | static int insert_space_in_file(char *fname, int num_bytes) | 120 | static int insert_space_in_file(char *fname, int fpos, int num_bytes) |
121 | { | 121 | { |
122 | int readlen; | 122 | int readlen; |
123 | int rc; | 123 | int rc; |
124 | int orig_fd, fd; | 124 | int orig_fd, fd; |
125 | char tmpname[MAX_PATH]; | 125 | char tmpname[MAX_PATH]; |
126 | 126 | ||
127 | /* Use the mp3 buffer to write 0's in the file */ | ||
128 | memset(mp3buf, 0, num_bytes); | ||
129 | |||
130 | snprintf(tmpname, MAX_PATH, "%s.tmp", fname); | 127 | snprintf(tmpname, MAX_PATH, "%s.tmp", fname); |
131 | 128 | ||
132 | orig_fd = open(fname, O_RDONLY); | 129 | orig_fd = open(fname, O_RDONLY); |
@@ -142,12 +139,35 @@ static int insert_space_in_file(char *fname, int num_bytes) | |||
142 | return 10*fd - 2; | 139 | return 10*fd - 2; |
143 | } | 140 | } |
144 | 141 | ||
142 | /* First, copy the initial portion (the ID3 tag) */ | ||
143 | if(fpos) | ||
144 | { | ||
145 | readlen = read(orig_fd, mp3buf, fpos); | ||
146 | if(readlen < 0) | ||
147 | { | ||
148 | close(fd); | ||
149 | close(orig_fd); | ||
150 | return 10*readlen - 3; | ||
151 | } | ||
152 | |||
153 | rc = write(fd, mp3buf, readlen); | ||
154 | if(rc < 0) | ||
155 | { | ||
156 | close(fd); | ||
157 | close(orig_fd); | ||
158 | return 10*rc - 4; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | /* Now insert some 0's in the file */ | ||
163 | memset(mp3buf, 0, num_bytes); | ||
164 | |||
145 | rc = write(fd, mp3buf, num_bytes); | 165 | rc = write(fd, mp3buf, num_bytes); |
146 | if(rc < 0) | 166 | if(rc < 0) |
147 | { | 167 | { |
148 | close(orig_fd); | 168 | close(orig_fd); |
149 | close(fd); | 169 | close(fd); |
150 | return 10*rc - 3; | 170 | return 10*rc - 5; |
151 | } | 171 | } |
152 | 172 | ||
153 | rc = lseek(orig_fd, 0, SEEK_SET); | 173 | rc = lseek(orig_fd, 0, SEEK_SET); |
@@ -155,7 +175,7 @@ static int insert_space_in_file(char *fname, int num_bytes) | |||
155 | { | 175 | { |
156 | close(orig_fd); | 176 | close(orig_fd); |
157 | close(fd); | 177 | close(fd); |
158 | return 10*rc - 4; | 178 | return 10*rc - 6; |
159 | } | 179 | } |
160 | 180 | ||
161 | /* Copy the file */ | 181 | /* Copy the file */ |
@@ -166,7 +186,7 @@ static int insert_space_in_file(char *fname, int num_bytes) | |||
166 | { | 186 | { |
167 | close(fd); | 187 | close(fd); |
168 | close(orig_fd); | 188 | close(orig_fd); |
169 | return 10*readlen - 5; | 189 | return 10*readlen - 7; |
170 | } | 190 | } |
171 | 191 | ||
172 | rc = write(fd, mp3buf, readlen); | 192 | rc = write(fd, mp3buf, readlen); |
@@ -174,7 +194,7 @@ static int insert_space_in_file(char *fname, int num_bytes) | |||
174 | { | 194 | { |
175 | close(fd); | 195 | close(fd); |
176 | close(orig_fd); | 196 | close(orig_fd); |
177 | return 10*rc - 6; | 197 | return 10*rc - 8; |
178 | } | 198 | } |
179 | } while(readlen > 0); | 199 | } while(readlen > 0); |
180 | 200 | ||
@@ -185,14 +205,14 @@ static int insert_space_in_file(char *fname, int num_bytes) | |||
185 | rc = remove(fname); | 205 | rc = remove(fname); |
186 | if(rc < 0) | 206 | if(rc < 0) |
187 | { | 207 | { |
188 | return 10*rc - 7; | 208 | return 10*rc - 9; |
189 | } | 209 | } |
190 | 210 | ||
191 | /* Replace the old file with the new */ | 211 | /* Replace the old file with the new */ |
192 | rc = rename(tmpname, fname); | 212 | rc = rename(tmpname, fname); |
193 | if(rc < 0) | 213 | if(rc < 0) |
194 | { | 214 | { |
195 | return 10*rc - 8; | 215 | return 10*rc - 9; |
196 | } | 216 | } |
197 | 217 | ||
198 | return 0; | 218 | return 0; |
@@ -207,6 +227,7 @@ static bool vbr_fix(void) | |||
207 | int flen; | 227 | int flen; |
208 | int num_frames; | 228 | int num_frames; |
209 | int fpos; | 229 | int fpos; |
230 | int numbytes; | ||
210 | 231 | ||
211 | if(mpeg_status()) | 232 | if(mpeg_status()) |
212 | { | 233 | { |
@@ -222,11 +243,17 @@ static bool vbr_fix(void) | |||
222 | 243 | ||
223 | rc = mp3info(&entry, selected_file); | 244 | rc = mp3info(&entry, selected_file); |
224 | if(rc < 0) | 245 | if(rc < 0) |
225 | return rc * 10 - 1; | 246 | { |
247 | splash(HZ*2, 0, true, "File error: %d", rc); | ||
248 | return true; | ||
249 | } | ||
226 | 250 | ||
227 | fd = open(selected_file, O_RDWR); | 251 | fd = open(selected_file, O_RDWR); |
228 | if(fd < 0) | 252 | if(fd < 0) |
229 | return fd * 10 - 2; | 253 | { |
254 | splash(HZ*2, 0, true, "File error: %d", fd); | ||
255 | return true; | ||
256 | } | ||
230 | 257 | ||
231 | flen = lseek(fd, 0, SEEK_END); | 258 | flen = lseek(fd, 0, SEEK_END); |
232 | 259 | ||
@@ -259,31 +286,33 @@ static bool vbr_fix(void) | |||
259 | } | 286 | } |
260 | else | 287 | else |
261 | { | 288 | { |
262 | /* If not, insert some space, but only if there is no ID3 | 289 | /* If not, insert some space. If there is an ID3 tag in the |
263 | tag in the file */ | 290 | file we only insert just enough to squeeze the Xing header |
291 | in. If not, we insert 4K. */ | ||
264 | close(fd); | 292 | close(fd); |
265 | if(entry.first_frame_offset == 0) | 293 | if(entry.first_frame_offset) |
294 | numbytes = 417; | ||
295 | else | ||
296 | numbytes = 4096; | ||
297 | |||
298 | rc = insert_space_in_file(selected_file, | ||
299 | entry.first_frame_offset, numbytes); | ||
300 | |||
301 | if(rc < 0) | ||
266 | { | 302 | { |
267 | rc = insert_space_in_file(selected_file, 4096); | 303 | splash(HZ*2, 0, true, "File error: %d", rc); |
268 | if(rc < 0) | 304 | return true; |
269 | { | ||
270 | splash(HZ*2, 0, true, "File error: %d", rc); | ||
271 | return rc * 10 - 3; | ||
272 | } | ||
273 | |||
274 | /* Reopen the file */ | ||
275 | fd = open(selected_file, O_RDWR); | ||
276 | if(fd < 0) | ||
277 | return fd * 10 - 4; | ||
278 | |||
279 | fpos = 4096-417; | ||
280 | } | 305 | } |
281 | else | 306 | |
307 | /* Reopen the file */ | ||
308 | fd = open(selected_file, O_RDWR); | ||
309 | if(fd < 0) | ||
282 | { | 310 | { |
283 | splash(HZ*2, 0, true, | 311 | splash(HZ*2, 0, true, "File reopen error: %d", fd); |
284 | "There is no room for a Xing header"); | 312 | return true; |
285 | return -3; | ||
286 | } | 313 | } |
314 | |||
315 | fpos = numbytes - 417; | ||
287 | } | 316 | } |
288 | } | 317 | } |
289 | 318 | ||