@livekit/rtc-node 0.12.2 → 0.13.1
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/dist/audio_frame.cjs +2 -2
- package/dist/audio_frame.cjs.map +1 -1
- package/dist/audio_frame.d.cts +2 -3
- package/dist/audio_frame.d.ts +2 -3
- package/dist/audio_frame.d.ts.map +1 -1
- package/dist/audio_frame.js +3 -3
- package/dist/audio_frame.js.map +1 -1
- package/dist/audio_resampler.cjs +10 -7
- package/dist/audio_resampler.cjs.map +1 -1
- package/dist/audio_resampler.d.cts +2 -3
- package/dist/audio_resampler.d.ts +2 -3
- package/dist/audio_resampler.d.ts.map +1 -1
- package/dist/audio_resampler.js +13 -10
- package/dist/audio_resampler.js.map +1 -1
- package/dist/audio_source.cjs +6 -4
- package/dist/audio_source.cjs.map +1 -1
- package/dist/audio_source.d.cts +3 -3
- package/dist/audio_source.d.ts +3 -3
- package/dist/audio_source.d.ts.map +1 -1
- package/dist/audio_source.js +9 -7
- package/dist/audio_source.js.map +1 -1
- package/dist/audio_stream.cjs +1 -2
- package/dist/audio_stream.cjs.map +1 -1
- package/dist/audio_stream.d.cts +2 -3
- package/dist/audio_stream.d.ts +2 -3
- package/dist/audio_stream.d.ts.map +1 -1
- package/dist/audio_stream.js +2 -3
- package/dist/audio_stream.js.map +1 -1
- package/dist/e2ee.cjs +19 -20
- package/dist/e2ee.cjs.map +1 -1
- package/dist/e2ee.d.cts +5 -6
- package/dist/e2ee.d.ts +5 -6
- package/dist/e2ee.d.ts.map +1 -1
- package/dist/e2ee.js +29 -30
- package/dist/e2ee.js.map +1 -1
- package/dist/ffi_client.cjs +6 -5
- package/dist/ffi_client.cjs.map +1 -1
- package/dist/ffi_client.d.cts +10 -10
- package/dist/ffi_client.d.ts +10 -10
- package/dist/ffi_client.d.ts.map +1 -1
- package/dist/ffi_client.js +6 -10
- package/dist/ffi_client.js.map +1 -1
- package/dist/index.cjs +16 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -35
- package/dist/index.d.ts +6 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -46
- package/dist/index.js.map +1 -1
- package/dist/napi/native.d.cjs.map +1 -1
- package/dist/napi/native.d.ts +5 -5
- package/dist/native.d.ts +5 -5
- package/dist/participant.cjs +60 -36
- package/dist/participant.cjs.map +1 -1
- package/dist/participant.d.cts +11 -11
- package/dist/participant.d.ts +11 -11
- package/dist/participant.d.ts.map +1 -1
- package/dist/participant.js +78 -52
- package/dist/participant.js.map +1 -1
- package/dist/proto/audio_frame_pb.cjs +977 -125
- package/dist/proto/audio_frame_pb.cjs.map +1 -1
- package/dist/proto/audio_frame_pb.d.cts +502 -417
- package/dist/proto/audio_frame_pb.d.ts +502 -417
- package/dist/proto/audio_frame_pb.d.ts.map +1 -1
- package/dist/proto/audio_frame_pb.js +943 -85
- package/dist/proto/audio_frame_pb.js.map +1 -1
- package/dist/proto/e2ee_pb.cjs +700 -85
- package/dist/proto/e2ee_pb.cjs.map +1 -1
- package/dist/proto/e2ee_pb.d.cts +331 -263
- package/dist/proto/e2ee_pb.d.ts +331 -263
- package/dist/proto/e2ee_pb.d.ts.map +1 -1
- package/dist/proto/e2ee_pb.js +675 -57
- package/dist/proto/e2ee_pb.js.map +1 -1
- package/dist/proto/ffi_pb.cjs +369 -36
- package/dist/proto/ffi_pb.cjs.map +1 -1
- package/dist/proto/ffi_pb.d.cts +156 -109
- package/dist/proto/ffi_pb.d.ts +156 -109
- package/dist/proto/ffi_pb.d.ts.map +1 -1
- package/dist/proto/ffi_pb.js +364 -29
- package/dist/proto/ffi_pb.js.map +1 -1
- package/dist/proto/handle_pb.cjs +27 -7
- package/dist/proto/handle_pb.cjs.map +1 -1
- package/dist/proto/handle_pb.d.cts +13 -15
- package/dist/proto/handle_pb.d.ts +13 -15
- package/dist/proto/handle_pb.d.ts.map +1 -1
- package/dist/proto/handle_pb.js +26 -5
- package/dist/proto/handle_pb.js.map +1 -1
- package/dist/proto/participant_pb.cjs +112 -15
- package/dist/proto/participant_pb.cjs.map +1 -1
- package/dist/proto/participant_pb.d.cts +140 -52
- package/dist/proto/participant_pb.d.ts +140 -52
- package/dist/proto/participant_pb.d.ts.map +1 -1
- package/dist/proto/participant_pb.js +109 -11
- package/dist/proto/participant_pb.js.map +1 -1
- package/dist/proto/room_pb.cjs +2693 -302
- package/dist/proto/room_pb.cjs.map +1 -1
- package/dist/proto/room_pb.d.cts +1265 -862
- package/dist/proto/room_pb.d.ts +1265 -862
- package/dist/proto/room_pb.d.ts.map +1 -1
- package/dist/proto/room_pb.js +2603 -210
- package/dist/proto/room_pb.js.map +1 -1
- package/dist/proto/rpc_pb.cjs +302 -37
- package/dist/proto/rpc_pb.cjs.map +1 -1
- package/dist/proto/rpc_pb.d.cts +138 -108
- package/dist/proto/rpc_pb.d.ts +138 -108
- package/dist/proto/rpc_pb.d.ts.map +1 -1
- package/dist/proto/rpc_pb.js +291 -25
- package/dist/proto/rpc_pb.js.map +1 -1
- package/dist/proto/stats_pb.cjs +1253 -139
- package/dist/proto/stats_pb.cjs.map +1 -1
- package/dist/proto/stats_pb.d.cts +803 -692
- package/dist/proto/stats_pb.d.ts +803 -692
- package/dist/proto/stats_pb.d.ts.map +1 -1
- package/dist/proto/stats_pb.js +1216 -93
- package/dist/proto/stats_pb.js.map +1 -1
- package/dist/proto/track_pb.cjs +462 -64
- package/dist/proto/track_pb.cjs.map +1 -1
- package/dist/proto/track_pb.d.cts +250 -218
- package/dist/proto/track_pb.d.ts +250 -218
- package/dist/proto/track_pb.d.ts.map +1 -1
- package/dist/proto/track_pb.js +447 -45
- package/dist/proto/track_pb.js.map +1 -1
- package/dist/proto/track_publication_pb.cjs +130 -0
- package/dist/proto/track_publication_pb.cjs.map +1 -0
- package/dist/proto/track_publication_pb.d.cts +80 -0
- package/dist/proto/track_publication_pb.d.ts +80 -0
- package/dist/proto/track_publication_pb.d.ts.map +1 -0
- package/dist/proto/track_publication_pb.js +103 -0
- package/dist/proto/track_publication_pb.js.map +1 -0
- package/dist/proto/video_frame_pb.cjs +648 -88
- package/dist/proto/video_frame_pb.cjs.map +1 -1
- package/dist/proto/video_frame_pb.d.cts +371 -328
- package/dist/proto/video_frame_pb.d.ts +371 -328
- package/dist/proto/video_frame_pb.d.ts.map +1 -1
- package/dist/proto/video_frame_pb.js +626 -60
- package/dist/proto/video_frame_pb.js.map +1 -1
- package/dist/room.cjs +85 -125
- package/dist/room.cjs.map +1 -1
- package/dist/room.d.cts +6 -17
- package/dist/room.d.ts +6 -17
- package/dist/room.d.ts.map +1 -1
- package/dist/room.js +85 -123
- package/dist/room.js.map +1 -1
- package/dist/rpc.cjs.map +1 -1
- package/dist/rpc.d.cts +0 -1
- package/dist/rpc.d.ts +0 -1
- package/dist/rpc.js.map +1 -1
- package/dist/track.cjs +12 -8
- package/dist/track.cjs.map +1 -1
- package/dist/track.d.cts +8 -9
- package/dist/track.d.ts +8 -9
- package/dist/track.d.ts.map +1 -1
- package/dist/track.js +13 -9
- package/dist/track.js.map +1 -1
- package/dist/track_publication.cjs +21 -12
- package/dist/track_publication.cjs.map +1 -1
- package/dist/track_publication.d.cts +12 -13
- package/dist/track_publication.d.ts +12 -13
- package/dist/track_publication.d.ts.map +1 -1
- package/dist/track_publication.js +22 -13
- package/dist/track_publication.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/video_frame.cjs +26 -45
- package/dist/video_frame.cjs.map +1 -1
- package/dist/video_frame.d.cts +2 -3
- package/dist/video_frame.d.ts +2 -3
- package/dist/video_frame.d.ts.map +1 -1
- package/dist/video_frame.js +29 -48
- package/dist/video_frame.js.map +1 -1
- package/dist/video_source.cjs +7 -4
- package/dist/video_source.cjs.map +1 -1
- package/dist/video_source.d.cts +4 -4
- package/dist/video_source.d.ts +4 -4
- package/dist/video_source.d.ts.map +1 -1
- package/dist/video_source.js +9 -6
- package/dist/video_source.js.map +1 -1
- package/dist/video_stream.cjs +16 -5
- package/dist/video_stream.cjs.map +1 -1
- package/dist/video_stream.d.cts +3 -4
- package/dist/video_stream.d.ts +3 -4
- package/dist/video_stream.d.ts.map +1 -1
- package/dist/video_stream.js +17 -6
- package/dist/video_stream.js.map +1 -1
- package/package.json +9 -9
- package/src/audio_frame.ts +10 -10
- package/src/audio_resampler.ts +15 -13
- package/src/audio_source.ts +11 -8
- package/src/audio_stream.ts +3 -4
- package/src/e2ee.ts +41 -42
- package/src/ffi_client.ts +8 -16
- package/src/index.ts +5 -68
- package/src/napi/native.d.ts +5 -5
- package/src/participant.ts +102 -73
- package/src/proto/audio_frame_pb.ts +1220 -496
- package/src/proto/e2ee_pb.ts +858 -337
- package/src/proto/ffi_pb.ts +442 -135
- package/src/proto/handle_pb.ts +33 -19
- package/src/proto/participant_pb.ts +225 -60
- package/src/proto/room_pb.ts +3149 -1013
- package/src/proto/rpc_pb.ts +358 -129
- package/src/proto/stats_pb.ts +1891 -877
- package/src/proto/track_pb.ts +587 -253
- package/src/proto/track_publication_pb.ts +180 -0
- package/src/proto/video_frame_pb.ts +861 -394
- package/src/room.ts +137 -189
- package/src/rpc.ts +1 -1
- package/src/track.ts +16 -17
- package/src/track_publication.ts +25 -26
- package/src/version.ts +1 -1
- package/src/video_frame.ts +48 -72
- package/src/video_source.ts +11 -8
- package/src/video_stream.ts +18 -8
package/dist/video_source.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { create } from "@bufbuild/protobuf";
|
|
2
1
|
import { FfiClient, FfiHandle } from "./ffi_client.js";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
CaptureVideoFrameRequest,
|
|
4
|
+
NewVideoSourceRequest,
|
|
6
5
|
VideoRotation,
|
|
7
6
|
VideoSourceType
|
|
8
7
|
} from "./proto/video_frame_pb.js";
|
|
9
8
|
class VideoSource {
|
|
10
9
|
constructor(width, height) {
|
|
10
|
+
var _a;
|
|
11
11
|
this.width = width;
|
|
12
12
|
this.height = height;
|
|
13
|
-
const req =
|
|
13
|
+
const req = new NewVideoSourceRequest({
|
|
14
14
|
type: VideoSourceType.VIDEO_SOURCE_NATIVE,
|
|
15
15
|
resolution: {
|
|
16
16
|
width,
|
|
@@ -23,11 +23,11 @@ class VideoSource {
|
|
|
23
23
|
value: req
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
|
-
this.info = res.source.info;
|
|
26
|
+
this.info = (_a = res.source) == null ? void 0 : _a.info;
|
|
27
27
|
this.ffiHandle = new FfiHandle(res.source.handle.id);
|
|
28
28
|
}
|
|
29
29
|
captureFrame(frame, timestampUs = BigInt(0), rotation = VideoRotation.VIDEO_ROTATION_0) {
|
|
30
|
-
const req =
|
|
30
|
+
const req = new CaptureVideoFrameRequest({
|
|
31
31
|
sourceHandle: this.ffiHandle.handle,
|
|
32
32
|
buffer: frame.protoInfo(),
|
|
33
33
|
rotation,
|
|
@@ -37,6 +37,9 @@ class VideoSource {
|
|
|
37
37
|
message: { case: "captureVideoFrame", value: req }
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
+
async close() {
|
|
41
|
+
this.ffiHandle.dispose();
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
export {
|
|
42
45
|
VideoSource
|
package/dist/video_source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/video_source.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/video_source.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { FfiClient, FfiHandle } from './ffi_client.js';\nimport type {\n CaptureVideoFrameResponse,\n NewVideoSourceResponse,\n VideoSourceInfo,\n} from './proto/video_frame_pb.js';\nimport {\n CaptureVideoFrameRequest,\n NewVideoSourceRequest,\n VideoRotation,\n VideoSourceType,\n} from './proto/video_frame_pb.js';\nimport type { VideoFrame } from './video_frame.js';\n\nexport class VideoSource {\n /** @internal */\n info?: VideoSourceInfo;\n /** @internal */\n ffiHandle: FfiHandle;\n\n width: number;\n height: number;\n\n constructor(width: number, height: number) {\n this.width = width;\n this.height = height;\n\n const req = new NewVideoSourceRequest({\n type: VideoSourceType.VIDEO_SOURCE_NATIVE,\n resolution: {\n width: width,\n height: height,\n },\n });\n\n const res = FfiClient.instance.request<NewVideoSourceResponse>({\n message: {\n case: 'newVideoSource',\n value: req,\n },\n });\n\n this.info = res.source?.info;\n this.ffiHandle = new FfiHandle(res.source!.handle!.id!);\n }\n\n captureFrame(\n frame: VideoFrame,\n timestampUs = BigInt(0),\n rotation = VideoRotation.VIDEO_ROTATION_0,\n ) {\n const req = new CaptureVideoFrameRequest({\n sourceHandle: this.ffiHandle.handle,\n buffer: frame.protoInfo(),\n rotation,\n timestampUs,\n });\n\n FfiClient.instance.request<CaptureVideoFrameResponse>({\n message: { case: 'captureVideoFrame', value: req },\n });\n }\n\n async close() {\n this.ffiHandle.dispose();\n }\n}\n"],"mappings":"AAGA,SAAS,WAAW,iBAAiB;AAMrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,MAAM,YAAY;AAAA,EASvB,YAAY,OAAe,QAAgB;AA1B7C;AA2BI,SAAK,QAAQ;AACb,SAAK,SAAS;AAEd,UAAM,MAAM,IAAI,sBAAsB;AAAA,MACpC,MAAM,gBAAgB;AAAA,MACtB,YAAY;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,MAAM,UAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,QAAO,SAAI,WAAJ,mBAAY;AACxB,SAAK,YAAY,IAAI,UAAU,IAAI,OAAQ,OAAQ,EAAG;AAAA,EACxD;AAAA,EAEA,aACE,OACA,cAAc,OAAO,CAAC,GACtB,WAAW,cAAc,kBACzB;AACA,UAAM,MAAM,IAAI,yBAAyB;AAAA,MACvC,cAAc,KAAK,UAAU;AAAA,MAC7B,QAAQ,MAAM,UAAU;AAAA,MACxB;AAAA,MACA;AAAA,IACF,CAAC;AAED,cAAU,SAAS,QAAmC;AAAA,MACpD,SAAS,EAAE,MAAM,qBAAqB,OAAO,IAAI;AAAA,IACnD,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,QAAQ;AACZ,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;","names":[]}
|
package/dist/video_stream.cjs
CHANGED
|
@@ -21,7 +21,6 @@ __export(video_stream_exports, {
|
|
|
21
21
|
VideoStream: () => VideoStream
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(video_stream_exports);
|
|
24
|
-
var import_protobuf = require("@bufbuild/protobuf");
|
|
25
24
|
var import_mutex = require("@livekit/mutex");
|
|
26
25
|
var import_ffi_client = require("./ffi_client.cjs");
|
|
27
26
|
var import_video_frame_pb = require("./proto/video_frame_pb.cjs");
|
|
@@ -46,9 +45,20 @@ class VideoStream {
|
|
|
46
45
|
const frame = import_video_frame.VideoFrame.fromOwnedInfo(streamEvent.value.buffer);
|
|
47
46
|
const value = { rotation, timestampUs, frame };
|
|
48
47
|
if (this.queueResolve) {
|
|
49
|
-
this.queueResolve({
|
|
48
|
+
this.queueResolve({
|
|
49
|
+
done: false,
|
|
50
|
+
value: {
|
|
51
|
+
frame: value.frame,
|
|
52
|
+
timestampUs: value.timestampUs,
|
|
53
|
+
rotation: value.rotation
|
|
54
|
+
}
|
|
55
|
+
});
|
|
50
56
|
} else {
|
|
51
|
-
this.eventQueue.push(
|
|
57
|
+
this.eventQueue.push({
|
|
58
|
+
frame: value.frame,
|
|
59
|
+
timestampUs: value.timestampUs,
|
|
60
|
+
rotation: value.rotation
|
|
61
|
+
});
|
|
52
62
|
}
|
|
53
63
|
break;
|
|
54
64
|
case "eos":
|
|
@@ -56,8 +66,9 @@ class VideoStream {
|
|
|
56
66
|
break;
|
|
57
67
|
}
|
|
58
68
|
};
|
|
69
|
+
var _a;
|
|
59
70
|
this.track = track;
|
|
60
|
-
const req =
|
|
71
|
+
const req = new import_video_frame_pb.NewVideoStreamRequest({
|
|
61
72
|
type: import_video_frame_pb.VideoStreamType.VIDEO_STREAM_NATIVE,
|
|
62
73
|
trackHandle: track.ffi_handle.handle
|
|
63
74
|
});
|
|
@@ -67,7 +78,7 @@ class VideoStream {
|
|
|
67
78
|
value: req
|
|
68
79
|
}
|
|
69
80
|
});
|
|
70
|
-
this.info = res.stream.info;
|
|
81
|
+
this.info = (_a = res.stream) == null ? void 0 : _a.info;
|
|
71
82
|
this.ffiHandle = new import_ffi_client.FfiHandle(res.stream.handle.id);
|
|
72
83
|
import_ffi_client.FfiClient.instance.on(import_ffi_client.FfiClientEvent.FfiEvent, this.onEvent);
|
|
73
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/video_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/video_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Mutex } from '@livekit/mutex';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type {\n NewVideoStreamResponse,\n VideoRotation,\n VideoStreamInfo,\n} from './proto/video_frame_pb.js';\nimport { NewVideoStreamRequest, VideoStreamType } from './proto/video_frame_pb.js';\nimport type { Track } from './track.js';\nimport { VideoFrame } from './video_frame.js';\n\nexport type VideoFrameEvent = {\n frame: VideoFrame;\n timestampUs: bigint;\n rotation: VideoRotation;\n};\n\nexport class VideoStream implements AsyncIterableIterator<VideoFrameEvent> {\n /** @internal */\n info?: VideoStreamInfo;\n /** @internal */\n ffiHandle: FfiHandle;\n /** @internal */\n eventQueue: (VideoFrameEvent | null)[] = [];\n /** @internal */\n queueResolve: ((value: IteratorResult<VideoFrameEvent>) => void) | null = null;\n /** @internal */\n mutex = new Mutex();\n\n track: Track;\n\n constructor(track: Track) {\n this.track = track;\n\n const req = new NewVideoStreamRequest({\n type: VideoStreamType.VIDEO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n });\n\n const res = FfiClient.instance.request<NewVideoStreamResponse>({\n message: {\n case: 'newVideoStream',\n value: req,\n },\n });\n\n this.info = res.stream?.info;\n this.ffiHandle = new FfiHandle(res.stream!.handle!.id!);\n\n FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);\n }\n\n private onEvent = (ev: FfiEvent) => {\n if (\n ev.message.case != 'videoStreamEvent' ||\n ev.message.value.streamHandle != this.ffiHandle.handle\n ) {\n return;\n }\n\n const streamEvent = ev.message.value.message;\n switch (streamEvent.case) {\n case 'frameReceived':\n const rotation = streamEvent.value.rotation;\n const timestampUs = streamEvent.value.timestampUs;\n const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer!);\n const value = { rotation, timestampUs, frame };\n if (this.queueResolve) {\n this.queueResolve({\n done: false,\n value: {\n frame: value.frame,\n timestampUs: value.timestampUs!,\n rotation: value.rotation!,\n },\n });\n } else {\n this.eventQueue.push({\n frame: value.frame,\n timestampUs: value.timestampUs!,\n rotation: value.rotation!,\n });\n }\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n break;\n }\n };\n\n async next(): Promise<IteratorResult<VideoFrameEvent>> {\n const unlock = await this.mutex.lock();\n if (this.eventQueue.length > 0) {\n unlock();\n const value = this.eventQueue.shift();\n if (value) {\n return { done: false, value };\n } else {\n return { done: true, value: undefined };\n }\n }\n const promise = new Promise<IteratorResult<VideoFrameEvent>>(\n (resolve) => (this.queueResolve = resolve),\n );\n unlock();\n return promise;\n }\n\n close() {\n this.eventQueue.push(null);\n this.ffiHandle.dispose();\n }\n\n [Symbol.asyncIterator](): VideoStream {\n return this;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,mBAAsB;AAEtB,wBAAqD;AAMrD,4BAAuD;AAEvD,yBAA2B;AAQpB,MAAM,YAA8D;AAAA,EAczE,YAAY,OAAc;AAR1B;AAAA,sBAAyC,CAAC;AAE1C;AAAA,wBAA0E;AAE1E;AAAA,iBAAQ,IAAI,mBAAM;AAyBlB,SAAQ,UAAU,CAAC,OAAiB;AAClC,UACE,GAAG,QAAQ,QAAQ,sBACnB,GAAG,QAAQ,MAAM,gBAAgB,KAAK,UAAU,QAChD;AACA;AAAA,MACF;AAEA,YAAM,cAAc,GAAG,QAAQ,MAAM;AACrC,cAAQ,YAAY,MAAM;AAAA,QACxB,KAAK;AACH,gBAAM,WAAW,YAAY,MAAM;AACnC,gBAAM,cAAc,YAAY,MAAM;AACtC,gBAAM,QAAQ,8BAAW,cAAc,YAAY,MAAM,MAAO;AAChE,gBAAM,QAAQ,EAAE,UAAU,aAAa,MAAM;AAC7C,cAAI,KAAK,cAAc;AACrB,iBAAK,aAAa;AAAA,cAChB,MAAM;AAAA,cACN,OAAO;AAAA,gBACL,OAAO,MAAM;AAAA,gBACb,aAAa,MAAM;AAAA,gBACnB,UAAU,MAAM;AAAA,cAClB;AAAA,YACF,CAAC;AAAA,UACH,OAAO;AACL,iBAAK,WAAW,KAAK;AAAA,cACnB,OAAO,MAAM;AAAA,cACb,aAAa,MAAM;AAAA,cACnB,UAAU,MAAM;AAAA,YAClB,CAAC;AAAA,UACH;AACA;AAAA,QACF,KAAK;AACH,sCAAU,SAAS,IAAI,iCAAe,UAAU,KAAK,OAAO;AAC5D;AAAA,MACJ;AAAA,IACF;AA5FF;AAoCI,SAAK,QAAQ;AAEb,UAAM,MAAM,IAAI,4CAAsB;AAAA,MACpC,MAAM,sCAAgB;AAAA,MACtB,aAAa,MAAM,WAAW;AAAA,IAChC,CAAC;AAED,UAAM,MAAM,4BAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,QAAO,SAAI,WAAJ,mBAAY;AACxB,SAAK,YAAY,IAAI,4BAAU,IAAI,OAAQ,OAAQ,EAAG;AAEtD,gCAAU,SAAS,GAAG,iCAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EAwCA,MAAM,OAAiD;AACrD,UAAM,SAAS,MAAM,KAAK,MAAM,KAAK;AACrC,QAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAO;AACP,YAAM,QAAQ,KAAK,WAAW,MAAM;AACpC,UAAI,OAAO;AACT,eAAO,EAAE,MAAM,OAAO,MAAM;AAAA,MAC9B,OAAO;AACL,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AACA,UAAM,UAAU,IAAI;AAAA,MAClB,CAAC,YAAa,KAAK,eAAe;AAAA,IACpC;AACA,WAAO;AACP,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,WAAW,KAAK,IAAI;AACzB,SAAK,UAAU,QAAQ;AAAA,EACzB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAiB;AACpC,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/video_stream.d.cts
CHANGED
|
@@ -3,12 +3,11 @@ import { FfiHandle } from './napi/native.d.cjs';
|
|
|
3
3
|
import { VideoRotation, VideoStreamInfo } from './proto/video_frame_pb.cjs';
|
|
4
4
|
import { Track } from './track.cjs';
|
|
5
5
|
import { VideoFrame } from './video_frame.cjs';
|
|
6
|
-
import '@bufbuild/protobuf/codegenv1';
|
|
7
|
-
import './proto/handle_pb.cjs';
|
|
8
6
|
import '@bufbuild/protobuf';
|
|
9
7
|
import './proto/track_pb.cjs';
|
|
10
|
-
import './proto/e2ee_pb.cjs';
|
|
11
8
|
import './proto/stats_pb.cjs';
|
|
9
|
+
import './proto/e2ee_pb.cjs';
|
|
10
|
+
import './proto/handle_pb.cjs';
|
|
12
11
|
import './audio_source.cjs';
|
|
13
12
|
import './audio_frame.cjs';
|
|
14
13
|
import './proto/audio_frame_pb.cjs';
|
|
@@ -21,7 +20,7 @@ type VideoFrameEvent = {
|
|
|
21
20
|
};
|
|
22
21
|
declare class VideoStream implements AsyncIterableIterator<VideoFrameEvent> {
|
|
23
22
|
/** @internal */
|
|
24
|
-
info
|
|
23
|
+
info?: VideoStreamInfo;
|
|
25
24
|
/** @internal */
|
|
26
25
|
ffiHandle: FfiHandle;
|
|
27
26
|
/** @internal */
|
package/dist/video_stream.d.ts
CHANGED
|
@@ -3,12 +3,11 @@ import { FfiHandle } from './napi/native.d.js';
|
|
|
3
3
|
import { VideoRotation, VideoStreamInfo } from './proto/video_frame_pb.js';
|
|
4
4
|
import { Track } from './track.js';
|
|
5
5
|
import { VideoFrame } from './video_frame.js';
|
|
6
|
-
import '@bufbuild/protobuf/codegenv1';
|
|
7
|
-
import './proto/handle_pb.js';
|
|
8
6
|
import '@bufbuild/protobuf';
|
|
9
7
|
import './proto/track_pb.js';
|
|
10
|
-
import './proto/e2ee_pb.js';
|
|
11
8
|
import './proto/stats_pb.js';
|
|
9
|
+
import './proto/e2ee_pb.js';
|
|
10
|
+
import './proto/handle_pb.js';
|
|
12
11
|
import './audio_source.js';
|
|
13
12
|
import './audio_frame.js';
|
|
14
13
|
import './proto/audio_frame_pb.js';
|
|
@@ -21,7 +20,7 @@ type VideoFrameEvent = {
|
|
|
21
20
|
};
|
|
22
21
|
declare class VideoStream implements AsyncIterableIterator<VideoFrameEvent> {
|
|
23
22
|
/** @internal */
|
|
24
|
-
info
|
|
23
|
+
info?: VideoStreamInfo;
|
|
25
24
|
/** @internal */
|
|
26
25
|
ffiHandle: FfiHandle;
|
|
27
26
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video_stream.d.ts","sourceRoot":"","sources":["../src/video_stream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"video_stream.d.ts","sourceRoot":"","sources":["../src/video_stream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAEV,aAAa,EACb,eAAe,EAChB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,aAAa,CAAC;CACzB,CAAC;AAEF,qBAAa,WAAY,YAAW,qBAAqB,CAAC,eAAe,CAAC;IACxE,gBAAgB;IAChB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,gBAAgB;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB;IAChB,UAAU,EAAE,CAAC,eAAe,GAAG,IAAI,CAAC,EAAE,CAAM;IAC5C,gBAAgB;IAChB,YAAY,EAAE,CAAC,CAAC,KAAK,EAAE,cAAc,CAAC,eAAe,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC/E,gBAAgB;IAChB,KAAK,QAAe;IAEpB,KAAK,EAAE,KAAK,CAAC;gBAED,KAAK,EAAE,KAAK;IAqBxB,OAAO,CAAC,OAAO,CAoCb;IAEI,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;IAkBtD,KAAK;IAKL,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,WAAW;CAGtC"}
|
package/dist/video_stream.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { create } from "@bufbuild/protobuf";
|
|
2
1
|
import { Mutex } from "@livekit/mutex";
|
|
3
2
|
import { FfiClient, FfiClientEvent, FfiHandle } from "./ffi_client.js";
|
|
4
|
-
import {
|
|
3
|
+
import { NewVideoStreamRequest, VideoStreamType } from "./proto/video_frame_pb.js";
|
|
5
4
|
import { VideoFrame } from "./video_frame.js";
|
|
6
5
|
class VideoStream {
|
|
7
6
|
constructor(track) {
|
|
@@ -23,9 +22,20 @@ class VideoStream {
|
|
|
23
22
|
const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer);
|
|
24
23
|
const value = { rotation, timestampUs, frame };
|
|
25
24
|
if (this.queueResolve) {
|
|
26
|
-
this.queueResolve({
|
|
25
|
+
this.queueResolve({
|
|
26
|
+
done: false,
|
|
27
|
+
value: {
|
|
28
|
+
frame: value.frame,
|
|
29
|
+
timestampUs: value.timestampUs,
|
|
30
|
+
rotation: value.rotation
|
|
31
|
+
}
|
|
32
|
+
});
|
|
27
33
|
} else {
|
|
28
|
-
this.eventQueue.push(
|
|
34
|
+
this.eventQueue.push({
|
|
35
|
+
frame: value.frame,
|
|
36
|
+
timestampUs: value.timestampUs,
|
|
37
|
+
rotation: value.rotation
|
|
38
|
+
});
|
|
29
39
|
}
|
|
30
40
|
break;
|
|
31
41
|
case "eos":
|
|
@@ -33,8 +43,9 @@ class VideoStream {
|
|
|
33
43
|
break;
|
|
34
44
|
}
|
|
35
45
|
};
|
|
46
|
+
var _a;
|
|
36
47
|
this.track = track;
|
|
37
|
-
const req =
|
|
48
|
+
const req = new NewVideoStreamRequest({
|
|
38
49
|
type: VideoStreamType.VIDEO_STREAM_NATIVE,
|
|
39
50
|
trackHandle: track.ffi_handle.handle
|
|
40
51
|
});
|
|
@@ -44,7 +55,7 @@ class VideoStream {
|
|
|
44
55
|
value: req
|
|
45
56
|
}
|
|
46
57
|
});
|
|
47
|
-
this.info = res.stream.info;
|
|
58
|
+
this.info = (_a = res.stream) == null ? void 0 : _a.info;
|
|
48
59
|
this.ffiHandle = new FfiHandle(res.stream.handle.id);
|
|
49
60
|
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);
|
|
50
61
|
}
|
package/dist/video_stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/video_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/video_stream.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport { Mutex } from '@livekit/mutex';\nimport type { FfiEvent } from './ffi_client.js';\nimport { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';\nimport type {\n NewVideoStreamResponse,\n VideoRotation,\n VideoStreamInfo,\n} from './proto/video_frame_pb.js';\nimport { NewVideoStreamRequest, VideoStreamType } from './proto/video_frame_pb.js';\nimport type { Track } from './track.js';\nimport { VideoFrame } from './video_frame.js';\n\nexport type VideoFrameEvent = {\n frame: VideoFrame;\n timestampUs: bigint;\n rotation: VideoRotation;\n};\n\nexport class VideoStream implements AsyncIterableIterator<VideoFrameEvent> {\n /** @internal */\n info?: VideoStreamInfo;\n /** @internal */\n ffiHandle: FfiHandle;\n /** @internal */\n eventQueue: (VideoFrameEvent | null)[] = [];\n /** @internal */\n queueResolve: ((value: IteratorResult<VideoFrameEvent>) => void) | null = null;\n /** @internal */\n mutex = new Mutex();\n\n track: Track;\n\n constructor(track: Track) {\n this.track = track;\n\n const req = new NewVideoStreamRequest({\n type: VideoStreamType.VIDEO_STREAM_NATIVE,\n trackHandle: track.ffi_handle.handle,\n });\n\n const res = FfiClient.instance.request<NewVideoStreamResponse>({\n message: {\n case: 'newVideoStream',\n value: req,\n },\n });\n\n this.info = res.stream?.info;\n this.ffiHandle = new FfiHandle(res.stream!.handle!.id!);\n\n FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);\n }\n\n private onEvent = (ev: FfiEvent) => {\n if (\n ev.message.case != 'videoStreamEvent' ||\n ev.message.value.streamHandle != this.ffiHandle.handle\n ) {\n return;\n }\n\n const streamEvent = ev.message.value.message;\n switch (streamEvent.case) {\n case 'frameReceived':\n const rotation = streamEvent.value.rotation;\n const timestampUs = streamEvent.value.timestampUs;\n const frame = VideoFrame.fromOwnedInfo(streamEvent.value.buffer!);\n const value = { rotation, timestampUs, frame };\n if (this.queueResolve) {\n this.queueResolve({\n done: false,\n value: {\n frame: value.frame,\n timestampUs: value.timestampUs!,\n rotation: value.rotation!,\n },\n });\n } else {\n this.eventQueue.push({\n frame: value.frame,\n timestampUs: value.timestampUs!,\n rotation: value.rotation!,\n });\n }\n break;\n case 'eos':\n FfiClient.instance.off(FfiClientEvent.FfiEvent, this.onEvent);\n break;\n }\n };\n\n async next(): Promise<IteratorResult<VideoFrameEvent>> {\n const unlock = await this.mutex.lock();\n if (this.eventQueue.length > 0) {\n unlock();\n const value = this.eventQueue.shift();\n if (value) {\n return { done: false, value };\n } else {\n return { done: true, value: undefined };\n }\n }\n const promise = new Promise<IteratorResult<VideoFrameEvent>>(\n (resolve) => (this.queueResolve = resolve),\n );\n unlock();\n return promise;\n }\n\n close() {\n this.eventQueue.push(null);\n this.ffiHandle.dispose();\n }\n\n [Symbol.asyncIterator](): VideoStream {\n return this;\n }\n}\n"],"mappings":"AAGA,SAAS,aAAa;AAEtB,SAAS,WAAW,gBAAgB,iBAAiB;AAMrD,SAAS,uBAAuB,uBAAuB;AAEvD,SAAS,kBAAkB;AAQpB,MAAM,YAA8D;AAAA,EAczE,YAAY,OAAc;AAR1B;AAAA,sBAAyC,CAAC;AAE1C;AAAA,wBAA0E;AAE1E;AAAA,iBAAQ,IAAI,MAAM;AAyBlB,SAAQ,UAAU,CAAC,OAAiB;AAClC,UACE,GAAG,QAAQ,QAAQ,sBACnB,GAAG,QAAQ,MAAM,gBAAgB,KAAK,UAAU,QAChD;AACA;AAAA,MACF;AAEA,YAAM,cAAc,GAAG,QAAQ,MAAM;AACrC,cAAQ,YAAY,MAAM;AAAA,QACxB,KAAK;AACH,gBAAM,WAAW,YAAY,MAAM;AACnC,gBAAM,cAAc,YAAY,MAAM;AACtC,gBAAM,QAAQ,WAAW,cAAc,YAAY,MAAM,MAAO;AAChE,gBAAM,QAAQ,EAAE,UAAU,aAAa,MAAM;AAC7C,cAAI,KAAK,cAAc;AACrB,iBAAK,aAAa;AAAA,cAChB,MAAM;AAAA,cACN,OAAO;AAAA,gBACL,OAAO,MAAM;AAAA,gBACb,aAAa,MAAM;AAAA,gBACnB,UAAU,MAAM;AAAA,cAClB;AAAA,YACF,CAAC;AAAA,UACH,OAAO;AACL,iBAAK,WAAW,KAAK;AAAA,cACnB,OAAO,MAAM;AAAA,cACb,aAAa,MAAM;AAAA,cACnB,UAAU,MAAM;AAAA,YAClB,CAAC;AAAA,UACH;AACA;AAAA,QACF,KAAK;AACH,oBAAU,SAAS,IAAI,eAAe,UAAU,KAAK,OAAO;AAC5D;AAAA,MACJ;AAAA,IACF;AA5FF;AAoCI,SAAK,QAAQ;AAEb,UAAM,MAAM,IAAI,sBAAsB;AAAA,MACpC,MAAM,gBAAgB;AAAA,MACtB,aAAa,MAAM,WAAW;AAAA,IAChC,CAAC;AAED,UAAM,MAAM,UAAU,SAAS,QAAgC;AAAA,MAC7D,SAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,SAAK,QAAO,SAAI,WAAJ,mBAAY;AACxB,SAAK,YAAY,IAAI,UAAU,IAAI,OAAQ,OAAQ,EAAG;AAEtD,cAAU,SAAS,GAAG,eAAe,UAAU,KAAK,OAAO;AAAA,EAC7D;AAAA,EAwCA,MAAM,OAAiD;AACrD,UAAM,SAAS,MAAM,KAAK,MAAM,KAAK;AACrC,QAAI,KAAK,WAAW,SAAS,GAAG;AAC9B,aAAO;AACP,YAAM,QAAQ,KAAK,WAAW,MAAM;AACpC,UAAI,OAAO;AACT,eAAO,EAAE,MAAM,OAAO,MAAM;AAAA,MAC9B,OAAO;AACL,eAAO,EAAE,MAAM,MAAM,OAAO,OAAU;AAAA,MACxC;AAAA,IACF;AACA,UAAM,UAAU,IAAI;AAAA,MAClB,CAAC,YAAa,KAAK,eAAe;AAAA,IACpC;AACA,WAAO;AACP,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,WAAW,KAAK,IAAI;AACzB,SAAK,UAAU,QAAQ;AAAA,EACzB;AAAA,EAEA,CAAC,OAAO,aAAa,IAAiB;AACpC,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "LiveKit RTC Node",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "LiveKit",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.13.1",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"require": "dist/index.cjs",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
@@ -46,24 +46,24 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@bufbuild/protobuf": "^
|
|
49
|
+
"@bufbuild/protobuf": "^1.10.0",
|
|
50
50
|
"@livekit/mutex": "^1.0.0",
|
|
51
51
|
"@livekit/typed-emitter": "^3.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@bufbuild/protoc-gen-es": "^2.2.0",
|
|
55
54
|
"@napi-rs/cli": "^2.18.0",
|
|
56
55
|
"@types/node": "^20.9.2",
|
|
57
56
|
"prettier": "^3.0.3",
|
|
58
57
|
"tsup": "^8.3.5",
|
|
59
|
-
"typescript": "^5.2.2"
|
|
58
|
+
"typescript": "^5.2.2",
|
|
59
|
+
"@bufbuild/protoc-gen-es": "^1.10.0"
|
|
60
60
|
},
|
|
61
61
|
"optionalDependencies": {
|
|
62
|
-
"@livekit/rtc-node-darwin-arm64": "0.
|
|
63
|
-
"@livekit/rtc-node-darwin-x64": "0.
|
|
64
|
-
"@livekit/rtc-node-linux-arm64-gnu": "0.
|
|
65
|
-
"@livekit/rtc-node-linux-x64-gnu": "0.
|
|
66
|
-
"@livekit/rtc-node-win32-x64-msvc": "0.
|
|
62
|
+
"@livekit/rtc-node-darwin-arm64": "0.13.1",
|
|
63
|
+
"@livekit/rtc-node-darwin-x64": "0.13.1",
|
|
64
|
+
"@livekit/rtc-node-linux-arm64-gnu": "0.13.1",
|
|
65
|
+
"@livekit/rtc-node-linux-x64-gnu": "0.13.1",
|
|
66
|
+
"@livekit/rtc-node-win32-x64-msvc": "0.13.1"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">= 18"
|
package/src/audio_frame.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { create } from '@bufbuild/protobuf';
|
|
5
4
|
import { FfiClient, FfiHandle } from './ffi_client.js';
|
|
6
5
|
import type { OwnedAudioFrameBuffer } from './proto/audio_frame_pb.js';
|
|
7
|
-
import {
|
|
6
|
+
import { AudioFrameBufferInfo } from './proto/audio_frame_pb.js';
|
|
8
7
|
|
|
9
8
|
export class AudioFrame {
|
|
10
9
|
data: Int16Array;
|
|
@@ -32,20 +31,20 @@ export class AudioFrame {
|
|
|
32
31
|
/** @internal */
|
|
33
32
|
static fromOwnedInfo(owned: OwnedAudioFrameBuffer): AudioFrame {
|
|
34
33
|
const info = owned.info!;
|
|
35
|
-
const len = info.numChannels * info.samplesPerChannel * 2; // c_int16
|
|
36
|
-
const data = FfiClient.instance.copyBuffer(info.dataPtr
|
|
37
|
-
new FfiHandle(owned.handle!.id).dispose();
|
|
34
|
+
const len = info.numChannels! * info.samplesPerChannel! * 2; // c_int16
|
|
35
|
+
const data = FfiClient.instance.copyBuffer(info.dataPtr!, len);
|
|
36
|
+
new FfiHandle(owned.handle!.id!).dispose();
|
|
38
37
|
return new AudioFrame(
|
|
39
38
|
new Int16Array(data.buffer),
|
|
40
|
-
info.sampleRate
|
|
41
|
-
info.numChannels
|
|
42
|
-
info.samplesPerChannel
|
|
39
|
+
info.sampleRate!,
|
|
40
|
+
info.numChannels!,
|
|
41
|
+
info.samplesPerChannel!,
|
|
43
42
|
);
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
/** @internal */
|
|
47
46
|
protoInfo(): AudioFrameBufferInfo {
|
|
48
|
-
return
|
|
47
|
+
return new AudioFrameBufferInfo({
|
|
49
48
|
dataPtr: FfiClient.instance.retrievePtr(new Uint8Array(this.data.buffer)),
|
|
50
49
|
sampleRate: this.sampleRate,
|
|
51
50
|
numChannels: this.channels,
|
|
@@ -65,8 +64,9 @@ export class AudioFrame {
|
|
|
65
64
|
*/
|
|
66
65
|
export const combineAudioFrames = (buffer: AudioFrame | AudioFrame[]): AudioFrame => {
|
|
67
66
|
if (!Array.isArray(buffer)) {
|
|
68
|
-
return buffer
|
|
67
|
+
return buffer;
|
|
69
68
|
}
|
|
69
|
+
buffer = buffer as AudioFrame[];
|
|
70
70
|
|
|
71
71
|
if (buffer.length === 0) {
|
|
72
72
|
throw new Error('buffer is empty');
|
package/src/audio_resampler.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { create } from '@bufbuild/protobuf';
|
|
5
4
|
import { AudioFrame } from './audio_frame.js';
|
|
6
5
|
import { FfiClient, FfiHandle } from './ffi_client.js';
|
|
7
6
|
import type {
|
|
@@ -10,9 +9,9 @@ import type {
|
|
|
10
9
|
PushSoxResamplerResponse,
|
|
11
10
|
} from './proto/audio_frame_pb.js';
|
|
12
11
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
FlushSoxResamplerRequest,
|
|
13
|
+
NewSoxResamplerRequest,
|
|
14
|
+
PushSoxResamplerRequest,
|
|
16
15
|
SoxQualityRecipe,
|
|
17
16
|
SoxResamplerDataType,
|
|
18
17
|
} from './proto/audio_frame_pb.js';
|
|
@@ -59,7 +58,7 @@ export class AudioResampler {
|
|
|
59
58
|
this.#outputRate = outputRate;
|
|
60
59
|
this.#channels = channels;
|
|
61
60
|
|
|
62
|
-
const req =
|
|
61
|
+
const req = new NewSoxResamplerRequest({
|
|
63
62
|
inputRate,
|
|
64
63
|
outputRate,
|
|
65
64
|
numChannels: channels,
|
|
@@ -76,11 +75,14 @@ export class AudioResampler {
|
|
|
76
75
|
},
|
|
77
76
|
});
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
switch (res.message.case) {
|
|
79
|
+
case 'resampler':
|
|
80
|
+
this.#ffiHandle = new FfiHandle(res.message.value.handle!.id!);
|
|
81
|
+
break;
|
|
82
|
+
case 'error':
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(res.message.value);
|
|
81
85
|
}
|
|
82
|
-
|
|
83
|
-
this.#ffiHandle = new FfiHandle(res.message.value.handle!.id);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
/**
|
|
@@ -95,7 +97,7 @@ export class AudioResampler {
|
|
|
95
97
|
* be empty if no output data is available yet.
|
|
96
98
|
*/
|
|
97
99
|
push(data: AudioFrame): AudioFrame[] {
|
|
98
|
-
const req =
|
|
100
|
+
const req = new PushSoxResamplerRequest({
|
|
99
101
|
resamplerHandle: this.#ffiHandle.handle,
|
|
100
102
|
dataPtr: data.protoInfo().dataPtr,
|
|
101
103
|
size: data.data.byteLength,
|
|
@@ -116,7 +118,7 @@ export class AudioResampler {
|
|
|
116
118
|
return [];
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
const outputData = FfiClient.instance.copyBuffer(res.outputPtr, res.size);
|
|
121
|
+
const outputData = FfiClient.instance.copyBuffer(res.outputPtr, res.size!);
|
|
120
122
|
return [
|
|
121
123
|
new AudioFrame(
|
|
122
124
|
new Int16Array(outputData.buffer),
|
|
@@ -135,7 +137,7 @@ export class AudioResampler {
|
|
|
135
137
|
* internal buffers are processed and all resampled data is output.
|
|
136
138
|
*/
|
|
137
139
|
flush(): AudioFrame[] {
|
|
138
|
-
const req =
|
|
140
|
+
const req = new FlushSoxResamplerRequest({
|
|
139
141
|
resamplerHandle: this.#ffiHandle.handle,
|
|
140
142
|
});
|
|
141
143
|
|
|
@@ -154,7 +156,7 @@ export class AudioResampler {
|
|
|
154
156
|
return [];
|
|
155
157
|
}
|
|
156
158
|
|
|
157
|
-
const outputData = FfiClient.instance.copyBuffer(res.outputPtr, res.size);
|
|
159
|
+
const outputData = FfiClient.instance.copyBuffer(res.outputPtr, res.size!);
|
|
158
160
|
return [
|
|
159
161
|
new AudioFrame(
|
|
160
162
|
new Int16Array(outputData.buffer),
|
package/src/audio_source.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { create } from '@bufbuild/protobuf';
|
|
5
4
|
import type { AudioFrame } from './audio_frame.js';
|
|
6
5
|
import { FfiClient } from './ffi_client.js';
|
|
7
6
|
import { FfiHandle } from './napi/native.js';
|
|
@@ -14,9 +13,9 @@ import type {
|
|
|
14
13
|
} from './proto/audio_frame_pb.js';
|
|
15
14
|
import {
|
|
16
15
|
AudioSourceType,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
CaptureAudioFrameRequest,
|
|
17
|
+
ClearAudioBufferRequest,
|
|
18
|
+
NewAudioSourceRequest,
|
|
20
19
|
} from './proto/audio_frame_pb.js';
|
|
21
20
|
|
|
22
21
|
export class AudioSource {
|
|
@@ -46,7 +45,7 @@ export class AudioSource {
|
|
|
46
45
|
this.lastCapture = 0;
|
|
47
46
|
this.currentQueueSize = 0;
|
|
48
47
|
|
|
49
|
-
const req =
|
|
48
|
+
const req = new NewAudioSourceRequest({
|
|
50
49
|
type: AudioSourceType.AUDIO_SOURCE_NATIVE,
|
|
51
50
|
sampleRate: sampleRate,
|
|
52
51
|
numChannels: numChannels,
|
|
@@ -61,7 +60,7 @@ export class AudioSource {
|
|
|
61
60
|
});
|
|
62
61
|
|
|
63
62
|
this.info = res.source!.info!;
|
|
64
|
-
this.ffiHandle = new FfiHandle(res.source!.handle!.id);
|
|
63
|
+
this.ffiHandle = new FfiHandle(res.source!.handle!.id!);
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
get queuedDuration(): number {
|
|
@@ -72,7 +71,7 @@ export class AudioSource {
|
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
clearQueue() {
|
|
75
|
-
const req =
|
|
74
|
+
const req = new ClearAudioBufferRequest({
|
|
76
75
|
sourceHandle: this.ffiHandle.handle,
|
|
77
76
|
});
|
|
78
77
|
|
|
@@ -117,7 +116,7 @@ export class AudioSource {
|
|
|
117
116
|
// (e.g. using wait_for_playout for very small chunks)
|
|
118
117
|
this.timeout = setTimeout(this.release, this.currentQueueSize - 50);
|
|
119
118
|
|
|
120
|
-
const req =
|
|
119
|
+
const req = new CaptureAudioFrameRequest({
|
|
121
120
|
sourceHandle: this.ffiHandle.handle,
|
|
122
121
|
buffer: frame.protoInfo(),
|
|
123
122
|
});
|
|
@@ -134,4 +133,8 @@ export class AudioSource {
|
|
|
134
133
|
throw new Error(cb.error);
|
|
135
134
|
}
|
|
136
135
|
}
|
|
136
|
+
|
|
137
|
+
async close() {
|
|
138
|
+
this.ffiHandle.dispose();
|
|
139
|
+
}
|
|
137
140
|
}
|
package/src/audio_stream.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import { create } from '@bufbuild/protobuf';
|
|
5
4
|
import { Mutex } from '@livekit/mutex';
|
|
6
5
|
import { AudioFrame } from './audio_frame.js';
|
|
7
6
|
import type { FfiEvent } from './ffi_client.js';
|
|
8
7
|
import { FfiClient, FfiClientEvent, FfiHandle } from './ffi_client.js';
|
|
9
8
|
import type { AudioStreamInfo, NewAudioStreamResponse } from './proto/audio_frame_pb.js';
|
|
10
|
-
import { AudioStreamType,
|
|
9
|
+
import { AudioStreamType, NewAudioStreamRequest } from './proto/audio_frame_pb.js';
|
|
11
10
|
import type { Track } from './track.js';
|
|
12
11
|
|
|
13
12
|
export class AudioStream implements AsyncIterableIterator<AudioFrame> {
|
|
@@ -31,7 +30,7 @@ export class AudioStream implements AsyncIterableIterator<AudioFrame> {
|
|
|
31
30
|
this.sampleRate = sampleRate;
|
|
32
31
|
this.numChannels = numChannels;
|
|
33
32
|
|
|
34
|
-
const req =
|
|
33
|
+
const req = new NewAudioStreamRequest({
|
|
35
34
|
type: AudioStreamType.AUDIO_STREAM_NATIVE,
|
|
36
35
|
trackHandle: track.ffi_handle.handle,
|
|
37
36
|
sampleRate: sampleRate,
|
|
@@ -46,7 +45,7 @@ export class AudioStream implements AsyncIterableIterator<AudioFrame> {
|
|
|
46
45
|
});
|
|
47
46
|
|
|
48
47
|
this.info = res.stream!.info!;
|
|
49
|
-
this.ffiHandle = new FfiHandle(res.stream!.handle!.id);
|
|
48
|
+
this.ffiHandle = new FfiHandle(res.stream!.handle!.id!);
|
|
50
49
|
|
|
51
50
|
FfiClient.instance.on(FfiClientEvent.FfiEvent, this.onEvent);
|
|
52
51
|
}
|