Skip to content

Fix planar audio conversion; release 0.5.6 - #1

Merged
kixelated merged 5 commits into
masterfrom
fix-planar-copy
Oct 23, 2026
Merged

kixelated merged 5 commits into
masterfrom
fix-planar-copy

Conversation

@kixelated

Copy link
Copy Markdown
Owner

Fixes the polyfill's planar audio for moq-dev/moq, whose @moq/hang patches around both bugs today.

  • Package as @kixelated/libavjs-webcodecs-polyfill. The packaging published as 0.5.5 was never pushed here. Building that commit reproduces the published dist/ byte for byte.
  • Fix AudioData.copyTo from interleaved to f32-planar. An interleaved resource is a single plane, but copyTo offset it by planeIndex * numberOfFrames before stepping to the channel, so every channel after the first read past its frames (NaN). Stereo Opus lost its right channel. The same path refused an explicit frameCount equal to the frames left, accepted negative or fractional indices, and threw on a destination view not aligned to the sample size.
  • Label planar decoder output as planar. AudioDecoder concatenated a planar libav frame's planes but labeled the result f32 (interleaved), so AAC read back garbled.
  • Release 0.5.6, with the package metadata pointing at this fork.

Testing

The regression tests live in moq (moq-dev/moq#6492, js/hang/src/util/libav.test.ts): stereo AAC decoded through the polyfill, plus copyTo from f32 and s16 interleaved into every plane, frame ranges, an unaligned view, and invalid indices. Both tests fail on 0.5.5 with the moq workarounds removed and pass on this branch's build.

To release

After merging: npm run build && npm publish from master (needs an npm login with publish rights to @kixelated).

(Written by Claude Opus 5.5)

kixelated and others added 4 commits October 22, 2026 21:28
Restores the packaging published as @kixelated/libavjs-webcodecs-polyfill@0.5.5,
which was never pushed: an ES module build with declarations under dist/.
Building this commit reproduces the published dist/ byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An interleaved resource is a single plane, but copyTo offset it by
planeIndex * numberOfFrames before also stepping to the channel, so every
channel after the first read past its frames. Stereo Opus lost its right
channel.

The same path refused an explicit frameCount equal to the frames left,
accepted negative or fractional indices, and threw on a destination view
that is not aligned to the sample size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AudioDecoder concatenated the planes of a planar libav frame but labeled the
result with the interleaved format, so AAC's planar float read back as
interleaved samples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Points the package metadata at this fork, where its source lives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T04:46:25.324215Z aa38559 New commits
🔒 Security Review 🔄 Running since 2026-10-23T04:43:38.380152Z aa38559 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4cb77130f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread package.json
"files": ["dist"],
"scripts": {
"build": "tsc && rollup -c",
"build": "tsc",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Publish a browser-loadable bundle

Changing the build to plain tsc stops producing dist/libavjs-webcodecs-polyfill.js and .min.js, although the checked-in Makefile:1-4, samples/worker-util.js:36, and multiple sample HTML files still load those exact artifacts as classic scripts. After a clean build those URLs therefore 404, and dist/main.js is not a drop-in replacement because it contains ESM imports rather than defining the expected LibAVWebCodecs global; retain the Rollup bundle or update every documented browser-loading flow.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining: this fork exists only to publish @kixelated/libavjs-webcodecs-polyfill as an ESM package for @moq/hang, and the published 0.5.5 was already built with plain tsc, so this PR changes nothing for that flow. The UMD Makefile, rollup.config.mjs and samples/ are untouched upstream files that the fork's packaging has never built; they stay as-is to keep the diff from upstream small.

(Written by Claude Opus 5.5)

Comment thread package.json
"types": "./src/main.ts"
".": {
"types": "./dist/main.d.ts",
"import": "./dist/main.js"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Emit resolvable specifiers in the ESM entry point

For consumers importing this package directly in Node or a native browser module, tsc preserves extensionless source specifiers such as ./encoded-audio-chunk in dist/main.js; standard ESM resolution does not append .js, so loading the exported entry fails on its first relative dependency unless a bundler rewrites it. Publish a bundled ESM file or emit .js-suffixed imports so the declared export is executable without bundler-specific resolution.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in aa38559: relative imports now carry .js and the package declares "type": "module". Confirmed the published 0.5.5 failed import() under Node with ERR_MODULE_NOT_FOUND; the rebuilt dist/main.js now loads under Node and Bun, and moq's js/hang/src/util/libav.test.ts passes against it.

(Written by Claude Opus 5.5)

tsc keeps extensionless relative specifiers, which Node's ESM resolver
refuses, so `import("@kixelated/libavjs-webcodecs-polyfill")` failed
with ERR_MODULE_NOT_FOUND outside Bun or a bundler. Suffix relative
imports with .js and declare "type": "module".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa38559a78

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread package.json
"types": "./src/main.ts"
".": {
"types": "./dist/main.d.ts",
"import": "./dist/main.js"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bundle the remaining bare browser dependency

When dist/main.js is served directly as a native browser module, loading still fails because the emitted graph preserves import '@ungap/global-this' from src/main.ts:37 (and other modules), and browsers cannot resolve that bare package specifier without a consumer-supplied import map. The new .js suffixes fix the relative imports, but this fresh remaining specifier means the advertised unbundled ESM entry is still not browser-loadable; bundle this dependency or publish browser-resolvable imports.

Useful? React with 👍 / 👎.

@kixelated
kixelated merged commit 13a8228 into master Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant