Skip to content

@seydx/rtsp / wrapAvPacket

Function: wrapAvPacket()

wrapAvPacket(packet, streamIndex?): MediaPacket

Defined in: av-packet.ts:39

Wrap a node-av packet as a relay media packet.

Adapts a native node-av packet to the MediaPacket interface that the relay fan-out machinery consumes, while keeping a direct reference to the native handle so AV-backed sinks can recover it. Cloning is ref-counted and shares the payload buffer, which keeps fanning a single demuxed packet out to many consumers cheap, and freeing releases only the specific handle it is called on.

The relay typically clones once per consumer and frees the original, leaving each consumer responsible for freeing its own clone after it has been written.

Parameters

packet

Packet

The native node-av packet to wrap

streamIndex?

number = packet.streamIndex

Stream index to expose on the wrapper; defaults to the packet's own index. Override it when several demuxers are merged into one source and a per-demuxer index must be remapped onto a global stream index.

Returns

MediaPacket

A MediaPacket backed by the given native packet

Throws

If a later clone() call fails because av_packet_clone returns null

Example

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

const media = wrapAvPacket(nativePacket);
const copy = media.clone(); // cheap, ref-counted fan-out
media.free();

See