Skip to content

Commit

Permalink
Merge branch 'main' into nbsp/audiostream/iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp authored Sep 20, 2024
2 parents acf0f13 + c6766b8 commit 0daf003
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 1 addition & 2 deletions examples/publish-wav/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ while (written < dataSize) {
Math.trunc(frameSize / channels),
);
await source.captureFrame(frame);
await source.waitForPlayout();

written += frameSize;
}
await source.waitForPlayout();

await room.disconnect();
await dispose();
17 changes: 13 additions & 4 deletions packages/livekit-rtc/src/audio_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class AudioSource {
/** @internal */
currentQueueSize: number;
/** @internal */
releaseQueue = new Queue<void>();
release = () => {};
promise = this.newPromise();
/** @internal */
timeout?: ReturnType<typeof setTimeout> = undefined;

Expand Down Expand Up @@ -82,13 +83,21 @@ export class AudioSource {
},
});

this.releaseQueue.put();
this.release();
}

/** @internal */
async newPromise() {
return new Promise<void>((resolve) => {
this.release = resolve;
});
}

async waitForPlayout() {
await this.releaseQueue.get().then(() => {
return this.promise.then(() => {
this.lastCapture = 0;
this.currentQueueSize = 0;
this.promise = this.newPromise();
});
}

Expand All @@ -105,7 +114,7 @@ export class AudioSource {

// remove 50ms to account for processing time
// (e.g. using wait_for_playout for very small chunks)
this.timeout = setTimeout(this.releaseQueue.put, this.currentQueueSize - 50);
this.timeout = setTimeout(this.release, this.currentQueueSize - 50);

const req = new CaptureAudioFrameRequest({
sourceHandle: this.ffiHandle.handle,
Expand Down
1 change: 1 addition & 0 deletions packages/livekit-rtc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ export {
export { EncryptionType, EncryptionState } from './proto/e2ee_pb.js';
export { StreamState, TrackKind, TrackSource } from './proto/track_pb.js';
export { VideoBufferType, VideoRotation } from './proto/video_frame_pb.js';
export { ParticipantKind } from './proto/participant_pb.js';
export { dispose } from './ffi_client.js';
6 changes: 5 additions & 1 deletion packages/livekit-rtc/src/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0
import { FfiClient, FfiHandle } from './ffi_client.js';
import type { OwnedParticipant, ParticipantInfo } from './proto/participant_pb.js';
import type { OwnedParticipant, ParticipantInfo, ParticipantKind } from './proto/participant_pb.js';
import type {
PublishDataCallback,
PublishDataResponse,
Expand Down Expand Up @@ -71,6 +71,10 @@ export abstract class Participant {
get attributes(): Record<string, string> {
return this.info.attributes;
}

get kind(): ParticipantKind {
return this.info.kind;
}
}

export type DataPublishOptions = {
Expand Down

0 comments on commit 0daf003

Please sign in to comment.