Skip to content

@seydx/rtsp / BackchannelTranscoder

Class: BackchannelTranscoder

Defined in: sinks/rtsp-server/backchannel-transcoder.ts:197

Transcodes inbound viewer talkback audio into the upstream camera's codec.

Bridges the format advertised to RTSP clients and the format an upstream camera expects on its ONVIF backchannel by running an in-process audio pipeline that decodes, resamples, re-encodes, and muxes the received audio. The result is delivered through a caller-supplied callback as either RTP packets or raw container bytes, depending on the chosen target format.

Example

typescript
import { BackchannelTranscoder } from '@seydx/rtsp';

const transcoder = new BackchannelTranscoder({
  from: { codec: 'opus', payloadType: 97, clockRate: 48000, channels: 1 },
  to: { codecId: cameraCodecId, sampleRate: 8000, channels: 1 },
  output: (rtp) => camera.sendBackchannel(rtp),
});

await transcoder.start();
transcoder.push(viewerRtpPacket);
await transcoder.close();

See

RtspServerSink For the sink that drives talkback delivery

Constructors

Constructor

new BackchannelTranscoder(options): BackchannelTranscoder

Defined in: sinks/rtsp-server/backchannel-transcoder.ts:214

Create a backchannel transcoder.

The transcoder is inert until BackchannelTranscoder.start is called; the constructor only captures configuration.

Parameters

options

BackchannelTranscoderOptions

Inbound/target formats, output callback, and tuning

Returns

BackchannelTranscoder

Methods

close()

close(): Promise<void>

Defined in: sinks/rtsp-server/backchannel-transcoder.ts:322

Stop the transcoder and release all pipeline resources.

Marks the transcoder inactive, ending the background loop, then closes the input demuxer, decoder, filter, encoder, and output muxer. Safe to call when the transcoder was never started or is already closed.

Returns

Promise<void>

Resolves once all resources are released

Example

typescript
await transcoder.close();

push()

push(rtp): void

Defined in: sinks/rtsp-server/backchannel-transcoder.ts:304

Feed one inbound RTP packet from a viewer into the pipeline.

Packets are queued into the synthetic input demuxer and consumed by the background transcode loop. Calling push before BackchannelTranscoder.start (or after BackchannelTranscoder.close) is a silent no-op.

Parameters

rtp

Buffer

A single inbound RTP packet in the advertised viewer codec

Returns

void

Example

typescript
transcoder.push(viewerRtpPacket);

start()

start(): Promise<void>

Defined in: sinks/rtsp-server/backchannel-transcoder.ts:235

Start the transcode pipeline.

Resolves the decoder and encoder, builds a synthetic input SDP for the inbound viewer format, and wires up the decode, resample, encode, and mux stages. Once started, inbound packets fed via BackchannelTranscoder.push flow through the pipeline and produced output is delivered to the configured callback. Calling start when already active is a no-op.

Returns

Promise<void>

Resolves once the pipeline is running

Throws

If the inbound decoder or target encoder cannot be resolved, or the generated SDP contains no audio stream

Example

typescript
await transcoder.start();