diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2003-04-03 00:27:49 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2003-04-03 00:27:49 +0000 |
commit | 11edfa8d96a4a84af58663b0aa9cce55ed8d8798 (patch) | |
tree | 6f1e8f5e6e93fb4a3e475bbd9f2c594390a3c236 | |
parent | a91713a2161c8af54d6570e5f39d53fae3b6ba99 (diff) | |
download | rockbox-11edfa8d96a4a84af58663b0aa9cce55ed8d8798.tar.gz rockbox-11edfa8d96a4a84af58663b0aa9cce55ed8d8798.zip |
Now inserts a xing header if there is no room for it
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3513 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/onplay.c | 114 |
1 files changed, 110 insertions, 4 deletions
diff --git a/apps/onplay.c b/apps/onplay.c index 482697bf4b..74e7136738 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -112,6 +112,92 @@ static void xingupdate(int percent) | |||
112 | lcd_update(); | 112 | lcd_update(); |
113 | } | 113 | } |
114 | 114 | ||
115 | |||
116 | /* defined in linker script */ | ||
117 | extern unsigned char mp3buf[]; | ||
118 | extern unsigned char mp3end[]; | ||
119 | |||
120 | static int insert_space_in_file(char *fname, int num_bytes) | ||
121 | { | ||
122 | int readlen; | ||
123 | int rc; | ||
124 | int orig_fd, fd; | ||
125 | char tmpname[MAX_PATH]; | ||
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); | ||
131 | |||
132 | orig_fd = open(fname, O_RDONLY); | ||
133 | if(orig_fd < 0) | ||
134 | { | ||
135 | return 10*orig_fd - 1; | ||
136 | } | ||
137 | |||
138 | fd = creat(tmpname, O_WRONLY); | ||
139 | if(fd < 0) | ||
140 | { | ||
141 | close(orig_fd); | ||
142 | return 10*fd - 2; | ||
143 | } | ||
144 | |||
145 | rc = write(fd, mp3buf, num_bytes); | ||
146 | if(rc < 0) | ||
147 | { | ||
148 | close(orig_fd); | ||
149 | close(fd); | ||
150 | return 10*rc - 3; | ||
151 | } | ||
152 | |||
153 | rc = lseek(orig_fd, 0, SEEK_SET); | ||
154 | if(rc < 0) | ||
155 | { | ||
156 | close(orig_fd); | ||
157 | close(fd); | ||
158 | return 10*rc - 4; | ||
159 | } | ||
160 | |||
161 | /* Copy the file */ | ||
162 | do | ||
163 | { | ||
164 | readlen = read(orig_fd, mp3buf, mp3end - mp3buf); | ||
165 | if(readlen < 0) | ||
166 | { | ||
167 | close(fd); | ||
168 | close(orig_fd); | ||
169 | return 10*readlen - 5; | ||
170 | } | ||
171 | |||
172 | rc = write(fd, mp3buf, readlen); | ||
173 | if(rc < 0) | ||
174 | { | ||
175 | close(fd); | ||
176 | close(orig_fd); | ||
177 | return 10*rc - 6; | ||
178 | } | ||
179 | } while(readlen > 0); | ||
180 | |||
181 | close(fd); | ||
182 | close(orig_fd); | ||
183 | |||
184 | /* Remove the old file */ | ||
185 | rc = remove(fname); | ||
186 | if(rc < 0) | ||
187 | { | ||
188 | return 10*rc - 7; | ||
189 | } | ||
190 | |||
191 | /* Replace the old file with the new */ | ||
192 | rc = rename(tmpname, fname); | ||
193 | if(rc < 0) | ||
194 | { | ||
195 | return 10*rc - 8; | ||
196 | } | ||
197 | |||
198 | return 0; | ||
199 | } | ||
200 | |||
115 | static bool vbr_fix(void) | 201 | static bool vbr_fix(void) |
116 | { | 202 | { |
117 | unsigned char xingbuf[417]; | 203 | unsigned char xingbuf[417]; |
@@ -122,7 +208,6 @@ static bool vbr_fix(void) | |||
122 | int num_frames; | 208 | int num_frames; |
123 | int fpos; | 209 | int fpos; |
124 | 210 | ||
125 | |||
126 | if(mpeg_status()) | 211 | if(mpeg_status()) |
127 | { | 212 | { |
128 | splash(HZ*2, 0, true, "Stop the playback"); | 213 | splash(HZ*2, 0, true, "Stop the playback"); |
@@ -174,9 +259,31 @@ static bool vbr_fix(void) | |||
174 | } | 259 | } |
175 | else | 260 | else |
176 | { | 261 | { |
262 | /* If not, insert some space, but only if there is no ID3 | ||
263 | tag in the file */ | ||
177 | close(fd); | 264 | close(fd); |
178 | splash(HZ*2, 0, true, "No room for header"); | 265 | if(entry.first_frame_offset == 0) |
179 | return -3; | 266 | { |
267 | rc = insert_space_in_file(selected_file, 4096); | ||
268 | if(rc < 0) | ||
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 | } | ||
281 | else | ||
282 | { | ||
283 | splash(HZ*2, 0, true, | ||
284 | "There is no room for a Xing header"); | ||
285 | return -3; | ||
286 | } | ||
180 | } | 287 | } |
181 | } | 288 | } |
182 | 289 | ||
@@ -195,7 +302,6 @@ static bool vbr_fix(void) | |||
195 | 302 | ||
196 | return false; | 303 | return false; |
197 | } | 304 | } |
198 | |||
199 | int onplay(char* file, int attr) | 305 | int onplay(char* file, int attr) |
200 | { | 306 | { |
201 | struct menu_items menu[5]; /* increase this if you add entries! */ | 307 | struct menu_items menu[5]; /* increase this if you add entries! */ |