mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-22 11:32:41 -05:00
Removed vbr_fix, as it now is a plugin
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4727 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
a6142ab7ab
commit
183e1463bb
2 changed files with 7 additions and 260 deletions
|
|
@ -1316,21 +1316,21 @@ voice: ""
|
||||||
new:
|
new:
|
||||||
|
|
||||||
id: LANG_VBRFIX_STOP_PLAY
|
id: LANG_VBRFIX_STOP_PLAY
|
||||||
desc: Tells the user to stop the playback
|
desc: DEPRECATED
|
||||||
eng: "Stop the playback first"
|
eng: ""
|
||||||
voice: ""
|
voice: ""
|
||||||
new:
|
new:
|
||||||
|
|
||||||
id: LANG_VBRFIX_NOT_VBR
|
id: LANG_VBRFIX_NOT_VBR
|
||||||
desc: Tells the user that the selected file is not a VBR file
|
desc: DEPRECATED
|
||||||
eng: "Not a VBR file"
|
eng: ""
|
||||||
voice: ""
|
voice: ""
|
||||||
new:
|
new:
|
||||||
|
|
||||||
id: LANG_VBRFIX
|
id: LANG_VBRFIX
|
||||||
desc: The context menu entry
|
desc: DEPRECATED
|
||||||
eng: "Update VBR file"
|
eng: ""
|
||||||
voice: "Update VBR file"
|
voice: ""
|
||||||
new:
|
new:
|
||||||
|
|
||||||
id: LANG_INVERT_CURSOR
|
id: LANG_INVERT_CURSOR
|
||||||
|
|
|
||||||
253
apps/onplay.c
253
apps/onplay.c
|
|
@ -374,251 +374,6 @@ static bool rename_file(void)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xingupdate(int percent)
|
|
||||||
{
|
|
||||||
char buf[32];
|
|
||||||
|
|
||||||
snprintf(buf, 32, "%d%%", percent);
|
|
||||||
lcd_puts(0, 1, buf);
|
|
||||||
lcd_update();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int insert_data_in_file(char *fname, int fpos, char *buf, int num_bytes)
|
|
||||||
{
|
|
||||||
int readlen;
|
|
||||||
int rc;
|
|
||||||
int orig_fd, fd;
|
|
||||||
char tmpname[MAX_PATH];
|
|
||||||
|
|
||||||
talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
|
|
||||||
|
|
||||||
snprintf(tmpname, MAX_PATH, "%s.tmp", fname);
|
|
||||||
|
|
||||||
orig_fd = open(fname, O_RDONLY);
|
|
||||||
if(orig_fd < 0) {
|
|
||||||
return 10*orig_fd - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = creat(tmpname, O_WRONLY);
|
|
||||||
if(fd < 0) {
|
|
||||||
close(orig_fd);
|
|
||||||
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 the data into the file */
|
|
||||||
rc = write(fd, buf, num_bytes);
|
|
||||||
if(rc < 0) {
|
|
||||||
close(orig_fd);
|
|
||||||
close(fd);
|
|
||||||
return 10*rc - 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy the file */
|
|
||||||
do {
|
|
||||||
readlen = read(orig_fd, mp3buf, mp3end - mp3buf);
|
|
||||||
if(readlen < 0) {
|
|
||||||
close(fd);
|
|
||||||
close(orig_fd);
|
|
||||||
return 10*readlen - 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = write(fd, mp3buf, readlen);
|
|
||||||
if(rc < 0) {
|
|
||||||
close(fd);
|
|
||||||
close(orig_fd);
|
|
||||||
return 10*rc - 8;
|
|
||||||
}
|
|
||||||
} while(readlen > 0);
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
close(orig_fd);
|
|
||||||
|
|
||||||
/* Remove the old file */
|
|
||||||
rc = remove(fname);
|
|
||||||
if(rc < 0) {
|
|
||||||
return 10*rc - 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Replace the old file with the new */
|
|
||||||
rc = rename(tmpname, fname);
|
|
||||||
if(rc < 0) {
|
|
||||||
return 10*rc - 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fileerror(int rc)
|
|
||||||
{
|
|
||||||
splash(HZ*2, true, "File error: %d", rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const unsigned char empty_id3_header[] =
|
|
||||||
{
|
|
||||||
'I', 'D', '3', 0x04, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x1f, 0x76 /* Size is 4096 minus 10 bytes for the header */
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool vbr_fix(void)
|
|
||||||
{
|
|
||||||
unsigned char xingbuf[1500];
|
|
||||||
struct mp3entry entry;
|
|
||||||
int fd;
|
|
||||||
int rc;
|
|
||||||
int flen;
|
|
||||||
int num_frames;
|
|
||||||
int numbytes;
|
|
||||||
int framelen;
|
|
||||||
int unused_space;
|
|
||||||
|
|
||||||
if(mpeg_status()) {
|
|
||||||
splash(HZ*2, true, str(LANG_VBRFIX_STOP_PLAY));
|
|
||||||
return onplay_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
talk_buffer_steal(); /* we use the mp3 buffer, need to tell */
|
|
||||||
|
|
||||||
lcd_clear_display();
|
|
||||||
lcd_puts_scroll(0, 0, selected_file);
|
|
||||||
lcd_update();
|
|
||||||
|
|
||||||
xingupdate(0);
|
|
||||||
|
|
||||||
rc = mp3info(&entry, selected_file);
|
|
||||||
if(rc < 0) {
|
|
||||||
fileerror(rc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open(selected_file, O_RDWR);
|
|
||||||
if(fd < 0) {
|
|
||||||
fileerror(fd);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
flen = lseek(fd, 0, SEEK_END);
|
|
||||||
|
|
||||||
xingupdate(0);
|
|
||||||
|
|
||||||
num_frames = count_mp3_frames(fd, entry.first_frame_offset,
|
|
||||||
flen, xingupdate);
|
|
||||||
|
|
||||||
if(num_frames) {
|
|
||||||
/* Note: We don't need to pass a template header because it will be
|
|
||||||
taken from the mpeg stream */
|
|
||||||
framelen = create_xing_header(fd, entry.first_frame_offset,
|
|
||||||
flen, xingbuf, num_frames,
|
|
||||||
0, xingupdate, true);
|
|
||||||
|
|
||||||
/* Try to fit the Xing header first in the stream. Replace the existing
|
|
||||||
VBR header if there is one, else see if there is room between the
|
|
||||||
ID3 tag and the first MP3 frame. */
|
|
||||||
if(entry.first_frame_offset - entry.id3v2len >=
|
|
||||||
(unsigned int)framelen) {
|
|
||||||
DEBUGF("Using existing space between ID3 and first frame\n");
|
|
||||||
|
|
||||||
/* Seek to the beginning of the unused space */
|
|
||||||
rc = lseek(fd, entry.id3v2len, SEEK_SET);
|
|
||||||
if(rc < 0) {
|
|
||||||
close(fd);
|
|
||||||
fileerror(rc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
unused_space =
|
|
||||||
entry.first_frame_offset - entry.id3v2len - framelen;
|
|
||||||
|
|
||||||
/* Fill the unused space with 0's (using the MP3 buffer)
|
|
||||||
and write it to the file */
|
|
||||||
if(unused_space)
|
|
||||||
{
|
|
||||||
memset(mp3buf, 0, unused_space);
|
|
||||||
rc = write(fd, mp3buf, unused_space);
|
|
||||||
if(rc < 0) {
|
|
||||||
close(fd);
|
|
||||||
fileerror(rc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then write the Xing header */
|
|
||||||
rc = write(fd, xingbuf, framelen);
|
|
||||||
if(rc < 0) {
|
|
||||||
close(fd);
|
|
||||||
fileerror(rc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
} else {
|
|
||||||
/* 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 an additional empty ID3 tag of 4K. */
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
/* Nasty trick alert! The insert_data_in_file() function
|
|
||||||
uses the MP3 buffer when copying the data. We assume
|
|
||||||
that the ID3 tag isn't longer than 1MB so the xing
|
|
||||||
buffer won't be overwritten. */
|
|
||||||
|
|
||||||
if(entry.first_frame_offset) {
|
|
||||||
DEBUGF("Inserting %d bytes\n", framelen);
|
|
||||||
numbytes = framelen;
|
|
||||||
} else {
|
|
||||||
DEBUGF("Inserting 4096+%d bytes\n", framelen);
|
|
||||||
numbytes = 4096 + framelen;
|
|
||||||
|
|
||||||
memset(mp3buf + 0x100000, 0, numbytes);
|
|
||||||
|
|
||||||
/* Insert the ID3 header */
|
|
||||||
memcpy(mp3buf + 0x100000, empty_id3_header,
|
|
||||||
sizeof(empty_id3_header));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Copy the Xing header */
|
|
||||||
memcpy(mp3buf + 0x100000 + numbytes - framelen, xingbuf, framelen);
|
|
||||||
|
|
||||||
rc = insert_data_in_file(selected_file,
|
|
||||||
entry.first_frame_offset,
|
|
||||||
mp3buf + 0x100000, numbytes);
|
|
||||||
|
|
||||||
if(rc < 0) {
|
|
||||||
fileerror(rc);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
xingupdate(100);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Not a VBR file */
|
|
||||||
DEBUGF("Not a VBR file\n");
|
|
||||||
splash(HZ*2, true, str(LANG_VBRFIX_NOT_VBR));
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool create_dir(void)
|
bool create_dir(void)
|
||||||
{
|
{
|
||||||
char dirname[MAX_PATH];
|
char dirname[MAX_PATH];
|
||||||
|
|
@ -696,14 +451,6 @@ int onplay(char* file, int attr)
|
||||||
items[i].function = delete_dir;
|
items[i].function = delete_dir;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((attr & TREE_ATTR_MASK) == TREE_ATTR_MPA)
|
|
||||||
{
|
|
||||||
items[i].desc = str(LANG_VBRFIX);
|
|
||||||
items[i].voice_id = LANG_VBRFIX;
|
|
||||||
items[i].function = vbr_fix;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
items[i].desc = str(LANG_CREATE_DIR);
|
items[i].desc = str(LANG_CREATE_DIR);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue