@howaboua/pi-durable-gippity-voice 0.10.0 → 0.11.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 +2 -2
- package/dist/activation.js +369 -148
- package/dist/index.js +369 -148
- package/dist/packages/execution/src/tool-contract.d.ts +2 -2
- package/dist/packages/gippity-voice/src/agent-observation.d.ts +13 -0
- package/dist/packages/gippity-voice/src/host.d.ts +6 -0
- package/dist/packages/gippity-voice/src/index.d.ts +2 -1
- package/dist/packages/gippity-voice/src/voice/conversation/peer.d.ts +4 -0
- package/dist/packages/gippity-voice/src/voice/conversation/public-turns.d.ts +2 -1
- package/dist/packages/gippity-voice/src/voice/conversation/session.d.ts +1 -0
- package/dist/packages/gippity-voice/src/voice/helper-protocol.d.ts +35 -0
- package/dist/packages/gippity-voice/src/voice/lan/browser-clients.d.ts +1 -1
- package/dist/packages/gippity-voice/src/voice/lan/browser-connections.d.ts +17 -0
- package/dist/packages/gippity-voice/src/voice/lan/browser-session.d.ts +4 -2
- package/dist/packages/gippity-voice/src/voice/lan/server.d.ts +4 -2
- package/dist/packages/gippity-voice/src/voice/realtime-auth.d.ts +3 -2
- package/dist/packages/gippity-voice/src/voice/turns.d.ts +2 -1
- package/dist/voice/bin/darwin-arm64/pi-codex-voice +0 -0
- package/dist/voice/bin/darwin-x64/pi-codex-voice +0 -0
- package/dist/voice/bin/linux-arm64/pi-codex-voice +0 -0
- package/dist/voice/bin/linux-x64/pi-codex-voice +0 -0
- package/dist/voice/bin/win32-arm64/pi-codex-voice.exe +0 -0
- package/dist/voice/bin/win32-x64/pi-codex-voice.exe +0 -0
- package/package.json +6 -5
- package/src/voice/rust/src/audio.rs +2 -2
- package/src/voice/rust/src/playout.rs +68 -8
- package/src/voice/rust/src/protocol.rs +43 -1
- package/src/voice/rust/src/v3_media.rs +138 -31
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type JsonValue } from "@earendil-works/chord";
|
|
2
|
-
import type { TSchema } from "@earendil-works/pi-ai";
|
|
3
2
|
import type { ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
export declare const nestedToolDiscoveryGuidance = "Tools without a shown call signature: help is required only while their current arguments are unknown. Call with no arguments and read the result before composing an operation. Reuse known arguments without repeating help. Structured discovery uses {}";
|
|
4
4
|
/** Optional runtime presentation and observation policy on an ordinary registration. */
|
|
5
5
|
export interface ExecutionToolHints {
|
|
6
6
|
readonly usage?: string;
|
|
@@ -13,7 +13,7 @@ export interface ExecutionToolHints {
|
|
|
13
13
|
/** Keep the tool on the provider surface and prohibit calls from execution cells. */
|
|
14
14
|
readonly nativeOnly?: boolean;
|
|
15
15
|
}
|
|
16
|
-
export type ExecutionToolRegistration<T extends
|
|
16
|
+
export type ExecutionToolRegistration<T extends object = object, D extends JsonValue = JsonValue> = ToolRegistration<T, D> & {
|
|
17
17
|
readonly executionHints?: ExecutionToolHints;
|
|
18
18
|
};
|
|
19
19
|
interface ExecutionToolContract {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Conversation, type ConversationView, type EntryRecord } from "@earendil-works/pi-durable";
|
|
3
|
+
/** Call-local observation, never replayed as conversation input. */
|
|
4
|
+
export declare function observeVoiceAgent(conversation: Conversation, context: Context, callbacks: {
|
|
5
|
+
state(working: boolean): void;
|
|
6
|
+
entry(entry: EntryRecord): void;
|
|
7
|
+
partial(delta: string, working: boolean): void;
|
|
8
|
+
compacting(reason: "overflow" | "threshold"): void;
|
|
9
|
+
failed(error: unknown): void;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
readonly view: ConversationView;
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
}>;
|
|
@@ -40,6 +40,12 @@ export interface GippityLanPermission {
|
|
|
40
40
|
export type GippityPresentation = {
|
|
41
41
|
type: "voice-event";
|
|
42
42
|
event: RealtimeVoiceEventDetails;
|
|
43
|
+
} | {
|
|
44
|
+
type: "audio-diagnostics";
|
|
45
|
+
diagnostics: import("./voice/helper-protocol.ts").VoiceAudioDiagnostics;
|
|
46
|
+
} | {
|
|
47
|
+
type: "lan-playback-diagnostics";
|
|
48
|
+
diagnostics: import("./voice/lan/browser-connections.ts").LanPlaybackDiagnostics;
|
|
43
49
|
} | {
|
|
44
50
|
type: "status";
|
|
45
51
|
status: string;
|
|
@@ -9,5 +9,6 @@ export { createNativeGippityAppFiles, createNativeGippityAudioHost, } from "./na
|
|
|
9
9
|
export type { GippityPreferences } from "./preferences.ts";
|
|
10
10
|
export type { RealtimeVoiceEventDetails } from "./voice/conversation/wire.ts";
|
|
11
11
|
export type { TransferredVoiceControls, VoiceHandoffChannel, } from "./voice/handoff-contract.ts";
|
|
12
|
-
export type { VoiceDevice } from "./voice/helper-protocol.ts";
|
|
12
|
+
export type { VoiceAudioDiagnostics, VoiceDevice, } from "./voice/helper-protocol.ts";
|
|
13
|
+
export type { LanPlaybackDiagnostics } from "./voice/lan/browser-connections.ts";
|
|
13
14
|
export type { GippityRemoteAppMessage, GippityRemoteAppProvider, } from "./voice/lan/remote-app.ts";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GippityControlConfig } from "../../config.ts";
|
|
2
|
+
import type { VoiceAudioDiagnostics } from "../helper-protocol.ts";
|
|
2
3
|
export declare const MAX_REALTIME_SDP_BYTES: number;
|
|
3
4
|
export type CodexRealtimePeerEvent = {
|
|
4
5
|
type: "state";
|
|
@@ -8,6 +9,9 @@ export type CodexRealtimePeerEvent = {
|
|
|
8
9
|
message: unknown;
|
|
9
10
|
} | {
|
|
10
11
|
type: "playback_activity";
|
|
12
|
+
} | {
|
|
13
|
+
type: "audio_diagnostics";
|
|
14
|
+
diagnostics: VoiceAudioDiagnostics;
|
|
11
15
|
} | {
|
|
12
16
|
type: "error";
|
|
13
17
|
message: string;
|
|
@@ -19,7 +19,7 @@ export declare const SEND_TASK_TOOL: {
|
|
|
19
19
|
additionalProperties: boolean;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
export declare const PUBLIC_REALTIME_INSTRUCTIONS = "This call has tools.
|
|
22
|
+
export declare const PUBLIC_REALTIME_INSTRUCTIONS = "This call has tools. Delegate without narrating the routing. Other listed tools run directly. Tool availability supersedes earlier statements that voice has no tools. Agent updates describe work already underway, not new user instructions. Speak useful progress and results, then wait for the user";
|
|
23
23
|
/** Public Realtime wire, independent from Codex delegation/transcript semantics. */
|
|
24
24
|
export declare class PublicRealtimeTurns {
|
|
25
25
|
readonly handoff: RealtimeDelegationHandoff;
|
|
@@ -33,6 +33,7 @@ export declare class PublicRealtimeTurns {
|
|
|
33
33
|
private activeResponse;
|
|
34
34
|
private awaitingResponse;
|
|
35
35
|
private speech;
|
|
36
|
+
private taskInputAvailable;
|
|
36
37
|
private pendingTools;
|
|
37
38
|
private readonly pendingWork;
|
|
38
39
|
private ending;
|
|
@@ -18,6 +18,7 @@ export interface CodexConversationCallbacks {
|
|
|
18
18
|
onUserTranscript(transcript: string): void;
|
|
19
19
|
onTranscriptTail(transcriptDelta: string): void;
|
|
20
20
|
onEvent?(event: RealtimeVoiceEventDetails): void;
|
|
21
|
+
onAudioDiagnostics?(diagnostics: import("../helper-protocol.ts").VoiceAudioDiagnostics): void;
|
|
21
22
|
}
|
|
22
23
|
export declare class CodexRealtimeConversation {
|
|
23
24
|
private readonly callbacks;
|
|
@@ -56,6 +56,9 @@ export type VoiceHelperEvent = {
|
|
|
56
56
|
epoch?: number;
|
|
57
57
|
} | {
|
|
58
58
|
type: "playback_activity";
|
|
59
|
+
} | {
|
|
60
|
+
type: "audio_diagnostics";
|
|
61
|
+
diagnostics: VoiceAudioDiagnostics;
|
|
59
62
|
} | {
|
|
60
63
|
type: "error";
|
|
61
64
|
message: string;
|
|
@@ -67,6 +70,38 @@ export interface VoiceDevice {
|
|
|
67
70
|
name: string;
|
|
68
71
|
is_default: boolean;
|
|
69
72
|
}
|
|
73
|
+
export interface VoiceAudioDiagnostics {
|
|
74
|
+
epoch: number;
|
|
75
|
+
suppressed: boolean;
|
|
76
|
+
elapsed_ms: number;
|
|
77
|
+
transitions: number;
|
|
78
|
+
drained_packets: number;
|
|
79
|
+
release_drained_packets: number;
|
|
80
|
+
rejected_packets: number;
|
|
81
|
+
buffering_entries: number;
|
|
82
|
+
tail_flushes: number;
|
|
83
|
+
clock_rebases: number;
|
|
84
|
+
decode_failures: number;
|
|
85
|
+
received_packets: number;
|
|
86
|
+
missing_packets: number;
|
|
87
|
+
decoded_packets: number;
|
|
88
|
+
decoded_packet_samples: number;
|
|
89
|
+
min_decoded_packet_samples: number;
|
|
90
|
+
max_decoded_packet_samples: number;
|
|
91
|
+
late_packets: number;
|
|
92
|
+
duplicate_packets: number;
|
|
93
|
+
reordered_packets: number;
|
|
94
|
+
resyncs: number;
|
|
95
|
+
resync_discarded_packets: number;
|
|
96
|
+
read_gaps_over_40ms: number;
|
|
97
|
+
max_read_gap_ms: number;
|
|
98
|
+
max_playout_lateness_us: number;
|
|
99
|
+
bridge_frames: number;
|
|
100
|
+
bridge_channel_full: number;
|
|
101
|
+
bridge_sends_over_1ms: number;
|
|
102
|
+
max_bridge_send_us: number;
|
|
103
|
+
first_packet_ms: number | null;
|
|
104
|
+
}
|
|
70
105
|
export declare class BoundedJsonlReader {
|
|
71
106
|
private readonly chunks;
|
|
72
107
|
private readonly maxLineBytes;
|
|
@@ -17,7 +17,7 @@ export declare class LanVoiceBrowserClients {
|
|
|
17
17
|
sendConversationAudio(pcm: Buffer): void;
|
|
18
18
|
setConversationSpeakerSuppressed(suppressed: boolean): void;
|
|
19
19
|
resetConversationInputLevel(): void;
|
|
20
|
-
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean):
|
|
20
|
+
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean): Promise<boolean>;
|
|
21
21
|
heartbeat(): void;
|
|
22
22
|
close(): Promise<void>;
|
|
23
23
|
private receive;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { ServerResponse } from "node:http";
|
|
2
2
|
import { type RawData, WebSocket } from "ws";
|
|
3
|
+
export interface LanPlaybackDiagnostics {
|
|
4
|
+
source: "lan-playback";
|
|
5
|
+
reason: "interval" | "closed" | "replaced" | "server-closed";
|
|
6
|
+
windowMs: number;
|
|
7
|
+
sentFrames: number;
|
|
8
|
+
sentBytes: number;
|
|
9
|
+
droppedFrames: number;
|
|
10
|
+
droppedBytes: number;
|
|
11
|
+
maxSocketBacklogBytes: number;
|
|
12
|
+
sourcePcmArrivalGapMaxMs: number;
|
|
13
|
+
sourcePcmArrivalGapIncludesPauses: true;
|
|
14
|
+
}
|
|
3
15
|
interface AudioConnectionCallbacks {
|
|
4
16
|
onMessage(data: RawData, isBinary: boolean): void;
|
|
5
17
|
onReplaced(previous: WebSocket): void;
|
|
@@ -8,6 +20,9 @@ interface AudioConnectionCallbacks {
|
|
|
8
20
|
export declare class LanVoiceBrowserConnections {
|
|
9
21
|
private readonly eventResponses;
|
|
10
22
|
private readonly audioSockets;
|
|
23
|
+
private readonly audioReports;
|
|
24
|
+
private readonly onAudioDiagnostics;
|
|
25
|
+
constructor(onAudioDiagnostics?: (report: LanPlaybackDiagnostics) => void);
|
|
11
26
|
connectEvents(clientId: string, response: ServerResponse, closed: boolean): void;
|
|
12
27
|
connectAudio(clientId: string, socket: WebSocket, closed: boolean, callbacks: AudioConnectionCallbacks): void;
|
|
13
28
|
isCurrentAudio(clientId: string, socket: WebSocket): boolean;
|
|
@@ -16,6 +31,8 @@ export declare class LanVoiceBrowserConnections {
|
|
|
16
31
|
hasAudioClients(): boolean;
|
|
17
32
|
broadcastControl(value: unknown): void;
|
|
18
33
|
sendAudio(socket: WebSocket, pcm: Buffer): void;
|
|
34
|
+
private flushAudioReport;
|
|
35
|
+
private finishAudioReport;
|
|
19
36
|
sendAudioControl(socket: WebSocket, value: unknown): void;
|
|
20
37
|
heartbeat(): void;
|
|
21
38
|
close(failures: unknown[]): void;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { WebSocket } from "ws";
|
|
2
|
-
import { LanVoiceBrowserConnections } from "./browser-connections.ts";
|
|
2
|
+
import type { LanPlaybackDiagnostics, LanVoiceBrowserConnections } from "./browser-connections.ts";
|
|
3
3
|
import type { LanVoiceDraftSelection } from "./draft.ts";
|
|
4
4
|
export type LanVoiceBrowserMode = "conversation" | "dictation";
|
|
5
5
|
export interface LanVoiceBrowserClientsOptions {
|
|
6
|
+
onAudioDiagnostics?(diagnostics: LanPlaybackDiagnostics): void;
|
|
6
7
|
ensureConversation(takeoverToken?: string): Promise<void>;
|
|
7
8
|
startDictation(clientId: string): Promise<void>;
|
|
8
9
|
finishDictation(clientId: string, draft?: string, revision?: number, selection?: LanVoiceDraftSelection): Promise<void>;
|
|
@@ -20,6 +21,7 @@ export declare class LanVoiceBrowserSession {
|
|
|
20
21
|
private state;
|
|
21
22
|
private operation;
|
|
22
23
|
private conversationOwnerId;
|
|
24
|
+
private stopCompletion;
|
|
23
25
|
private conversationSpeakerSuppressed;
|
|
24
26
|
private readonly microphoneLevel;
|
|
25
27
|
constructor(options: LanVoiceBrowserClientsOptions, connections: LanVoiceBrowserConnections);
|
|
@@ -27,7 +29,7 @@ export declare class LanVoiceBrowserSession {
|
|
|
27
29
|
get conversationSocket(): WebSocket | undefined;
|
|
28
30
|
sendConversationAudio(pcm: Buffer): void;
|
|
29
31
|
setConversationSpeakerSuppressed(suppressed: boolean): void;
|
|
30
|
-
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean):
|
|
32
|
+
release(clientId: string, socket?: WebSocket, terminateConversation?: boolean): Promise<boolean>;
|
|
31
33
|
releaseStarting(clientId: string, socket?: WebSocket): void;
|
|
32
34
|
claim(clientId: string, socket: WebSocket, mode: LanVoiceBrowserMode, takeoverToken?: string): Promise<void>;
|
|
33
35
|
finish(clientId: string, socket: WebSocket, draft: string, revision: number, selection: LanVoiceDraftSelection): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord";
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntryRecord } from "@earendil-works/pi-durable";
|
|
3
3
|
import type { GippityVoiceControls } from "../../controller.ts";
|
|
4
4
|
import type { AudioLease, GippityAppFiles, GippityAudioHost, GippityLanPermission, GippityPresentation } from "../../host.ts";
|
|
5
5
|
import type { CodexVoiceAuth } from "../auth.ts";
|
|
@@ -14,7 +14,8 @@ export interface GippityLanServer {
|
|
|
14
14
|
releaseForTakeover(): Promise<void>;
|
|
15
15
|
publish(event: GippityPresentation): void;
|
|
16
16
|
broadcast(event: unknown): void;
|
|
17
|
-
|
|
17
|
+
agentState(working: boolean): void;
|
|
18
|
+
agentEntry(entry: EntryRecord): void;
|
|
18
19
|
sessionEvent(event: string, data: unknown): void;
|
|
19
20
|
close(): Promise<void>;
|
|
20
21
|
}
|
|
@@ -30,6 +31,7 @@ export declare function startGippityLanServer(options: {
|
|
|
30
31
|
context: Context;
|
|
31
32
|
resolveAuth(): Promise<CodexVoiceAuth>;
|
|
32
33
|
remoteApps: GippityRemoteApps;
|
|
34
|
+
onAudioDiagnostics?(diagnostics: import("./browser-connections.ts").LanPlaybackDiagnostics): void;
|
|
33
35
|
takeoverToken?: string;
|
|
34
36
|
startConversation?(factory: () => LanHostRealtimePeer, token?: string): Promise<void>;
|
|
35
37
|
}): Promise<GippityLanServer>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Models
|
|
1
|
+
import type { Models } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { JsonSchema } from "@earendil-works/pi-schema";
|
|
2
3
|
import type { CodexVoiceAuth } from "./auth.ts";
|
|
3
4
|
export interface PublicRealtimeAccess {
|
|
4
5
|
tools: {
|
|
@@ -6,7 +7,7 @@ export interface PublicRealtimeAccess {
|
|
|
6
7
|
type: "function";
|
|
7
8
|
name: string;
|
|
8
9
|
description: string;
|
|
9
|
-
parameters:
|
|
10
|
+
parameters: JsonSchema;
|
|
10
11
|
}>;
|
|
11
12
|
execute(name: string, args: unknown, context: {
|
|
12
13
|
signal: AbortSignal;
|
|
@@ -19,6 +19,7 @@ export declare class RealtimeVoiceTurnTracker {
|
|
|
19
19
|
private delegatedUserFinishes;
|
|
20
20
|
private readonly delegatedUserTurns;
|
|
21
21
|
private readonly delegationIds;
|
|
22
|
+
private readonly delegatedTurnInputs;
|
|
22
23
|
private readonly outstandingDelegations;
|
|
23
24
|
private readonly outstandingInputs;
|
|
24
25
|
get hasPendingInput(): boolean;
|
|
@@ -26,7 +27,7 @@ export declare class RealtimeVoiceTurnTracker {
|
|
|
26
27
|
inputAdded(input: string): void;
|
|
27
28
|
outputAdded(output: string): void;
|
|
28
29
|
userFinished(input: string): boolean;
|
|
29
|
-
delegated(input: string, delegationId: string): TrackedRealtimeDelegation | undefined;
|
|
30
|
+
delegated(input: string, delegationId: string, userTurnId?: string): TrackedRealtimeDelegation | undefined;
|
|
30
31
|
delegationSettled(delegationId: string): void;
|
|
31
32
|
assistantFinished(output?: string): RealtimeVoiceTurn | undefined;
|
|
32
33
|
takeTranscriptTail(): string | undefined;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-durable-gippity-voice",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Codex Live and OpenAI Realtime WebRTC voice and dictation for Pi Durable",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,12 +42,13 @@
|
|
|
42
42
|
"typebox": "1.3.27",
|
|
43
43
|
"undici": "8.10.2",
|
|
44
44
|
"ws": "8.21.3",
|
|
45
|
-
"@howaboua/pi-durable-components": "0.
|
|
45
|
+
"@howaboua/pi-durable-components": "0.11.0",
|
|
46
|
+
"@earendil-works/pi-schema": "1.5.0"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"@earendil-works/chord": "1.
|
|
49
|
-
"@earendil-works/pi-ai": "1.
|
|
50
|
-
"@earendil-works/pi-durable": "1.
|
|
49
|
+
"@earendil-works/chord": "1.5.0",
|
|
50
|
+
"@earendil-works/pi-ai": "1.5.0",
|
|
51
|
+
"@earendil-works/pi-durable": "1.5.0",
|
|
51
52
|
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
52
53
|
},
|
|
53
54
|
"publishConfig": {
|
|
@@ -253,7 +253,7 @@ mod tests {
|
|
|
253
253
|
crate::v3_media::drain_ready_packets(&mut read, || {
|
|
254
254
|
Box::pin(queued_read(Arc::clone(&remaining)))
|
|
255
255
|
}),
|
|
256
|
-
crate::v3_media::ReadyDrain::Pending
|
|
256
|
+
crate::v3_media::ReadyDrain::Pending(budget)
|
|
257
257
|
);
|
|
258
258
|
assert_eq!(remaining.load(Ordering::Acquire), 0);
|
|
259
259
|
remaining.store(1, Ordering::Release);
|
|
@@ -261,7 +261,7 @@ mod tests {
|
|
|
261
261
|
crate::v3_media::drain_ready_packets(&mut read, || {
|
|
262
262
|
Box::pin(queued_read(Arc::clone(&remaining)))
|
|
263
263
|
}),
|
|
264
|
-
crate::v3_media::ReadyDrain::Pending
|
|
264
|
+
crate::v3_media::ReadyDrain::Pending(1)
|
|
265
265
|
);
|
|
266
266
|
assert_eq!(remaining.load(Ordering::Acquire), 0);
|
|
267
267
|
|
|
@@ -5,6 +5,8 @@ use bytes::Bytes;
|
|
|
5
5
|
use tokio::time::Instant;
|
|
6
6
|
|
|
7
7
|
const START_PACKETS: usize = 3;
|
|
8
|
+
// Retain the reorder warmup, but never strand a short utterance or resumed tail.
|
|
9
|
+
const MAX_BUFFERING_WAIT: Duration = Duration::from_millis(60);
|
|
8
10
|
const MAX_SEQUENCE_DISTANCE: usize = 6;
|
|
9
11
|
const MAX_PENDING_PACKETS: usize = MAX_SEQUENCE_DISTANCE + 1;
|
|
10
12
|
|
|
@@ -12,13 +14,23 @@ const MAX_PENDING_PACKETS: usize = MAX_SEQUENCE_DISTANCE + 1;
|
|
|
12
14
|
pub enum PlayoutFrame {
|
|
13
15
|
Buffering,
|
|
14
16
|
Packet(Bytes),
|
|
15
|
-
Missing,
|
|
17
|
+
Missing { successor: Option<Bytes> },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
pub enum PacketAdmission {
|
|
21
|
+
// Reordering within the pending window, not a network loss estimate.
|
|
22
|
+
Accepted { reordered: bool },
|
|
23
|
+
// Includes already-played duplicates; only pending duplicates are distinct.
|
|
24
|
+
Late,
|
|
25
|
+
Duplicate,
|
|
26
|
+
Resynchronized { discarded: usize },
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
pub struct PacketPlayout {
|
|
19
30
|
pending: BTreeMap<i64, Bytes>,
|
|
20
31
|
expected: Option<i64>,
|
|
21
32
|
playing: bool,
|
|
33
|
+
buffering_since: Option<Instant>,
|
|
22
34
|
}
|
|
23
35
|
|
|
24
36
|
pub struct PlayoutClock {
|
|
@@ -38,12 +50,17 @@ impl PlayoutClock {
|
|
|
38
50
|
self.deadline
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
pub fn advance(&mut self, samples: usize, sample_rate: u32) {
|
|
53
|
+
pub fn advance(&mut self, samples: usize, sample_rate: u32) -> bool {
|
|
42
54
|
let Some(deadline) = self.deadline else {
|
|
43
|
-
return;
|
|
55
|
+
return false;
|
|
44
56
|
};
|
|
45
57
|
let frame_duration = Duration::from_secs_f64(samples as f64 / sample_rate as f64);
|
|
46
|
-
|
|
58
|
+
let now = Instant::now();
|
|
59
|
+
let late = now.saturating_duration_since(deadline) >= frame_duration;
|
|
60
|
+
// Small scheduler jitter preserves cadence. A full missed frame rebases
|
|
61
|
+
// without discarding audio or emitting a run of immediately due frames.
|
|
62
|
+
self.deadline = Some(if late { now } else { deadline } + frame_duration);
|
|
63
|
+
late
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
pub fn stop(&mut self) {
|
|
@@ -57,24 +74,42 @@ impl PacketPlayout {
|
|
|
57
74
|
pending: BTreeMap::new(),
|
|
58
75
|
expected: None,
|
|
59
76
|
playing: false,
|
|
77
|
+
buffering_since: None,
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
80
|
|
|
63
|
-
pub fn push(&mut self, sequence: u16, payload: Bytes) {
|
|
81
|
+
pub fn push(&mut self, sequence: u16, payload: Bytes) -> PacketAdmission {
|
|
64
82
|
let expected = *self.expected.get_or_insert(sequence as i64);
|
|
65
83
|
let delta = sequence.wrapping_sub(expected as u16) as i16 as i64;
|
|
66
84
|
let extended = expected + delta;
|
|
85
|
+
let mut admission = PacketAdmission::Accepted {
|
|
86
|
+
reordered: self
|
|
87
|
+
.pending
|
|
88
|
+
.keys()
|
|
89
|
+
.next_back()
|
|
90
|
+
.is_some_and(|last| *last > extended),
|
|
91
|
+
};
|
|
67
92
|
if extended < expected {
|
|
68
93
|
if self.playing || expected - extended > MAX_SEQUENCE_DISTANCE as i64 {
|
|
69
|
-
return;
|
|
94
|
+
return PacketAdmission::Late;
|
|
70
95
|
}
|
|
71
96
|
self.expected = Some(extended);
|
|
72
97
|
} else if extended - expected > MAX_SEQUENCE_DISTANCE as i64 {
|
|
98
|
+
admission = PacketAdmission::Resynchronized {
|
|
99
|
+
discarded: self.pending.len(),
|
|
100
|
+
};
|
|
73
101
|
self.pending.clear();
|
|
74
102
|
self.expected = Some(extended);
|
|
75
103
|
self.playing = false;
|
|
104
|
+
self.buffering_since = None;
|
|
105
|
+
}
|
|
106
|
+
if self.pending.contains_key(&extended) {
|
|
107
|
+
admission = PacketAdmission::Duplicate;
|
|
76
108
|
}
|
|
77
109
|
self.pending.entry(extended).or_insert(payload);
|
|
110
|
+
if !self.playing {
|
|
111
|
+
self.buffering_since.get_or_insert_with(Instant::now);
|
|
112
|
+
}
|
|
78
113
|
while self.pending.len() > MAX_PENDING_PACKETS {
|
|
79
114
|
let Some(oldest) = self.pending.keys().next().copied() else {
|
|
80
115
|
break;
|
|
@@ -84,9 +119,16 @@ impl PacketPlayout {
|
|
|
84
119
|
if !self.playing && self.pending.len() >= START_PACKETS {
|
|
85
120
|
self.playing = true;
|
|
86
121
|
}
|
|
122
|
+
admission
|
|
87
123
|
}
|
|
88
124
|
|
|
89
125
|
pub fn next(&mut self) -> PlayoutFrame {
|
|
126
|
+
if self
|
|
127
|
+
.buffering_deadline()
|
|
128
|
+
.is_some_and(|deadline| deadline <= Instant::now())
|
|
129
|
+
{
|
|
130
|
+
self.playing = true;
|
|
131
|
+
}
|
|
90
132
|
if !self.playing {
|
|
91
133
|
return PlayoutFrame::Buffering;
|
|
92
134
|
}
|
|
@@ -101,9 +143,13 @@ impl PacketPlayout {
|
|
|
101
143
|
.next()
|
|
102
144
|
.is_some_and(|sequence| *sequence > expected)
|
|
103
145
|
{
|
|
104
|
-
|
|
146
|
+
// Borrow redundancy without consuming the successor's own slot.
|
|
147
|
+
PlayoutFrame::Missing {
|
|
148
|
+
successor: self.pending.get(&(expected + 1)).cloned(),
|
|
149
|
+
}
|
|
105
150
|
} else {
|
|
106
151
|
self.playing = false;
|
|
152
|
+
self.buffering_since = None;
|
|
107
153
|
return PlayoutFrame::Buffering;
|
|
108
154
|
};
|
|
109
155
|
self.expected = Some(expected + 1);
|
|
@@ -114,10 +160,19 @@ impl PacketPlayout {
|
|
|
114
160
|
self.playing
|
|
115
161
|
}
|
|
116
162
|
|
|
163
|
+
pub fn buffering_deadline(&self) -> Option<Instant> {
|
|
164
|
+
if self.playing || self.pending.is_empty() {
|
|
165
|
+
None
|
|
166
|
+
} else {
|
|
167
|
+
self.buffering_since.map(|since| since + MAX_BUFFERING_WAIT)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
117
171
|
pub fn reset(&mut self) {
|
|
118
172
|
self.pending.clear();
|
|
119
173
|
self.expected = None;
|
|
120
174
|
self.playing = false;
|
|
175
|
+
self.buffering_since = None;
|
|
121
176
|
}
|
|
122
177
|
}
|
|
123
178
|
|
|
@@ -147,7 +202,12 @@ mod tests {
|
|
|
147
202
|
gap.push(22, packet(22));
|
|
148
203
|
gap.push(23, packet(23));
|
|
149
204
|
assert_eq!(gap.next(), PlayoutFrame::Packet(packet(20)));
|
|
150
|
-
assert_eq!(
|
|
205
|
+
assert_eq!(
|
|
206
|
+
gap.next(),
|
|
207
|
+
PlayoutFrame::Missing {
|
|
208
|
+
successor: Some(packet(22))
|
|
209
|
+
}
|
|
210
|
+
);
|
|
151
211
|
assert_eq!(gap.next(), PlayoutFrame::Packet(packet(22)));
|
|
152
212
|
}
|
|
153
213
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use serde::{Deserialize, Serialize};
|
|
2
2
|
use serde_json::Value;
|
|
3
3
|
|
|
4
|
-
pub const PROTOCOL_VERSION: u8 =
|
|
4
|
+
pub const PROTOCOL_VERSION: u8 = 8;
|
|
5
5
|
pub const MAX_SDP_BYTES: usize = 256 * 1024;
|
|
6
6
|
pub const MAX_DATA_MESSAGE_BYTES: usize = 64 * 1024;
|
|
7
7
|
pub const MAX_PCM_BYTES: usize = 64 * 1024;
|
|
@@ -97,6 +97,9 @@ pub enum Event {
|
|
|
97
97
|
epoch: Option<u64>,
|
|
98
98
|
},
|
|
99
99
|
PlaybackActivity,
|
|
100
|
+
AudioDiagnostics {
|
|
101
|
+
diagnostics: AudioDiagnostics,
|
|
102
|
+
},
|
|
100
103
|
Error {
|
|
101
104
|
message: String,
|
|
102
105
|
},
|
|
@@ -110,6 +113,45 @@ pub struct AudioDevice {
|
|
|
110
113
|
pub is_default: bool,
|
|
111
114
|
}
|
|
112
115
|
|
|
116
|
+
// Interval totals may span epochs; epoch/suppressed describe the final state.
|
|
117
|
+
// Counts and local relative timing only: never audio, captions or provider data.
|
|
118
|
+
#[derive(Clone, Debug, Default, Serialize)]
|
|
119
|
+
pub struct AudioDiagnostics {
|
|
120
|
+
pub epoch: u64,
|
|
121
|
+
pub suppressed: bool,
|
|
122
|
+
pub elapsed_ms: u32,
|
|
123
|
+
pub transitions: u32,
|
|
124
|
+
pub drained_packets: u32,
|
|
125
|
+
pub release_drained_packets: u32,
|
|
126
|
+
pub rejected_packets: u32,
|
|
127
|
+
pub buffering_entries: u32,
|
|
128
|
+
pub tail_flushes: u32,
|
|
129
|
+
pub clock_rebases: u32,
|
|
130
|
+
pub decode_failures: u32,
|
|
131
|
+
pub received_packets: u32,
|
|
132
|
+
pub missing_packets: u32,
|
|
133
|
+
// Successful received-packet decodes only (not PLC), per channel at 48 kHz.
|
|
134
|
+
// Min/max are zero if no packet was decoded in the interval.
|
|
135
|
+
pub decoded_packets: u32,
|
|
136
|
+
pub decoded_packet_samples: u32,
|
|
137
|
+
pub min_decoded_packet_samples: u32,
|
|
138
|
+
pub max_decoded_packet_samples: u32,
|
|
139
|
+
pub late_packets: u32,
|
|
140
|
+
pub duplicate_packets: u32,
|
|
141
|
+
pub reordered_packets: u32,
|
|
142
|
+
pub resyncs: u32,
|
|
143
|
+
pub resync_discarded_packets: u32,
|
|
144
|
+
// Observed read spacing, not network arrival time; includes ordinary pauses.
|
|
145
|
+
pub read_gaps_over_40ms: u32,
|
|
146
|
+
pub max_read_gap_ms: u32,
|
|
147
|
+
pub max_playout_lateness_us: u32,
|
|
148
|
+
pub bridge_frames: u32,
|
|
149
|
+
pub bridge_channel_full: u32,
|
|
150
|
+
pub bridge_sends_over_1ms: u32,
|
|
151
|
+
pub max_bridge_send_us: u32,
|
|
152
|
+
pub first_packet_ms: Option<u32>,
|
|
153
|
+
}
|
|
154
|
+
|
|
113
155
|
impl Command {
|
|
114
156
|
pub fn validate(&self) -> anyhow::Result<()> {
|
|
115
157
|
match self {
|