Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
776 changes: 4 additions & 772 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"name": "libavjs-webcodecs-polyfill",
"version": "0.5.5",
"name": "@kixelated/libavjs-webcodecs-polyfill",
"version": "0.5.6",
"description": "A WebCodecs polyfill (ponyfill, really), using libav.js",
"main": "dist/libavjs-webcodecs-polyfill.js",
"types": "src/main.ts",
"type": "module",
"exports": {
"import": "./dist/libavjs-webcodecs-polyfill.mjs",
"default": "./dist/libavjs-webcodecs-polyfill.js",
"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)

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 👍 / 👎.

}
},
"main": "./dist/main.js",
"types": "./dist/main.d.ts",
"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)

"clean": "rm -rf dist/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ennuicastr/libavjs-webcodecs-polyfill.git"
"url": "git+https://github.com/kixelated/libavjs-webcodecs-polyfill.git"
},
"keywords": [
"webcodecs",
Expand All @@ -29,19 +32,15 @@
"author": "Yahweasel",
"license": "0BSD",
"bugs": {
"url": "https://github.com/ennuicastr/libavjs-webcodecs-polyfill/issues"
"url": "https://github.com/kixelated/libavjs-webcodecs-polyfill/issues"
},
"homepage": "https://github.com/ennuicastr/libavjs-webcodecs-polyfill#readme",
"homepage": "https://github.com/kixelated/libavjs-webcodecs-polyfill#readme",
"dependencies": {
"@libav.js/types": "^6.7.7",
"@ungap/global-this": "^0.4.4"
},
"devDependencies": {
"@libav.js/variant-webm-vp9": "=6.7.7",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"rollup": "^4.12.0",
"typescript": "^5.2.2"
}
}
47 changes: 32 additions & 15 deletions src/audio-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ export class AudioData {
/* 3. If destFormat describes an interleaved AudioSampleFormat and
* options.planeIndex is greater than 0, throw a RangeError. */
const isInterleaved_ = isInterleaved(destFormat);
if (!isIndex(options.planeIndex))
throw new RangeError("Invalid plane");
if (isInterleaved_) {
if (options.planeIndex > 0)
throw new RangeError("Invalid plane");
Expand All @@ -273,7 +275,7 @@ export class AudioData {
/* 7. If options.frameOffset is greater than or equal to frameCount,
* throw a RangeError. */
const frameOffset = options.frameOffset || 0;
if (frameOffset >= frameCount)
if (!isIndex(frameOffset) || frameOffset >= frameCount)
throw new RangeError("Frame offset out of range");

/* 8. Let copyFrameCount be the difference of subtracting
Expand All @@ -284,7 +286,8 @@ export class AudioData {
if (typeof options.frameCount === "number") {
/* 1. If options.frameCount is greater than copyFrameCount, throw a
* RangeError. */
if (options.frameCount >= copyFrameCount)
if (!isIndex(options.frameCount) ||
options.frameCount > copyFrameCount)
throw new RangeError("Frame count out of range");

// 2. Otherwise, assign options.frameCount to copyFrameCount.
Expand Down Expand Up @@ -333,9 +336,10 @@ export class AudioData {
const resource = this._data;

/* 8. Let planeFrames be the region of resource corresponding to
* options.planeIndex. */
const planeFrames = resource.subarray(
options.planeIndex * this.numberOfFrames);
* options.planeIndex. An interleaved resource is a single plane
* holding every channel. */
const planeFrames = isInterleaved(this.format) ? resource :
resource.subarray(options.planeIndex * this.numberOfFrames);

const frameOffset = options.frameOffset || 0;
const numberOfChannels = this.numberOfChannels;
Expand All @@ -345,11 +349,17 @@ export class AudioData {
* copyElementCount samples have been copied. If destFormat does not
* equal [[format]], convert elements to the destFormat
* AudioSampleFormat while making the copy. */
if (this.format === destFormat) {
const dest = audioView(destFormat,
(<any> destination).buffer || destination,
(<any> destination).byteOffset || 0);
// A typed array needs an aligned offset, so an unaligned destination
// is written through a temporary copy.
const destBuffer = (<any> destination).buffer || destination;
const destOffset = (<any> destination).byteOffset || 0;
const aligned = destOffset % bytesPerSample_ === 0;
const dest = aligned ?
audioView(destFormat, destBuffer, destOffset) :
audioView(destFormat,
new ArrayBuffer(bytesPerSample_ * copyElementCount), 0);

if (this.format === destFormat) {
if (isInterleaved(destFormat)) {
dest.set(planeFrames.subarray(
frameOffset * numberOfChannels,
Expand All @@ -363,10 +373,6 @@ export class AudioData {

} else {
// Actual conversion necessary. Always to f32-planar.
const out = audioView(destFormat,
(<any> destination).buffer || destination,
(<any> destination).byteOffset || 0);

// First work out the conversion
let sub = 0;
let div = 1;
Expand All @@ -393,16 +399,19 @@ export class AudioData {
for (let i = options.planeIndex + frameOffset * numberOfChannels, o = 0;
o < copyElementCount;
i += numberOfChannels, o++)
out[o] = (planeFrames[i] - sub) / div;
dest[o] = (planeFrames[i] - sub) / div;

} else {
for (let i = frameOffset, o = 0;
o < copyElementCount;
i++, o++)
out[o] = (planeFrames[i] - sub) / div;
dest[o] = (planeFrames[i] - sub) / div;
}

}

if (!aligned)
new Uint8Array(destBuffer, destOffset).set(new Uint8Array(dest.buffer));
}

clone(): AudioData {
Expand Down Expand Up @@ -512,6 +521,14 @@ switch (format) {
}
}

/**
* Is this a valid index or count: a non-negative integer?
* @param value Value to check
*/
function isIndex(value: number) {
return Number.isSafeInteger(value) && value >= 0;
}

/**
* Is this format interleaved?
* @param format Sample format
Expand Down
18 changes: 9 additions & 9 deletions src/audio-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as ad from "./audio-data";
import * as eac from "./encoded-audio-chunk";
import * as et from "./event-target";
import * as libavs from "./avloader";
import * as misc from "./misc";
import * as ad from "./audio-data.js";
import * as eac from "./encoded-audio-chunk.js";
import * as et from "./event-target.js";
import * as libavs from "./avloader.js";
import * as misc from "./misc.js";

import type * as LibAVJS from "@libav.js/types";

Expand Down Expand Up @@ -314,22 +314,22 @@ export class AudioDecoder extends et.DequeueEventTarget {
break;

case libav.AV_SAMPLE_FMT_U8P:
format = "u8";
format = "u8-planar";
planar = true;
break;

case libav.AV_SAMPLE_FMT_S16P:
format = "s16";
format = "s16-planar";
planar = true;
break;

case libav.AV_SAMPLE_FMT_S32P:
format = "s32";
format = "s32-planar";
planar = true;
break;

case libav.AV_SAMPLE_FMT_FLTP:
format = "f32";
format = "f32-planar";
planar = true;
break;

Expand Down
12 changes: 6 additions & 6 deletions src/audio-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as ad from "./audio-data";
import * as adec from "./audio-decoder";
import * as eac from "./encoded-audio-chunk";
import * as et from "./event-target";
import * as libavs from "./avloader";
import * as misc from "./misc";
import * as ad from "./audio-data.js";
import * as adec from "./audio-decoder.js";
import * as eac from "./encoded-audio-chunk.js";
import * as et from "./event-target.js";
import * as libavs from "./avloader.js";
import * as misc from "./misc.js";

import type * as LibAVJS from "@libav.js/types";

Expand Down
18 changes: 9 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as eac from "./encoded-audio-chunk";
import * as ad from "./audio-data";
import * as adec from "./audio-decoder";
import * as aenc from "./audio-encoder";

import * as evc from "./encoded-video-chunk";
import * as vf from "./video-frame";
import * as vdec from "./video-decoder";
import * as venc from "./video-encoder";
import * as eac from "./encoded-audio-chunk.js";
import * as ad from "./audio-data.js";
import * as adec from "./audio-decoder.js";
import * as aenc from "./audio-encoder.js";

import * as evc from "./encoded-video-chunk.js";
import * as vf from "./video-frame.js";
import * as vdec from "./video-decoder.js";
import * as venc from "./video-encoder.js";
import '@ungap/global-this';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/encoded-video-chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as eac from "./encoded-audio-chunk";
import * as eac from "./encoded-audio-chunk.js";

export type EncodedVideoChunk = eac.EncodedAudioChunk;
export const EncodedVideoChunk = eac.EncodedAudioChunk;
Expand Down
24 changes: 12 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as eac from "./encoded-audio-chunk";
import * as ad from "./audio-data";
import * as adec from "./audio-decoder";
import * as aenc from "./audio-encoder";
import * as eac from "./encoded-audio-chunk.js";
import * as ad from "./audio-data.js";
import * as adec from "./audio-decoder.js";
import * as aenc from "./audio-encoder.js";

import * as evc from "./encoded-video-chunk";
import * as vf from "./video-frame";
import * as vdec from "./video-decoder";
import * as venc from "./video-encoder";
import * as evc from "./encoded-video-chunk.js";
import * as vf from "./video-frame.js";
import * as vdec from "./video-decoder.js";
import * as venc from "./video-encoder.js";

import * as rendering from "./rendering";
import * as rendering from "./rendering.js";

import * as config from "./config";
import * as libav from "./avloader";
import * as misc from "./misc";
import * as config from "./config.js";
import * as libav from "./avloader.js";
import * as misc from "./misc.js";

import type * as LibAVJS from "@libav.js/types";
import '@ungap/global-this';
Expand Down
4 changes: 2 additions & 2 deletions src/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as libav from "./avloader";
import * as vf from "./video-frame";
import * as libav from "./avloader.js";
import * as vf from "./video-frame.js";
import '@ungap/global-this';

import type * as LibAVJS from "@libav.js/types";
Expand Down
10 changes: 5 additions & 5 deletions src/video-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as evc from "./encoded-video-chunk";
import * as et from "./event-target";
import * as libavs from "./avloader";
import * as misc from "./misc";
import * as vf from "./video-frame";
import * as evc from "./encoded-video-chunk.js";
import * as et from "./event-target.js";
import * as libavs from "./avloader.js";
import * as misc from "./misc.js";
import * as vf from "./video-frame.js";

import * as LibAVJS from "@libav.js/types";

Expand Down
12 changes: 6 additions & 6 deletions src/video-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

import * as evc from "./encoded-video-chunk";
import * as et from "./event-target";
import * as libavs from "./avloader";
import * as misc from "./misc";
import * as vd from "./video-decoder";
import * as vf from "./video-frame";
import * as evc from "./encoded-video-chunk.js";
import * as et from "./event-target.js";
import * as libavs from "./avloader.js";
import * as misc from "./misc.js";
import * as vd from "./video-decoder.js";
import * as vf from "./video-frame.js";

import type * as LibAVJS from "@libav.js/types";

Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"lib": ["es2020", "dom"]
}
"lib": ["es2020", "dom"],
"declaration": true,
"outDir": "dist"
},
"include": ["src"]
}