diff options
author | Ryan Jackson <rdjackso@rockbox.org> | 2005-07-12 16:45:38 +0000 |
---|---|---|
committer | Ryan Jackson <rdjackso@rockbox.org> | 2005-07-12 16:45:38 +0000 |
commit | d1917562864754fd01f735311f15e028554f30bc (patch) | |
tree | 3e2c7c91e8966e6e7a48fcdf64a771624928a86c | |
parent | 40a8401cd35cef71b0ffa017106ee156fb3239ed (diff) | |
download | rockbox-d1917562864754fd01f735311f15e028554f30bc.tar.gz rockbox-d1917562864754fd01f735311f15e028554f30bc.zip |
Resume now starts playback at the point it was stopped, not 2-7 seconds later.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7125 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs.c | 3 | ||||
-rw-r--r-- | apps/codecs.h | 1 | ||||
-rw-r--r-- | apps/codecs/vorbis.c | 4 | ||||
-rw-r--r-- | apps/playback.c | 22 |
4 files changed, 26 insertions, 4 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index dd87ddf0ed..b1d30868bc 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -244,6 +244,7 @@ struct codec_api ci = { #endif memchr, + NULL, }; int codec_load_ram(char* codecptr, int size, void* ptr2, int bufwrap) @@ -292,7 +293,7 @@ int codec_load_file(const char *plugin) /* zero out codec buffer to ensure a properly zeroed bss area */ memset(codecbuf, 0, CODEC_SIZE); - + fd = open(plugin, O_RDONLY); if (fd < 0) { snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", plugin); diff --git a/apps/codecs.h b/apps/codecs.h index 4d8c95eab0..a675245d27 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -327,6 +327,7 @@ struct codec_api { #endif void *(*memchr)(const void *s1, int c, size_t n); + void (*set_offset)(unsigned int value); }; /* defined by the codec loader (codec.c) */ diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index 82ebdbf1f5..03f1ae95b5 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -227,8 +227,8 @@ enum codec_status codec_start(struct codec_api* api) if ( rb->id3->offset ) { rb->advance_buffer(rb->id3->offset); ov_raw_seek(&vf,rb->id3->offset); - rb->id3->offset = ov_raw_tell(&vf); rb->set_elapsed(ov_time_tell(&vf)); + rb->set_offset(ov_raw_tell(&vf)); } eof=0; @@ -272,7 +272,7 @@ enum codec_status codec_start(struct codec_api* api) } } if ( !rb->seek_time ) { - rb->id3->offset = ov_raw_tell(&vf); + rb->set_offset(ov_raw_tell(&vf)); rb->set_elapsed(ov_time_tell(&vf)); rb->yield(); } diff --git a/apps/playback.c b/apps/playback.c index 7c8be5d405..671312583b 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -370,6 +370,25 @@ void codec_set_elapsed_callback(unsigned int value) } } +void codec_set_offset_callback(unsigned int value) +{ + unsigned int latency; + + if (ci.stop_codec) + return ; + + /* The 1000 here is a hack. audiobuffer_get_latency() should + * be more accurate + */ + latency = (audiobuffer_get_latency() + 1000) * cur_ti->id3.bitrate / 8; + + if (value < latency) { + cur_ti->id3.offset = 0; + } else if (value - latency > (unsigned int)cur_ti->id3.offset ) { + cur_ti->id3.offset = value - latency; + } +} + long codec_filebuf_callback(void *ptr, long size) { char *buf = (char *)ptr; @@ -498,7 +517,7 @@ void codec_advance_buffer_callback(long amount) cur_ti->available -= amount; codecbufused -= amount; ci.curpos += amount; - cur_ti->id3.offset = ci.curpos; + codec_set_offset_callback(ci.curpos); } void codec_advance_buffer_loc_callback(void *ptr) @@ -1896,6 +1915,7 @@ void audio_init(void) ci.mp3_get_filepos = codec_mp3_get_filepos_callback; ci.seek_buffer = codec_seek_buffer_callback; ci.set_elapsed = codec_set_elapsed_callback; + ci.set_offset = codec_set_offset_callback; ci.configure = codec_configure_callback; mutex_init(&mutex_bufferfill); |