Some code-police work, plus localized strings in vbrfix

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3524 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2003-04-10 00:16:46 +00:00
parent 0a74476ad0
commit 427e7495dd
2 changed files with 58 additions and 54 deletions

View file

@ -1447,3 +1447,13 @@ id: LANG_SETTINGS_SAVED2
desc: Feedback shown when a .cfg file is saved desc: Feedback shown when a .cfg file is saved
eng: "Saved" eng: "Saved"
new: new:
id: LANG_VBRFIX_STOP_PLAY
desc: Tells the user to stop the playback
eng: "Stop the playback first"
new:
id: LANG_VBRFIX_NOT_VBR
desc: Tells the user that the selected file is not a VBR file
eng: "Not a VBR file"
new:

View file

@ -127,32 +127,27 @@ static int insert_space_in_file(char *fname, int fpos, int num_bytes)
snprintf(tmpname, MAX_PATH, "%s.tmp", fname); snprintf(tmpname, MAX_PATH, "%s.tmp", fname);
orig_fd = open(fname, O_RDONLY); orig_fd = open(fname, O_RDONLY);
if(orig_fd < 0) if(orig_fd < 0) {
{
return 10*orig_fd - 1; return 10*orig_fd - 1;
} }
fd = creat(tmpname, O_WRONLY); fd = creat(tmpname, O_WRONLY);
if(fd < 0) if(fd < 0) {
{
close(orig_fd); close(orig_fd);
return 10*fd - 2; return 10*fd - 2;
} }
/* First, copy the initial portion (the ID3 tag) */ /* First, copy the initial portion (the ID3 tag) */
if(fpos) if(fpos) {
{
readlen = read(orig_fd, mp3buf, fpos); readlen = read(orig_fd, mp3buf, fpos);
if(readlen < 0) if(readlen < 0) {
{
close(fd); close(fd);
close(orig_fd); close(orig_fd);
return 10*readlen - 3; return 10*readlen - 3;
} }
rc = write(fd, mp3buf, readlen); rc = write(fd, mp3buf, readlen);
if(rc < 0) if(rc < 0) {
{
close(fd); close(fd);
close(orig_fd); close(orig_fd);
return 10*rc - 4; return 10*rc - 4;
@ -163,35 +158,30 @@ static int insert_space_in_file(char *fname, int fpos, int num_bytes)
memset(mp3buf, 0, num_bytes); memset(mp3buf, 0, num_bytes);
rc = write(fd, mp3buf, num_bytes); rc = write(fd, mp3buf, num_bytes);
if(rc < 0) if(rc < 0) {
{
close(orig_fd); close(orig_fd);
close(fd); close(fd);
return 10*rc - 5; return 10*rc - 5;
} }
rc = lseek(orig_fd, 0, SEEK_SET); rc = lseek(orig_fd, 0, SEEK_SET);
if(rc < 0) if(rc < 0) {
{
close(orig_fd); close(orig_fd);
close(fd); close(fd);
return 10*rc - 6; return 10*rc - 6;
} }
/* Copy the file */ /* Copy the file */
do do {
{
readlen = read(orig_fd, mp3buf, mp3end - mp3buf); readlen = read(orig_fd, mp3buf, mp3end - mp3buf);
if(readlen < 0) if(readlen < 0) {
{
close(fd); close(fd);
close(orig_fd); close(orig_fd);
return 10*readlen - 7; return 10*readlen - 7;
} }
rc = write(fd, mp3buf, readlen); rc = write(fd, mp3buf, readlen);
if(rc < 0) if(rc < 0) {
{
close(fd); close(fd);
close(orig_fd); close(orig_fd);
return 10*rc - 8; return 10*rc - 8;
@ -203,21 +193,24 @@ static int insert_space_in_file(char *fname, int fpos, int num_bytes)
/* Remove the old file */ /* Remove the old file */
rc = remove(fname); rc = remove(fname);
if(rc < 0) if(rc < 0) {
{
return 10*rc - 9; return 10*rc - 9;
} }
/* Replace the old file with the new */ /* Replace the old file with the new */
rc = rename(tmpname, fname); rc = rename(tmpname, fname);
if(rc < 0) if(rc < 0) {
{
return 10*rc - 9; return 10*rc - 9;
} }
return 0; return 0;
} }
static void fileerror(int rc)
{
splash(HZ*2, 0, true, "File error: %d", rc);
}
static bool vbr_fix(void) static bool vbr_fix(void)
{ {
unsigned char xingbuf[417]; unsigned char xingbuf[417];
@ -229,9 +222,8 @@ static bool vbr_fix(void)
int fpos; int fpos;
int numbytes; int numbytes;
if(mpeg_status()) if(mpeg_status()) {
{ splash(HZ*2, 0, true, str(LANG_VBRFIX_STOP_PLAY));
splash(HZ*2, 0, true, "Stop the playback");
return reload_dir; return reload_dir;
} }
@ -242,16 +234,14 @@ static bool vbr_fix(void)
xingupdate(0); xingupdate(0);
rc = mp3info(&entry, selected_file); rc = mp3info(&entry, selected_file);
if(rc < 0) if(rc < 0) {
{ fileerror(rc);
splash(HZ*2, 0, true, "File error: %d", rc);
return true; return true;
} }
fd = open(selected_file, O_RDWR); fd = open(selected_file, O_RDWR);
if(fd < 0) if(fd < 0) {
{ fileerror(fd);
splash(HZ*2, 0, true, "File error: %d", fd);
return true; return true;
} }
@ -262,30 +252,23 @@ static bool vbr_fix(void)
num_frames = count_mp3_frames(fd, entry.first_frame_offset, num_frames = count_mp3_frames(fd, entry.first_frame_offset,
flen, xingupdate); flen, xingupdate);
if(num_frames) if(num_frames) {
{
create_xing_header(fd, entry.first_frame_offset, create_xing_header(fd, entry.first_frame_offset,
flen, xingbuf, num_frames, xingupdate, true); flen, xingbuf, num_frames, xingupdate, true);
/* Try to fit the Xing header first in the stream. Replace the existing /* Try to fit the Xing header first in the stream. Replace the existing
Xing header if there is one, else see if there is room between the Xing header if there is one, else see if there is room between the
ID3 tag and the first MP3 frame. */ ID3 tag and the first MP3 frame. */
if(entry.vbr_header_pos) if(entry.vbr_header_pos) {
{
/* Reuse existing Xing header */ /* Reuse existing Xing header */
fpos = entry.vbr_header_pos; fpos = entry.vbr_header_pos;
DEBUGF("Reusing Xing header at %d\n", fpos); DEBUGF("Reusing Xing header at %d\n", fpos);
} } else {
else
{
/* Any room between ID3 tag and first MP3 frame? */ /* Any room between ID3 tag and first MP3 frame? */
if(entry.first_frame_offset - entry.id3v2len > 417) if(entry.first_frame_offset - entry.id3v2len > 417) {
{
fpos = entry.first_frame_offset - 417; fpos = entry.first_frame_offset - 417;
} } else {
else
{
/* If not, insert some space. If there is an ID3 tag in the /* If not, insert some space. If there is an ID3 tag in the
file we only insert just enough to squeeze the Xing header file we only insert just enough to squeeze the Xing header
in. If not, we insert 4K. */ in. If not, we insert 4K. */
@ -298,16 +281,14 @@ static bool vbr_fix(void)
rc = insert_space_in_file(selected_file, rc = insert_space_in_file(selected_file,
entry.first_frame_offset, numbytes); entry.first_frame_offset, numbytes);
if(rc < 0) if(rc < 0) {
{ fileerror(rc);
splash(HZ*2, 0, true, "File error: %d", rc);
return true; return true;
} }
/* Reopen the file */ /* Reopen the file */
fd = open(selected_file, O_RDWR); fd = open(selected_file, O_RDWR);
if(fd < 0) if(fd < 0) {
{
splash(HZ*2, 0, true, "File reopen error: %d", fd); splash(HZ*2, 0, true, "File reopen error: %d", fd);
return true; return true;
} }
@ -316,8 +297,20 @@ static bool vbr_fix(void)
} }
} }
lseek(fd, fpos, SEEK_SET); rc = lseek(fd, fpos, SEEK_SET);
write(fd, xingbuf, 417); if(rc < 0) {
close(fd);
fileerror(rc);
return true;
}
rc = write(fd, xingbuf, 417);
if(rc < 0) {
close(fd);
fileerror(rc);
return true;
}
close(fd); close(fd);
xingupdate(100); xingupdate(100);
@ -326,11 +319,12 @@ static bool vbr_fix(void)
{ {
/* Not a VBR file */ /* Not a VBR file */
DEBUGF("Not a VBR file\n"); DEBUGF("Not a VBR file\n");
splash(HZ*2, 0, true, "Not a VBR file"); splash(HZ*2, 0, true, str(LANG_VBRFIX_NOT_VBR));
} }
return false; return false;
} }
int onplay(char* file, int attr) int onplay(char* file, int attr)
{ {
struct menu_items menu[5]; /* increase this if you add entries! */ struct menu_items menu[5]; /* increase this if you add entries! */