diff options
-rw-r--r-- | apps/codecs.c | 1 | ||||
-rw-r--r-- | apps/codecs.h | 6 | ||||
-rw-r--r-- | apps/codecs/mpa.c | 53 | ||||
-rw-r--r-- | apps/playback.c | 66 |
4 files changed, 54 insertions, 72 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index f2c74522cc..062487d6c8 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -86,7 +86,6 @@ struct codec_api ci = { NULL, /* advance_buffer_loc */ NULL, /* seek_buffer */ NULL, /* seek_complete */ - NULL, /* mp3_get_filepos */ NULL, /* request_next_track */ NULL, /* discard_codec */ NULL, /* set_offset */ diff --git a/apps/codecs.h b/apps/codecs.h index fb5675fd84..c543226935 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -80,12 +80,12 @@ #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ /* increase this every time the api struct changes */ -#define CODEC_API_VERSION 23 +#define CODEC_API_VERSION 24 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define CODEC_MIN_API_VERSION 23 +#define CODEC_MIN_API_VERSION 24 /* codec return codes */ enum codec_status { @@ -146,8 +146,6 @@ struct codec_api { bool (*seek_buffer)(size_t newpos); /* Codec should call this function when it has done the seeking. */ void (*seek_complete)(void); - /* Calculate mp3 seek position from given time data in ms. */ - off_t (*mp3_get_filepos)(int newtime); /* Request file change from file buffer. Returns true is next track is available and changed. If return value is false, codec should exit immediately with PLUGIN_OK status. */ diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 3de7684b2b..f9a27f5b41 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -58,6 +58,57 @@ void init_mad(void) stream.main_data = &mad_main_data; } +int get_file_pos(int newtime) +{ + int pos = -1; + struct mp3entry *id3 = ci->id3; + + if (id3->vbr) { + if (id3->has_toc) { + /* Use the TOC to find the new position */ + unsigned int percent, remainder; + int curtoc, nexttoc, plen; + + percent = (newtime*100) / id3->length; + if (percent > 99) + percent = 99; + + curtoc = id3->toc[percent]; + + if (percent < 99) { + nexttoc = id3->toc[percent+1]; + } else { + nexttoc = 256; + } + + pos = (id3->filesize/256)*curtoc; + + /* Use the remainder to get a more accurate position */ + remainder = (newtime*100) % id3->length; + remainder = (remainder*100) / id3->length; + plen = (nexttoc - curtoc)*(id3->filesize/256); + pos += (plen/100)*remainder; + } else { + /* No TOC exists, estimate the new position */ + pos = (id3->filesize / (id3->length / 1000)) * + (newtime / 1000); + } + } else if (id3->bitrate) { + pos = newtime * (id3->bitrate / 8); + } else { + return -1; + } + + pos += id3->first_frame_offset; + + /* Don't seek right to the end of the file so that we can + transition properly to the next song */ + if (pos >= (int)(id3->filesize - id3->id3v1len)) + pos = id3->filesize - id3->id3v1len - 1; + + return pos; +} + /* this is the codec entry point */ enum codec_status codec_main(void) { @@ -146,7 +197,7 @@ next_track: newpos = ci->id3->first_frame_offset; samples_to_skip = start_skip; } else { - newpos = ci->mp3_get_filepos(ci->seek_time-1); + newpos = get_file_pos(ci->seek_time-1); samples_to_skip = 0; } diff --git a/apps/playback.c b/apps/playback.c index 88f1bb5816..e632486694 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -1042,71 +1042,6 @@ static void codec_advance_buffer_loc_callback(void *ptr) codec_advance_buffer_callback(amount); } -/* Copied from mpeg.c. Should be moved somewhere else. */ -static int codec_get_file_pos(void) -{ - int pos = -1; - struct mp3entry *id3 = audio_current_track(); - - if (id3->vbr) - { - if (id3->has_toc) - { - /* Use the TOC to find the new position */ - unsigned int percent, remainder; - int curtoc, nexttoc, plen; - - percent = (id3->elapsed*100)/id3->length; - if (percent > 99) - percent = 99; - - curtoc = id3->toc[percent]; - - if (percent < 99) - nexttoc = id3->toc[percent+1]; - else - nexttoc = 256; - - pos = (id3->filesize/256)*curtoc; - - /* Use the remainder to get a more accurate position */ - remainder = (id3->elapsed*100)%id3->length; - remainder = (remainder*100)/id3->length; - plen = (nexttoc - curtoc)*(id3->filesize/256); - pos += (plen/100)*remainder; - } - else - { - /* No TOC exists, estimate the new position */ - pos = (id3->filesize / (id3->length / 1000)) * - (id3->elapsed / 1000); - } - } - else if (id3->bitrate) - pos = id3->elapsed * (id3->bitrate / 8); - else - return -1; - - pos += id3->first_frame_offset; - - /* Don't seek right to the end of the file so that we can - transition properly to the next song */ - if (pos >= (int)(id3->filesize - id3->id3v1len)) - pos = id3->filesize - id3->id3v1len - 1; - - return pos; -} - -static off_t codec_mp3_get_filepos_callback(int newtime) -{ - off_t newpos; - - curtrack_id3.elapsed = newtime; - newpos = codec_get_file_pos(); - - return newpos; -} - static void codec_seek_complete_callback(void) { logf("seek_complete"); @@ -2577,7 +2512,6 @@ void audio_init(void) ci.advance_buffer = codec_advance_buffer_callback; ci.advance_buffer_loc = codec_advance_buffer_loc_callback; ci.request_next_track = codec_request_next_track_callback; - ci.mp3_get_filepos = codec_mp3_get_filepos_callback; ci.seek_buffer = codec_seek_buffer_callback; ci.seek_complete = codec_seek_complete_callback; ci.set_elapsed = codec_set_elapsed_callback; |