Skip to content

Commit

Permalink
Merge pull request #21 from eshaz/opus-channel-families
Browse files Browse the repository at this point in the history
fix: opus channel family parsing, memory leaks
  • Loading branch information
eshaz authored Mar 14, 2022
2 parents 3f9c7eb + 80fa666 commit a2fd9f0
Show file tree
Hide file tree
Showing 17 changed files with 66,213 additions and 30,227 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ Each codec has it's own `CodecHeader` data type. See each class below for docume
data: Uint8Array,
sampleRate: 48000,
bandwidth: "fullband",
channelMappingFamily: 0,
channelMappingFamily: 1,
channelMappingTable: [0, 1],
coupledStreamCount: 1,
streamCount: 1,
channelMode: "stereo (left, right)",
frameCount: 1,
frameSize: 20,
Expand Down
2,633 changes: 1,340 additions & 1,293 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codec-parser",
"version": "2.0.0",
"version": "2.0.1",
"description": "Library that parses raw data from audio codecs into frames containing data, header values, duration, and other information.",
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -35,8 +35,8 @@
"type": "module",
"homepage": "https://github.com/eshaz/codec-parser#readme",
"devDependencies": {
"@types/jest": "^27.0.3",
"jest": "^27.3.1",
"prettier": "^2.4.1"
"@types/jest": "^27.4.1",
"jest": "^27.5.1",
"prettier": "^2.5.1"
}
}
15 changes: 9 additions & 6 deletions src/codecs/opus/OpusHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const channelMappingFamilies = {
6: "6.1 surround (front left, front center, front right, side left, side right, rear center, LFE)"
7: "7.1 surround (front left, front center, front right, side left, side right, rear left, rear right, LFE)"
*/
// additional channel mappings are user defined
};

const silkOnly = "SILK-only";
Expand Down Expand Up @@ -194,11 +195,13 @@ export default class OpusHeader extends CodecHeader {
// Byte (19 of 19)
// * `GGGGGGGG`: Channel Mapping Family
// set earlier to determine length
if (!header.channelMappingFamily in channelMappingFamilies) return null;

header.channelMode =
channelMappingFamilies[header.channelMappingFamily][header.channels - 1];
if (!header.channelMode) return null;
if (header.channelMappingFamily in channelMappingFamilies) {
header.channelMode =
channelMappingFamilies[header.channelMappingFamily][
header.channels - 1
];
if (!header.channelMode) return null;
}

if (header.channelMappingFamily !== 0) {
// * `HHHHHHHH`: Stream count
Expand All @@ -208,7 +211,7 @@ export default class OpusHeader extends CodecHeader {
header.coupledStreamCount = data[20];

// * `JJJJJJJJ|...` Channel Mapping table
header.channelMappingTable = data.subarray(21, header.channels + 21);
header.channelMappingTable = [...data.subarray(21, header.channels + 21)];
}

const packetConfig = configTable[0b11111000 & packetData[0]];
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ogg/OggPageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class OggPageHeader {

header.frameLength = 0;
header.pageSegmentTable = [];
header.pageSegmentBytes = data.subarray(27, header.length);
header.pageSegmentBytes = Uint8Array.from(data.subarray(27, header.length));

for (let i = 0, segmentLength = 0; i < pageSegmentTableLength; i++) {
const segmentByte = header.pageSegmentBytes[i];
Expand Down
1 change: 1 addition & 0 deletions test/CodecParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ describe("CodecParser", () => {
testParser("ogg.opus.framesize_40", mimeType, "opus", 0);
testParser("ogg.opus.framesize_60", mimeType, "opus", 0);
testParser("ogg.opus.surround", mimeType, "opus", 0);
testParser("ogg.opus.channel_family_255", mimeType, "opus", 0);
});

describe("Ogg Vorbis", () => {
Expand Down
Loading

0 comments on commit a2fd9f0

Please sign in to comment.