Skip to content

Commit

Permalink
chore(clean up): fixes onData callback and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Samir Das committed Aug 25, 2024
1 parent 5235edc commit a828b60
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"globals": {
"ENV": true
},
"parser": "@babel/eslint-parser",
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {
Expand Down
2 changes: 1 addition & 1 deletion dist/jmuxer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/jmuxer.min.js

Large diffs are not rendered by default.

123 changes: 94 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"author": "Samir Das",
"devDependencies": {
"@babel/core": "^7.10.5",
"@babel/eslint-parser": "^7.25.1",
"@babel/plugin-external-helpers": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@rollup/plugin-babel": "^5.2.1",
Expand Down
8 changes: 4 additions & 4 deletions src/jmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class JMuxer extends Event {
this.isMSESupported = !!window.MediaSource;
this.mediaSource = new window.MediaSource();
this.url = URL.createObjectURL(this.mediaSource);
if(window.MediaSource === window.ManagedMediaSource) {
if (window.MediaSource === window.ManagedMediaSource) {
try {
this.node.removeAttribute('src');
// ManagedMediaSource will not open without disableRemotePlayback set to false or source alternatives
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class JMuxer extends Event {
}
}
if (data.audio) {
slices = this.remuxController.aacParser.extractAAC(data.audio);
slices = AACParser.extractAAC(data.audio);
if (slices.length > 0) {
chunks.audio = this.getAudioFrames(slices, duration);
remux = true;
Expand Down Expand Up @@ -415,8 +415,8 @@ export default class JMuxer extends Event {
} else if (this.stream) {
this.stream.push(data.payload);
}
if (this.onData) {
this.onData(data.payload);
if (this.options.onData) {
this.options.onData(data.payload);
}
if (this.options.flushingTime === 0) {
this.applyAndClearBuffer();
Expand Down
10 changes: 6 additions & 4 deletions src/parsers/aac.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as debug from '../util/debug';

export class AACParser {
static aacHeader;

static get samplingRateMap() {
return [96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350];
}
Expand All @@ -17,7 +19,7 @@ export class AACParser {
return data[0] === 0xff && (data[1] & 0xf0) === 0xf0 && (data[1] & 0x06) === 0x00;
}

extractAAC(buffer) {
static extractAAC(buffer) {
let i = 0,
length = buffer.byteLength,
result = [],
Expand All @@ -29,8 +31,8 @@ export class AACParser {
return result;
}
headerLength = AACParser.getHeaderLength(buffer);
if (!this.aacHeader) {
this.aacHeader = buffer.subarray(0, headerLength);
if (!AACParser.aacHeader) {
AACParser.aacHeader = buffer.subarray(0, headerLength);
}

while (i < length) {
Expand All @@ -52,7 +54,7 @@ export class AACParser {
sampleIndex,
channelCount,
config = new Uint8Array(2),
headerData = this.aacHeader;
headerData = AACParser.aacHeader;

if (!headerData) return;

Expand Down
1 change: 0 additions & 1 deletion src/util/nalu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export class NALU {

static get NDR() { return 1; }
static get IDR() { return 5; }
static get SEI() { return 6; }
Expand Down
41 changes: 20 additions & 21 deletions test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ var aac = new Uint8Array([255, 241, 80, 128, 35, 159, 252, 33, 10, 84, 140, 49,

describe('Parser tests --', function() {

it('Number of extracted h264 NAL unit should be 2', function() {
var result = H264Parser.extractNALu(h264);
assert.equal(result.length, 2);
});

it('AAC pattern should return true', function() {
assert.equal(AACParser.isAACPattern(aac), true);
});

it('AAC header length should be 7 since CRC not present', function() {
assert.equal(AACParser.getHeaderLength(aac), 7);
});

it('AAC frame length should be 284', function() {
assert.equal(AACParser.getFrameLength(aac), 284);
});
it('Number of extracted h264 NAL unit should be 2', function() {
var result = H264Parser.extractNALu(h264);
assert.equal(result.length, 2);
});

it('AAC pattern should return true', function() {
assert.equal(AACParser.isAACPattern(aac), true);
});

it('AAC header length should be 7 since CRC not present', function() {
assert.equal(AACParser.getHeaderLength(aac), 7);
});

it('AAC frame length should be 284', function() {
assert.equal(AACParser.getFrameLength(aac), 284);
});

it('Number of extracted AAC frames should be 1', function() {
const parser = new AACParser(new BaseRemuxer());
var result = parser.extractAAC(aac);
assert.equal(result.length, 1);
});
it('Number of extracted AAC frames should be 1', function() {
var result = AACParser.extractAAC(aac);
assert.equal(result.length, 1);
});
});

0 comments on commit a828b60

Please sign in to comment.