Commit graph

357 commits

Author SHA1 Message Date
roman.artiukhin
67b98292a3 Temp quick fix for broken bookmarks
Mark playlist as not modified in playlist_resume

Change-Id: I8a9769a1fc1265f024da230e496eac9a10186097
2023-04-22 12:58:18 -04:00
Aidan MacDonald
2e99e2175b playlist: Remove control file cache
Control cache entries cost 24 bytes per command, but cacheable
commands are always less than that when written out to the file.
We can actually cache *more* data by writing commands directly
to the fd (native Rockbox has a 512-byte cache per fd) and it's
much simpler.

Change-Id: Ibb1b9ffa56ef17431b281419a04082e14d0cbd85
2023-03-24 19:02:56 +00:00
Aidan MacDonald
a4cfa8ae6a playlist: Unconditionally strip bogus dirs in playlist_peek()
The intent behind the check is to only do this if the filename
comes from an on-disk file. With the RAM buffer is gone this is
now "always" the case.

Change-Id: I4c26e32c482dde176b69a6071e9562e9955d7171
2023-03-24 19:02:56 +00:00
Aidan MacDonald
1f1893f520 playlist: Remove in-ram filename storage
Use the playlist control file for directory playback instead of
storing filenames in RAM. The implementation of that feature is
very iffy and probably responsible for random crashes that may
occur when skipping through directories rapidly.

Change-Id: I3863940cd4542410d8046a3ca47508b5d97309a1
2023-03-24 11:10:12 +00:00
Aidan MacDonald
ac1cbd5dd0 playlist: Clean up close_playlist_control_file()
Move locking outside the function since most callers already
hold the lock.

Change-Id: I4b6774e2322c86962b4cc7a5f33d13cd4ffb1c7b
2023-03-24 11:10:12 +00:00
Aidan MacDonald
e6534b051e playlist: Add helpers for opening/closing .m3u playlist
This helps maintainability and ensures the opening is done
consistently.

Change-Id: I7805716182dfa93f917d54d40f8e420e87da16b0
2023-03-24 06:36:23 -04:00
Aidan MacDonald
5eb24a9582 playlist: Cleanup get_next_dir()
Pass the direction as a signed integer to avoid jumping through
unnecessary hoops.

Change-Id: I1a36c3804b5f7103464f0d2ee69d060505261274
2023-03-24 06:12:01 -04:00
Aidan MacDonald
a64cad847e playlist: Simplify playlist modified detection
Any modifications to the playlist (insert, delete, shuffle, etc)
will cause the modified flag to be set. The flag is cleared when
the playlist is saved. Code that generates playlists can manually
clear the modified flag if appropriate; there is now a proper API
for this so the tagcache and pictureflow don't need to resort to
hacks.

Change-Id: I8d3c723265a41db07a13de3f1d2abb0444528d57
2023-03-23 13:01:23 -04:00
Aidan MacDonald
78718aa7eb playlist: Annotate locks as read/write
Distinguish read locks from write locks to aid converting the
mutex to an MRSW lock at some point in the future. Everything
is a write lock for now and a mutex is still used, so there's
no change in behavior.

Change-Id: I25aeed580580bdb0c3048fc7e1eaad1c32c30159
2023-01-29 08:24:48 -05:00
Aidan MacDonald
25bd3bc971 playlist: Optimize playlist_remove_all_tracks()
This was insanely slow for large playlists. Implement it as a
constant-time operation to avoid the O(N!) blowup, and add a
new "clear" command to the control file to avoid flooding it
with individual delete commands.

Change-Id: Ied82d1cba015591edd583f2a2ff6772108f4e176
2023-01-29 07:55:10 -05:00
Aidan MacDonald
2c4546ba99 playlist: Remove unused PLAYLIST_DELETE_CURRENT
Change-Id: I4d1a8798aca249d343ca27a9973213d427b73963
2023-01-29 07:32:26 -05:00
Aidan MacDonald
c0c1a6e5f0 Fix yellow 65b3ff81c5
Change-Id: Ibf99e4e6f98021b35d420520219287336bf25f0e
2023-01-23 14:46:02 +00:00
Aidan MacDonald
65b3ff81c5 playlist: Fix dircache scan thread deadlocks
Fix deadlocks in the dircache scan thread caused by incorrect
lock ordering. Mutating operations need to stop the thread to
prevent it from accessing invalid data; this must always be
done before taking the playlist lock to avoid deadlocking the
scan thread.

Change-Id: If719a8b28ed0b0b3eac068073581e606c4a5f58a
2023-01-23 12:24:12 +00:00
Aidan MacDonald
ce52d0c870 playlist: Fix mutex initialization
This is a one-time thing; make sure it doesn't happen more than once.

Change-Id: Ic42f48e5714dff2906c252ecd091989d2d6e5a86
2023-01-23 12:24:12 +00:00
Aidan MacDonald
2a40d42012 playlist: Refactor control cache flush
Make background control file flushing work on non-dircache targets.
It has nothing to do with dircache and doesn't belong in the dircache
scan thread.

Change-Id: I3f39261ccaebb5dce69e7db3d2e0c0c0c54f640b
2023-01-23 12:24:12 +00:00
Aidan MacDonald
fcb6239aba playlist: Remove current flag
Only current_playlist will have it set, so compare pointers instead.

Change-Id: I46dc7baef9699990962176db7c8796bba1e4809d
2023-01-23 12:24:12 +00:00
Aidan MacDonald
c307d98e3f playlist: pin dircache fileref buffer during background scanning
dircache_search() can yield, which would lead to memory corruption
if the playlist dcfrefs buffer is moved at that point. Prevent this
from happening by storing the buflib handle and pinning the buffer
while scanning the dircache.

Change-Id: I28b122de283953dd6d54c1d00598759f5bdcbe93
2023-01-22 13:47:50 +00:00
William Wilgus
1b383ef480 chunk alloc add buflib_get_pinned and chunk caching
Change-Id: Ia581656793b8ce9b80545705cfbba0fb225bb616
2023-01-19 00:04:25 -05:00
Aidan MacDonald
aae34b2e7f playlist: enable queue send
Apparently queue_send() silently falls back to queue_post()
if sending isn't enabled. Doesn't seem like a good idea, as
post and send are definitely *not* interchangeable!

The playlist code relies on queue_send()'s blocking behavior
to prevent the dircache thread from using potentially stale
pointers.

Change-Id: Ibf4b0def3bf9c96cb2fe80cd75043b7ce1dcf250
2023-01-16 16:57:23 +00:00
Aidan MacDonald
1e9ad3ca0d Remove buflib allocation names, part two
Remove allocation names from the buflib API and fix up all callers.

Change-Id: I3df922e258d5f0d711d70e72b56b4ed634fb0f5a
2023-01-13 10:32:54 +00:00
William Wilgus
2d9cb673e5 add chunk_alloc to playlist.c #2
dc_thread_playlist was asking for invalid indices
since previously the name buffer would have been valid
it just got whatever junk data was left over

add dc_discard_playlist_pointers for HAVE_DIRCACHE targets
this allows the dc_playlist_thread to stop its current lookup loop

Change-Id: I6f25b97b8c4e314d27c5e1e6ff0925b5a3e93f26
2023-01-12 19:36:38 -05:00
William Wilgus
00c7817c9c [BugFix] playlist.c DIRCACHE stop scanning when changing indices
dc_playlist_thread may continue loading pointers even while
underlying indices are changing instead stop the loop by marking
pointers as clean and rebuild later

Change-Id: If154f673b4af8d6e9c364499d58f1321834a76a4
2023-01-12 19:36:38 -05:00
William Wilgus
746fd7f2db Revert "add chunk_alloc to playlist.c"
This reverts commit 89c021fbfa.

Reason for revert: crash when playing on disk playlist then playing a directory as an in-ram playlist

Change-Id: Ia5cf5da9f46f8c10c5c0f3707e7978c05664b8a4
2023-01-11 01:14:22 -05:00
William Wilgus
89c021fbfa add chunk_alloc to playlist.c
Change-Id: Ia2e02a61f0b269dc0508717a56a2ca1a334d2378
2023-01-10 23:59:19 -05:00
William Wilgus
282a54b23c [Feature] filetree fallback to loading a playlist from disk
give user option to load playlist from disk when
namebuffer is too small -- max_playlist size still
limits the total entries but filename length
 won't stop them from playing the directory

Change-Id: I1787689417661ea670a211f575f2c52e84465869
2023-01-08 09:52:23 -05:00
Aidan MacDonald
5bb062391f playlist.c fix old out of bounds read
In case next_index == -1, this would read before the start of
the playlist->indices buffer.

Change-Id: I0a32a31c7c97c755a1217b8bea90a650f9e36a93
2023-01-06 14:19:28 -05:00
William Wilgus
152a238947 playlist add mutex to public functions
mutexes are in just trying to refactor the rest and make it a smaller
and more robust system

--Done

Change-Id: If64807c3e0ee1966f7593795f26f1f538caf831b
2022-12-06 23:40:02 -05:00
William Wilgus
f033fd390e Fix Red playlist update a few functions
Change-Id: I0d9b4c8f7e4b128dd7378c6b7515f8195534fce7
2022-12-03 06:49:07 -05:00
William Wilgus
03c225fe54 playlist.c clean-up and organize
No functional changes

Change-Id: I5c7a4a63c54bc867b7d6c2ca6cbc8ef135e01a90
2022-12-03 06:28:48 -05:00
William Wilgus
773fa7874d RFC playlist.c add_indices_to_playlist() seek back to start of file
get_filename() changes the seek pos with out restoring it
seek back to the beginning or after the BOM if utf8
--
the other option is to open our own file descriptor this will
remove the need for the mutex but it would no longer block get_filename
from getting potential stale / bad data

Change-Id: I0d2b8a1a297c7aaf453b3bc558b2b5b53dbe591b
2022-12-01 17:56:31 -05:00
William Wilgus
c9c340704f playlist_create fix race condition
I'm pretty sure this is a very old bug I traced it down to the
current_playlist getting changed out from under add_indices_to_playlist
causing myriad of issues from buffer full to invalid control file to shifting indices

this only appears to happen with the dircache on

I still get an incorrect resume state with the wrong song very rarely -- turns out get_filename seeks the file FIXED

Some debugging left in for now till we can verify there are no other instances

Change-Id: I289a775462eddfe93da4a326dc9e38605af06816
2022-11-30 23:15:49 -05:00
Aidan MacDonald
5fdd491ceb playlist: reduce memory usage for loading playlists
There's probably little benefit to using core_alloc_maximum() for
loading playlists since they are parsed incrementally. I/O speed
does not increase with increased read sizes beyond a certain point.
Read by 32 KiB chunks since that is what the buffering thread does.
Fall back to core_alloc_maximum() if a small allocation fails so
that buflib will try harder to free up space.

Change-Id: I08b94317d12b98af09ef2bd84aa1195c4c51d1b1
2022-11-16 06:47:38 -05:00
William Wilgus
687767bd8f convert a few more strlcpy to strmemccpy calls Fix Red and Yellow
albumart is imported to plugins just use a macro substitution
for now

Change-Id: I7c2e10d7559c087f0b3d0e6b844027d3b323da55
2022-11-15 01:24:26 -05:00
William Wilgus
f6c719d7ec replace strlcpy with strmemccpy
replace applicable calls to strlcpy with calls to strmemccpy
which null terminates on truncation

in theory the strmemccpy calls should be slightly faster since they
don't traverse the rest of the source string on truncation
but I seriously doubt there is too much of that going on in the code base

Change-Id: Ia0251514e36a6242bbf3f03c5e0df123aba60ed2
2022-11-14 23:56:16 -05:00
William Wilgus
f9ea1fc79d splash_progress add delay function
I figure this is a better way to allow a delay before showing the
progress meter

Change-Id: I909902a52619023b0b87635d2eb94ed00cb4bcec
2022-10-13 00:10:25 -04:00
William Wilgus
0374dea33a playlist_resume add delay before progress splash
Change-Id: I2927ddc49c3dbe96746237c8577f26f240182eeb
2022-10-10 07:20:07 -04:00
William Wilgus
d73aaf3d9e add splash_progress
the loading track splash flashes and is ugly
add a function to display a progressbar along with the splash message

spruce up database commit message as well

Change-Id: I2749b958c1ee5dad2631a5f999a4b00ddca7f225
2022-10-09 08:46:51 -04:00
Christian Soffke
5e757b4d6e Playlists: Fix losing cached control data when resuming
Shuffle and Unshuffle commands are not flushed to
disk when control data is updated. The same applies
to Delete and Reset commands, unless HAVE_DIRCACHE
is undefined (see update_control() function in playlist.c)

playlist_resume() discards cached control data.

This resulted in a bug where (e.g.) removed tracks
from the current playlist would reappear if you stopped
and resumed playing immediately afterwards (instead of
restarting in between).

Change-Id: I273f61e823a1d99426a18079b81aa07915620f30
2022-08-19 00:28:35 -04:00
Aidan MacDonald
e5e457b526 apps: fix int/long mismatch in playlist.c
A couple of places use sizeof(int) for allocations and copying but
the indices are longs, which causes bugs in the simulator on 64-bit.

Change-Id: Ie101ac57d44217c4b1657cf0152c97e276bd7043
2022-05-02 16:10:15 +01:00
Aidan MacDonald
5ffe520de4 playlist: use path_strip_last_volume, clarify path conventions
The comment regarding Windows paths was fairly confusing as to
its intent. What the code is trying to do is replace the drive
letter with the volume containing the playlist, which appears
reasonable. The middle of the comment was devoted to explaining
why the code below was potentially incorrect which only served
to add to the confusion.

AFAICT the last volume specifier in a path will cause search to
start from the root of that volume, so any incorrect result can
be avoided by using the new function path_strip_last_volume().

Finally, add a comment at the top of the function that explains
what it does.

Change-Id: If4e4938801f2f81eb52f5d32b5461872995e5e83
2022-04-01 11:40:02 -04:00
William Wilgus
eecf840989 playlist.c fix red for non-DIRCACHE targets
Change-Id: Id02f67dee6f40a80c832dea785f56f32885a5528
2022-03-11 22:52:02 -05:00
William Wilgus
a59b3c5d11 playlist_resume, wait for dircache to complete before loading songs
with root redirect and even relative paths eventually we need the dircache
to get files from the disk

Change-Id: Ia443f473f09dd534674d5fdb71251214ce01eed7
2022-03-11 22:30:39 -05:00
William Wilgus
95af36d0dd playlist.c fix red for non multivolume targets
Change-Id: Ic0fdb325bc9c8d886c7627679fb2d02521400da7
2022-03-11 20:05:14 -05:00
William Wilgus
eb32238b22 playlist.c use basename for playlist_get_filename_crc32
strip the vol and use the relative portion

Change-Id: I6259343e63a84f0ab97bd6f491de09320d74eac4
2022-03-11 19:45:58 -05:00
William Wilgus
355553baf4 playlist_resume, fix control fd, add some error info
I ocassionally see Playlist Invalid messages but which part is failing?
eventually it works so its probably a race

Change-Id: Ib2b09ab13ce09a55130430a2e94bc0498443b6ec
2022-03-11 09:40:31 -05:00
Aidan MacDonald
e8faf2f2ad buflib: add a common dummy callbacks struct & use it
There are various allocations that can't be moved or shrunk.
Provide a global callback struct for this use case instead of
making each caller declare its own dummy struct.

Also fixed ROLO and x1000 installer code which incorrectly
used movable allocations.

Change-Id: I00088396b9826e02e69a4a33477fe1a7816374f1
2022-02-12 10:24:32 -05:00
William Wilgus
8c88d5c5e2 playlist.c remove panic from OOM conditions
the splash suffices as warning let the calling code decide what to do with it

everything I saw calling expected failure with a -1 return so it shouldn't
cause any issue removing the panic

Change-Id: Idc1fba91c3ab4f1fd78e1d6a07dc2e6a0bfd8970
2021-12-08 21:44:12 -05:00
James D. Smith
760277e096 Dir cache: Fix resume of relative path playlists.
Slightly modified from original patch by Fabrice Bellard.

Change-Id: I9ae04fa460f0f1b9c616e6f99505d4c5d4358f68
2021-09-19 21:05:58 -04:00
Aidan MacDonald
257ba1d2e0 Fix possible negative fd in playlist.c
Change-Id: I59d88609ec3f20ec9f482a777396cd72be23a35b
2021-08-06 19:38:06 +01:00
William Wilgus
ee05b8574a playlist.c fix multitude of sins Invalid Control file on USB unplug?
failure to close file handles
reading memory prior to buffer on error
loop variable integer overflow on error

Change-Id: I2893c34cd041d085fd7f56a88cb4cb14131cea11
2021-07-30 00:40:43 -04:00