diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/id3.c | 2 | ||||
-rw-r--r-- | firmware/mp3data.c | 22 | ||||
-rw-r--r-- | firmware/mpeg.c | 67 |
3 files changed, 56 insertions, 35 deletions
diff --git a/firmware/id3.c b/firmware/id3.c index ab638807c3..96b660658d 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -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; diff --git a/firmware/mp3data.c b/firmware/mp3data.c index 21f01ea19e..f38b51c8f4 100644 --- a/firmware/mp3data.c +++ b/firmware/mp3data.c @@ -555,9 +555,9 @@ 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; + bool is_vbr = false; + int last_bitrate = 0; - /* Nasty stuff to avoid passing the file handle around */ - 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) @@ -583,8 +591,14 @@ int count_mp3_frames(int fd, int startpos, int filesize, } } 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, diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 13c4b01b8a..9528ede0ec 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -3030,42 +3030,49 @@ 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); - create_xing_header(fd, entry.first_frame_offset, - 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 */ - fpos = entry.vbr_header_pos; - - DEBUGF("Reusing Xing header at %d\n", fpos); - } - else + if(num_frames) { - /* Any room between ID3 tag and first MP3 frame? */ - if(entry.first_frame_offset - entry.id3v2len > 417) + create_xing_header(fd, entry.first_frame_offset, + 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) { - fpos = entry.first_frame_offset - 417; + /* Reuse existing Xing header */ + fpos = entry.vbr_header_pos; + + DEBUGF("Reusing Xing header at %d\n", fpos); } else { - close(fd); - return -3; + /* Any room between ID3 tag and first MP3 frame? */ + 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; } |