summaryrefslogtreecommitdiff
path: root/apps/playlist.c
diff options
context:
space:
mode:
authorRichard Quirk <richard.quirk@gmail.com>2012-12-09 21:04:17 +0100
committerJonathan Gordon <rockbox@jdgordon.info>2013-01-02 08:29:38 +0100
commit212e7808d5f39e1d7fc1bd487de8f13c50d136f2 (patch)
treedc16ed3fc3a4857554e0d58d4a277d558eefab77 /apps/playlist.c
parent17181ecf30d2f7c73eba73309a35e770fab2c7ca (diff)
downloadrockbox-212e7808d5f39e1d7fc1bd487de8f13c50d136f2.tar.gz
rockbox-212e7808d5f39e1d7fc1bd487de8f13c50d136f2.zip
Use crc32 of filename to resume tracks
As well as using an index, which breaks when a file is added or removed, use the crc32 of the filename. When the crc32 check passes the index is used directly. When it fails, the slow path is taken checking each file name in the playlist until the right crc is found. If that fails the playlist is started from the beginning. See http://www.rockbox.org/tracker/6411 Bump plugin API and nvram version numbers Change-Id: I156f61a9f1ac428b4a682bc680379cb6b60b1b10 Reviewed-on: http://gerrit.rockbox.org/372 Tested-by: Jonathan Gordon <rockbox@jdgordon.info> Reviewed-by: Jonathan Gordon <rockbox@jdgordon.info>
Diffstat (limited to 'apps/playlist.c')
-rwxr-xr-xapps/playlist.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index c5e2e83462..35b7e35baa 100755
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -2514,6 +2514,44 @@ int playlist_shuffle(int random_seed, int start_index)
2514 return playlist->index; 2514 return playlist->index;
2515} 2515}
2516 2516
2517/* returns the crc32 of the filename of the track at the specified index */
2518unsigned int playlist_get_filename_crc32(struct playlist_info *playlist,
2519 int index)
2520{
2521 struct playlist_track_info track_info;
2522 if (playlist_get_track_info(playlist, index, &track_info) == -1)
2523 return -1;
2524
2525 return crc_32(track_info.filename, strlen(track_info.filename), -1);
2526}
2527
2528/* resume a playlist track with the given crc_32 of the track name. */
2529void playlist_resume_track(int start_index, unsigned int crc, int offset)
2530{
2531 int i;
2532 unsigned int tmp_crc;
2533 struct playlist_info* playlist = &current_playlist;
2534 tmp_crc = playlist_get_filename_crc32(playlist, start_index);
2535 if (tmp_crc == crc)
2536 {
2537 playlist_start(start_index, offset);
2538 return;
2539 }
2540
2541 for (i = 0 ; i < playlist->amount; i++)
2542 {
2543 tmp_crc = playlist_get_filename_crc32(playlist, i);
2544 if (tmp_crc == crc)
2545 {
2546 playlist_start(i, offset);
2547 return;
2548 }
2549 }
2550
2551 /* If we got here the file wasnt found, so start from the beginning */
2552 playlist_start(0,0);
2553}
2554
2517/* start playing current playlist at specified index/offset */ 2555/* start playing current playlist at specified index/offset */
2518void playlist_start(int start_index, int offset) 2556void playlist_start(int start_index, int offset)
2519{ 2557{
@@ -2726,7 +2764,9 @@ int playlist_update_resume_info(const struct mp3entry* id3)
2726 if (global_status.resume_index != playlist->index || 2764 if (global_status.resume_index != playlist->index ||
2727 global_status.resume_offset != id3->offset) 2765 global_status.resume_offset != id3->offset)
2728 { 2766 {
2767 unsigned int crc = crc_32(id3->path, strlen(id3->path), -1);
2729 global_status.resume_index = playlist->index; 2768 global_status.resume_index = playlist->index;
2769 global_status.resume_crc32 = crc;
2730 global_status.resume_offset = id3->offset; 2770 global_status.resume_offset = id3->offset;
2731 status_save(); 2771 status_save();
2732 } 2772 }
@@ -2734,6 +2774,7 @@ int playlist_update_resume_info(const struct mp3entry* id3)
2734 else 2774 else
2735 { 2775 {
2736 global_status.resume_index = -1; 2776 global_status.resume_index = -1;
2777 global_status.resume_crc32 = -1;
2737 global_status.resume_offset = -1; 2778 global_status.resume_offset = -1;
2738 status_save(); 2779 status_save();
2739 } 2780 }