Skip to content

Decoder Class Reference

malachaifrazier edited this page Jan 5, 2013 · 9 revisions

The AV.Decoder class is a class abstraction that subclasses and extends audio decoding for various codecs (e.g. MP3, AAC, FLAC, etc.,). Decoders receive data from the AV.Demuxer and implement the readChunk method to decode the audio data into Linear PCM. This is passed to the audio hardware for playback (or any other output destination).

When you implement your own decoders, remember to call AV.Decoder.register(id, YourDecoder) to register your decoder with the framework.

Properties

Methods To Implement

Events

Registering and Finding

Properties

AV.Decoder#stream

A AV.Stream object containing the audio data.

AV.Decoder#bitstream

A AV.Bitstream object containing the audio data.

AV.Decoder#receivedFinalBuffer

A boolean that keeps track of whether the decoder has been sent the final buffer from the AV.Demuxer yet.

Methods To Implement

AV.Decoder#setCookie(cookie)

This method is optional and is called when a 'cookie' event is emitted by the AV.Demuxer. The cookie is passed as an AV.Buffer object.

AV.Decoder#readChunk()

readChunk is required, and is called by the framework whenever decoding is necessary. readChunk is responsible for decoding the audio data found in the stream or bitstream and emitting data events containing the decoded audio data as a Typed Array.

If not enough data is available in the stream at the time readChunk is called, schedule it to be called later by registering readChunk for the 'available' event once in the future, e.g. this.once('available', this.readChunk).

If there is an error in the decoding process, emit an error event to stop the whole decoding process entirely.

Events

'data', buffer

You should emit the data event whenever you have decoded some number of samples of Linear PCM audio data. You should include the data as a Typed Array.

'available'

This event is emitted by the AV.Decoder class whenever new data is available from the AV.Demuxer.

'error', err

You should emit the error event whenever there is an error in the decoder. Emitting this event will halt the rest of the decoding process.

Registering and Finding

AV.Decoder.register(id, decoder)

All AV.Decoder subclasses should be registered with the AV.Decoder class using this class method. You can register your decoder for multiple ids if you know that different containers use different FOURCCs for the codec, for example.

AV.Decoder.find(id)

Finds a registered decoder using the 4 (or less) character FOURCC code the decoder registered itself as.

Clone this wiki locally