-
Notifications
You must be signed in to change notification settings - Fork 185
Demuxer Class Reference
The AV.Demuxer
class is an abstract class that subclasses extend to implement probing, and reading of container formats (e.g. WAV, M4A, CAF, etc.). Demuxers receive data from an AV.Source and implement the readChunk
method to read the format information, duration, metadata, and actual audio data to be passed to the AV.Decoder object.
When you implement your own demuxers, remember to call AV.Demuxer.register(YourDemuxer)
to register your demuxer with the framework.
The AV.Stream object that you can use for reading the file.
The class level probe
method is provided with the first buffer in the audio file (variable length) since you can usually tell the container format within the first few bytes of the file. The buffer is a AV.Stream object. The probe
method should return a boolean representing whether the file is in the demuxer's recognized container format or not.
readChunk
is called whenever new data is available from the source. It must be written in a way that accounts for the fact that not all data will have been received when it is called. Thus it may need to defer some parsing until the next time readChunk
is called in order to read an entire data structure. readChunk
should emit the events specified below.
The format
event should be emitted by the demuxer with the following information:
{
formatID: 'abcd', // <= 4 letter string representing the decoder that should be used
sampleRate: 44100, // the sampleRate of the file
channelsPerFrame: 2, // the number of audio channels
bitsPerChannel: 16 // the sample bit depth
}
Other information is allowed in the format object, but will be ignored by the framework.
The duration
event should be emitted with the duration of the audio file in milliseconds. If the duration of the file is unknown, the event should not be emitted.
The metadata
event should be emitted with an object containing any metadata embedded in the file. If not metadata is included in the file, the event should not be emitted.
The cookie
event should be emitted with an AV.Buffer object containing the "magic cookie" or decoder specific information to be read by the decoder. If no magic cookie is embedded in the file, the event should not be emitted.
The data
event should be emitted whenever actual audio data is encountered. It should be emitted with a buffer containing the audio data and a boolean saying whether this is the last buffer that will be emitted.
Emitted when there is an error in the demuxer.
Called by the framework to initialize the demuxer. You should not override the demuxer's constructor but provide the init
method instead to perform your initialization. If an init
method is not provided, the default implementation does nothing.
All Demuxer
subclasses should be registered with the AV.Demuxer
class using this class method.
Finds a registered demuxer that supports the format as probed using the probe class method. An AV.Buffer object should be passed to this method.