summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-09-29 17:42:03 +0200
committerChristian Soffke <christian.soffke@gmail.com>2024-10-26 11:28:01 -0400
commit7592d2ca5eab2e684f45b7a7163f1594f3c36c96 (patch)
treecee9b60519d66649f65369c8a842596a63b6b944 /apps
parentcb1346b640017a821105e8d8b4cc51640858c8d1 (diff)
downloadrockbox-7592d2ca5eab2e684f45b7a7163f1594f3c36c96.tar.gz
rockbox-7592d2ca5eab2e684f45b7a7163f1594f3c36c96.zip
playlist: deprecate PLAYLIST_COMMAND_CLEAR
In the following scenario, a garbage file name would be written to the control file for the playing track (resulting in a failure to resume correctly): - "Keep Current Track When Replacing Playlist" option is set - A track is playing that was not inserted but instead comes from a playlist file on disk - User performs "Playing Next..." -> "Play" on some tracks, so that the current playlist is replaced (but leaving the playing track queued) - User saves the playlist while queued track is still playing (the offer to remove queued tracks is declined) The failure occurs because the pl_save_update_control function assumes that the seek offset for queued files always points into the control file. Meanwhile, the remove_all_tracks_unlocked function adds the PLAYLIST_QUEUED flag indiscriminately, even if a track comes from a playlist file instead of having been inserted. Theoretically, this could be addressed by adding the playing track's file name as a parameter to PLAYLIST_COMMAND_CLEAR, which the track is then updated to point to, unless it was already inserted (alternatively, we could seek within the playlist file for such tracks). Unless I'm missing something, it may be preferable, though, to get rid of PLAYLIST_COMMAND_CLEAR completely, and instead have the remove_all_tracks_unlocked function start over with a fresh control file, into which we insert a single ('P' and) 'Q' command. This seems to have several advantages: - When resuming, we eliminate the need to parse and handle all of the outdated entries again that end up being cleared anyway - It is ensured that the control file doesn't rely on the existence of a playlist file anymore after the playlist has been cleared - We can reset the playlist's file name, which should make it less likely for the user to overwrite their previous (now unconnected) playlist that was still displayed in the Save dialog - Unrelated bookmarks for the previous playlist aren't displayed anymore - Improved consistency with existing behavior when the "Keep Current Track When Replacing Playlist" was disabled. Change-Id: I41a89295bbac878807d65db9cf67b8a485daf0e5
Diffstat (limited to 'apps')
-rw-r--r--apps/playlist.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index af5e1b5df0..23d3355708 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -138,9 +138,10 @@
138 * v4 added the (F)lags command. 138 * v4 added the (F)lags command.
139 * v5 added index to the (C)lear command. Added PLAYLIST_INSERT_LAST_ROTATED (-8) as 139 * v5 added index to the (C)lear command. Added PLAYLIST_INSERT_LAST_ROTATED (-8) as
140 * a supported position for (A)dd or (Q)eue commands. 140 * a supported position for (A)dd or (Q)eue commands.
141 * v6 removed the (C)lear command.
141 */ 142 */
142#define PLAYLIST_CONTROL_FILE_MIN_VERSION 2 143#define PLAYLIST_CONTROL_FILE_MIN_VERSION 2
143#define PLAYLIST_CONTROL_FILE_VERSION 5 144#define PLAYLIST_CONTROL_FILE_VERSION 6
144 145
145#define PLAYLIST_COMMAND_SIZE (MAX_PATH+12) 146#define PLAYLIST_COMMAND_SIZE (MAX_PATH+12)
146 147
@@ -436,9 +437,6 @@ static int update_control_unlocked(struct playlist_info* playlist,
436 case PLAYLIST_COMMAND_RESET: 437 case PLAYLIST_COMMAND_RESET:
437 result = write(fd, "R\n", 2); 438 result = write(fd, "R\n", 2);
438 break; 439 break;
439 case PLAYLIST_COMMAND_CLEAR:
440 result = fdprintf(fd, "C:%d\n", i1);
441 break;
442 case PLAYLIST_COMMAND_FLAGS: 440 case PLAYLIST_COMMAND_FLAGS:
443 result = fdprintf(fd, "F:%u:%u\n", i1, i2); 441 result = fdprintf(fd, "F:%u:%u\n", i1, i2);
444 break; 442 break;
@@ -1174,9 +1172,32 @@ static int create_and_play_dir(int direction, bool play_last)
1174 */ 1172 */
1175static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write) 1173static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write)
1176{ 1174{
1175 char filename[MAX_PATH];
1176 int seek_pos = -1;
1177
1177 if (playlist->amount <= 0) 1178 if (playlist->amount <= 0)
1178 return 0; 1179 return 0;
1179 1180
1181 if (write) /* Write control file commands to disk */
1182 {
1183 if (playlist->control_fd < 0)
1184 return -1;
1185
1186 if (get_track_filename(playlist, playlist->index,
1187 filename, sizeof(filename)) != 0)
1188 return -1;
1189
1190 /* Start over with fresh control file for emptied dynamic playlist */
1191 pl_close_control(playlist);
1192 create_control_unlocked(playlist);
1193 update_control_unlocked(playlist, PLAYLIST_COMMAND_PLAYLIST,
1194 PLAYLIST_CONTROL_FILE_VERSION, -1,
1195 "", "", NULL);
1196 update_control_unlocked(playlist, PLAYLIST_COMMAND_QUEUE,
1197 0, 0, filename, NULL, &seek_pos);
1198 sync_control_unlocked(playlist);
1199 }
1200
1180 /* Move current track down to position 0 */ 1201 /* Move current track down to position 0 */
1181 playlist->indices[0] = playlist->indices[playlist->index]; 1202 playlist->indices[0] = playlist->indices[playlist->index];
1182#ifdef HAVE_DIRCACHE 1203#ifdef HAVE_DIRCACHE
@@ -1190,22 +1211,25 @@ static int remove_all_tracks_unlocked(struct playlist_info *playlist, bool write
1190 1211
1191 /* Update playlist state as if by remove_track_unlocked() */ 1212 /* Update playlist state as if by remove_track_unlocked() */
1192 playlist->first_index = 0; 1213 playlist->first_index = 0;
1214 playlist->index = 0;
1193 playlist->amount = 1; 1215 playlist->amount = 1;
1194 playlist->indices[0] |= PLAYLIST_QUEUED; 1216 playlist->indices[0] |= PLAYLIST_QUEUED;
1217 playlist->flags = 0; /* Reset dirplay and modified flags */
1195 1218
1196 if (playlist->last_insert_pos == 0) 1219 if (playlist->last_insert_pos == 0)
1197 playlist->last_insert_pos = -1; 1220 playlist->last_insert_pos = -1;
1198 else 1221 else
1199 playlist->last_insert_pos = 0; 1222 playlist->last_insert_pos = 0;
1200 1223
1201 if (write && playlist->control_fd >= 0) 1224 if (seek_pos == -1)
1202 { 1225 return 0;
1203 update_control_unlocked(playlist, PLAYLIST_COMMAND_CLEAR,
1204 playlist->index, -1, NULL, NULL, NULL);
1205 sync_control_unlocked(playlist);
1206 }
1207 1226
1208 playlist->index = 0; 1227 /* Update seek offset so it points into the new control file. */
1228 playlist->indices[0] &= ~PLAYLIST_INSERT_TYPE_MASK & ~PLAYLIST_SEEK_MASK;
1229 playlist->indices[0] |= PLAYLIST_INSERT_TYPE_INSERT | seek_pos;
1230
1231 /* Cut connection to playlist file */
1232 update_playlist_filename_unlocked(playlist, "", "");
1209 1233
1210 return 0; 1234 return 0;
1211} 1235}
@@ -3402,6 +3426,8 @@ int playlist_resume(void)
3402 playlist->last_insert_pos = -1; 3426 playlist->last_insert_pos = -1;
3403 break; 3427 break;
3404 } 3428 }
3429 /* FIXME: Deprecated.
3430 * Adjust PLAYLIST_CONTROL_FILE_MIN_VERSION after removal */
3405 case PLAYLIST_COMMAND_CLEAR: 3431 case PLAYLIST_COMMAND_CLEAR:
3406 { 3432 {
3407 if (strp[0]) 3433 if (strp[0])
@@ -3960,11 +3986,12 @@ static int pl_save_update_control(struct playlist_info* playlist,
3960 playlist->last_insert_pos = rotate_index(playlist, playlist->last_insert_pos); 3986 playlist->last_insert_pos = rotate_index(playlist, playlist->last_insert_pos);
3961 playlist->first_index = 0; 3987 playlist->first_index = 0;
3962 } 3988 }
3963 3989
3964 for (int index = 0; index < playlist->amount; ++index) 3990 for (int index = 0; index < playlist->amount; ++index)
3965 { 3991 {
3966 /* We only need to update queued files */ 3992 /* We only need to update queued files */
3967 if (!(playlist->indices[index] & PLAYLIST_QUEUED)) 3993 if (!(playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK &&
3994 playlist->indices[index] & PLAYLIST_QUEUED))
3968 continue; 3995 continue;
3969 3996
3970 /* Read filename from old control file */ 3997 /* Read filename from old control file */