Codec Memory Usage
This page is for documenting the memory usage of Rockbox codecs, with a view to reducing the size of the codec buffer (the amount of memory reserved for codecs).
Once this page starts to get populated, and we know what information is important, we should perhaps change to a table format.
Overview of codec memory consumption
The following graphic displays the memory layout for all codecs. The measurement has been done with a iPod Video build. I have manually added the dynamic memory allocation for AAC-HE files. Not visible is the dynamic amount of memory which is consumed by the m4a seek table (aac, alac), ape and vorbis. Those can additionally allocate up to several hundreds KB depending on the files.
Details about codec memory layout
Since a rework malloc() is only used by libm4a
and when decoding AAC-HE (SBR, PS). AAC-HE can be compiled with FAAD_STATIC_ALLOC to use static buffers only. AAC-LC generally uses static buffers. Under rockbox AAC-HE is only build for targets with CODEC_SIZE >= 512 KB.
Measured memory usage in bytes on iPod Video (PP5022) when compiled for AAC-LC, AAC-HE (SBR) and AAC-HE (SBR+PS) based on r30514:
|| 204.200 KB
| AAC-HE (SBR)
|| 387.992 KB
| AAC-HE (SBR+PS)
|| 475.588 KB
is used for container parsing. Depending on the type of file and its duration the additionally required amount of memory easily reaches several hundred KB.
No malloc() use.
for container parsing.
Uses malloc() for seek table.
No malloc() use. Seektable stored in a static array, containing a maximum of 5000 seekpoints. Each array element is 10 bytes (padded to 12 bytes on ARM for alignment) - a total of 60000 bytes. In the case of a file with more than 5000 seekpoints, the codec will just store the first 5000, with the effect that seeking in later parts of the file will be slightly slower (but still functional) - seekpoints aren't required for seeking, they just provide clues to help seek faster.
In reality, files are likely to have far fewer seekpoints - see discussion in comments at top of apps/codecs/flac.c
Codec has a few malloc(), but none are used in Rockbox.
No malloc() use. A fixed size seek table uses 8192 entries whereas each entry by default represents one frame. If a file has more than 8192 frames the time resolution of the seek table is reduced to cover the whole file length (e.g. 4 frames per entry).
The Ogg framing code uses malloc(). The codec code itself has malloc(), but none are used in Rockbox.
Uses malloc() everywhere. Memory usage varies widely between encoders and bitrates (differences of 500KB+ are possible). Removing malloc() is not feasible given how the format works.
Uses malloc() for the seek tables. Depending on the files the seek tables may require up to several hundred KB.
Copyright © by the contributing authors.