Codec Memory Usage
Introduction
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
AAC
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:
Profile |
IRAM |
IBSS |
BSS |
Text |
malloc |
total |
AAC-LC |
38.144 |
38.912 |
43.648 |
79.888 |
3.608 |
204.200 KB |
AAC-HE (SBR) |
41.600 |
38.912 |
43.648 |
133.968 |
129.864 |
387.992 KB |
AAC-HE (SBR+PS) |
41.600 |
38.912 |
68.752 |
162.864 |
163.460 |
475.588 KB |
libm4a 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.
ALAC
No malloc() use.
Uses
libm4a for container parsing.
APE
Uses malloc() for seek table.
FLAC
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
MPEG Audio
Codec has a few malloc(), but none are used in Rockbox.
Musepack
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).
Speex
The Ogg framing code uses malloc(). The codec code itself has malloc(), but none are used in Rockbox.
Vorbis
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.
Support code
libm4a
Uses malloc() for the seek tables. Depending on the files the seek tables may require up to several hundred KB (up to 250 KB/hour give or take).
Copyright © by the contributing authors.