@audio/decode-aac 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/decode-aac.js +17 -8
  2. package/package.json +7 -4
package/decode-aac.js CHANGED
@@ -121,17 +121,23 @@ class AACDecoder {
121
121
 
122
122
  _tryM4AInit() {
123
123
  let buf = this._catAccum()
124
- let asc = null, alacCookie = null, stsz = null, stco = null, stsc = null
124
+ // tables are collected per trak — a second non-audio track (e.g. a QuickTime
125
+ // chapter/text track, github #48) must not clobber the audio track's tables
126
+ let traks = [], t = null
125
127
 
126
128
  parseBoxes(buf, 0, buf.length, (type, data) => {
127
- if (type === 'esds') asc = parseEsds(data)
128
- else if (type === 'alac') alacCookie = data // ALAC magic cookie: version/flags(4) + ALACSpecificConfig(24)
129
- else if (type === 'stsz') stsz = parseStsz(data)
130
- else if (type === 'stco') stco = parseStco(data)
131
- else if (type === 'co64') stco = parseCo64(data)
132
- else if (type === 'stsc') stsc = parseStsc(data)
129
+ if (type === 'trak') traks.push(t = {})
130
+ else if (!t) return
131
+ else if (type === 'esds') t.asc = parseEsds(data)
132
+ else if (type === 'alac') t.alacCookie = data // ALAC magic cookie: version/flags(4) + ALACSpecificConfig(24)
133
+ else if (type === 'stsz') t.stsz = parseStsz(data)
134
+ else if (type === 'stco') t.stco = parseStco(data)
135
+ else if (type === 'co64') t.stco = parseCo64(data)
136
+ else if (type === 'stsc') t.stsc = parseStsc(data)
133
137
  })
134
138
 
139
+ // the audio track: first trak with an audio config + sample tables
140
+ let { asc, alacCookie, stsz, stco, stsc } = traks.find(t => (t.asc || t.alacCookie) && t.stsz && t.stco?.length) ?? {}
135
141
  if ((!asc && !alacCookie) || !stsz || !stco?.length) return EMPTY // moov/tables not ready
136
142
 
137
143
  if (alacCookie) {
@@ -341,7 +347,10 @@ function parseBoxes(buf, start, end, cb) {
341
347
 
342
348
  let bodyOff = off + 8
343
349
  if (type === 'stsd') parseSampleDesc(buf, bodyOff, size - 8, cb)
344
- else if (CONTAINERS.has(type)) parseBoxes(buf, bodyOff + (type === 'meta' ? 4 : 0), off + size, cb)
350
+ else if (CONTAINERS.has(type)) {
351
+ if (type === 'trak') cb(type, null) // track boundary — tables that follow belong to this trak
352
+ parseBoxes(buf, bodyOff + (type === 'meta' ? 4 : 0), off + size, cb)
353
+ }
345
354
  else cb(type, buf.subarray(bodyOff, off + size))
346
355
 
347
356
  off += size
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@audio/decode-aac",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Decode AAC/M4A (FAAD2 WASM) and ALAC/Apple Lossless (pure JS) to PCM samples",
5
5
  "type": "module",
6
6
  "main": "decode-aac.js",
@@ -51,10 +51,13 @@
51
51
  "bugs": "https://github.com/audiojs/decode-aac/issues",
52
52
  "repository": {
53
53
  "type": "git",
54
- "url": "git+https://github.com/audiojs/decode-aac.git"
54
+ "url": "git+https://github.com/audiojs/decode-aac.git",
55
+ "directory": "packages/decode-aac"
55
56
  },
56
57
  "engines": {
57
- "node": ">=16"
58
+ "node": ">=18"
58
59
  },
59
- "audio": "./audio.js"
60
+ "audio": "./audio.js",
61
+ "sideEffects": false,
62
+ "funding": "https://github.com/sponsors/audiojs"
60
63
  }