pw-client
Version:
Node.js wrapper for developing PipeWire clients
128 lines (127 loc) • 3.75 kB
text/typescript
/**
* Performance monitoring and metrics collection for audio streams.
* Tracks buffer health, processing times, and diagnostic events.
*/
/**
* Performance metrics collected over time.
*/
export interface StreamMetrics {
/** Total number of write operations */
writeCount: number;
/** Total frames processed */
framesProcessed: number;
/** Buffer underrun count */
underrunCount: number;
/** Buffer overrun count */
overrunCount: number;
/** Processing time statistics (milliseconds) */
processingTime: {
min: number;
max: number;
average: number;
recent: number;
};
/** Buffer fill statistics (0.0-1.0) */
bufferFill: {
min: number;
max: number;
average: number;
current: number;
};
/** Latency measurements (milliseconds) */
latency: {
min: number;
max: number;
average: number;
current: number;
};
/** Real-time performance ratio (1.0 = perfect real-time) */
realTimeRatio: number;
/** Timestamp of last update */
lastUpdate: number;
}
/**
* Diagnostic event types for stream health monitoring.
*/
export declare enum DiagnosticEvent {
/** Buffer underrun detected - increase buffer size */
BufferUnderrun = "buffer-underrun",
/** Buffer overrun detected - reduce input rate */
BufferOverrun = "buffer-overrun",
/** Processing taking too long - optimize or increase buffer */
ProcessingDelay = "processing-delay",
/** Format negotiation failed */
FormatMismatch = "format-mismatch",
/** Latency spike detected */
LatencySpike = "latency-spike",
/** Buffer size adjusted automatically */
BufferAdjusted = "buffer-adjusted",
/** Performance degradation detected */
PerformanceDrop = "performance-drop"
}
/**
* Diagnostic event with context information.
*/
export interface DiagnosticEventInfo {
event: DiagnosticEvent;
timestamp: number;
severity: "info" | "warning" | "error";
message: string;
data?: Record<string, unknown>;
suggestion?: string;
}
/**
* Performance monitor for audio streams.
* Collects metrics and emits diagnostic events.
*/
export declare class StreamPerformanceMonitor {
private readonly rate;
private readonly channels;
private readonly bufferSize;
private readonly metrics;
private readonly maxSamples;
private readonly processingTimes;
private readonly bufferFills;
private readonly latencies;
private lastProcessingTime;
private readonly eventCallbacks;
constructor(rate: number, channels: number, bufferSize: number);
/**
* Record a write operation with performance data.
*/
recordWrite(frameCount: number, processingTimeMs: number, bufferFillRatio: number): void;
/**
* Record a buffer underrun event.
*/
recordUnderrun(): void;
/**
* Record a buffer overrun event.
*/
recordOverrun(): void;
/**
* Update latency measurement.
*/
recordLatency(latencyMs: number): void;
/**
* Get current performance metrics.
*/
getMetrics(): StreamMetrics;
/**
* Subscribe to diagnostic events.
*/
onDiagnostic(event: DiagnosticEvent, callback: (info: DiagnosticEventInfo) => void): void;
/**
* Unsubscribe from diagnostic events.
*/
offDiagnostic(event: DiagnosticEvent, callback: (info: DiagnosticEventInfo) => void): void;
/**
* Get health assessment of the stream.
*/
getHealthAssessment(): {
overall: "good" | "warning" | "critical";
issues: Array<string>;
suggestions: Array<string>;
};
private checkDiagnostics;
private emitDiagnostic;
}