FS#11916 - MP4 parser fails with filesize = 0

Attached to Project: Rockbox
Opened by MichaelGiacomelli (saratoga) - Monday, 31 January 2011, 21:26 GMT
Last edited by Andree Buschmann (Buschel) - Wednesday, 02 February 2011, 09:39 GMT
Task Type Bugs
Category Codecs
Status Closed
Assigned To Andree Buschmann (Buschel)
Operating System All players
Severity Low
Priority Normal
Reported Version Release 3.7.1
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


This file fails with the following message in the sim:

Read metadata for /radiozu.mp4
MP4 metadata error. errno 0, samples 2428928, frequency 44100, filesize 0
parsing /radiozu.mp4 failed (format: AAC)

This is printed in apps/metadata/mp4.c because the read_mp4_container returns a filesize of 0 bytes. The file seems to play ok in foobar2000.
This task depends upon

Closed by  Andree Buschmann (Buschel)
Wednesday, 02 February 2011, 09:39 GMT
Reason for closing:  Fixed
Additional comments about closing:  Fixed with r29185 and r29186.
Comment by Andree Buschmann (Buschel) - Monday, 31 January 2011, 23:08 GMT
This patch does simply take the file_size when recognizing "free" as id3->filesize.

Edit: This is of course not a proper solution. Main reason for the failure seems to be that the parser does not find the "mdat" signature which is present in the file.

The runtime is also not correctly identified for this song. rockbox does only show half the runtime (0:55 min). During playback rockbox plays the full 1:50 min duration and the counter rises with half speed.
Comment by Andree Buschmann (Buschel) - Tuesday, 01 February 2011, 15:42 GMT
Here is the real fix: Our parser tries to read metadata from an "ilst" tag of size 0. In consequence the next "mdat" is missed. The fix does only try to read metadata if the "ilst" size is at least 8 bytes (= size of an mp4 atom).

Still the runtime is not calculated correctly.
Comment by Andree Buschmann (Buschel) - Tuesday, 01 February 2011, 18:52 GMT
Here we go. This patch does two things:
1) Fix the parser to allow playback in general (like v02)
2) Fix seek, timebar and duration for files with SBR upsampling.

For 2) there are only few changes neccessary. "upsampling" can be detected from the stream. In this case the decoder outputs twice as much samples/framesize. So, the runtime is doubled and the the bitrate is halfed. The time-based seek methos alac_seek() does not know of this fact and needs input (and generates output) based on the smaller runtime/framesize. This is done via a simple correction factor "sbr_fac" which was introduced.

So far this patch works for all my test files including AAC, AAC-HE, seek/resume.
Comment by Andree Buschmann (Buschel) - Tuesday, 01 February 2011, 21:13 GMT
Found a way to detect implictly signalled SBR upsampling in our metadata parser. Now the length and bitrate is correct right after parsing the metadata.