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;
|
||||
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 */
|
||||
entry->first_frame_offset = bytecount;
|
||||
|
|
|
@ -555,8 +555,8 @@ int count_mp3_frames(int fd, int startpos, int filesize,
|
|||
int cnt;
|
||||
int progress_chunk = filesize / 50; /* Max is 50%, in 1% increments */
|
||||
int progress_cnt = 0;
|
||||
|
||||
/* Nasty stuff to avoid passing the file handle around */
|
||||
bool is_vbr = false;
|
||||
int last_bitrate = 0;
|
||||
|
||||
if(lseek(fd, startpos, SEEK_SET) < 0)
|
||||
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))) {
|
||||
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);
|
||||
num_frames++;
|
||||
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);
|
||||
|
||||
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,
|
||||
|
|
|
@ -3030,9 +3030,10 @@ int mpeg_create_xing_header(char *filename, void (*progressfunc)(int))
|
|||
progressfunc(0);
|
||||
|
||||
num_frames = count_mp3_frames(fd, entry.first_frame_offset,
|
||||
flen,
|
||||
progressfunc);
|
||||
flen, progressfunc);
|
||||
|
||||
if(num_frames)
|
||||
{
|
||||
create_xing_header(fd, entry.first_frame_offset,
|
||||
flen, xingbuf, num_frames, progressfunc, true);
|
||||
|
||||
|
@ -3066,6 +3067,12 @@ int mpeg_create_xing_header(char *filename, void (*progressfunc)(int))
|
|||
|
||||
if(progressfunc)
|
||||
progressfunc(100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not a VBR file */
|
||||
DEBUGF("Not a VBR file\n");
|
||||
return -9;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue