diff options
| author | Brandon Low <lostlogic@rockbox.org> | 2006-04-15 02:03:11 +0000 |
|---|---|---|
| committer | Brandon Low <lostlogic@rockbox.org> | 2006-04-15 02:03:11 +0000 |
| commit | ebadcc633ae8ad2a6048aff9c815cdb37f012e44 (patch) | |
| tree | 2749a0dccbec61669b99d83867b7cf18c661f3e0 | |
| parent | ae33f37678311c5d6893aa526fad947bce912eff (diff) | |
| download | rockbox-ebadcc633ae8ad2a6048aff9c815cdb37f012e44.zip rockbox-ebadcc633ae8ad2a6048aff9c815cdb37f012e44.tar.gz rockbox-ebadcc633ae8ad2a6048aff9c815cdb37f012e44.tar.bz2 rockbox-ebadcc633ae8ad2a6048aff9c815cdb37f012e44.tar.xz | |
Put new_track on the codec_api, and use it instead of the reload_codec variable in most places. Should help with problems people have had with GUI vs. playback sync.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9670 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/codecs.c | 33 | ||||
| -rw-r--r-- | apps/codecs.h | 16 | ||||
| -rw-r--r-- | apps/codecs/a52.c | 2 | ||||
| -rw-r--r-- | apps/codecs/aac.c | 4 | ||||
| -rw-r--r-- | apps/codecs/aiff.c | 2 | ||||
| -rw-r--r-- | apps/codecs/alac.c | 2 | ||||
| -rw-r--r-- | apps/codecs/flac.c | 2 | ||||
| -rw-r--r-- | apps/codecs/mpa.c | 2 | ||||
| -rw-r--r-- | apps/codecs/mpc.c | 2 | ||||
| -rw-r--r-- | apps/codecs/shorten.c | 2 | ||||
| -rw-r--r-- | apps/codecs/vorbis.c | 2 | ||||
| -rw-r--r-- | apps/codecs/wav.c | 2 | ||||
| -rw-r--r-- | apps/codecs/wavpack.c | 4 | ||||
| -rw-r--r-- | apps/playback.c | 51 |
14 files changed, 59 insertions, 67 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index c332d7a..9a0688b 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -73,22 +73,23 @@ struct codec_api ci = { NULL, /* id3 */ NULL, /* taginfo_ready */ false, /* stop_codec */ - false, /* reload_codec */ + 0, /* new_track */ 0, /* seek_time */ - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, + NULL, /* get_codec_memory */ + NULL, /* pcmbuf_insert */ + NULL, /* pcmbuf_insert_split */ + NULL, /* set_elapsed */ + NULL, /* read_filebuf */ + NULL, /* request_buffer */ + NULL, /* advance_buffer */ + NULL, /* advance_buffer_loc */ + NULL, /* seek_buffer */ + NULL, /* seek_complete */ + NULL, /* mp3_get_filepos */ + NULL, /* request_next_track */ + NULL, /* discard_codec */ + NULL, /* set_offset */ + NULL, /* configure */ gui_syncsplash, @@ -210,8 +211,6 @@ struct codec_api ci = { /* new stuff at the end, sort into place next time the API gets incompatible */ - NULL, /* discard_codec */ - }; int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap, diff --git a/apps/codecs.h b/apps/codecs.h index 1bc37ad..5d85a42 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -85,12 +85,12 @@ #define CODEC_MAGIC 0x52434F44 /* RCOD */ /* increase this every time the api struct changes */ -#define CODEC_API_VERSION 7 +#define CODEC_API_VERSION 8 /* 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 6 +#define CODEC_MIN_API_VERSION 8 /* codec return codes */ enum codec_status { @@ -115,11 +115,11 @@ struct codec_api { 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. */ + In case it is, codec must return 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; + /* Codec should periodically check if new_track is non zero. + When it is, the codec should request a new track. */ + int new_track; /* If seek_time != 0, codec should seek to that song position (in ms) if codec supports seeking. */ long seek_time; @@ -155,6 +155,8 @@ struct codec_api { track is available and changed. If return value is false, codec should exit immediately with PLUGIN_OK status. */ bool (*request_next_track)(void); + /* Free the buffer area of the current codec after its loaded */ + void (*discard_codec)(void); void (*set_offset)(size_t value); /* Configure different codec buffer parameters. */ @@ -287,8 +289,6 @@ struct codec_api { /* new stuff at the end, sort into place next time the API gets incompatible */ - void (*discard_codec)(void); - }; /* codec header */ diff --git a/apps/codecs/a52.c b/apps/codecs/a52.c index 5a55d8b..8ad9d37 100644 --- a/apps/codecs/a52.c +++ b/apps/codecs/a52.c @@ -164,7 +164,7 @@ next_track: /* The main decoding loop */ samplesdone = 0; while (1) { - if (ci->stop_codec || ci->reload_codec) + if (ci->stop_codec || ci->new_track) break; if (ci->seek_time) { diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index ddaa07c..02d4606 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -68,7 +68,7 @@ enum codec_status codec_start(struct codec_api* api) ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(29)); - next_track: +next_track: if (codec_init(api)) { LOGF("FAAD: Error initialising codec\n"); @@ -122,7 +122,7 @@ enum codec_status codec_start(struct codec_api* api) /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { rb->yield(); - if (ci->stop_codec || ci->reload_codec) { + if (ci->stop_codec || ci->new_track) { break; } diff --git a/apps/codecs/aiff.c b/apps/codecs/aiff.c index 144f462..20d2dd3 100644 --- a/apps/codecs/aiff.c +++ b/apps/codecs/aiff.c @@ -219,7 +219,7 @@ next_track: while (!endofstream) { ci->yield(); - if (ci->stop_codec || ci->reload_codec) + if (ci->stop_codec || ci->new_track) break; if (ci->seek_time) { diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c index 0db3c80..73f45fc 100644 --- a/apps/codecs/alac.c +++ b/apps/codecs/alac.c @@ -101,7 +101,7 @@ enum codec_status codec_start(struct codec_api* api) /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { rb->yield(); - if (ci->stop_codec || ci->reload_codec) { + if (ci->stop_codec || ci->new_track) { break; } diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c index 2eec4da..cc2ce63 100644 --- a/apps/codecs/flac.c +++ b/apps/codecs/flac.c @@ -275,7 +275,7 @@ enum codec_status codec_start(struct codec_api* api) buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); while (bytesleft) { ci->yield(); - if (ci->stop_codec || ci->reload_codec) { + if (ci->stop_codec || ci->new_track) { break; } diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 787d669..7219095 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -155,7 +155,7 @@ enum codec_status codec_start(struct codec_api *api) int framelength; ci->yield(); - if (ci->stop_codec || ci->reload_codec) + if (ci->stop_codec || ci->new_track) break; if (ci->seek_time) { diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 3d3a23e..4201b25 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c @@ -164,7 +164,7 @@ next_track: ci->seek_complete(); } #endif - if (ci->stop_codec || ci->reload_codec) + if (ci->stop_codec || ci->new_track) break; status = mpc_decoder_decode(&decoder, sample_buffer, NULL, NULL); diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c index 2cfb4c9..03a0802 100644 --- a/apps/codecs/shorten.c +++ b/apps/codecs/shorten.c @@ -123,7 +123,7 @@ seek_start: buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE); while (bytesleft) { ci->yield(); - if (ci->stop_codec || ci->reload_codec) { + if (ci->stop_codec || ci->new_track) { break; } diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index fb50859..a9a2745 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -207,7 +207,7 @@ next_track: eof = 0; while (!eof) { rb->yield(); - if (rb->stop_codec || rb->reload_codec) + if (rb->stop_codec || rb->new_track) break; if (rb->seek_time) { diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c index 70d4144..c89d121 100644 --- a/apps/codecs/wav.c +++ b/apps/codecs/wav.c @@ -432,7 +432,7 @@ next_track: while (!endofstream) { ci->yield(); - if (ci->stop_codec || ci->reload_codec) { + if (ci->stop_codec || ci->new_track) { break; } diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c index febea1e..f864aa3 100644 --- a/apps/codecs/wavpack.c +++ b/apps/codecs/wavpack.c @@ -129,12 +129,12 @@ enum codec_status codec_start(struct codec_api* api) nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / nchans); - if (!nsamples || ci->stop_codec || ci->reload_codec) + if (!nsamples || ci->stop_codec || ci->new_track) break; ci->yield (); - if (ci->stop_codec || ci->reload_codec) + if (ci->stop_codec || ci->new_track) break; while (!ci->pcmbuf_insert ((char *) temp_buffer, nsamples * nchans * 4)) diff --git a/apps/playback.c b/apps/playback.c index 26eec2b..cb2cbac 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -222,9 +222,7 @@ static bool playlist_end = false; extern struct codec_api ci; extern struct codec_api ci_voice; -/* When we change a song and buffer is not in filling state, this - variable keeps information about whether to go a next/previous track. */ -static volatile int new_track; +/* Was the skip being executed manual or automatic? */ static volatile bool manual_skip; /* Callback function to call when current track has really changed. */ @@ -324,13 +322,13 @@ bool codec_pcmbuf_insert_split_callback(const void *ch1, const void *ch2, else { /* Prevent audio from a previous position from hitting the buffer */ - if (ci.reload_codec || ci.stop_codec) + if (ci.new_track || ci.stop_codec) return true; while ((dest = pcmbuf_request_buffer(est_output_size, &output_size)) == NULL) { sleep(1); - if (ci.seek_time || ci.reload_codec || ci.stop_codec) + if (ci.seek_time || ci.new_track || ci.stop_codec) return true; } } @@ -526,7 +524,7 @@ size_t codec_filebuf_callback(void *ptr, size_t size) while (copy_n > cur_ti->available) { queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0); yield(); - if (ci.stop_codec || ci.reload_codec) + if (ci.stop_codec || ci.new_track) return 0; } @@ -608,7 +606,7 @@ void* codec_request_buffer_callback(size_t *realsize, size_t reqsize) while (copy_n > cur_ti->available) { queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0); yield(); - if (ci.stop_codec || ci.reload_codec) { + if (ci.stop_codec || ci.new_track) { *realsize = 0; return NULL; } @@ -789,33 +787,33 @@ static void audio_check_new_track(bool require_codec) bool forward; /* If the playlist isn't that big */ - if (!playlist_check(new_track)) + if (!playlist_check(ci.new_track)) { - if (new_track >= 0) + if (ci.new_track >= 0) { queue_post(&codec_callback_queue, Q_CODEC_REQUEST_FAILED, 0); return; } /* Find the beginning backward if the user over-skips it */ - while (!playlist_check(++new_track)) - if (new_track >= 0) + while (!playlist_check(++ci.new_track)) + if (ci.new_track >= 0) { queue_post(&codec_callback_queue, Q_CODEC_REQUEST_FAILED, 0); return; } } /* Update the playlist */ - last_peek_offset -= new_track; - playlist_next(new_track); + last_peek_offset -= ci.new_track; + playlist_next(ci.new_track); - track_ridx+=new_track; + track_ridx+=ci.new_track; if (track_ridx >= MAX_TRACK) track_ridx -= MAX_TRACK; else if (track_ridx < 0) track_ridx += MAX_TRACK; - forward = new_track > 0; - new_track = 0; + forward = ci.new_track > 0; + ci.new_track = 0; /* Save the old track */ prev_ti = cur_ti; @@ -825,7 +823,7 @@ static void audio_check_new_track(bool require_codec) track_changed = manual_skip; /* If it is not safe to even skip this many track entries */ - if (new_track >= track_count || new_track <= track_count - MAX_TRACK) + if (ci.new_track >= track_count || ci.new_track <= track_count - MAX_TRACK) { cur_ti->taginfo_ready = false; audio_rebuffer(); @@ -1695,7 +1693,7 @@ static void audio_play_start(size_t offset) playlist_end = false; playing = true; - ci.reload_codec = false; + ci.new_track = 0; ci.seek_time = 0; if (current_fd >= 0) { @@ -1842,9 +1840,9 @@ static bool load_next_track(bool require_codec) { logf("Request new track"); - if (new_track == 0) + if (ci.new_track == 0) { - new_track++; + ci.new_track++; manual_skip = false; } else @@ -1889,14 +1887,12 @@ static bool codec_request_next_track_callback(void) get_codec_base_type(cur_ti->id3.codectype)) { logf("New track loaded"); - ci.reload_codec = false; codec_discard_codec_callback(); return true; } else { logf("New codec:%d/%d", cur_ti->id3.codectype, prev_ti->id3.codectype); - ci.reload_codec = true; return false; } } @@ -1930,8 +1926,7 @@ void audio_invalidate_tracks(void) static void initiate_track_change(long direction) { playlist_end = false; - new_track += direction; - ci.reload_codec = true; + ci.new_track += direction; track_changed = true; } @@ -1940,7 +1935,6 @@ static void initiate_dir_change(long direction) if(!playlist_next_dir(direction)) return; - ci.reload_codec = true; queue_post(&audio_queue, Q_AUDIO_PLAY, 0); } @@ -2116,7 +2110,7 @@ void codec_thread(void) case Q_CODEC_LOAD_DISK: case Q_CODEC_LOAD: if (playing) { - if (new_track || ci.reload_codec || status == CODEC_OK) { + if (ci.new_track || status == CODEC_OK) { logf("Codec finished"); if (ci.stop_codec) queue_post(&audio_queue, Q_AUDIO_STOP, 0); @@ -2133,7 +2127,6 @@ void codec_thread(void) queue_post(&audio_queue, Q_AUDIO_STOP, 0); } } - ci.reload_codec = false; } } } @@ -2233,7 +2226,7 @@ struct mp3entry* audio_current_track(void) const char *filename; const char *p; static struct mp3entry temp_id3; - int cur_idx = track_ridx + new_track; + int cur_idx = track_ridx + ci.new_track; if (cur_idx >= MAX_TRACK) cur_idx += MAX_TRACK; @@ -2245,7 +2238,7 @@ struct mp3entry* audio_current_track(void) memset(&temp_id3, 0, sizeof(struct mp3entry)); - filename = playlist_peek(new_track); + filename = playlist_peek(ci.new_track); if (!filename) filename = "No file!"; |