@mediabunny/server 1.45.5 → 1.47.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 +16 -0
- package/dist/bundles/mediabunny-server.cjs +48 -5
- package/dist/bundles/mediabunny-server.min.cjs +2 -2
- package/dist/bundles/mediabunny-server.min.mjs +2 -2
- package/dist/bundles/mediabunny-server.mjs +55 -6
- package/dist/mediabunny-server.d.ts +20 -1
- package/dist/modules/src/audio-sample.d.ts.map +1 -1
- package/dist/modules/src/audio-sample.js +3 -0
- package/dist/modules/src/index.d.ts +21 -2
- package/dist/modules/src/index.d.ts.map +1 -1
- package/dist/modules/src/index.js +20 -2
- package/dist/modules/src/misc.d.ts +2 -2
- package/dist/modules/src/misc.d.ts.map +1 -1
- package/dist/modules/src/misc.js +23 -2
- package/dist/modules/src/video-decoder.js +1 -1
- package/dist/modules/src/video-encoder.js +1 -1
- package/dist/modules/src/video-sample.d.ts.map +1 -1
- package/dist/modules/src/video-sample.js +3 -0
- package/dist/modules/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/audio-sample.ts +3 -0
- package/src/index.ts +59 -2
- package/src/misc.ts +31 -2
- package/src/video-decoder.ts +1 -1
- package/src/video-encoder.ts +1 -1
- package/src/video-sample.ts +3 -0
package/dist/modules/src/misc.js
CHANGED
|
@@ -42,6 +42,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
43
|
exports.getChannelLayout = exports.fromAudioSampleFormat = exports.toAudioSampleFormat = exports.fromPixelFormat = exports.toPixelFormat = exports.unmapMatrixCoefficients = exports.mapMatrixCoefficients = exports.unmapTransferCharacteristics = exports.mapTransferCharacteristics = exports.unmapColorPrimaries = exports.mapColorPrimaries = exports.getHardwareEncoderCodec = exports.getHardwareDecoderCodec = exports.getHardwareContext = exports.CODEC_TO_CODEC_ID = void 0;
|
|
44
44
|
const NodeAv = __importStar(require("node-av"));
|
|
45
|
+
const index_1 = require("./index");
|
|
45
46
|
exports.CODEC_TO_CODEC_ID = {
|
|
46
47
|
avc: NodeAv.AV_CODEC_ID_H264,
|
|
47
48
|
hevc: NodeAv.AV_CODEC_ID_HEVC,
|
|
@@ -58,14 +59,29 @@ exports.CODEC_TO_CODEC_ID = {
|
|
|
58
59
|
};
|
|
59
60
|
let cachedHardwareContext = undefined;
|
|
60
61
|
const getHardwareContext = () => {
|
|
62
|
+
if (index_1._serverOptions.hardwareContext !== undefined && typeof index_1._serverOptions.hardwareContext !== 'function') {
|
|
63
|
+
// Return the user-provided one
|
|
64
|
+
return index_1._serverOptions.hardwareContext;
|
|
65
|
+
}
|
|
61
66
|
if (cachedHardwareContext === undefined) {
|
|
62
67
|
cachedHardwareContext = NodeAv.HardwareContext.auto();
|
|
63
68
|
}
|
|
64
69
|
return cachedHardwareContext;
|
|
65
70
|
};
|
|
66
71
|
exports.getHardwareContext = getHardwareContext;
|
|
72
|
+
const validateHwContext = (hw) => {
|
|
73
|
+
if (hw !== null && !(hw instanceof NodeAv.HardwareContext)) {
|
|
74
|
+
throw new TypeError('When serverOptions.hardwareContext is a function, it must return or resolve to a'
|
|
75
|
+
+ ' NodeAv.HardwareContext or null.');
|
|
76
|
+
}
|
|
77
|
+
};
|
|
67
78
|
const hardwareDecoderCodecCache = new Map();
|
|
68
|
-
const getHardwareDecoderCodec = (codecId) => {
|
|
79
|
+
const getHardwareDecoderCodec = async (codecId) => {
|
|
80
|
+
if (typeof index_1._serverOptions.hardwareContext === 'function') {
|
|
81
|
+
const hw = await index_1._serverOptions.hardwareContext(codecId);
|
|
82
|
+
validateHwContext(hw);
|
|
83
|
+
return hw?.getDecoderCodec(codecId) ?? null;
|
|
84
|
+
}
|
|
69
85
|
if (!hardwareDecoderCodecCache.has(codecId)) {
|
|
70
86
|
const hw = (0, exports.getHardwareContext)();
|
|
71
87
|
hardwareDecoderCodecCache.set(codecId, hw?.getDecoderCodec(codecId) ?? null);
|
|
@@ -74,7 +90,12 @@ const getHardwareDecoderCodec = (codecId) => {
|
|
|
74
90
|
};
|
|
75
91
|
exports.getHardwareDecoderCodec = getHardwareDecoderCodec;
|
|
76
92
|
const hardwareEncoderCodecCache = new Map();
|
|
77
|
-
const getHardwareEncoderCodec = (codecId) => {
|
|
93
|
+
const getHardwareEncoderCodec = async (codecId) => {
|
|
94
|
+
if (typeof index_1._serverOptions.hardwareContext === 'function') {
|
|
95
|
+
const hw = await index_1._serverOptions.hardwareContext(codecId);
|
|
96
|
+
validateHwContext(hw);
|
|
97
|
+
return hw?.getEncoderCodec(codecId) ?? null;
|
|
98
|
+
}
|
|
78
99
|
if (!hardwareEncoderCodecCache.has(codecId)) {
|
|
79
100
|
const hw = (0, exports.getHardwareContext)();
|
|
80
101
|
hardwareEncoderCodecCache.set(codecId, hw?.getEncoderCodec(codecId) ?? null);
|
|
@@ -82,7 +82,7 @@ class NodeAvVideoDecoder extends mediabunny_1.CustomVideoDecoder {
|
|
|
82
82
|
codec = NodeAv.Codec.findDecoder(codecId);
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
|
-
codec = (0, misc_1.getHardwareDecoderCodec)(codecId) ?? NodeAv.Codec.findDecoder(codecId);
|
|
85
|
+
codec = (await (0, misc_1.getHardwareDecoderCodec)(codecId)) ?? NodeAv.Codec.findDecoder(codecId);
|
|
86
86
|
}
|
|
87
87
|
if (!codec) {
|
|
88
88
|
throw new Error(`Unable to obtain libav codec for '${this.codec}'.`);
|
|
@@ -80,7 +80,7 @@ class NodeAvVideoEncoder extends mediabunny_1.CustomVideoEncoder {
|
|
|
80
80
|
codec = NodeAv.Codec.findEncoder(codecId);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
codec = (0, misc_1.getHardwareEncoderCodec)(codecId) ?? NodeAv.Codec.findEncoder(codecId);
|
|
83
|
+
codec = (await (0, misc_1.getHardwareEncoderCodec)(codecId)) ?? NodeAv.Codec.findEncoder(codecId);
|
|
84
84
|
}
|
|
85
85
|
if (!codec) {
|
|
86
86
|
throw new Error(`Unable to obtain libav codec for '${this.codec}'.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video-sample.d.ts","sourceRoot":"","sources":["../../../src/video-sample.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,KAAK,YAAY,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,WAAW,EACX,cAAc,EACd,oCAAoC,EACpC,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAqBlC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,0BAA2B,SAAQ,mBAAmB;IAIlE;;;OAGG;IACH,IAAI,KAAK,iBAMR;gBAEW,KAAK,EAAE,MAAM,CAAC,KAAK;
|
|
1
|
+
{"version":3,"file":"video-sample.d.ts","sourceRoot":"","sources":["../../../src/video-sample.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,KAAK,YAAY,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,WAAW,EACX,cAAc,EACd,oCAAoC,EACpC,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAqBlC;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,0BAA2B,SAAQ,mBAAmB;IAIlE;;;OAGG;IACH,IAAI,KAAK,iBAMR;gBAEW,KAAK,EAAE,MAAM,CAAC,KAAK;IAa/B,SAAS,IAAI,sBAAsB,GAAG,IAAI;IAI1C,aAAa,IAAI,MAAM;IAIvB,cAAc,IAAI,MAAM;IAIxB,mBAAmB,IAAI,MAAM;IAQ7B,oBAAoB,IAAI,MAAM;IAQ9B,aAAa,IAAI,qBAAqB;IActC,KAAK,IAAI,IAAI;IAKb,aAAa,IAAI,YAAY,CAAC,cAAc,EAAE,CAAC;IASzC,WAAW,CAChB,IAAI,EAAE,WAAW,CAAC,eAAe,EAAE,WAAW,CAAC,EAG/C,UAAU,EAAE,oBAAoB,GAC9B,OAAO,CAAC,WAAW,CAAC;CAiCvB;AAED,eAAO,MAAM,wBAAwB,GAAU,QAAQ,WAAW,EAAE,OAAO,MAAM,CAAC,KAAK,EAAE,YAAY,MAAM,GAAG,IAAI,qCA+BjH,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAChC,QAAQ,WAAW,EACnB,aAAa,oCAAoC,KAC/C,OAAO,CAAC,WAAW,GAAG,IAAI,CAkG5B,CAAC"}
|
|
@@ -81,6 +81,9 @@ class AvFrameVideoSampleResource extends mediabunny_1.VideoSampleResource {
|
|
|
81
81
|
}
|
|
82
82
|
constructor(frame) {
|
|
83
83
|
super();
|
|
84
|
+
if (!(frame instanceof NodeAv.Frame)) {
|
|
85
|
+
throw new TypeError('frame must be a NodeAv.Frame.');
|
|
86
|
+
}
|
|
84
87
|
if (frame.getMediaType() !== NodeAv.AVMEDIA_TYPE_VIDEO) {
|
|
85
88
|
throw new Error('AvFrameVideoSampleResource must be initialized with a video frame.');
|
|
86
89
|
}
|