summaryrefslogtreecommitdiff
path: root/node_modules/prism-media/src/vorbis/WebmDemuxer.js
blob: 9ef84dc7d05190e697de9f411559649bee641c30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const WebmBaseDemuxer = require('../core/WebmBase');

const VORBIS_HEAD = Buffer.from([...'vorbis'].map(x => x.charCodeAt(0)));

/**
 * Demuxes a Webm stream (containing Vorbis audio) to output a Vorbis stream.
 * @memberof vorbis
 * @extends core.WebmBaseDemuxer
 */
class WebmDemuxer extends WebmBaseDemuxer {
  _checkHead(data) {
    if (data.readUInt8(0) !== 2 || !data.slice(4, 10).equals(VORBIS_HEAD)) {
      throw Error('Audio codec is not Vorbis!');
    }

    this.push(data.slice(3, 3 + data.readUInt8(1)));
    this.push(data.slice(3 + data.readUInt8(1), 3 + data.readUInt8(1) + data.readUInt8(2)));
    this.push(data.slice(3 + data.readUInt8(1) + data.readUInt8(2)));
  }
}

module.exports = WebmDemuxer;