This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24220 - mp3 without id3 header cannot be sniffed reliably using only 512 bytes
Summary: mp3 without id3 header cannot be sniffed reliably using only 512 bytes
Status: RESOLVED MOVED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: MIME (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: Unsorted
Assignee: Gordon P. Hemsley
QA Contact: sideshowbarker+mimespec
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-07 14:33 UTC by paul@paul.cx
Modified: 2016-03-02 16:42 UTC (History)
3 users (show)

See Also:


Attachments
Tentative algorithm to sniff mp3 without id3 (3.18 KB, text/x-markdown)
2014-01-07 14:33 UTC, paul@paul.cx
Details

Description paul@paul.cx 2014-01-07 14:33:37 UTC
Created attachment 1421 [details]
Tentative algorithm to sniff mp3 without id3

While trying to find an algorithm to sniff mp3 without ID3 headers reliably for Gecko, we found that it seems impossible to sniff such bit stream reliably without going past the 512 bytes limit mandated by the spec.

The technique we use is to check if there is an mp3 sync pattern at the beginning of the bit stream, and then determine the location of the next sync pattern, using values such as the bit rate, the sample rate, etc. found in the header of the first packet, by parsing the mp3 bit stream.

Then, seeking to the next sync pattern and checking if there is another mp3 sync pattern at the expected offset tell us if we are effectively sniffing an mp3 stream.

This works very reliably, but there is one major problem: the second sync pattern is often past the 512 bytes limit, especially with high bit rate/sample rate media files. The second sync pattern can be at a max offset of 1441 bytes (320kbps * 144 / 32kHz + 1 padding byte), and the sync pattern itself is 4 bytes long, so minimum 1445 bytes are needed.

Attached is a (draft) algorithm one can implement to sniff an mp3 bit stream without id3 header.

[1]: the complete implementation: http://dxr.mozilla.org/mozilla-central/source/toolkit/components/mediasniffer/mp3sniff.c