Skip to content

Commit

Permalink
Fix bugs of issue audiocogs#27
Browse files Browse the repository at this point in the history
  • Loading branch information
aleen42 committed Sep 5, 2016
1 parent 6d76459 commit 6dfbfc3
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions src/ogg.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,42 @@ var AV = require('av');
try {
var OggDemuxer = require('ogg.js');
} catch (e) {};
if (!OggDemuxer) return;

OggDemuxer.plugins.push({
magic: "\177FLAC",

init: function() {
this.list = new AV.BufferList();
this.stream = new AV.Stream(this.list);
},

readHeaders: function(packet) {
var stream = this.stream;
this.list.append(new AV.Buffer(packet));

stream.advance(5); // magic
if (stream.readUInt8() != 1)
throw new Error('Unsupported FLAC version');

stream.advance(3);
if (stream.peekString(0, 4) != 'fLaC')
throw new Error('Not flac');

this.flac = AV.Demuxer.find(stream.peekSingleBuffer(0, stream.remainingBytes()));
if (!this.flac)
throw new Error('Flac demuxer not found');

this.flac.prototype.readChunk.call(this);
return true;
},

readPacket: function(packet) {
this.list.append(new AV.Buffer(packet));
this.flac.prototype.readChunk.call(this);
}
});

// return calling outside a function will be not proper.
// if (!OggDemuxer) return;

if (OggDemuxer) {
OggDemuxer.plugins.push({
magic: "\177FLAC",

init: function() {
this.list = new AV.BufferList();
this.stream = new AV.Stream(this.list);
},

readHeaders: function(packet) {
var stream = this.stream;
this.list.append(new AV.Buffer(packet));

stream.advance(5); // magic
if (stream.readUInt8() != 1)
throw new Error('Unsupported FLAC version');

stream.advance(3);
if (stream.peekString(0, 4) != 'fLaC')
throw new Error('Not flac');

this.flac = AV.Demuxer.find(stream.peekSingleBuffer(0, stream.remainingBytes()));
if (!this.flac)
throw new Error('Flac demuxer not found');

this.flac.prototype.readChunk.call(this);
return true;
},

readPacket: function(packet) {
this.list.append(new AV.Buffer(packet));
this.flac.prototype.readChunk.call(this);
}
});
}

0 comments on commit 6dfbfc3

Please sign in to comment.