webcodecs-node 0.2.2 → 0.5.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/README.md +4 -0
- package/dist/__tests__/AudioData.test.js +2 -1
- package/dist/__tests__/AudioData.test.js.map +1 -1
- package/dist/__tests__/AudioDecoder.test.js +8 -8
- package/dist/__tests__/AudioDecoder.test.js.map +1 -1
- package/dist/__tests__/AudioEncoder.test.js +3 -3
- package/dist/__tests__/AudioEncoder.test.js.map +1 -1
- package/dist/__tests__/EncodedChunks.test.js +3 -2
- package/dist/__tests__/EncodedChunks.test.js.map +1 -1
- package/dist/__tests__/HardwareAcceleration.test.js +2 -1
- package/dist/__tests__/HardwareAcceleration.test.js.map +1 -1
- package/dist/__tests__/ImageDecoder.test.js +16 -45
- package/dist/__tests__/ImageDecoder.test.js.map +1 -1
- package/dist/__tests__/ImageDecoder.wpt.test.d.ts +8 -0
- package/dist/__tests__/ImageDecoder.wpt.test.d.ts.map +1 -0
- package/dist/__tests__/ImageDecoder.wpt.test.js +135 -0
- package/dist/__tests__/ImageDecoder.wpt.test.js.map +1 -0
- package/dist/__tests__/NodeAvDecoder.test.d.ts +2 -0
- package/dist/__tests__/NodeAvDecoder.test.d.ts.map +1 -0
- package/dist/__tests__/NodeAvDecoder.test.js +206 -0
- package/dist/__tests__/NodeAvDecoder.test.js.map +1 -0
- package/dist/__tests__/NodeAvEncoder.test.d.ts +2 -0
- package/dist/__tests__/NodeAvEncoder.test.d.ts.map +1 -0
- package/dist/__tests__/NodeAvEncoder.test.js +176 -0
- package/dist/__tests__/NodeAvEncoder.test.js.map +1 -0
- package/dist/__tests__/VideoDecoder.test.js +5 -5
- package/dist/__tests__/VideoDecoder.test.js.map +1 -1
- package/dist/__tests__/VideoEncoder.test.js +3 -3
- package/dist/__tests__/VideoEncoder.test.js.map +1 -1
- package/dist/__tests__/VideoFrame.test.js +4 -1
- package/dist/__tests__/VideoFrame.test.js.map +1 -1
- package/dist/backends/index.d.ts +3 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +2 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/types.d.ts +168 -0
- package/dist/backends/types.d.ts.map +1 -0
- package/dist/backends/types.js +25 -0
- package/dist/backends/types.js.map +1 -0
- package/dist/codec-utils/audio-codecs.d.ts +60 -0
- package/dist/codec-utils/audio-codecs.d.ts.map +1 -0
- package/dist/codec-utils/audio-codecs.js +117 -0
- package/dist/codec-utils/audio-codecs.js.map +1 -0
- package/dist/codec-utils/formats.d.ts +42 -0
- package/dist/codec-utils/formats.d.ts.map +1 -0
- package/dist/codec-utils/formats.js +147 -0
- package/dist/codec-utils/formats.js.map +1 -0
- package/dist/codec-utils/index.d.ts +9 -0
- package/dist/codec-utils/index.d.ts.map +1 -0
- package/dist/codec-utils/index.js +12 -0
- package/dist/codec-utils/index.js.map +1 -0
- package/dist/codec-utils/types.d.ts +87 -0
- package/dist/codec-utils/types.d.ts.map +1 -0
- package/dist/codec-utils/types.js +10 -0
- package/dist/codec-utils/types.js.map +1 -0
- package/dist/containers/Demuxer.d.ts +114 -0
- package/dist/containers/Demuxer.d.ts.map +1 -0
- package/dist/containers/Demuxer.js +256 -0
- package/dist/containers/Demuxer.js.map +1 -0
- package/dist/containers/Muxer.d.ts +142 -0
- package/dist/containers/Muxer.d.ts.map +1 -0
- package/dist/containers/Muxer.js +295 -0
- package/dist/containers/Muxer.js.map +1 -0
- package/dist/containers/extract.d.ts +25 -0
- package/dist/containers/extract.d.ts.map +1 -0
- package/dist/containers/extract.js +64 -0
- package/dist/containers/extract.js.map +1 -0
- package/dist/containers/index.d.ts +40 -0
- package/dist/containers/index.d.ts.map +1 -0
- package/dist/containers/index.js +41 -0
- package/dist/containers/index.js.map +1 -0
- package/dist/containers/transcode.d.ts +138 -0
- package/dist/containers/transcode.d.ts.map +1 -0
- package/dist/containers/transcode.js +536 -0
- package/dist/containers/transcode.js.map +1 -0
- package/dist/core/AudioData.d.ts +5 -1
- package/dist/core/AudioData.d.ts.map +1 -1
- package/dist/core/AudioData.js +69 -13
- package/dist/core/AudioData.js.map +1 -1
- package/dist/core/EncodedAudioChunk.d.ts +1 -1
- package/dist/core/EncodedAudioChunk.d.ts.map +1 -1
- package/dist/core/EncodedAudioChunk.js +1 -1
- package/dist/core/EncodedAudioChunk.js.map +1 -1
- package/dist/core/EncodedVideoChunk.d.ts.map +1 -1
- package/dist/core/EncodedVideoChunk.js +3 -19
- package/dist/core/EncodedVideoChunk.js.map +1 -1
- package/dist/core/VideoFrame.d.ts +31 -11
- package/dist/core/VideoFrame.d.ts.map +1 -1
- package/dist/core/VideoFrame.js +244 -81
- package/dist/core/VideoFrame.js.map +1 -1
- package/dist/decoders/AudioDecoder.d.ts +14 -12
- package/dist/decoders/AudioDecoder.d.ts.map +1 -1
- package/dist/decoders/AudioDecoder.js +113 -173
- package/dist/decoders/AudioDecoder.js.map +1 -1
- package/dist/decoders/ImageDecoder.d.ts +1 -3
- package/dist/decoders/ImageDecoder.d.ts.map +1 -1
- package/dist/decoders/ImageDecoder.js +39 -192
- package/dist/decoders/ImageDecoder.js.map +1 -1
- package/dist/decoders/VideoDecoder.d.ts +14 -13
- package/dist/decoders/VideoDecoder.d.ts.map +1 -1
- package/dist/decoders/VideoDecoder.js +115 -166
- package/dist/decoders/VideoDecoder.js.map +1 -1
- package/dist/demos/demo-1080p-transcode.d.ts +8 -0
- package/dist/demos/demo-1080p-transcode.d.ts.map +1 -0
- package/dist/demos/demo-1080p-transcode.js +188 -0
- package/dist/demos/demo-1080p-transcode.js.map +1 -0
- package/dist/demos/demo-containers.d.ts +7 -0
- package/dist/demos/demo-containers.d.ts.map +1 -0
- package/dist/demos/demo-containers.js +140 -0
- package/dist/demos/demo-containers.js.map +1 -0
- package/dist/demos/demo-conversion.js +2 -2
- package/dist/demos/demo-conversion.js.map +1 -1
- package/dist/demos/demo-four-corners.d.ts +6 -0
- package/dist/demos/demo-four-corners.d.ts.map +1 -0
- package/dist/demos/demo-four-corners.js +218 -0
- package/dist/demos/demo-four-corners.js.map +1 -0
- package/dist/demos/demo-hwaccel-conversion.js +1 -1
- package/dist/demos/demo-hwaccel-conversion.js.map +1 -1
- package/dist/demos/demo-hwaccel.js +1 -1
- package/dist/demos/demo-hwaccel.js.map +1 -1
- package/dist/demos/demo-samples.js +232 -68
- package/dist/demos/demo-samples.js.map +1 -1
- package/dist/demos/demo-streaming.js +6 -6
- package/dist/demos/demo-streaming.js.map +1 -1
- package/dist/encoders/AudioEncoder.d.ts +14 -13
- package/dist/encoders/AudioEncoder.d.ts.map +1 -1
- package/dist/encoders/AudioEncoder.js +138 -228
- package/dist/encoders/AudioEncoder.js.map +1 -1
- package/dist/encoders/VideoEncoder.d.ts +13 -14
- package/dist/encoders/VideoEncoder.d.ts.map +1 -1
- package/dist/encoders/VideoEncoder.js +92 -161
- package/dist/encoders/VideoEncoder.js.map +1 -1
- package/dist/ffmpeg/index.d.ts +3 -2
- package/dist/ffmpeg/index.d.ts.map +1 -1
- package/dist/ffmpeg/index.js +3 -3
- package/dist/ffmpeg/index.js.map +1 -1
- package/dist/formats/conversions/batch-converter.d.ts +61 -0
- package/dist/formats/conversions/batch-converter.d.ts.map +1 -0
- package/dist/formats/conversions/batch-converter.js +274 -0
- package/dist/formats/conversions/batch-converter.js.map +1 -0
- package/dist/formats/conversions/frame-converter.d.ts +17 -0
- package/dist/formats/conversions/frame-converter.d.ts.map +1 -1
- package/dist/formats/conversions/frame-converter.js +144 -10
- package/dist/formats/conversions/frame-converter.js.map +1 -1
- package/dist/formats/conversions/index.d.ts +2 -0
- package/dist/formats/conversions/index.d.ts.map +1 -1
- package/dist/formats/conversions/index.js +4 -0
- package/dist/formats/conversions/index.js.map +1 -1
- package/dist/hardware/decoder-args.d.ts +2 -7
- package/dist/hardware/decoder-args.d.ts.map +1 -1
- package/dist/hardware/decoder-args.js +2 -32
- package/dist/hardware/decoder-args.js.map +1 -1
- package/dist/hardware/detection.d.ts +1 -1
- package/dist/hardware/detection.d.ts.map +1 -1
- package/dist/hardware/detection.js +54 -27
- package/dist/hardware/detection.js.map +1 -1
- package/dist/hardware/encoder-args.d.ts +2 -11
- package/dist/hardware/encoder-args.d.ts.map +1 -1
- package/dist/hardware/encoder-args.js +2 -71
- package/dist/hardware/encoder-args.js.map +1 -1
- package/dist/hardware/index.d.ts +2 -2
- package/dist/hardware/index.d.ts.map +1 -1
- package/dist/hardware/index.js +2 -2
- package/dist/hardware/index.js.map +1 -1
- package/dist/index.d.ts +5 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts +4 -17
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.js +57 -185
- package/dist/mediabunny/FFmpegAudioDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts +6 -39
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.js +66 -329
- package/dist/mediabunny/FFmpegAudioEncoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts +5 -38
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.js +39 -283
- package/dist/mediabunny/FFmpegVideoDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts +9 -37
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.js +49 -336
- package/dist/mediabunny/FFmpegVideoEncoder.js.map +1 -1
- package/dist/node-av/HardwarePipeline.d.ts +36 -0
- package/dist/node-av/HardwarePipeline.d.ts.map +1 -0
- package/dist/node-av/HardwarePipeline.js +243 -0
- package/dist/node-av/HardwarePipeline.js.map +1 -0
- package/dist/node-av/NodeAvAudioDecoder.d.ts +46 -0
- package/dist/node-av/NodeAvAudioDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvAudioDecoder.js +350 -0
- package/dist/node-av/NodeAvAudioDecoder.js.map +1 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts +50 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvAudioEncoder.js +506 -0
- package/dist/node-av/NodeAvAudioEncoder.js.map +1 -0
- package/dist/node-av/NodeAvImageDecoder.d.ts +114 -0
- package/dist/node-av/NodeAvImageDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvImageDecoder.js +406 -0
- package/dist/node-av/NodeAvImageDecoder.js.map +1 -0
- package/dist/node-av/NodeAvVideoDecoder.d.ts +43 -0
- package/dist/node-av/NodeAvVideoDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvVideoDecoder.js +365 -0
- package/dist/node-av/NodeAvVideoDecoder.js.map +1 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts +56 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvVideoEncoder.js +509 -0
- package/dist/node-av/NodeAvVideoEncoder.js.map +1 -0
- package/dist/polyfill.d.ts.map +1 -1
- package/dist/polyfill.js +11 -9
- package/dist/polyfill.js.map +1 -1
- package/dist/utils/aac.d.ts.map +1 -1
- package/dist/utils/aac.js +6 -0
- package/dist/utils/aac.js.map +1 -1
- package/dist/utils/buffer-pool.d.ts +109 -0
- package/dist/utils/buffer-pool.d.ts.map +1 -0
- package/dist/utils/buffer-pool.js +278 -0
- package/dist/utils/buffer-pool.js.map +1 -0
- package/dist/utils/codec-cache.d.ts +65 -0
- package/dist/utils/codec-cache.d.ts.map +1 -0
- package/dist/utils/codec-cache.js +116 -0
- package/dist/utils/codec-cache.js.map +1 -0
- package/dist/utils/errors.d.ts +62 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +84 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/event-target.d.ts +42 -0
- package/dist/utils/event-target.d.ts.map +1 -0
- package/dist/utils/event-target.js +96 -0
- package/dist/utils/event-target.js.map +1 -0
- package/dist/utils/hardware-pool.d.ts +88 -0
- package/dist/utils/hardware-pool.d.ts.map +1 -0
- package/dist/utils/hardware-pool.js +266 -0
- package/dist/utils/hardware-pool.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +12 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/timeout.d.ts +44 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/timeout.js +73 -0
- package/dist/utils/timeout.js.map +1 -0
- package/dist/utils/type-guards.d.ts +11 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js.map +1 -1
- package/package.json +20 -34
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standardized error utilities for WebCodecs compliance
|
|
3
|
+
*
|
|
4
|
+
* The WebCodecs spec uses specific DOMException error names:
|
|
5
|
+
* - InvalidStateError: operation on wrong state
|
|
6
|
+
* - NotSupportedError: unsupported codec/config
|
|
7
|
+
* - DataError: malformed/corrupt data
|
|
8
|
+
* - EncodingError: codec processing failure
|
|
9
|
+
* - AbortError: operation was aborted
|
|
10
|
+
* - TypeError: invalid parameters (thrown, not via callback)
|
|
11
|
+
* - QuotaExceededError: queue full
|
|
12
|
+
* - TimeoutError: operation timed out
|
|
13
|
+
*/
|
|
14
|
+
import { DOMException } from '../types/index.js';
|
|
15
|
+
/**
|
|
16
|
+
* Create a WebCodecs-compliant error
|
|
17
|
+
*/
|
|
18
|
+
export function createWebCodecsError(message, name) {
|
|
19
|
+
return new DOMException(message, name);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create an InvalidStateError (e.g., encoder not configured)
|
|
23
|
+
*/
|
|
24
|
+
export function invalidStateError(message) {
|
|
25
|
+
return new DOMException(message, 'InvalidStateError');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a NotSupportedError (e.g., unsupported codec)
|
|
29
|
+
*/
|
|
30
|
+
export function notSupportedError(message) {
|
|
31
|
+
return new DOMException(message, 'NotSupportedError');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a DataError (e.g., corrupt input data)
|
|
35
|
+
*/
|
|
36
|
+
export function dataError(message) {
|
|
37
|
+
return new DOMException(message, 'DataError');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create an EncodingError (e.g., codec processing failed)
|
|
41
|
+
*/
|
|
42
|
+
export function encodingError(message) {
|
|
43
|
+
return new DOMException(message, 'EncodingError');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create an AbortError (e.g., operation was reset/closed)
|
|
47
|
+
*/
|
|
48
|
+
export function abortError(message) {
|
|
49
|
+
return new DOMException(message, 'AbortError');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create a QuotaExceededError (e.g., queue full)
|
|
53
|
+
*/
|
|
54
|
+
export function quotaExceededError(message) {
|
|
55
|
+
return new DOMException(message, 'QuotaExceededError');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a TimeoutError (e.g., operation timed out)
|
|
59
|
+
*/
|
|
60
|
+
export function timeoutError(message) {
|
|
61
|
+
return new DOMException(message, 'TimeoutError');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Wrap an error as a DOMException if it isn't already
|
|
65
|
+
*
|
|
66
|
+
* @param error - The error to wrap
|
|
67
|
+
* @param defaultName - The error name to use if error is not a DOMException
|
|
68
|
+
*/
|
|
69
|
+
export function wrapAsWebCodecsError(error, defaultName = 'EncodingError') {
|
|
70
|
+
if (error instanceof DOMException) {
|
|
71
|
+
return error;
|
|
72
|
+
}
|
|
73
|
+
if (error instanceof Error) {
|
|
74
|
+
return new DOMException(error.message, defaultName);
|
|
75
|
+
}
|
|
76
|
+
return new DOMException(String(error), defaultName);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if an error is a specific WebCodecs error type
|
|
80
|
+
*/
|
|
81
|
+
export function isWebCodecsError(error, name) {
|
|
82
|
+
return error instanceof DOMException && error.name === name;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAcjD;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,IAAwB;IAExB,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAC/C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AACpD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe;IACxC,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,cAAkC,eAAe;IAEjD,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,IAAI,YAAY,CAAC,KAAK,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,IAAwB;IACvE,OAAO,KAAK,YAAY,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventTarget mixin for WebCodecs classes
|
|
3
|
+
* Provides addEventListener/removeEventListener/dispatchEvent compatibility
|
|
4
|
+
* while extending Node.js EventEmitter
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
export interface EventListenerOptions {
|
|
8
|
+
capture?: boolean;
|
|
9
|
+
once?: boolean;
|
|
10
|
+
passive?: boolean;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export type EventListener = (event: Event | {
|
|
14
|
+
type: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* WebCodecsEventTarget - Base class that extends EventEmitter
|
|
18
|
+
* and provides EventTarget-compatible methods
|
|
19
|
+
*/
|
|
20
|
+
export declare class WebCodecsEventTarget extends EventEmitter {
|
|
21
|
+
private _eventListeners;
|
|
22
|
+
/**
|
|
23
|
+
* Add an event listener (EventTarget-compatible)
|
|
24
|
+
*/
|
|
25
|
+
addEventListener(type: string, listener: EventListener | null, options?: boolean | EventListenerOptions): void;
|
|
26
|
+
/**
|
|
27
|
+
* Remove an event listener (EventTarget-compatible)
|
|
28
|
+
*/
|
|
29
|
+
removeEventListener(type: string, listener: EventListener | null, _options?: boolean | EventListenerOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Dispatch an event (EventTarget-compatible)
|
|
32
|
+
*/
|
|
33
|
+
dispatchEvent(event: Event | {
|
|
34
|
+
type: string;
|
|
35
|
+
}): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Event handler property support (e.g., ondequeue)
|
|
38
|
+
*/
|
|
39
|
+
protected _setEventHandler(type: string, handler: EventListener | null): void;
|
|
40
|
+
protected _getEventHandler(type: string): EventListener | null;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=event-target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-target.d.ts","sourceRoot":"","sources":["../../src/utils/event-target.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,IAAI,CAAC;AAEtE;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,OAAO,CAAC,eAAe,CAA2E;IAElG;;OAEG;IACH,gBAAgB,CACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,GAAG,IAAI,EAC9B,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACvC,IAAI;IA2CP;;OAEG;IACH,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,GAAG,IAAI,EAC9B,QAAQ,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACxC,IAAI;IAiBP;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO;IAMvD;;OAEG;IACH,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI;IAY7E,SAAS,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI;CAG/D"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventTarget mixin for WebCodecs classes
|
|
3
|
+
* Provides addEventListener/removeEventListener/dispatchEvent compatibility
|
|
4
|
+
* while extending Node.js EventEmitter
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
/**
|
|
8
|
+
* WebCodecsEventTarget - Base class that extends EventEmitter
|
|
9
|
+
* and provides EventTarget-compatible methods
|
|
10
|
+
*/
|
|
11
|
+
export class WebCodecsEventTarget extends EventEmitter {
|
|
12
|
+
_eventListeners = new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Add an event listener (EventTarget-compatible)
|
|
15
|
+
*/
|
|
16
|
+
addEventListener(type, listener, options) {
|
|
17
|
+
if (!listener)
|
|
18
|
+
return;
|
|
19
|
+
const once = typeof options === 'object' ? options.once ?? false : false;
|
|
20
|
+
// Store listener for removeEventListener
|
|
21
|
+
if (!this._eventListeners.has(type)) {
|
|
22
|
+
this._eventListeners.set(type, new Set());
|
|
23
|
+
}
|
|
24
|
+
this._eventListeners.get(type).add({ listener, once });
|
|
25
|
+
// Create wrapper that calls with Event-like object
|
|
26
|
+
const wrapper = (...args) => {
|
|
27
|
+
const eventData = typeof args[0] === 'object' && args[0] !== null ? args[0] : {};
|
|
28
|
+
const event = { type, target: this, ...eventData };
|
|
29
|
+
listener(event);
|
|
30
|
+
if (once) {
|
|
31
|
+
this._eventListeners.get(type)?.forEach((entry) => {
|
|
32
|
+
if (entry.listener === listener) {
|
|
33
|
+
this._eventListeners.get(type)?.delete(entry);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
// Store reference to wrapper for removal
|
|
39
|
+
listener._wrapper = wrapper;
|
|
40
|
+
if (once) {
|
|
41
|
+
this.once(type, wrapper);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.on(type, wrapper);
|
|
45
|
+
}
|
|
46
|
+
// Handle abort signal
|
|
47
|
+
if (typeof options === 'object' && options.signal) {
|
|
48
|
+
options.signal.addEventListener('abort', () => {
|
|
49
|
+
this.removeEventListener(type, listener);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Remove an event listener (EventTarget-compatible)
|
|
55
|
+
*/
|
|
56
|
+
removeEventListener(type, listener, _options) {
|
|
57
|
+
if (!listener)
|
|
58
|
+
return;
|
|
59
|
+
// Remove from our tracking
|
|
60
|
+
this._eventListeners.get(type)?.forEach((entry) => {
|
|
61
|
+
if (entry.listener === listener) {
|
|
62
|
+
this._eventListeners.get(type)?.delete(entry);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// Remove the wrapper from EventEmitter
|
|
66
|
+
const wrapper = listener._wrapper;
|
|
67
|
+
if (wrapper) {
|
|
68
|
+
this.off(type, wrapper);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Dispatch an event (EventTarget-compatible)
|
|
73
|
+
*/
|
|
74
|
+
dispatchEvent(event) {
|
|
75
|
+
const type = event.type;
|
|
76
|
+
this.emit(type, event);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Event handler property support (e.g., ondequeue)
|
|
81
|
+
*/
|
|
82
|
+
_setEventHandler(type, handler) {
|
|
83
|
+
const existingHandler = this[`_on${type}Handler`];
|
|
84
|
+
if (existingHandler) {
|
|
85
|
+
this.removeEventListener(type, existingHandler);
|
|
86
|
+
}
|
|
87
|
+
if (handler) {
|
|
88
|
+
this[`_on${type}Handler`] = handler;
|
|
89
|
+
this.addEventListener(type, handler);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
_getEventHandler(type) {
|
|
93
|
+
return this[`_on${type}Handler`] ?? null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=event-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-target.js","sourceRoot":"","sources":["../../src/utils/event-target.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAWtC;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAC5C,eAAe,GAAiE,IAAI,GAAG,EAAE,CAAC;IAElG;;OAEG;IACH,gBAAgB,CACd,IAAY,EACZ,QAA8B,EAC9B,OAAwC;QAExC,IAAI,CAAC,QAAQ;YAAE,OAAO;QAEtB,MAAM,IAAI,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAEzE,yCAAyC;QACzC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,GAAG,CA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ACrC,OAAQ,IAAY,CAAC,MAAM,IAAI,SAAS,CAAC,IAAI,IAAI,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Context Pool - Reuses GPU hardware contexts across encoders/decoders
|
|
3
|
+
*
|
|
4
|
+
* Creating hardware contexts (VAAPI, CUDA, QSV, etc.) has overhead.
|
|
5
|
+
* This pool maintains a set of reusable contexts to improve performance
|
|
6
|
+
* when encoding/decoding multiple streams or files sequentially.
|
|
7
|
+
*/
|
|
8
|
+
import { HardwareContext } from 'node-av/api';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for the hardware context pool
|
|
11
|
+
*/
|
|
12
|
+
export interface HardwarePoolConfig {
|
|
13
|
+
/** Maximum number of contexts to keep in the pool per device type */
|
|
14
|
+
maxContextsPerType?: number;
|
|
15
|
+
/** Time in ms after which unused contexts are disposed (default: 60000ms = 1 minute) */
|
|
16
|
+
idleTimeoutMs?: number;
|
|
17
|
+
/** Whether to automatically initialize contexts on first acquire (default: true) */
|
|
18
|
+
lazyInit?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Pool for reusing hardware contexts
|
|
22
|
+
*/
|
|
23
|
+
declare class HardwareContextPool {
|
|
24
|
+
private pools;
|
|
25
|
+
private config;
|
|
26
|
+
private cleanupTimer;
|
|
27
|
+
private disposed;
|
|
28
|
+
constructor(config?: HardwarePoolConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Acquire a hardware context from the pool
|
|
31
|
+
* Creates a new one if none available
|
|
32
|
+
*
|
|
33
|
+
* @param preferredType - Preferred device type (vaapi, cuda, qsv, videotoolbox)
|
|
34
|
+
* @returns Hardware context or null if none available
|
|
35
|
+
*/
|
|
36
|
+
acquire(preferredType?: string): HardwareContext | null;
|
|
37
|
+
/**
|
|
38
|
+
* Release a hardware context back to the pool
|
|
39
|
+
* The context will be reused by future acquire() calls
|
|
40
|
+
*
|
|
41
|
+
* @param context - The hardware context to release
|
|
42
|
+
*/
|
|
43
|
+
release(context: HardwareContext | null): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get pool statistics
|
|
46
|
+
*/
|
|
47
|
+
stats(): {
|
|
48
|
+
deviceType: string;
|
|
49
|
+
total: number;
|
|
50
|
+
inUse: number;
|
|
51
|
+
idle: number;
|
|
52
|
+
}[];
|
|
53
|
+
/**
|
|
54
|
+
* Dispose all contexts and stop the pool
|
|
55
|
+
*/
|
|
56
|
+
dispose(): void;
|
|
57
|
+
private acquireFromPool;
|
|
58
|
+
private acquireAnyAvailable;
|
|
59
|
+
private trackContext;
|
|
60
|
+
private disposeContext;
|
|
61
|
+
private startCleanupTimer;
|
|
62
|
+
private cleanupIdleContexts;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the global hardware context pool
|
|
66
|
+
* Creates one on first access with default configuration
|
|
67
|
+
*/
|
|
68
|
+
export declare function getHardwarePool(): HardwareContextPool;
|
|
69
|
+
/**
|
|
70
|
+
* Initialize the global pool with custom configuration
|
|
71
|
+
* Should be called before first use if custom config is needed
|
|
72
|
+
*/
|
|
73
|
+
export declare function initHardwarePool(config: HardwarePoolConfig): HardwareContextPool;
|
|
74
|
+
/**
|
|
75
|
+
* Dispose the global pool and release all contexts
|
|
76
|
+
* Call this when shutting down the application
|
|
77
|
+
*/
|
|
78
|
+
export declare function disposeHardwarePool(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Convenience function to acquire a hardware context from the global pool
|
|
81
|
+
*/
|
|
82
|
+
export declare function acquireHardwareContext(preferredType?: string): HardwareContext | null;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience function to release a hardware context back to the global pool
|
|
85
|
+
*/
|
|
86
|
+
export declare function releaseHardwareContext(context: HardwareContext | null): void;
|
|
87
|
+
export { HardwareContextPool };
|
|
88
|
+
//# sourceMappingURL=hardware-pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardware-pool.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1C;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAErF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAE5E;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardware Context Pool - Reuses GPU hardware contexts across encoders/decoders
|
|
3
|
+
*
|
|
4
|
+
* Creating hardware contexts (VAAPI, CUDA, QSV, etc.) has overhead.
|
|
5
|
+
* This pool maintains a set of reusable contexts to improve performance
|
|
6
|
+
* when encoding/decoding multiple streams or files sequentially.
|
|
7
|
+
*/
|
|
8
|
+
import { HardwareContext } from 'node-av/api';
|
|
9
|
+
import { createLogger } from './logger.js';
|
|
10
|
+
const logger = createLogger('HardwarePool');
|
|
11
|
+
const DEFAULT_CONFIG = {
|
|
12
|
+
maxContextsPerType: 2,
|
|
13
|
+
idleTimeoutMs: 60_000,
|
|
14
|
+
lazyInit: true,
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Pool for reusing hardware contexts
|
|
18
|
+
*/
|
|
19
|
+
class HardwareContextPool {
|
|
20
|
+
pools = new Map();
|
|
21
|
+
config;
|
|
22
|
+
cleanupTimer = null;
|
|
23
|
+
disposed = false;
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
26
|
+
this.startCleanupTimer();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Acquire a hardware context from the pool
|
|
30
|
+
* Creates a new one if none available
|
|
31
|
+
*
|
|
32
|
+
* @param preferredType - Preferred device type (vaapi, cuda, qsv, videotoolbox)
|
|
33
|
+
* @returns Hardware context or null if none available
|
|
34
|
+
*/
|
|
35
|
+
acquire(preferredType) {
|
|
36
|
+
if (this.disposed) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
// Try to get from pool first
|
|
40
|
+
if (preferredType) {
|
|
41
|
+
const pooled = this.acquireFromPool(preferredType);
|
|
42
|
+
if (pooled) {
|
|
43
|
+
logger.debug(`Reusing ${preferredType} context from pool`);
|
|
44
|
+
return pooled;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Try auto-detection
|
|
48
|
+
const pooled = this.acquireAnyAvailable();
|
|
49
|
+
if (pooled) {
|
|
50
|
+
return pooled;
|
|
51
|
+
}
|
|
52
|
+
// Create new context
|
|
53
|
+
try {
|
|
54
|
+
const context = HardwareContext.auto();
|
|
55
|
+
if (context) {
|
|
56
|
+
const deviceType = context.deviceTypeName || 'unknown';
|
|
57
|
+
logger.info(`Created new hardware context: ${deviceType}`);
|
|
58
|
+
this.trackContext(context, deviceType);
|
|
59
|
+
return context;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
logger.debug(`Failed to create hardware context: ${err.message}`);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Release a hardware context back to the pool
|
|
69
|
+
* The context will be reused by future acquire() calls
|
|
70
|
+
*
|
|
71
|
+
* @param context - The hardware context to release
|
|
72
|
+
*/
|
|
73
|
+
release(context) {
|
|
74
|
+
if (!context || this.disposed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const deviceType = context.deviceTypeName || 'unknown';
|
|
78
|
+
const pool = this.pools.get(deviceType);
|
|
79
|
+
if (!pool) {
|
|
80
|
+
// Context wasn't tracked, dispose it
|
|
81
|
+
this.disposeContext(context);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const entry = pool.find(e => e.context === context);
|
|
85
|
+
if (entry) {
|
|
86
|
+
entry.inUse = false;
|
|
87
|
+
entry.lastUsed = Date.now();
|
|
88
|
+
logger.debug(`Released ${deviceType} context back to pool (uses: ${entry.useCount})`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Context not in pool but matches type - add if pool not full
|
|
92
|
+
if (pool.length < this.config.maxContextsPerType) {
|
|
93
|
+
pool.push({
|
|
94
|
+
context,
|
|
95
|
+
inUse: false,
|
|
96
|
+
lastUsed: Date.now(),
|
|
97
|
+
useCount: 1,
|
|
98
|
+
});
|
|
99
|
+
logger.debug(`Added ${deviceType} context to pool`);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.disposeContext(context);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get pool statistics
|
|
108
|
+
*/
|
|
109
|
+
stats() {
|
|
110
|
+
const result = [];
|
|
111
|
+
for (const [deviceType, pool] of this.pools) {
|
|
112
|
+
const inUse = pool.filter(e => e.inUse).length;
|
|
113
|
+
result.push({
|
|
114
|
+
deviceType,
|
|
115
|
+
total: pool.length,
|
|
116
|
+
inUse,
|
|
117
|
+
idle: pool.length - inUse,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Dispose all contexts and stop the pool
|
|
124
|
+
*/
|
|
125
|
+
dispose() {
|
|
126
|
+
if (this.disposed)
|
|
127
|
+
return;
|
|
128
|
+
this.disposed = true;
|
|
129
|
+
if (this.cleanupTimer) {
|
|
130
|
+
clearInterval(this.cleanupTimer);
|
|
131
|
+
this.cleanupTimer = null;
|
|
132
|
+
}
|
|
133
|
+
for (const [deviceType, pool] of this.pools) {
|
|
134
|
+
for (const entry of pool) {
|
|
135
|
+
this.disposeContext(entry.context);
|
|
136
|
+
}
|
|
137
|
+
logger.debug(`Disposed ${pool.length} ${deviceType} contexts`);
|
|
138
|
+
}
|
|
139
|
+
this.pools.clear();
|
|
140
|
+
logger.info('Hardware context pool disposed');
|
|
141
|
+
}
|
|
142
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
143
|
+
// Private methods
|
|
144
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
145
|
+
acquireFromPool(deviceType) {
|
|
146
|
+
const pool = this.pools.get(deviceType);
|
|
147
|
+
if (!pool)
|
|
148
|
+
return null;
|
|
149
|
+
const available = pool.find(e => !e.inUse);
|
|
150
|
+
if (available) {
|
|
151
|
+
available.inUse = true;
|
|
152
|
+
available.useCount++;
|
|
153
|
+
return available.context;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
acquireAnyAvailable() {
|
|
158
|
+
for (const [deviceType, pool] of this.pools) {
|
|
159
|
+
const available = pool.find(e => !e.inUse);
|
|
160
|
+
if (available) {
|
|
161
|
+
available.inUse = true;
|
|
162
|
+
available.useCount++;
|
|
163
|
+
logger.debug(`Reusing ${deviceType} context from pool`);
|
|
164
|
+
return available.context;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
trackContext(context, deviceType) {
|
|
170
|
+
let pool = this.pools.get(deviceType);
|
|
171
|
+
if (!pool) {
|
|
172
|
+
pool = [];
|
|
173
|
+
this.pools.set(deviceType, pool);
|
|
174
|
+
}
|
|
175
|
+
pool.push({
|
|
176
|
+
context,
|
|
177
|
+
inUse: true,
|
|
178
|
+
lastUsed: Date.now(),
|
|
179
|
+
useCount: 1,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
disposeContext(context) {
|
|
183
|
+
try {
|
|
184
|
+
context.dispose();
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
logger.debug(`Error disposing context: ${err.message}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
startCleanupTimer() {
|
|
191
|
+
// Run cleanup every 10 seconds
|
|
192
|
+
this.cleanupTimer = setInterval(() => {
|
|
193
|
+
this.cleanupIdleContexts();
|
|
194
|
+
}, 10_000);
|
|
195
|
+
// Don't prevent process from exiting
|
|
196
|
+
if (this.cleanupTimer.unref) {
|
|
197
|
+
this.cleanupTimer.unref();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
cleanupIdleContexts() {
|
|
201
|
+
const now = Date.now();
|
|
202
|
+
for (const [deviceType, pool] of this.pools) {
|
|
203
|
+
// Keep at least one context per type, remove extras that are idle
|
|
204
|
+
const keepCount = 1;
|
|
205
|
+
let removed = 0;
|
|
206
|
+
for (let i = pool.length - 1; i >= keepCount; i--) {
|
|
207
|
+
const entry = pool[i];
|
|
208
|
+
if (!entry.inUse && (now - entry.lastUsed) > this.config.idleTimeoutMs) {
|
|
209
|
+
pool.splice(i, 1);
|
|
210
|
+
this.disposeContext(entry.context);
|
|
211
|
+
removed++;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (removed > 0) {
|
|
215
|
+
logger.debug(`Cleaned up ${removed} idle ${deviceType} contexts`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Singleton instance
|
|
221
|
+
let globalPool = null;
|
|
222
|
+
/**
|
|
223
|
+
* Get the global hardware context pool
|
|
224
|
+
* Creates one on first access with default configuration
|
|
225
|
+
*/
|
|
226
|
+
export function getHardwarePool() {
|
|
227
|
+
if (!globalPool) {
|
|
228
|
+
globalPool = new HardwareContextPool();
|
|
229
|
+
}
|
|
230
|
+
return globalPool;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Initialize the global pool with custom configuration
|
|
234
|
+
* Should be called before first use if custom config is needed
|
|
235
|
+
*/
|
|
236
|
+
export function initHardwarePool(config) {
|
|
237
|
+
if (globalPool) {
|
|
238
|
+
globalPool.dispose();
|
|
239
|
+
}
|
|
240
|
+
globalPool = new HardwareContextPool(config);
|
|
241
|
+
return globalPool;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Dispose the global pool and release all contexts
|
|
245
|
+
* Call this when shutting down the application
|
|
246
|
+
*/
|
|
247
|
+
export function disposeHardwarePool() {
|
|
248
|
+
if (globalPool) {
|
|
249
|
+
globalPool.dispose();
|
|
250
|
+
globalPool = null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Convenience function to acquire a hardware context from the global pool
|
|
255
|
+
*/
|
|
256
|
+
export function acquireHardwareContext(preferredType) {
|
|
257
|
+
return getHardwarePool().acquire(preferredType);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Convenience function to release a hardware context back to the global pool
|
|
261
|
+
*/
|
|
262
|
+
export function releaseHardwareContext(context) {
|
|
263
|
+
getHardwarePool().release(context);
|
|
264
|
+
}
|
|
265
|
+
export { HardwareContextPool };
|
|
266
|
+
//# sourceMappingURL=hardware-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hardware-pool.js","sourceRoot":"","sources":["../../src/utils/hardware-pool.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;AAwB5C,MAAM,cAAc,GAAiC;IACnD,kBAAkB,EAAE,CAAC;IACrB,aAAa,EAAE,MAAM;IACrB,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB;IACf,KAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;IAC5C,MAAM,CAA+B;IACrC,YAAY,GAA0B,IAAI,CAAC;IAC3C,QAAQ,GAAG,KAAK,CAAC;IAEzB,YAAY,SAA6B,EAAE;QACzC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;QAC/C,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,aAAsB;QAC5B,IAAI,IAAI,CAAC,QAAQ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U,GAAG,IAAI,mBAAmB,EAAE,CAAC;IACzC,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAA0B;IACzD,IAAI,UAAU,EAAE,CAAC;QACf,UAAU,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;IACD,UAAU,GAAG,IAAI,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,IAAI,UAAU,EAAE,CAAC;QACf,UAAU,CAAC,OAAO,EAAE,CAAC;QACrB,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAAsB;IAC3D,OAAO,eAAe,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA+B;IACpE,eAAe,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -8,4 +8,10 @@ export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, t
|
|
|
8
8
|
export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvcParameterSetsFromAnnexB, buildAvcDecoderConfig, convertAnnexBToAvcc, type AvcConfig, } from './avc.js';
|
|
9
9
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, type HvccConfig, } from './hevc.js';
|
|
10
10
|
export { parseAudioSpecificConfig, wrapAacFrameWithAdts, buildAudioSpecificConfig, stripAdtsHeader, type AacConfig, } from './aac.js';
|
|
11
|
+
export { WebCodecsEventTarget, type EventListener, type EventListenerOptions, } from './event-target.js';
|
|
12
|
+
export { getCodecBase, parseCodec, getVideoCodecName, getAudioCodecName, isVideoCodec, isAudioCodec, clearCodecCache, type ParsedCodec, type VideoCodecName, type AudioCodecName, } from './codec-cache.js';
|
|
13
|
+
export { withTimeout, createTimeoutWrapper, createTimeoutAbortController, DEFAULT_TIMEOUTS, } from './timeout.js';
|
|
14
|
+
export { createWebCodecsError, invalidStateError, notSupportedError, dataError, encodingError, abortError, quotaExceededError, timeoutError, wrapAsWebCodecsError, isWebCodecsError, type WebCodecsErrorName, } from './errors.js';
|
|
15
|
+
export { HardwareContextPool, getHardwarePool, initHardwarePool, disposeHardwarePool, acquireHardwareContext, releaseHardwareContext, type HardwarePoolConfig, } from './hardware-pool.js';
|
|
16
|
+
export { BufferPool, getBufferPool, initBufferPool, disposeBufferPool, acquireBuffer, releaseBuffer, type BufferPoolConfig, type BufferPoolStats, } from './buffer-pool.js';
|
|
11
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,KAAK,SAAS,GACf,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -13,4 +13,16 @@ export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, }
|
|
|
13
13
|
export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvcParameterSetsFromAnnexB, buildAvcDecoderConfig, convertAnnexBToAvcc, } from './avc.js';
|
|
14
14
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, } from './hevc.js';
|
|
15
15
|
export { parseAudioSpecificConfig, wrapAacFrameWithAdts, buildAudioSpecificConfig, stripAdtsHeader, } from './aac.js';
|
|
16
|
+
// EventTarget support
|
|
17
|
+
export { WebCodecsEventTarget, } from './event-target.js';
|
|
18
|
+
// Codec caching utilities
|
|
19
|
+
export { getCodecBase, parseCodec, getVideoCodecName, getAudioCodecName, isVideoCodec, isAudioCodec, clearCodecCache, } from './codec-cache.js';
|
|
20
|
+
// Timeout utilities
|
|
21
|
+
export { withTimeout, createTimeoutWrapper, createTimeoutAbortController, DEFAULT_TIMEOUTS, } from './timeout.js';
|
|
22
|
+
// Error utilities
|
|
23
|
+
export { createWebCodecsError, invalidStateError, notSupportedError, dataError, encodingError, abortError, quotaExceededError, timeoutError, wrapAsWebCodecsError, isWebCodecsError, } from './errors.js';
|
|
24
|
+
// Hardware context pooling
|
|
25
|
+
export { HardwareContextPool, getHardwarePool, initHardwarePool, disposeHardwarePool, acquireHardwareContext, releaseHardwareContext, } from './hardware-pool.js';
|
|
26
|
+
// Buffer pooling for efficient memory reuse
|
|
27
|
+
export { BufferPool, getBufferPool, initBufferPool, disposeBufferPool, acquireBuffer, releaseBuffer, } from './buffer-pool.js';
|
|
16
28
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,GAIpB,MAAM,kBAAkB,CAAC;AAE1B,gBAAgB;AAChB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,GAEpB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,GAEpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,GAEhB,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,GAIpB,MAAM,kBAAkB,CAAC;AAE1B,gBAAgB;AAChB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAA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