@napi-rs/webcodecs 0.0.0
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.
- package/LICENSE +21 -0
- package/README.md +398 -0
- package/index.d.ts +1299 -0
- package/index.js +772 -0
- package/package.json +150 -0
- package/polyfill.d.ts +33 -0
- package/polyfill.js +20 -0
- package/standard.d.ts +413 -0
package/package.json
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@napi-rs/webcodecs",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "WebCodecs API implementation for Node.js using FFmpeg",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"N-API",
|
|
7
|
+
"NAPI",
|
|
8
|
+
"Rust",
|
|
9
|
+
"napi-rs",
|
|
10
|
+
"node-addon",
|
|
11
|
+
"node-addon-api"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+ssh://git@github.com/Brooooooklyn/webcodecs-node.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"main": "index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"import": "./index.js",
|
|
23
|
+
"require": "./index.js"
|
|
24
|
+
},
|
|
25
|
+
"./polyfill": {
|
|
26
|
+
"types": "./polyfill.d.ts",
|
|
27
|
+
"import": "./polyfill.js",
|
|
28
|
+
"require": "./polyfill.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"browser": "browser.js",
|
|
32
|
+
"types": "index.d.ts",
|
|
33
|
+
"files": [
|
|
34
|
+
"index.d.ts",
|
|
35
|
+
"index.js",
|
|
36
|
+
"polyfill.d.ts",
|
|
37
|
+
"polyfill.js",
|
|
38
|
+
"standard.d.ts"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"artifacts": "napi artifacts",
|
|
42
|
+
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
|
|
43
|
+
"build": "napi build --platform --release",
|
|
44
|
+
"build:debug": "napi build --platform",
|
|
45
|
+
"format": "run-p format:rs format:toml format:oxfmt format:prettier",
|
|
46
|
+
"format:prettier": "prettier . \"!**/*.{js,jsx,ts,tsx}\" -w",
|
|
47
|
+
"format:oxfmt": "oxfmt",
|
|
48
|
+
"format:toml": "taplo format",
|
|
49
|
+
"format:rs": "cargo fmt",
|
|
50
|
+
"lint": "oxlint --type-aware",
|
|
51
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
52
|
+
"test": "ava",
|
|
53
|
+
"typecheck": "tsc -b tsconfig.json",
|
|
54
|
+
"version": "napi version"
|
|
55
|
+
},
|
|
56
|
+
"lint-staged": {
|
|
57
|
+
"*.@(js|ts|tsx)": [
|
|
58
|
+
"oxlint --fix",
|
|
59
|
+
"oxfmt"
|
|
60
|
+
],
|
|
61
|
+
"*.@(yml|yaml|md|json)": [
|
|
62
|
+
"prettier --write"
|
|
63
|
+
],
|
|
64
|
+
"*.toml": [
|
|
65
|
+
"taplo format"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@emnapi/core": "^1.7.1",
|
|
70
|
+
"@emnapi/runtime": "^1.7.1",
|
|
71
|
+
"@napi-rs/cli": "^3.5.0",
|
|
72
|
+
"@napi-rs/wasm-runtime": "^1.1.0",
|
|
73
|
+
"@oxc-node/core": "^0.0.35",
|
|
74
|
+
"@taplo/cli": "^0.7.0",
|
|
75
|
+
"@tybys/wasm-util": "^0.10.1",
|
|
76
|
+
"@types/node": "^25.0.2",
|
|
77
|
+
"ava": "^6.4.1",
|
|
78
|
+
"chalk": "^5.6.2",
|
|
79
|
+
"emnapi": "^1.7.1",
|
|
80
|
+
"husky": "^9.1.7",
|
|
81
|
+
"lint-staged": "^16.2.7",
|
|
82
|
+
"mediabunny": "1.26.0",
|
|
83
|
+
"npm-run-all2": "^8.0.4",
|
|
84
|
+
"oxfmt": "^0.18.0",
|
|
85
|
+
"oxlint": "^1.33.0",
|
|
86
|
+
"oxlint-tsgolint": "^0.9.1",
|
|
87
|
+
"prettier": "^3.7.4",
|
|
88
|
+
"tinybench": "^6.0.0",
|
|
89
|
+
"typescript": "^5.9.3"
|
|
90
|
+
},
|
|
91
|
+
"napi": {
|
|
92
|
+
"binaryName": "webcodecs",
|
|
93
|
+
"constEnum": false,
|
|
94
|
+
"dtsHeaderFile": "dts-header.d.ts",
|
|
95
|
+
"targets": [
|
|
96
|
+
"x86_64-apple-darwin",
|
|
97
|
+
"aarch64-apple-darwin",
|
|
98
|
+
"x86_64-unknown-linux-gnu",
|
|
99
|
+
"x86_64-unknown-linux-musl",
|
|
100
|
+
"x86_64-pc-windows-msvc",
|
|
101
|
+
"aarch64-unknown-linux-gnu",
|
|
102
|
+
"aarch64-unknown-linux-musl",
|
|
103
|
+
"aarch64-pc-windows-msvc",
|
|
104
|
+
"armv7-unknown-linux-gnueabihf"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"packageManager": "pnpm@10.26.0",
|
|
108
|
+
"prettier": {
|
|
109
|
+
"arrowParens": "always",
|
|
110
|
+
"printWidth": 120,
|
|
111
|
+
"semi": false,
|
|
112
|
+
"singleQuote": true,
|
|
113
|
+
"trailingComma": "all"
|
|
114
|
+
},
|
|
115
|
+
"ava": {
|
|
116
|
+
"environmentVariables": {
|
|
117
|
+
"TS_NODE_PROJECT": "./tsconfig.json"
|
|
118
|
+
},
|
|
119
|
+
"extensions": {
|
|
120
|
+
"ts": "module"
|
|
121
|
+
},
|
|
122
|
+
"files": [
|
|
123
|
+
"__test__/**/*.spec.ts"
|
|
124
|
+
],
|
|
125
|
+
"nodeArguments": [
|
|
126
|
+
"--import",
|
|
127
|
+
"@oxc-node/core/register"
|
|
128
|
+
],
|
|
129
|
+
"timeout": "5m",
|
|
130
|
+
"workerThreads": false
|
|
131
|
+
},
|
|
132
|
+
"engines": {
|
|
133
|
+
"node": ">= 10"
|
|
134
|
+
},
|
|
135
|
+
"publishConfig": {
|
|
136
|
+
"access": "public",
|
|
137
|
+
"registry": "https://registry.npmjs.org/"
|
|
138
|
+
},
|
|
139
|
+
"optionalDependencies": {
|
|
140
|
+
"@napi-rs/webcodecs-darwin-x64": "0.0.0",
|
|
141
|
+
"@napi-rs/webcodecs-darwin-arm64": "0.0.0",
|
|
142
|
+
"@napi-rs/webcodecs-linux-x64-gnu": "0.0.0",
|
|
143
|
+
"@napi-rs/webcodecs-linux-x64-musl": "0.0.0",
|
|
144
|
+
"@napi-rs/webcodecs-win32-x64-msvc": "0.0.0",
|
|
145
|
+
"@napi-rs/webcodecs-linux-arm64-gnu": "0.0.0",
|
|
146
|
+
"@napi-rs/webcodecs-linux-arm64-musl": "0.0.0",
|
|
147
|
+
"@napi-rs/webcodecs-win32-arm64-msvc": "0.0.0",
|
|
148
|
+
"@napi-rs/webcodecs-linux-arm-gnueabihf": "0.0.0"
|
|
149
|
+
}
|
|
150
|
+
}
|
package/polyfill.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AudioData,
|
|
3
|
+
AudioDecoder,
|
|
4
|
+
AudioEncoder,
|
|
5
|
+
DOMRectReadOnly,
|
|
6
|
+
EncodedAudioChunk,
|
|
7
|
+
EncodedVideoChunk,
|
|
8
|
+
ImageDecoder,
|
|
9
|
+
ImageTrack,
|
|
10
|
+
ImageTrackList,
|
|
11
|
+
VideoColorSpace,
|
|
12
|
+
VideoDecoder,
|
|
13
|
+
VideoEncoder,
|
|
14
|
+
VideoFrame,
|
|
15
|
+
} from './index'
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
var VideoEncoder: typeof import('./index').VideoEncoder
|
|
19
|
+
var VideoDecoder: typeof import('./index').VideoDecoder
|
|
20
|
+
var AudioEncoder: typeof import('./index').AudioEncoder
|
|
21
|
+
var AudioDecoder: typeof import('./index').AudioDecoder
|
|
22
|
+
var VideoFrame: typeof import('./index').VideoFrame
|
|
23
|
+
var AudioData: typeof import('./index').AudioData
|
|
24
|
+
var EncodedVideoChunk: typeof import('./index').EncodedVideoChunk
|
|
25
|
+
var EncodedAudioChunk: typeof import('./index').EncodedAudioChunk
|
|
26
|
+
var ImageDecoder: typeof import('./index').ImageDecoder
|
|
27
|
+
var VideoColorSpace: typeof import('./index').VideoColorSpace
|
|
28
|
+
var ImageTrack: typeof import('./index').ImageTrack
|
|
29
|
+
var ImageTrackList: typeof import('./index').ImageTrackList
|
|
30
|
+
var DOMRectReadOnly: typeof import('./index').DOMRectReadOnly
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {}
|
package/polyfill.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const webcodecs = require('./index.js')
|
|
2
|
+
|
|
3
|
+
// WebCodecs classes (W3C spec)
|
|
4
|
+
globalThis.VideoEncoder ??= webcodecs.VideoEncoder
|
|
5
|
+
globalThis.VideoDecoder ??= webcodecs.VideoDecoder
|
|
6
|
+
globalThis.AudioEncoder ??= webcodecs.AudioEncoder
|
|
7
|
+
globalThis.AudioDecoder ??= webcodecs.AudioDecoder
|
|
8
|
+
globalThis.VideoFrame ??= webcodecs.VideoFrame
|
|
9
|
+
globalThis.AudioData ??= webcodecs.AudioData
|
|
10
|
+
globalThis.EncodedVideoChunk ??= webcodecs.EncodedVideoChunk
|
|
11
|
+
globalThis.EncodedAudioChunk ??= webcodecs.EncodedAudioChunk
|
|
12
|
+
globalThis.ImageDecoder ??= webcodecs.ImageDecoder
|
|
13
|
+
globalThis.VideoColorSpace ??= webcodecs.VideoColorSpace
|
|
14
|
+
|
|
15
|
+
// Supporting types (W3C spec)
|
|
16
|
+
globalThis.ImageTrack ??= webcodecs.ImageTrack
|
|
17
|
+
globalThis.ImageTrackList ??= webcodecs.ImageTrackList
|
|
18
|
+
|
|
19
|
+
// DOM types needed by WebCodecs (not available in Node.js)
|
|
20
|
+
globalThis.DOMRectReadOnly ??= webcodecs.DOMRectReadOnly
|
package/standard.d.ts
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard WebCodecs type definitions
|
|
3
|
+
* W3C WebCodecs Spec: https://w3c.github.io/webcodecs/
|
|
4
|
+
*
|
|
5
|
+
* These types match the W3C WebCodecs specification for interoperability.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// BufferSource Types
|
|
10
|
+
// ============================================================================
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* BufferSource per WebIDL spec - union of ArrayBuffer and ArrayBufferView
|
|
14
|
+
*/
|
|
15
|
+
export type BufferSource = ArrayBufferView | ArrayBuffer
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* AllowSharedBufferSource per WebIDL spec - includes SharedArrayBuffer
|
|
19
|
+
*/
|
|
20
|
+
export type AllowSharedBufferSource = ArrayBuffer | SharedArrayBuffer | ArrayBufferView
|
|
21
|
+
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// EncodedVideoChunk Types
|
|
24
|
+
// ============================================================================
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Type of encoded video chunk
|
|
28
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-encodedvideochunktype
|
|
29
|
+
*/
|
|
30
|
+
export type EncodedVideoChunkType = 'key' | 'delta'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Init dictionary for EncodedVideoChunk constructor
|
|
34
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-encodedvideochunkinit
|
|
35
|
+
*/
|
|
36
|
+
export interface EncodedVideoChunkInit {
|
|
37
|
+
/** Chunk type - 'key' for keyframes, 'delta' for dependent frames */
|
|
38
|
+
type: EncodedVideoChunkType
|
|
39
|
+
/** Timestamp in microseconds */
|
|
40
|
+
timestamp: number
|
|
41
|
+
/** Duration in microseconds (optional) */
|
|
42
|
+
duration?: number
|
|
43
|
+
/** Encoded video data */
|
|
44
|
+
data: BufferSource
|
|
45
|
+
/** ArrayBuffers to transfer (optional, for zero-copy) */
|
|
46
|
+
transfer?: ArrayBuffer[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ============================================================================
|
|
50
|
+
// EncodedAudioChunk Types
|
|
51
|
+
// ============================================================================
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Type of encoded audio chunk
|
|
55
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-encodedaudiochunktype
|
|
56
|
+
*/
|
|
57
|
+
export type EncodedAudioChunkType = 'key' | 'delta'
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Init dictionary for EncodedAudioChunk constructor
|
|
61
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-encodedaudiochunkinit
|
|
62
|
+
*/
|
|
63
|
+
export interface EncodedAudioChunkInit {
|
|
64
|
+
/** Chunk type - 'key' for keyframes, 'delta' for dependent frames */
|
|
65
|
+
type: EncodedAudioChunkType
|
|
66
|
+
/** Timestamp in microseconds */
|
|
67
|
+
timestamp: number
|
|
68
|
+
/** Duration in microseconds (optional) */
|
|
69
|
+
duration?: number
|
|
70
|
+
/** Encoded audio data */
|
|
71
|
+
data: BufferSource
|
|
72
|
+
/** ArrayBuffers to transfer (optional, for zero-copy) */
|
|
73
|
+
transfer?: ArrayBuffer[]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ============================================================================
|
|
77
|
+
// VideoEncoder Types
|
|
78
|
+
// ============================================================================
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Hardware acceleration preference
|
|
82
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-hardwareacceleration
|
|
83
|
+
*/
|
|
84
|
+
export type HardwareAcceleration = 'no-preference' | 'prefer-hardware' | 'prefer-software'
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Latency mode for encoding
|
|
88
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-latencymode
|
|
89
|
+
*/
|
|
90
|
+
export type LatencyMode = 'quality' | 'realtime'
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Bitrate mode for video encoding
|
|
94
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-videoencoderbitratemode
|
|
95
|
+
*/
|
|
96
|
+
export type VideoEncoderBitrateMode = 'constant' | 'variable' | 'quantizer'
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Alpha channel handling
|
|
100
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-alphaoption
|
|
101
|
+
*/
|
|
102
|
+
export type AlphaOption = 'discard' | 'keep'
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* VideoEncoder configuration
|
|
106
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-videoencoderconfig
|
|
107
|
+
*/
|
|
108
|
+
export interface VideoEncoderConfig {
|
|
109
|
+
/** Codec string (e.g., 'avc1.42001E', 'vp8', 'vp09.00.10.08') */
|
|
110
|
+
codec: string
|
|
111
|
+
/** Coded width in pixels */
|
|
112
|
+
width: number
|
|
113
|
+
/** Coded height in pixels */
|
|
114
|
+
height: number
|
|
115
|
+
/** Display width (optional, defaults to width) */
|
|
116
|
+
displayWidth?: number
|
|
117
|
+
/** Display height (optional, defaults to height) */
|
|
118
|
+
displayHeight?: number
|
|
119
|
+
/** Target bitrate in bits per second */
|
|
120
|
+
bitrate?: number
|
|
121
|
+
/** Target framerate */
|
|
122
|
+
framerate?: number
|
|
123
|
+
/** Hardware acceleration preference */
|
|
124
|
+
hardwareAcceleration?: HardwareAcceleration
|
|
125
|
+
/** Alpha channel handling */
|
|
126
|
+
alpha?: AlphaOption
|
|
127
|
+
/** Scalability mode (e.g., 'L1T1', 'L1T2') */
|
|
128
|
+
scalabilityMode?: string
|
|
129
|
+
/** Bitrate mode */
|
|
130
|
+
bitrateMode?: VideoEncoderBitrateMode
|
|
131
|
+
/** Latency mode */
|
|
132
|
+
latencyMode?: LatencyMode
|
|
133
|
+
/** AVC-specific configuration */
|
|
134
|
+
avc?: AvcEncoderConfig
|
|
135
|
+
/** HEVC-specific configuration */
|
|
136
|
+
hevc?: HevcEncoderConfig
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* AVC (H.264) encoder configuration
|
|
141
|
+
* @see https://w3c.github.io/webcodecs/avc_codec_registration.html
|
|
142
|
+
*/
|
|
143
|
+
export interface AvcEncoderConfig {
|
|
144
|
+
/** Bitstream format */
|
|
145
|
+
format?: 'avc' | 'annexb'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* HEVC (H.265) encoder configuration
|
|
150
|
+
* @see https://w3c.github.io/webcodecs/hevc_codec_registration.html
|
|
151
|
+
*/
|
|
152
|
+
export interface HevcEncoderConfig {
|
|
153
|
+
/** Bitstream format */
|
|
154
|
+
format?: 'hevc' | 'annexb'
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ============================================================================
|
|
158
|
+
// VideoDecoder Types
|
|
159
|
+
// ============================================================================
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* VideoDecoder configuration
|
|
163
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-videodecoderconfig
|
|
164
|
+
*/
|
|
165
|
+
export interface VideoDecoderConfig {
|
|
166
|
+
/** Codec string */
|
|
167
|
+
codec: string
|
|
168
|
+
/** Coded width (optional for some codecs) */
|
|
169
|
+
codedWidth?: number
|
|
170
|
+
/** Coded height (optional for some codecs) */
|
|
171
|
+
codedHeight?: number
|
|
172
|
+
/** Display aspect width */
|
|
173
|
+
displayAspectWidth?: number
|
|
174
|
+
/** Display aspect height */
|
|
175
|
+
displayAspectHeight?: number
|
|
176
|
+
/** Color space information */
|
|
177
|
+
colorSpace?: VideoColorSpaceInit
|
|
178
|
+
/** Hardware acceleration preference */
|
|
179
|
+
hardwareAcceleration?: HardwareAcceleration
|
|
180
|
+
/** Optimize for latency */
|
|
181
|
+
optimizeForLatency?: boolean
|
|
182
|
+
/** Codec-specific description (e.g., avcC box for H.264) */
|
|
183
|
+
description?: BufferSource
|
|
184
|
+
/** Rotation in degrees clockwise (0, 90, 180, 270) - W3C WebCodecs spec */
|
|
185
|
+
rotation?: number
|
|
186
|
+
/** Horizontal flip - W3C WebCodecs spec */
|
|
187
|
+
flip?: boolean
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ============================================================================
|
|
191
|
+
// AudioEncoder Types
|
|
192
|
+
// ============================================================================
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Bitrate mode for audio encoding
|
|
196
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-bitratemode
|
|
197
|
+
*/
|
|
198
|
+
export type BitrateMode = 'constant' | 'variable'
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* AudioEncoder configuration
|
|
202
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-audioencoderconfig
|
|
203
|
+
*/
|
|
204
|
+
export interface AudioEncoderConfig {
|
|
205
|
+
/** Codec string (e.g., 'opus', 'mp4a.40.2') */
|
|
206
|
+
codec: string
|
|
207
|
+
/** Sample rate in Hz */
|
|
208
|
+
sampleRate: number
|
|
209
|
+
/** Number of audio channels */
|
|
210
|
+
numberOfChannels: number
|
|
211
|
+
/** Target bitrate in bits per second */
|
|
212
|
+
bitrate?: number
|
|
213
|
+
/** Bitrate mode */
|
|
214
|
+
bitrateMode?: BitrateMode
|
|
215
|
+
/** Opus-specific configuration */
|
|
216
|
+
opus?: OpusEncoderConfig
|
|
217
|
+
/** AAC-specific configuration */
|
|
218
|
+
aac?: AacEncoderConfig
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Opus encoder configuration
|
|
223
|
+
* @see https://w3c.github.io/webcodecs/opus_codec_registration.html
|
|
224
|
+
*/
|
|
225
|
+
export interface OpusEncoderConfig {
|
|
226
|
+
/** Opus application type */
|
|
227
|
+
application?: 'voip' | 'audio' | 'lowdelay'
|
|
228
|
+
/** Frame duration in microseconds */
|
|
229
|
+
frameDuration?: number
|
|
230
|
+
/** Complexity (0-10) */
|
|
231
|
+
complexity?: number
|
|
232
|
+
/** Use DTX (discontinuous transmission) */
|
|
233
|
+
usedtx?: boolean
|
|
234
|
+
/** Use in-band FEC */
|
|
235
|
+
useinbandfec?: boolean
|
|
236
|
+
/** Packet loss percentage hint */
|
|
237
|
+
packetlossperc?: number
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* AAC encoder configuration
|
|
242
|
+
* @see https://w3c.github.io/webcodecs/aac_codec_registration.html
|
|
243
|
+
*/
|
|
244
|
+
export interface AacEncoderConfig {
|
|
245
|
+
/** AAC format */
|
|
246
|
+
format?: 'aac' | 'adts'
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ============================================================================
|
|
250
|
+
// AudioDecoder Types
|
|
251
|
+
// ============================================================================
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* AudioDecoder configuration
|
|
255
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-audiodecoderconfig
|
|
256
|
+
*/
|
|
257
|
+
export interface AudioDecoderConfig {
|
|
258
|
+
/** Codec string */
|
|
259
|
+
codec: string
|
|
260
|
+
/** Sample rate in Hz */
|
|
261
|
+
sampleRate: number
|
|
262
|
+
/** Number of audio channels */
|
|
263
|
+
numberOfChannels: number
|
|
264
|
+
/** Codec-specific description */
|
|
265
|
+
description?: BufferSource
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ============================================================================
|
|
269
|
+
// VideoFrame Types
|
|
270
|
+
// ============================================================================
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Pixel format for video frames
|
|
274
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-videoframepixelformat
|
|
275
|
+
*/
|
|
276
|
+
export type VideoPixelFormat =
|
|
277
|
+
| 'I420'
|
|
278
|
+
| 'I420A'
|
|
279
|
+
| 'I422'
|
|
280
|
+
| 'I422A'
|
|
281
|
+
| 'I444'
|
|
282
|
+
| 'I444A'
|
|
283
|
+
| 'I420P10'
|
|
284
|
+
| 'I420AP10'
|
|
285
|
+
| 'I422P10'
|
|
286
|
+
| 'I422AP10'
|
|
287
|
+
| 'I444P10'
|
|
288
|
+
| 'I444AP10'
|
|
289
|
+
| 'I420P12'
|
|
290
|
+
| 'I422P12'
|
|
291
|
+
| 'I444P12'
|
|
292
|
+
| 'NV12'
|
|
293
|
+
| 'NV21'
|
|
294
|
+
| 'RGBA'
|
|
295
|
+
| 'RGBX'
|
|
296
|
+
| 'BGRA'
|
|
297
|
+
| 'BGRX'
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* VideoFrame buffer init
|
|
301
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-videoframebufferinit
|
|
302
|
+
*/
|
|
303
|
+
export interface VideoFrameBufferInit {
|
|
304
|
+
/** Pixel format */
|
|
305
|
+
format: VideoPixelFormat
|
|
306
|
+
/** Coded width */
|
|
307
|
+
codedWidth: number
|
|
308
|
+
/** Coded height */
|
|
309
|
+
codedHeight: number
|
|
310
|
+
/** Timestamp in microseconds */
|
|
311
|
+
timestamp: number
|
|
312
|
+
/** Duration in microseconds */
|
|
313
|
+
duration?: number
|
|
314
|
+
/** Display width */
|
|
315
|
+
displayWidth?: number
|
|
316
|
+
/** Display height */
|
|
317
|
+
displayHeight?: number
|
|
318
|
+
/** Color space */
|
|
319
|
+
colorSpace?: VideoColorSpaceInit
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// ============================================================================
|
|
323
|
+
// VideoColorSpace Types
|
|
324
|
+
// ============================================================================
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Color primaries
|
|
328
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-videocolorprimaries
|
|
329
|
+
*/
|
|
330
|
+
export type VideoColorPrimaries = 'bt709' | 'bt470bg' | 'smpte170m' | 'bt2020' | 'smpte432'
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Transfer characteristics
|
|
334
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-videotransfercharacteristics
|
|
335
|
+
*/
|
|
336
|
+
export type VideoTransferCharacteristics = 'bt709' | 'smpte170m' | 'iec61966-2-1' | 'srgb' | 'linear' | 'pq' | 'hlg'
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Matrix coefficients
|
|
340
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-videomatrixcoefficients
|
|
341
|
+
*/
|
|
342
|
+
export type VideoMatrixCoefficients = 'rgb' | 'bt709' | 'bt470bg' | 'smpte170m' | 'bt2020-ncl'
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* VideoColorSpace init dictionary
|
|
346
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-videocolorspaceinit
|
|
347
|
+
*/
|
|
348
|
+
export interface VideoColorSpaceInit {
|
|
349
|
+
/** Color primaries */
|
|
350
|
+
primaries?: VideoColorPrimaries | null
|
|
351
|
+
/** Transfer characteristics */
|
|
352
|
+
transfer?: VideoTransferCharacteristics | null
|
|
353
|
+
/** Matrix coefficients */
|
|
354
|
+
matrix?: VideoMatrixCoefficients | null
|
|
355
|
+
/** Full range flag */
|
|
356
|
+
fullRange?: boolean | null
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// ============================================================================
|
|
360
|
+
// AudioData Types
|
|
361
|
+
// ============================================================================
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Audio sample format
|
|
365
|
+
* @see https://w3c.github.io/webcodecs/#enumdef-audiosampleformat
|
|
366
|
+
*/
|
|
367
|
+
export type AudioSampleFormat = 'u8' | 's16' | 's32' | 'f32' | 'u8-planar' | 's16-planar' | 's32-planar' | 'f32-planar'
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* AudioData init dictionary
|
|
371
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-audiodatainit
|
|
372
|
+
*/
|
|
373
|
+
export interface AudioDataInit {
|
|
374
|
+
/** Sample format */
|
|
375
|
+
format: AudioSampleFormat
|
|
376
|
+
/** Sample rate in Hz */
|
|
377
|
+
sampleRate: number
|
|
378
|
+
/** Number of frames (samples per channel) */
|
|
379
|
+
numberOfFrames: number
|
|
380
|
+
/** Number of channels */
|
|
381
|
+
numberOfChannels: number
|
|
382
|
+
/** Timestamp in microseconds */
|
|
383
|
+
timestamp: number
|
|
384
|
+
/** Audio data */
|
|
385
|
+
data: BufferSource
|
|
386
|
+
/** ArrayBuffers to transfer */
|
|
387
|
+
transfer?: ArrayBuffer[]
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ============================================================================
|
|
391
|
+
// ImageDecoder Types
|
|
392
|
+
// ============================================================================
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* ImageDecoder init dictionary
|
|
396
|
+
* @see https://w3c.github.io/webcodecs/#dictdef-imagedecodeinit
|
|
397
|
+
*/
|
|
398
|
+
export interface ImageDecoderInit {
|
|
399
|
+
/** Image data */
|
|
400
|
+
data: BufferSource | ReadableStream<Uint8Array>
|
|
401
|
+
/** MIME type */
|
|
402
|
+
type: string
|
|
403
|
+
/** Color space conversion */
|
|
404
|
+
colorSpaceConversion?: 'none' | 'default'
|
|
405
|
+
/** Desired width */
|
|
406
|
+
desiredWidth?: number
|
|
407
|
+
/** Desired height */
|
|
408
|
+
desiredHeight?: number
|
|
409
|
+
/** Prefer animation */
|
|
410
|
+
preferAnimation?: boolean
|
|
411
|
+
/** ArrayBuffers to transfer */
|
|
412
|
+
transfer?: ArrayBuffer[]
|
|
413
|
+
}
|