1
0
Fork 0
forked from len0rd/rockbox

Move codec_get_file_pos somewhere else like the comment said should be done. Codec API version increment was needed so update all codecs.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16874 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2008-03-29 06:36:53 +00:00
parent d746b79317
commit 4855e734f3
4 changed files with 54 additions and 72 deletions

View file

@ -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 */

View file

@ -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. */

View file

@ -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;
}

View file

@ -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;