summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2003-04-03 07:20:57 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2003-04-03 07:20:57 +0000
commit6edea74ea6deab4302fffa476d2b2dd724fa8f05 (patch)
treee3c0c0981ff670a566f7bbd742698167d5b52bd6
parent11edfa8d96a4a84af58663b0aa9cce55ed8d8798 (diff)
downloadrockbox-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
-rw-r--r--apps/onplay.c93
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)
extern unsigned char mp3buf[];
extern unsigned char mp3end[];
-static int insert_space_in_file(char *fname, int num_bytes)
+static int insert_space_in_file(char *fname, int fpos, int num_bytes)
{
int readlen;
int rc;
int orig_fd, fd;
char tmpname[MAX_PATH];
- /* Use the mp3 buffer to write 0's in the file */
- memset(mp3buf, 0, num_bytes);
-
snprintf(tmpname, MAX_PATH, "%s.tmp", fname);
orig_fd = open(fname, O_RDONLY);
@@ -142,12 +139,35 @@ static int insert_space_in_file(char *fname, int num_bytes)
return 10*fd - 2;
}
+ /* First, copy the initial portion (the ID3 tag) */
+ if(fpos)
+ {
+ readlen = read(orig_fd, mp3buf, fpos);
+ if(readlen < 0)
+ {
+ close(fd);
+ close(orig_fd);
+ return 10*readlen - 3;
+ }
+
+ rc = write(fd, mp3buf, readlen);
+ if(rc < 0)
+ {
+ close(fd);
+ close(orig_fd);
+ return 10*rc - 4;
+ }
+ }
+
+ /* Now insert some 0's in the file */
+ memset(mp3buf, 0, num_bytes);
+
rc = write(fd, mp3buf, num_bytes);
if(rc < 0)
{
close(orig_fd);
close(fd);
- return 10*rc - 3;
+ return 10*rc - 5;
}
rc = lseek(orig_fd, 0, SEEK_SET);
@@ -155,7 +175,7 @@ static int insert_space_in_file(char *fname, int num_bytes)
{
close(orig_fd);
close(fd);
- return 10*rc - 4;
+ return 10*rc - 6;
}
/* Copy the file */
@@ -166,7 +186,7 @@ static int insert_space_in_file(char *fname, int num_bytes)
{
close(fd);
close(orig_fd);
- return 10*readlen - 5;
+ return 10*readlen - 7;
}
rc = write(fd, mp3buf, readlen);
@@ -174,7 +194,7 @@ static int insert_space_in_file(char *fname, int num_bytes)
{
close(fd);
close(orig_fd);
- return 10*rc - 6;
+ return 10*rc - 8;
}
} while(readlen > 0);
@@ -185,14 +205,14 @@ static int insert_space_in_file(char *fname, int num_bytes)
rc = remove(fname);
if(rc < 0)
{
- return 10*rc - 7;
+ return 10*rc - 9;
}
/* Replace the old file with the new */
rc = rename(tmpname, fname);
if(rc < 0)
{
- return 10*rc - 8;
+ return 10*rc - 9;
}
return 0;
@@ -207,6 +227,7 @@ static bool vbr_fix(void)
int flen;
int num_frames;
int fpos;
+ int numbytes;
if(mpeg_status())
{
@@ -222,11 +243,17 @@ static bool vbr_fix(void)
rc = mp3info(&entry, selected_file);
if(rc < 0)
- return rc * 10 - 1;
+ {
+ splash(HZ*2, 0, true, "File error: %d", rc);
+ return true;
+ }
fd = open(selected_file, O_RDWR);
if(fd < 0)
- return fd * 10 - 2;
+ {
+ splash(HZ*2, 0, true, "File error: %d", fd);
+ return true;
+ }
flen = lseek(fd, 0, SEEK_END);
@@ -259,31 +286,33 @@ static bool vbr_fix(void)
}
else
{
- /* If not, insert some space, but only if there is no ID3
- tag in the file */
+ /* If not, insert some space. If there is an ID3 tag in the
+ file we only insert just enough to squeeze the Xing header
+ in. If not, we insert 4K. */
close(fd);
- if(entry.first_frame_offset == 0)
+ if(entry.first_frame_offset)
+ numbytes = 417;
+ else
+ numbytes = 4096;
+
+ rc = insert_space_in_file(selected_file,
+ entry.first_frame_offset, numbytes);
+
+ if(rc < 0)
{
- rc = insert_space_in_file(selected_file, 4096);
- if(rc < 0)
- {
- splash(HZ*2, 0, true, "File error: %d", rc);
- return rc * 10 - 3;
- }
-
- /* Reopen the file */
- fd = open(selected_file, O_RDWR);
- if(fd < 0)
- return fd * 10 - 4;
-
- fpos = 4096-417;
+ splash(HZ*2, 0, true, "File error: %d", rc);
+ return true;
}
- else
+
+ /* Reopen the file */
+ fd = open(selected_file, O_RDWR);
+ if(fd < 0)
{
- splash(HZ*2, 0, true,
- "There is no room for a Xing header");
- return -3;
+ splash(HZ*2, 0, true, "File reopen error: %d", fd);
+ return true;
}
+
+ fpos = numbytes - 417;
}
}