Experimental patch to remember resume offset for every file. The resume offset is stored in the tagcache for later retrieval. --- apps/playback.c | 24 ++++++++++++++++++++---- apps/tagcache.c | 11 +++++++++-- apps/tagcache.h | 8 ++++++-- apps/tagtree.c | 22 ++++++++++++++++++++++ 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/apps/playback.c b/apps/playback.c index 829a77e..3949634 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -998,7 +998,16 @@ static void audio_update_trackinfo(void) /* Reset current position */ thistrack_id3->elapsed = 0; - thistrack_id3->offset = 0; + + /* XXX: [HACK:] Heuristic for ignoring resume position: + automatic songchange, and new track is shorter than 20 min */ + if (automatic_skip && + thistrack_id3->length < 20L /*min*/ * 60L /* s */ * 1000L /* ms */) + { + thistrack_id3->offset = 0; + } + logf("audio_update_trackinfo: Set offset for %s to %lX\n", + thistrack_id3->title, thistrack_id3->offset); /* Update the codec API */ ci.filesize = CUR_TI->filesize; @@ -1210,6 +1219,9 @@ static bool audio_load_track(size_t offset, bool start_play) { copy_mp3entry(thistrack_id3, id3); thistrack_id3->offset = offset; + logf("audio_load_track: set offset for %s to %lX\n", + thistrack_id3->title, + offset); /* XXX */ } else memset(thistrack_id3, 0, sizeof(struct mp3entry)); @@ -1415,19 +1427,23 @@ static void audio_finish_load_track(void) return; } - /* All required data is now available for the codec. */ - tracks[track_widx].taginfo_ready = true; - if (start_play) { ci.curpos=file_offset; buf_request_buffer_handle(tracks[track_widx].audio_hid); } + int old_track_widx = track_widx; + track_widx = (track_widx + 1) & MAX_TRACK_MASK; send_event(PLAYBACK_EVENT_TRACK_BUFFER, track_id3); + /* XXX: Set taginfo_ready only after offset has been set in + PLAYBACK_EVENT_TRACK_BUFFER handling */ + /* All required data is now available for the codec. */ + tracks[old_track_widx].taginfo_ready = true; + /* load next track */ LOGFQUEUE("audio > audio Q_AUDIO_FILL_BUFFER"); queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0); diff --git a/apps/tagcache.c b/apps/tagcache.c index 5bff697..39aa3bf 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -191,7 +191,7 @@ static const char *tagfile_entry_ec = "ll"; /** Note: This should be (1 + TAG_COUNT) amount of l's. */ -static const char *index_entry_ec = "lllllllllllllllllllll"; +static const char *index_entry_ec = "llllllllllllllllllllll"; static const char *tagcache_header_ec = "lll"; static const char *master_header_ec = "llllll"; @@ -1697,6 +1697,10 @@ bool tagcache_fill_tags(struct mp3entry *id3, const char *filename) if (id3->bitrate == 0) id3->bitrate = 1; + id3->offset = get_tag_numeric(entry, tag_lastoffset, idx_id); /* XXX */ + logf("tagcache_fill_tags: Set offset for %s to %lX\n", + id3->title, id3->offset); + return true; } #endif @@ -2317,7 +2321,10 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd) tmpdb_copy_tag(tag_playtime); tmpdb_copy_tag(tag_lastplayed); tmpdb_copy_tag(tag_commitid); - + tmpdb_copy_tag(tag_lastoffset); /* XXX */ + logf("build_numeric_indices: got offset %X\n", + idx.tag_seek[tag_lastoffset]); + /* Avoid processing this entry again. */ idx.flag |= FLAG_RESURRECTED; diff --git a/apps/tagcache.h b/apps/tagcache.h index b52da76..189eaf1 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -29,10 +29,11 @@ Note: When adding new tags, make sure to update index_entry_ec in tagcache.c and bump up the header version too. */ +/* XXX: added tag_lastoffset */ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, tag_filename, tag_composer, tag_comment, tag_albumartist, tag_grouping, tag_year, tag_discnumber, tag_tracknumber, tag_bitrate, tag_length, tag_playcount, tag_rating, - tag_playtime, tag_lastplayed, tag_commitid, tag_mtime, + tag_playtime, tag_lastplayed, tag_commitid, tag_mtime, tag_lastoffset, /* Real tags end here, count them. */ TAG_COUNT, /* Virtual tags */ @@ -50,7 +51,9 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, #define IDX_BUF_DEPTH 64 /* Tag Cache Header version 'TCHxx'. Increment when changing internal structures. */ -#define TAGCACHE_MAGIC 0x5443480d +/* XXX: added tag_lastoffset */ +/* #define TAGCACHE_MAGIC 0x5443480d */ +#define TAGCACHE_MAGIC 0x5443480e /* How much to allocate extra space for ramcache. */ #define TAGCACHE_RESERVE 32768 @@ -103,6 +106,7 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, (1LU << tag_tracknumber) | (1LU << tag_length) | (1LU << tag_bitrate) | \ (1LU << tag_playcount) | (1LU << tag_rating) | (1LU << tag_playtime) | \ (1LU << tag_lastplayed) | (1LU << tag_commitid) | (1LU << tag_mtime) | \ + (1LU << tag_lastoffset) | \ (1LU << tag_virt_length_min) | (1LU << tag_virt_length_sec) | \ (1LU << tag_virt_playtime_min) | (1LU << tag_virt_playtime_sec) | \ (1LU << tag_virt_entryage) | (1LU << tag_virt_autoscore)) diff --git a/apps/tagtree.c b/apps/tagtree.c index 1e6885d..ecc3337 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -168,6 +168,9 @@ static int current_entry_count; static struct tree_context *tc; +/* Track change controls */ +extern bool automatic_skip; /* Who initiated in-progress skip? (C/A-) */ + static int get_token_str(char *buf, int size) { /* Find the start. */ @@ -239,6 +242,7 @@ static int get_tag(int *tag) MATCH(tag, buf, "playcount", tag_playcount); MATCH(tag, buf, "rating", tag_rating); MATCH(tag, buf, "lastplayed", tag_lastplayed); + MATCH(tag, buf, "lastoffset", tag_lastoffset); /* XXX */ MATCH(tag, buf, "commitid", tag_commitid); MATCH(tag, buf, "entryage", tag_virt_entryage); MATCH(tag, buf, "autoscore", tag_virt_autoscore); @@ -667,6 +671,17 @@ static void tagtree_buffer_event(void *data) id3->lastplayed = tagcache_get_numeric(&tcs, tag_lastplayed); id3->score = tagcache_get_numeric(&tcs, tag_virt_autoscore) / 10; id3->playtime = tagcache_get_numeric(&tcs, tag_playtime); + + logf("-> %ld/%ld", id3->playcount, id3->playtime); + + /* XXX: load current file resume offset if not already defined + (by another resume mechanism) */ + if (id3->offset == 0) + { + id3->offset = tagcache_get_numeric(&tcs, tag_lastoffset); + logf("tagtree_buffer_event: Set offset for %s to %lX\n", + id3->title, id3->offset); + } /* Store our tagcache index pointer. */ id3->tagcache_idx = tcs.idx_id+1; @@ -723,6 +738,13 @@ static void tagtree_track_finish_event(void *data) tagcache_update_numeric(tagcache_idx, tag_playcount, playcount); tagcache_update_numeric(tagcache_idx, tag_playtime, playtime); tagcache_update_numeric(tagcache_idx, tag_lastplayed, lastplayed); + + /* XXX: save current file resume offset */ + tagcache_update_numeric(tagcache_idx, tag_lastoffset, + automatic_skip ? 0 : id3->offset); + logf("tagtree_track_finish_event: Save offset for %s: %lX\n", + id3->title, automatic_skip ? 0 : id3->offset); + } bool tagtree_export(void) -- 1.7.1