aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Dawson <mike@gp2x.org>2009-08-30 19:49:16 +0200
committerMax Kellermann <max@duempel.org>2009-08-30 19:49:16 +0200
commit430b5b049091a432946ca3a3242f7b79ac7a3cdf (patch)
tree0c4c2361956319feaa2375be06ef92f17f07b84b
parentcde9408bd883e6ea67c9c2ced3f928bc9c044eb5 (diff)
downloadmpd-430b5b049091a432946ca3a3242f7b79ac7a3cdf.tar.gz
mpd-430b5b049091a432946ca3a3242f7b79ac7a3cdf.tar.xz
mpd-430b5b049091a432946ca3a3242f7b79ac7a3cdf.zip
decoder/sidplay: support seeking
-rw-r--r--NEWS1
-rw-r--r--src/decoder/sidplay_plugin.cxx37
2 files changed, 35 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index e06543b8c..e311d94f9 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ ver 0.16 (20??/??/??)
- mpg123: new decoder plugin based on libmpg123
- sidplay: support sub-tunes
- sidplay: implemented songlength database
+ - sidplay: support seeking
* encoders:
- twolame: new encoder plugin based on libtwolame
* output:
diff --git a/src/decoder/sidplay_plugin.cxx b/src/decoder/sidplay_plugin.cxx
index f490586ac..5228dbe89 100644
--- a/src/decoder/sidplay_plugin.cxx
+++ b/src/decoder/sidplay_plugin.cxx
@@ -198,6 +198,9 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
int song_num=get_song_num(path_fs);
tune.selectSong(song_num);
+ int song_len=get_song_length(path_fs);
+ if(song_len==-1) song_len=default_songlength;
+
/* initialize the player */
sidplay2 player;
@@ -259,10 +262,12 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
struct audio_format audio_format;
audio_format_init(&audio_format, 48000, 16, 2);
- decoder_initialized(decoder, &audio_format, false, -1);
+ decoder_initialized(decoder, &audio_format, true, (float)song_len);
/* .. and play */
+ float data_time=0;
+ int timebase=player.timebase();
enum decoder_command cmd;
do {
char buffer[4096];
@@ -273,8 +278,34 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
break;
cmd = decoder_data(decoder, NULL, buffer, nbytes,
- 0, 0, NULL);
- } while (cmd == DECODE_COMMAND_NONE);
+ data_time, 0, NULL);
+
+ data_time=player.time()/timebase;
+
+ if(cmd==DECODE_COMMAND_SEEK) {
+ int target_time=decoder_seek_where(decoder);
+
+ /* can't rewind so return to zero and seek forward */
+ if(target_time<data_time) {
+ player.stop();
+ data_time=0;
+ }
+
+ /* ignore data until target time is reached */
+ while(data_time<target_time) {
+ nbytes=player.play(buffer, sizeof(buffer));
+ if(nbytes==0)
+ break;
+ data_time=player.time()/timebase;
+ }
+
+ decoder_command_finished(decoder);
+ }
+
+ if(song_len && data_time>=(float)song_len)
+ break;
+
+ } while (cmd != DECODE_COMMAND_STOP);
}
static struct tag *