OggVorbis player

Peter Crowther Peter at ozzard.org
Sun Nov 13 22:09:33 UTC 2005


> From: [...] Russell Penney
> *Signatures*
> How do you identify a file (rather than something that has a 
> MIME type) as being a certain type?

Allow each codec to sniff it and bid for handling it.  Many, though not
all, formats have some form of header at the start of the stream.  It's
typically small.

A possible algorithm:

Read in (say) 1k of the stream and pass it to each registered codec.
The codec returns one status from 'I can cope with this', 'I can't cope
with this', 'I might be able to cope with this but require xxx bytes
more information to make an informed decision' or 'I don't have a header
so can't tell'.

- If exactly one codec can cope with the format, use that codec.

- If more than one codec can cope with the format, choose one by some
means (might even ask the user) and use that codec.

- If no codecs can cope with the format but one or more need more
information, feed them the extra information (if possible) and go round
again with just the codecs that might be able to cope or can cope with
anything.  If that's not possible, prompt the user or perform some other
algorithm for selecting an essentially random codec :-).

- If no codecs can cope even after asking for more information, but one
or more codec can't tell, ask the user then try to use that codec.
Asking the user is polite; for example a .au codec will play any old
byte-stream but the user's ears may not appreciate the result.

- If no codecs match or the user has declined everything thus far, tell
'em to go to <insert central source server here> and download a suitable
codec.  If we're *really* smart, make that a Squeak-based server; pass
up the header information and let it do the same process with all the
codecs it knows, then offer one for download.

Disclaimers: Untested, late at night, too much beer and too little
coffee, etc.

		- Peter



More information about the Squeak-dev mailing list