Skip to content

@seydx/rtsp / ForwardAudioTranscoder

Class: ForwardAudioTranscoder

Defined in: sinks/rtsp-server/forward-audio-transcoder.ts:65

Decodes and re-encodes a single elementary audio track into a clean stream.

Some upstreams deliver elementary audio (for example raw ADTS AAC) whose header layout a passthrough bitstream filter cannot adapt — the filter aborts and, with it, the whole delivery channel. This transcoder sidesteps that by running an in-process decode → resample → re-encode pipeline: the re-encoded packets carry standards-compliant parameters (extradata, ASC, ...) that the RTP muxer accepts unconditionally.

It is push-based to match a sink that receives one packet at a time: each fed packet is decoded, filtered, and re-encoded, and the resulting packets are written to the caller-owned muxer stream created by start. This mirrors the send/receive discipline of a bitstream filter, so it slots into the same per-packet write path.

See

BackchannelTranscoder For the reverse (viewer → camera) pipeline

Constructors

Constructor

new ForwardAudioTranscoder(target, logger?): ForwardAudioTranscoder

Defined in: sinks/rtsp-server/forward-audio-transcoder.ts:81

Create a forward audio transcoder.

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

Parameters

target

AudioTranscodeTarget

Encoder target the audio is normalized into.

logger?

Logger

Optional logger used to report the resolved pipeline.

Returns

ForwardAudioTranscoder

Methods

close()

close(): Promise<void>

Defined in: sinks/rtsp-server/forward-audio-transcoder.ts:218

Release the decoder, filter, and encoder.

Does not close the muxer — that stream is owned by the caller. Safe to call when the transcoder was never started or is already closed.

Returns

Promise<void>

Example

typescript
await transcoder.close();

start()

start(source, muxer): Promise<number>

Defined in: sinks/rtsp-server/forward-audio-transcoder.ts:107

Start the decode/re-encode pipeline and register the output stream.

Resolves the target encoder, builds the decode → resample → encode chain from the source stream, and adds the encoder as a stream on the caller-owned muxer. The returned index must be used when writing packets back to that muxer.

Parameters

source

Stream

Source-native stream handle whose packets will be fed in.

muxer

Muxer

The caller-owned muxer the re-encoded packets are written to.

Returns

Promise<number>

The muxer stream index the encoded packets belong to.

Throws

If the target encoder cannot be resolved.

Example

typescript
const index = await transcoder.start(track.native, muxer);

write()

write(packet, muxer): Promise<number>

Defined in: sinks/rtsp-server/forward-audio-transcoder.ts:165

Feed one source packet through the pipeline and mux the encoded result.

Decodes the packet, runs the decoded frames through the resample filter, and re-encodes them, writing every produced packet to the muxer stream created by start. A single input packet may yield zero, one, or several output packets. Every intermediate frame/packet is freed before returning.

Decode, filter, and encode failures are contained: the offending packet or frame is dropped with a warning and the pipeline keeps running — this transcoder exists to survive unreliable upstream audio, so one corrupt packet must not tear down the whole delivery channel. Muxer write failures still propagate, since a broken output is not recoverable per packet.

Parameters

packet

Packet

The source-native packet to transcode.

muxer

Muxer

The muxer whose stream the encoded packets are written to.

Returns

Promise<number>

The number of encoded packets written to the muxer this call. Zero while the encoder is still buffering (no muxer header emitted yet), which the caller uses to defer SDP generation until the stream's parameters are known.

Throws

If writing an encoded packet to the muxer fails.

Example

typescript
const written = await transcoder.write(packet.av, muxer);