Forward seeking fixed. Some comments added.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6700 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Miika Pekkarinen 2005-06-13 15:26:53 +00:00
parent 7dad7d3a6a
commit d94cba6d0f
3 changed files with 58 additions and 24 deletions

View file

@ -125,19 +125,19 @@ static volatile int buf_widx;
#define MAX_TRACK 10
struct track_info {
struct mp3entry id3;
struct mp3info mp3data;
char *codecbuf;
size_t codecsize;
int codectype;
struct mp3entry id3; /* TAG metadata */
struct mp3info mp3data; /* MP3 metadata */
char *codecbuf; /* Pointer to codec buffer */
size_t codecsize; /* Codec length in bytes */
int codectype; /* Codec type (example AFMT_MPA_L3) */
volatile char *filebuf;
off_t filerem;
off_t filesize;
off_t filepos;
volatile int available;
bool taginfo_ready;
int playlist_offset;
off_t filerem; /* Remaining bytes of file NOT in buffer */
off_t filesize; /* File total length */
off_t filepos; /* Read position of file for next buffer fill */
off_t start_pos; /* Position to first bytes of file in buffer */
volatile int available; /* Available bytes to read from buffer */
bool taginfo_ready; /* Is metadata read */
int playlist_offset; /* File location in playlist */
};
/* Track information (count in file buffer, read/write indexes for
@ -286,7 +286,11 @@ void codec_advance_buffer_callback(size_t amount)
if ((int)amount > cur_ti->available) {
codecbufused = 0;
buf_ridx = buf_widx;
buf_ridx = 0;
buf_widx = 0;
cur_ti->start_pos += amount;
amount -= cur_ti->available;
ci.curpos += cur_ti->available;
cur_ti->available = 0;
while ((int)amount < cur_ti->available && !ci.stop_codec)
yield();
@ -343,7 +347,8 @@ bool codec_seek_buffer_callback(off_t newpos)
if (ci.curpos - difference < 0)
difference = ci.curpos;
if (codecbufused + difference > codecbuflen) {
if (ci.curpos - difference < cur_ti->start_pos) {
logf("Seek failed (reload song)");
/* We need to reload the song. FIX THIS! */
return false;
}
@ -473,8 +478,9 @@ void audio_fill_file_buffer(void)
fill_bytesleft -= rc;
}
tracks[track_widx].filerem -= i;
codecbufused += i;
tracks[track_widx].filerem -= i;
tracks[track_widx].start_pos = tracks[track_widx].filepos;
tracks[track_widx].filepos += i;
logf("Done:%d", tracks[track_widx].available);
if (tracks[track_widx].filerem == 0) {
@ -653,7 +659,8 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
close(fd);
return false;
}
tracks[track_widx].filebuf = &codecbuf[buf_widx];
// tracks[track_widx].filebuf = &codecbuf[buf_widx];
tracks[track_widx].start_pos = 0;
//logf("%s", trackname);
logf("Buffering track:%d/%d", track_widx, track_ridx);
@ -681,6 +688,7 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
tracks[track_widx].filepos = offset;
tracks[track_widx].filerem = tracks[track_widx].filesize - offset;
ci.curpos = offset;
tracks[track_widx].start_pos = offset;
} else {
lseek(fd, 0, SEEK_SET);
}
@ -943,7 +951,7 @@ bool audio_load_track(int offset, bool start_play, int peek_offset)
track_changed = true;
track_count++;
i = tracks[track_widx].filepos;
i = tracks[track_widx].start_pos;
while (i < size) {
/* Give codecs some processing time to prevent glitches. */
yield_codecs();

View file

@ -20,6 +20,7 @@
#ifndef _AUDIO_H
#define _AUDIO_H
/* Supported file types. */
#define AFMT_MPA_L1 0x0001 // MPEG Audio layer 1
#define AFMT_MPA_L2 0x0002 // MPEG Audio layer 2
#define AFMT_MPA_L3 0x0004 // MPEG Audio layer 3
@ -36,6 +37,7 @@
#define AFMT_UNKNOWN 0x1000 // Unknown file format
#define AFMT_WAVPACK 0x2000 // WavPack
/* File buffer configuration keys. */
#define CODEC_SET_FILEBUF_WATERMARK 1
#define CODEC_SET_FILEBUF_CHUNKSIZE 2
#define CODEC_SET_FILEBUF_LIMIT 3
@ -43,32 +45,56 @@
/* Not yet implemented. */
#define CODEC_SET_AUDIOBUF_WATERMARK 4
/* Codec Interface */
struct codec_api {
off_t filesize;
off_t curpos;
size_t bitspersampe;
off_t filesize; /* Total file length */
off_t curpos; /* Current buffer position */
/* For gapless mp3 */
struct mp3entry *id3;
struct mp3info *mp3data;
bool *taginfo_ready;
struct mp3entry *id3; /* TAG metadata pointer */
struct mp3info *mp3data; /* MP3 metadata pointer */
bool *taginfo_ready; /* Is metadata read */
/* Codec should periodically check if stop_codec is set to true.
In case it's, codec must return with PLUGIN_OK status immediately. */
bool stop_codec;
/* Codec should periodically check if reload_codec is set to true.
In case it's, codec should reload itself without exiting. */
bool reload_codec;
/* If seek_time != 0, codec should seek to that song position (in ms)
if codec supports seeking. */
int seek_time;
/* Returns buffer to malloc array. Only codeclib should need this. */
void* (*get_codec_memory)(size_t *size);
/* Insert PCM data into audio buffer for playback. Playback will start
automatically. */
bool (*audiobuffer_insert)(char *data, size_t length);
/* Set song position in WPS (value in ms). */
void (*set_elapsed)(unsigned int value);
/* Read next <size> amount bytes from file buffer to <ptr>.
Will return number of bytes read or 0 if end of file. */
size_t (*read_filebuf)(void *ptr, size_t size);
/* Request pointer to file buffer which can be used to read
<realsize> amount of data. <reqsize> tells the buffer system
how much data it should try to allocate. If <realsize> is 0,
end of file is reached. */
void* (*request_buffer)(size_t *realsize, size_t reqsize);
/* Advance file buffer position by <amount> amount of bytes. */
void (*advance_buffer)(size_t amount);
/* Advance file buffer to a pointer location inside file buffer. */
void (*advance_buffer_loc)(void *ptr);
/* Seek file buffer to position <newpos> beginning of file. */
bool (*seek_buffer)(off_t newpos);
/* 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. */
bool (*request_next_track)(void);
/* Configure different codec buffer parameters. */
void (*configure)(int setting, void *value);
};

View file

@ -305,12 +305,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parm)
sample_loc = ci->seek_time/1000 * ci->id3->frequency;
newpos = ci->mp3_get_filepos(ci->seek_time-1);
if (ci->seek_buffer(newpos)) {
ci->seek_time = 0;
if (sample_loc >= samplecount + samplesdone)
break ;
samplecount += samplesdone - sample_loc;
samplesdone = sample_loc;
}
ci->seek_time = 0;
}
/* Lock buffers */