-
Notifications
You must be signed in to change notification settings - Fork 185
Decoder Class Reference
The AV.Decoder
class is an abstract class that subclasses extend to implement actual 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 to be passed to the audio hardware for playback, or other output destination.
When you implement your own decoders, remember to call AV.Decoder.register(id, YourDecoder)
to register your decoder with the framework.
A AV.Stream object containing the audio data.
A AV.Bitstream object containing the audio data.
A boolean that keeps track of whether the decoder has been sent the final buffer from the AV.Demuxer yet.
This is the method called by higher levels of the framework (or you directly) to decode a packet. It wraps around the decoder's readChunk method to handle errors, underflows, emitting data and end events, and keeping track of the decoder's state.
The default implementation asks the demuxer to seek to the timestamp, and updates its underlying stream. Decoders can override for custom seeking behavior. Returns the timestamp of the actual seek point it jumped to.
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.
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 returning decoded audio packets as Typed Arrays.
If an error occurs during decoding, throw an error object (i.e. new Error(message)
).
If not enough data is available, throw an AV.UnderflowError
(this is automatically thrown by the builtin Stream and Bitstream classes, so you normally don't need to worry about underflows.
This method should not be called directly by your code, use the decode method.
Decoded audio data is emitted as a Typed Array
Emitted when the decoder has reached the end of its input.
The error
event is emitted whenever there is an error in the decoder. If an error occurs, the entire decoding process halts.
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.
Finds a registered decoder using the 4 (or less) character FOURCC code the decoder registered itself as.