Commit graph

280 commits

Author SHA1 Message Date
William Wilgus
1c26f565bf tagnavi make track submenu
add some faster options to the track menu
add a shortcut for basename formatting
sort basename results

filename - by sorted filename
title - just title no formatting untagged items are unsorted as well
title mm:ss - title and duration

Change-Id: I90aea95051f6231580ef7f1fc08cd2d0d69601fb
2023-02-07 08:44:57 -05:00
William Wilgus
d5a84d42b0 [BugFix] tagcache.c fix off by one error in find_entry_disk()
the tagcache counts the null terminator strlen however, does not
no matching entries makes for a terrible amount of disk searching
and a hang on devices without dircache to save them

Change-Id: Id3460037199ee9853de0f11e4763a7ff11130e45
2023-02-04 11:39:43 -05:00
William Wilgus
4e5fcbe898 fix red #2 d6fb80d4
Change-Id: I147e9b8f7c8e64234f55d39f9ac7c7253b065f9a
2023-01-27 01:12:42 -05:00
William Wilgus
1d6ce5193f fix red d6fb80d4
Change-Id: I805490f660626f48220b41de3ee1026c260d0067
2023-01-27 00:40:20 -05:00
William Wilgus
d6fb80d4ff Tagcache - Ramcache Move ref checks, speed up disk searches
move loading file reference to a separate function

some optimization of the disk search function check tag length before
reading the actual entry & reduce number of lseek calls
this affects startup resume as well before tagcache is done loading

Change-Id: I2bd2fc53c4870416ecd1a4034b34cb6984d8ad51
2023-01-27 00:03:51 -05:00
William Wilgus
d521020d21 [Feature] Add total entries to database info
show total database entries in debug>Database Info

Change-Id: Ic22b6a032ae0ee23e0f38c0da6a9cf1433ba29e2
2023-01-15 22:57:00 -05: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
Aidan MacDonald
879b5dae39 Fix red 8f582c90de
global_settings is not defined when building the database tool.
Add a path buffer in tc_stat to fix this. This also avoids race
conditions that may occur if changing the path setting at runtime.

Change-Id: Ib2ca92c2e34929c79b19ef145fd7ccdcd62c8d04
2022-12-03 13:13:16 +00:00
Aidan MacDonald
8f582c90de tagcache: add a setting for customizing the database path
Add a new setting,

    database path: /path/to/folder

to change where the database files are stored, which allows it to
be shared by multiple builds when using multiboot. This avoids the
need to maintain a separate copy of the database for each build.
This setting can only be set from the config file; it has no menu
option yet (due to lack of a GUI to pick the directory).

Change-Id: Ide7b3ccdd84abb62b52f900421bd3d101773e093
2022-12-03 07:29:42 -05:00
Aidan MacDonald
98c7505c60 tagcache: move TAGCACHE_STATEFILE define to .c file
Provide a function to remove the statefile so that external
users of this define can call that instead.

Change-Id: Id3e1e0564b25fe28bbc68c2e9365d8bf51e6e4f8
2022-12-03 06:34:47 -05:00
Aidan MacDonald
90dc64da32 tagcache: remove TAGCACHE_STRICT_ALIGN flag
This has been defined to 1 since forever, so the last remaining
check presumably isn't catching anything.

Change-Id: I0b60f831a6e5e8fc45788e7581fccb0cb62bce73
2022-12-03 11:00:35 +00:00
Aidan MacDonald
b6c2b54e01 tagcache: move most defines to .c file
Most of the defines in the header file are internal to the tagcache
and therefore should not be exposed in the header, to make it clear
that outside code does not depend on the values.

Change-Id: I83b0c83c61c755231e03719a6845a555f983194a
2022-12-03 11:00:27 +00:00
William Wilgus
3745c813f9 misc.c open_pathfmt caller supplied buffer
Amachronic raised concern about open() blocking causing a static buf
to get overwritten in multiple calls its prudent to just have the caller
supply the buffer to minimize stack issues later

Change-Id: Iae27c7d063adb1a65688f920f6aa5c395fa5694a
2022-11-23 22:09:46 -05:00
William Wilgus
e7e20fab1b create function open_pathfmt() to allow printf formatting on open()
save some space by allowing printf formatting directly rather than
having a buffer and using sprintf

Change-Id: I049c8f898fb4a68a26ad0f0646250c242647ba12
2022-11-19 23:13:42 -05:00
William Wilgus
3ad8c0ad7b fix another non shadowed variable
another variable that shouldn't have been removed in 034b6d5b

Change-Id: Ie16aa2687cec7f55e9cc2477951c228de18755cd
2022-11-15 19:17:41 -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
034b6d5bfb Remove some shadowed variables identified by -Wshadow
there are plenty more but these are the low hanging fruit

Change-Id: I86d9f4f56e8cd9b381d1bf6a6679cd58c6a4004d
2022-11-14 09:01:43 -05:00
Christian Soffke
498988d34a PictureFlow: Minor fixes & changed defaults
- Fix FPS counter overlapping
the artist string when
"Show album title" was set to
"Show album and artist at the top"

- Fix disappearance of center album
if certain Settings menus had been
accessed while list of tracks was
showing and you then returned to the
list of albums

- Fix disappearing album artwork after
cache had been created until you started
scrolling

- Enable context menu even if WPS
integration is disabled

- Make splash screen appear only
on first launch and for database
updates, when it is actually on screen
for long enough

- Eliminate 'Loading' splash if tagcache
is in RAM

- Show both album and artist by default on
displays whose height > 100px

Change-Id: Ie70c0d9093789294d288a4f88338ee4a588bf4a5
2022-10-22 09:33:50 +02:00
Aidan MacDonald
1718cf5f8a Convert a number of allocations to use buflib pinning
Several places in the codebase implemented an ad-hoc form of pinning;
they can be converted to use buflib pinning instead.

Change-Id: I4450be007e80f6c9cc9f56c2929fa4b9b85ebff3
2022-10-16 14:50:39 +01:00
Christian Soffke
8f6d0efd71 tagtree: Delay showing search progress when ramcache is enabled
The disk doesn't need to spin up when the
database is in RAM. Results are usually returned
without any noticeable delay, so the splash  only
creates distraction.

Change-Id: I04e5b7d2e00f045143dd86e0561091be3d8f9724
2022-08-19 00:27:34 -04:00
William Wilgus
79864c6ec2 add const to const * strings
I don't think this will amke any difference except maybe for hosted ports

Change-Id: I84f898aea92a6963901a6d889dd18b63f24c9a41
2022-05-03 23:00:58 -04:00
Aidan MacDonald
6b8c94a6e3 Fix some non-portable alignment values
UBSan reports an avalanche of unaligned pointer bugs stemming from
hardcoded 4-byte alignments used in certain places. Use sizeof(long)
instead to align to the machine word size.

Change-Id: I28e505212462c5268afa24e95df3a103ac3e2213
2022-05-02 15:38:48 +01:00
Aidan MacDonald
d55dceff37 apps: Add ability to do a clean reboot
Allow a clean shutdown to end in either power off or reboot. Add a
new event SYS_REBOOT to signal it and sys_reboot() to trigger the
event. SYS_REBOOT signals a reboot request and should be listened
for alongside SYS_POWEROFF events.

Change-Id: I99ba7fb5feed2bb5a0a40a274e8466ad74fe3a43
2022-04-16 14:36:39 +01:00
William Wilgus
61bc7b91bc tagcache.c remove 16-bit compression for add_uniqbuf
apparently there are tags such as year or genre that are indexed 1 byte
apart, as much as I like the idea of this I cannot come up with a way
to reliably denote 2 16 bit entries from a single 32 bit entry without
losing data or adding bookkeeping which would likely make it pointless

Change-Id: I8a9908575700cab9506c36f5422222145557fa6b
2022-03-22 00:22:42 -04:00
William Wilgus
08b42791ff tag_cache.c optimize str_begins_ends_oneof
the function is shared

Change-Id: I362a75ea5a39690647df4f421d9429ef2114ef02
2022-03-19 03:30:54 -04:00
William Wilgus
ddbca125a6 tagtree/tagcache add new clause operators begins/ends _oneof
new operators @^, @$
begins_oneof and ends_oneof

albumartist @^ "L|The L"
Led Zeppelin, The look

albumartist @$ "girls|Boys"
spice girls, beasty boys

Change-Id: I26ce3d8155d970a55e003f74e2f9478db76204f1
2022-03-19 02:24:14 -04:00
William Wilgus
0f2d623216 tagcache add logging option for clause matching #2
Change-Id: Ideaa89a6fb227ecc8a4a107dced98f85b6b40a4f
2022-03-19 02:11:57 -04:00
William Wilgus
a56975af6c tagcache add logging option for clause mtching
Change-Id: I5099287398b448d2f44283419395ab8919d6019c
2022-03-19 01:59:07 -04:00
William Wilgus
f88ea12bac tagcache compress uniqbuf 2 16-bit indices occupy a single 32 bit slot
a lot of space is wasted when file indices less than 65535
entries should be more than 1 byte apart so use the LSB as a flag
when indices are > 65535 set flag to 0 and proceed as before

explicitly mark uniqbuf as 32bit

Change-Id: I54e06c152c369eb6c0322186fe2c1e9a1e6d940d
2022-03-02 20:22:49 -05:00
William Wilgus
1bcb1e39ee tagcache, coverity cleanup, Add TAGS_ALL_COUNT
Change-Id: Ia880c921a00b603aa4ba81b0c0670ed00491e41a
2022-02-27 11:01:24 -05:00
William Wilgus
836616b937 Tagcache Don't create filters when parsing a logical OR
if possible search clauses are converted to filters

once a logical OR is added to the mix (CLAUSE1|CLAUSE2 & CLAUS3))
if CLAUSE1,2 are database non-numeric tags they get made into filters
but the logical OR gets carried to the next CLAUSE

Rather than trying to figure this out just keep all clauses around a logical OR

Change-Id: I03e064e7f897033c5d47d78a1d34238217cde485
2022-02-25 22:04:49 -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
Aidan MacDonald
aafe2dd2d1 tagcache: don't allow temp commit buffer to be moved
The temporary buffer used during database commit did not
have any buflib callbacks set, which allows it to be moved
by buflib at any time. The code is not prepared to deal
with this, so things break horribly if anything tries to
allocate during the commit.

The solution is to pass dummy callbacks to prevent the
buffer from being moved. I expect this may create other
issues since the commit uses up all available RAM, but
at least things won't get silently corrupted anymore.

Change-Id: I3183aaee58c94bfbaf4e24424030b8be6e341d22
2022-01-18 19:45:55 +00:00
James D. Smith
fcb9c06852 Database: Fix tag_albumartist; new tag_virt_canonicalartist.
Change-Id: I1d887f8a9d6690b8286407d2502432b0497cfeb9
2021-09-17 21:42:05 -04:00
Aidan MacDonald
005c414e5f Document intentional fallthroughs + fix harmless unintended ones
Change-Id: I1ca5b1027ec30cbf61093bab35b980196ed14e6b
2021-08-04 18:59:46 +00:00
William Wilgus
83653023d4 tagcache.c clean up
Change-Id: I658ee345461eeda77cbe856cec46c21dcce7715b
2021-08-02 00:43:52 +00:00
William Wilgus
ecf0d631e7 tagcache.c Fix potential buffer overruns WIP
Needs tested

Change-Id: I373b72c72f98777dc7a2d8085e975aeac164c297
2021-07-31 10:44:02 -04:00
William Wilgus
7413442411 tagcache.c WS changes
Change-Id: Ied0fa6010e8bfa82e1c46cafcfb0dec51478d346
2021-07-31 10:26:59 -04:00
Solomon Peachy
3ed035769c FS#9093: Database initialization hangs if there's no music file on the player
Original patch by William Poetra Yoga Hadisoeseno

Change-Id: I198a4d1b2899bd9200a35dbefd034a2e9857fa19
2021-05-19 16:30:32 -04:00
Solomon Peachy
8cb555460f [3/4] Completely remove HWCODEC support
'swcodec' is now always set (and recording_swcodec for recording-capable
units) in feature.txt so the manual and language strings don't need to
all be fixed up.

Change-Id: Ib2c9d5d157af8d33653e2d4b4a12881b9aa6ddb0
2020-07-24 21:20:13 +00:00
Igor B. Poretsky
293e3e0fd7 FS#9213 - Fix for audio dropout after startup
Original Patch by Martin Buck
Updated by Igor Poretsky
2019-08-20 13:17:23 +02:00
Michael Sevakis
b3de64e7c1 Database: Fix destabilization if ramcache fails to load + misc.
It seems to like not having any idea any attempt was made to load
it so just try to put it back like the option was never on.

Integrity check other tags besides the filename.

Fix a few logfs that spat out warnings and add a bit more detail
to a couple.

Move a buffer lock to the right spot.

Better aligning macro.

Add a "continue" that should have been there when filename is
seeked over during load.

Change-Id: Ib0c517a7b77d3ba0dd6530ddef19bed62116e4a8
2017-04-01 13:01:20 -04:00
Michael Sevakis
dc22522c2c Tweak a few tagcache things.
* Take out pointless dircache_search; nothing can be reconstructed
with the given info in find_entry_ram(); don't even try there.
Path AND index id must be known. Work it out later.

* Timed yield must be far more often than once every 1/4 second (?!)

* Do better the memory-remaining checks for ramcache load.

* Root separator mustn't be doubled up when searching files.

Change-Id: I091813f4495f3bd0d0c4672bc674df52343b3e48
2017-02-13 00:46:23 -05:00
Michael Sevakis
a4dc244b4e Fix warnings and errors from 7373cf5
dircache.h has to be included no matter what.

Change-Id: Ib9ae4277615e8573b931d42fc6f1b3681d898bca
2017-02-10 05:44:04 -05:00
Michael Sevakis
7373cf518f Restore dircache hookup in the database ramcache.
Do a few other changes to dircache and file code flags to
accomodate its demands.

Change-Id: I4742a54e8cfbe4d8b9cffb75faaf920dd907cf8a
2017-02-10 05:05:23 -05:00
Amaury Pouly
d7871914ac Fix dangerous casts
On Windows 64-bit, the size of long is 32-bit, thus any pointer to long cast is
not valid. In any case, one should use intptr_t and ptrdiff_t when casting
to integers. This commit attempts to fix all instances reported by GCC.
When relevant, I replaced code by the macros PTR_ADD, ALIGN_UP from system.h

Change-Id: I2273b0e8465d3c4689824717ed5afa5ed238a2dc
2017-02-04 17:24:47 +01:00
Michael Sevakis
16a9f84571 Reenable database ramcache and playlist dircache
Playlist dircache references should be back in working order.

Reenabling dircache references in the database ramcache is not
yet done as it requires quite a bit of rework. Otherwise, the
database in RAM is functional again.

Some buffer compatibility changes have been made for database
commit because the dircache buffer can no longer be stolen, only
freed by an API call.

Change-Id: Ib57c3e98cb23e798d4439e9da7ebd73826e733a4
2017-01-17 15:27:47 -05:00
Michael Sevakis
7d1a47cf13 Rewrite filesystem code (WIP)
This patch redoes the filesystem code from the FAT driver up to the
clipboard code in onplay.c.

Not every aspect of this is finished therefore it is still "WIP". I
don't wish to do too much at once (haha!). What is left to do is get
dircache back in the sim and find an implementation for the dircache
indicies in the tagcache and playlist code or do something else that
has the same benefit. Leaving these out for now does not make anything
unusable. All the basics are done.

Phone app code should probably get vetted (and app path handling
just plain rewritten as environment expansions); the SDL app and
Android run well.

Main things addressed:
1) Thread safety: There is none right now in the trunk code. Most of
what currently works is luck when multiple threads are involved or
multiple descriptors to the same file are open.

2) POSIX compliance: Many of the functions behave nothing like their
counterparts on a host system. This leads to inconsistent code or very
different behavior from native to hosted. One huge offender was
rename(). Going point by point would fill a book.

3) Actual running RAM usage: Many targets will use less RAM and less
stack space (some more RAM because I upped the number of cache buffers
for large memory). There's very little memory lying fallow in rarely-used
areas (see 'Key core changes' below). Also, all targets may open the same
number of directory streams whereas before those with less than 8MB RAM
were limited to 8, not 12 implying those targets will save slightly
less.

4) Performance: The test_disk plugin shows markedly improved performance,
particularly in the area of (uncached) directory scanning, due partly to
more optimal directory reading and to a better sector cache algorithm.
Uncached times tend to be better while there is a bit of a slowdown in
dircache due to it being a bit heavier of an implementation. It's not
noticeable by a human as far as I can say.

Key core changes:
1) Files and directories share core code and data structures.

2) The filesystem code knows which descriptors refer to same file.
This ensures that changes from one stream are appropriately reflected
in every open descriptor for that file (fileobj_mgr.c).

3) File and directory cache buffers are borrowed from the main sector
cache. This means that when they are not in use by a file, they are not
wasted, but used for the cache. Most of the time, only a few of them
are needed. It also means that adding more file and directory handles
is less expensive. All one must do in ensure a large enough cache to
borrow from.

4) Relative path components are supported and the namespace is unified.
It does not support full relative paths to an implied current directory;
what is does support is use of "." and "..". Adding the former would
not be very difficult. The namespace is unified in the sense that
volumes may be specified several times along with relative parts, e.g.:
"/<0>/foo/../../<1>/bar" :<=> "/<1>/bar".

5) Stack usage is down due to sharing of data, static allocation and
less duplication of strings on the stack. This requires more
serialization than I would like but since the number of threads is
limited to a low number, the tradoff in favor of the stack seems
reasonable.

6) Separates and heirarchicalizes (sic) the SIM and APP filesystem
code. SIM path and volume handling is just like the target. Some
aspects of the APP file code get more straightforward (e.g. no path
hashing is needed).

Dircache:
Deserves its own section. Dircache is new but pays homage to the old.
The old one was not compatible and so it, since it got redone, does
all the stuff it always should have done such as:

1) It may be update and used at any time during the build process.
No longer has one to wait for it to finish building to do basic file
management (create, remove, rename, etc.).

2) It does not need to be either fully scanned or completely disabled;
it can be incomplete (i.e. overfilled, missing paths), still be
of benefit and be correct.

3) Handles mounting and dismounting of individual volumes which means
a full rebuild is not needed just because you pop a new SD card in the
slot. Now, because it reuses its freed entry data, may rebuild only
that volume.

4) Much more fundamental to the file code. When it is built, it is
the keeper of the master file list whether enabled or not ("disabled"
is just a state of the cache). Its must always to ready to be started
and bind all streams opened prior to being enabled.

5) Maintains any short filenames in OEM format which means that it does
not need to be rebuilt when changing the default codepage.

Miscellaneous Compatibility:
1) Update any other code that would otherwise not work such as the
hotswap mounting code in various card drivers.

2) File management: Clipboard needed updating because of the behavioral
changes. Still needs a little more work on some finer points.

3) Remove now-obsolete functionality such as the mutex's "no preempt"
flag (which was only for the prior FAT driver).

4) struct dirinfo uses time_t rather than raw FAT directory entry
time fields. I plan to follow up on genericizing everything there
(i.e. no FAT attributes).

5) unicode.c needed some redoing so that the file code does not try
try to load codepages during a scan, which is actually a problem with
the current code. The default codepage, if any is required, is now
kept in RAM separarately (bufalloced) from codepages specified to
iso_decode() (which must not be bufalloced because the conversion
may be done by playback threads).

Brings with it some additional reusable core code:
1) Revised file functions: Reusable code that does things such as
safe path concatenation and parsing without buffer limitations or
data duplication. Variants that copy or alter the input path may be
based off these.

To do:
1) Put dircache functionality back in the sim. Treating it internally
as a different kind of file system seems the best approach at this
time.

2) Restore use of dircache indexes in the playlist and database or
something effectively the same. Since the cache doesn't have to be
complete in order to be used, not getting a hit on the cache doesn't
unambiguously say if the path exists or not.

Change-Id: Ia30f3082a136253e3a0eae0784e3091d138915c8
Reviewed-on: http://gerrit.rockbox.org/566
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2014-08-30 03:48:23 +02:00
Thomas Martitz
470989bd70 events: Rework event subsystem (add_event, send_event) to be more versatile.
add_event_ex is added that takes an extra user_data pointer. This pointer is
passed to the callback (add_event and add_event_ex have slightly different
callbacks types). All callbacks also get the event id passed. Events added
with add_event_ex must be removed with remove_event_ex because the user_data
pointer must match in addition to the callback pointer.

On the other add_event is simplified to omit the oneshort parameter which
was almost always false (still there with add_event_ex).

As a side effect the ata_idle_notify callbacks are changed as well, they
do not take a data parameter anymore which was always NULL anyway.

This commit also adds some documentation to events.h

Change-Id: I13e29a0f88ef908f175b376d83550f9e0231f772
2014-03-14 23:36:30 +01:00
Michael Sevakis
31b7122867 Implement time-based resume and playback start.
This complements offset-based resume and playback start funcionality.
The implementation is global on both HWCODEC and SWCODEC.

Basically, if either the specified elapsed or offset are non-zero,
it indicates a mid-track resume.

To resume by time only, set elapsed to nonzero and offset to zero.
To resume by offset only, set offset to nonzero and elapsed to zero.

Which one the codec uses and which has priority is up to the codec;
however, using an elapsed time covers more cases:

* Codecs not able to use an offset such as VGM or other atomic
formats

* Starting playback at a nonzero elapsed time from a source that
contains no offset, such as a cuesheet

The change re-versions pretty much everything from tagcache to nvram.

Change-Id: Ic7aebb24e99a03ae99585c5e236eba960d163f38
Reviewed-on: http://gerrit.rockbox.org/516
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested: Michael Sevakis <jethead71@rockbox.org>
2014-03-10 04:12:30 +01:00