forked from len0rd/rockbox
Don't accidentally add Xing headers to CBR files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3419 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6475aa0c85
commit
2c07e78efc
3 changed files with 56 additions and 35 deletions
|
@ -497,7 +497,7 @@ static int getsonglength(int fd, struct mp3entry *entry)
|
||||||
entry->has_toc = info.has_toc;
|
entry->has_toc = info.has_toc;
|
||||||
memcpy(entry->toc, info.toc, sizeof(info.toc));
|
memcpy(entry->toc, info.toc, sizeof(info.toc));
|
||||||
|
|
||||||
entry->xing_header_pos = info.xing_header_pos;
|
entry->vbr_header_pos = info.vbr_header_pos;
|
||||||
|
|
||||||
/* Update the seek point for the first playable frame */
|
/* Update the seek point for the first playable frame */
|
||||||
entry->first_frame_offset = bytecount;
|
entry->first_frame_offset = bytecount;
|
||||||
|
|
|
@ -555,8 +555,8 @@ int count_mp3_frames(int fd, int startpos, int filesize,
|
||||||
int cnt;
|
int cnt;
|
||||||
int progress_chunk = filesize / 50; /* Max is 50%, in 1% increments */
|
int progress_chunk = filesize / 50; /* Max is 50%, in 1% increments */
|
||||||
int progress_cnt = 0;
|
int progress_cnt = 0;
|
||||||
|
bool is_vbr = false;
|
||||||
/* Nasty stuff to avoid passing the file handle around */
|
int last_bitrate = 0;
|
||||||
|
|
||||||
if(lseek(fd, startpos, SEEK_SET) < 0)
|
if(lseek(fd, startpos, SEEK_SET) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -569,6 +569,14 @@ int count_mp3_frames(int fd, int startpos, int filesize,
|
||||||
|
|
||||||
while((header = buf_find_next_frame(fd, &bytes, -1, header))) {
|
while((header = buf_find_next_frame(fd, &bytes, -1, header))) {
|
||||||
mp3headerinfo(&info, header);
|
mp3headerinfo(&info, header);
|
||||||
|
|
||||||
|
/* See if this really is a VBR file */
|
||||||
|
if(last_bitrate && info.bitrate != last_bitrate)
|
||||||
|
{
|
||||||
|
is_vbr = true;
|
||||||
|
}
|
||||||
|
last_bitrate = info.bitrate;
|
||||||
|
|
||||||
buf_seek(fd, info.frame_size-4);
|
buf_seek(fd, info.frame_size-4);
|
||||||
num_frames++;
|
num_frames++;
|
||||||
if(progressfunc)
|
if(progressfunc)
|
||||||
|
@ -584,7 +592,13 @@ int count_mp3_frames(int fd, int startpos, int filesize,
|
||||||
}
|
}
|
||||||
DEBUGF("Total number of frames: %d\n", num_frames);
|
DEBUGF("Total number of frames: %d\n", num_frames);
|
||||||
|
|
||||||
return num_frames;
|
if(is_vbr)
|
||||||
|
return num_frames;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUGF("Not a VBR file\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_xing_header(int fd, int startpos, int filesize,
|
int create_xing_header(int fd, int startpos, int filesize,
|
||||||
|
|
|
@ -3030,42 +3030,49 @@ int mpeg_create_xing_header(char *filename, void (*progressfunc)(int))
|
||||||
progressfunc(0);
|
progressfunc(0);
|
||||||
|
|
||||||
num_frames = count_mp3_frames(fd, entry.first_frame_offset,
|
num_frames = count_mp3_frames(fd, entry.first_frame_offset,
|
||||||
flen,
|
flen, progressfunc);
|
||||||
progressfunc);
|
|
||||||
|
|
||||||
create_xing_header(fd, entry.first_frame_offset,
|
if(num_frames)
|
||||||
flen, xingbuf, num_frames, progressfunc, true);
|
|
||||||
|
|
||||||
/* 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
|
|
||||||
ID3 tag and the first MP3 frame. */
|
|
||||||
if(entry.vbr_header_pos)
|
|
||||||
{
|
{
|
||||||
/* Reuse existing Xing header */
|
create_xing_header(fd, entry.first_frame_offset,
|
||||||
fpos = entry.vbr_header_pos;
|
flen, xingbuf, num_frames, progressfunc, true);
|
||||||
|
|
||||||
DEBUGF("Reusing Xing header at %d\n", fpos);
|
/* 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
|
||||||
else
|
ID3 tag and the first MP3 frame. */
|
||||||
{
|
if(entry.vbr_header_pos)
|
||||||
/* Any room between ID3 tag and first MP3 frame? */
|
|
||||||
if(entry.first_frame_offset - entry.id3v2len > 417)
|
|
||||||
{
|
{
|
||||||
fpos = entry.first_frame_offset - 417;
|
/* Reuse existing Xing header */
|
||||||
|
fpos = entry.vbr_header_pos;
|
||||||
|
|
||||||
|
DEBUGF("Reusing Xing header at %d\n", fpos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
close(fd);
|
/* Any room between ID3 tag and first MP3 frame? */
|
||||||
return -3;
|
if(entry.first_frame_offset - entry.id3v2len > 417)
|
||||||
|
{
|
||||||
|
fpos = entry.first_frame_offset - 417;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lseek(fd, fpos, SEEK_SET);
|
||||||
|
write(fd, xingbuf, 417);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if(progressfunc)
|
||||||
|
progressfunc(100);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Not a VBR file */
|
||||||
|
DEBUGF("Not a VBR file\n");
|
||||||
|
return -9;
|
||||||
}
|
}
|
||||||
|
|
||||||
lseek(fd, fpos, SEEK_SET);
|
|
||||||
write(fd, xingbuf, 417);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if(progressfunc)
|
|
||||||
progressfunc(100);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue