initial commit — SIP B2BUA + WebRTC bridge with Rust codec engine
Full-featured SIP router with multi-provider trunking, browser softphone via WebRTC, real-time Opus/G.722/PCM transcoding in Rust, RNNoise ML noise suppression, Kokoro neural TTS announcements, and a Lit-based web dashboard with live call monitoring and REST API.
This commit is contained in:
40
ts/codec.ts
Normal file
40
ts/codec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Audio codec translation layer for bridging between WebRTC and SIP.
|
||||
*
|
||||
* All actual codec work (Opus, G.722, PCMU, PCMA) is done in Rust via
|
||||
* the smartrust bridge. This module provides the RTP-level transcoding
|
||||
* interface used by the webrtcbridge.
|
||||
*/
|
||||
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { transcode, isCodecReady } from './opusbridge.ts';
|
||||
|
||||
/** Opus dynamic payload type (standard WebRTC assignment). */
|
||||
export const OPUS_PT = 111;
|
||||
|
||||
export interface IRtpTranscoder {
|
||||
/** Transcode an RTP payload. Always async (Rust IPC). */
|
||||
payload(data: Buffer): Promise<Buffer>;
|
||||
fromPT: number;
|
||||
toPT: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a transcoder that converts RTP payloads between two codecs.
|
||||
* Returns null if the codecs are the same or the Rust bridge isn't ready.
|
||||
*
|
||||
* @param sessionId - optional Rust codec session for isolated state per call
|
||||
*/
|
||||
export function createTranscoder(fromPT: number, toPT: number, sessionId?: string, direction?: string): IRtpTranscoder | null {
|
||||
if (fromPT === toPT) return null;
|
||||
if (!isCodecReady()) return null;
|
||||
|
||||
return {
|
||||
fromPT,
|
||||
toPT,
|
||||
async payload(data: Buffer): Promise<Buffer> {
|
||||
const result = await transcode(data, fromPT, toPT, sessionId, direction);
|
||||
return result || Buffer.alloc(0); // return empty on failure — never pass raw codec bytes
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user