@seydx/rtsp / MediaPacket
Interface: MediaPacket
Defined in: types.ts:339
One unit of media flowing through the relay.
Represents a single demuxed packet for one track. The relay core only ever reads MediaPacket.streamIndex and MediaPacket.isKeyframe to route and gate packets; sinks that need the encoded payload reach for the underlying AV packet. Each packet is owned by exactly one holder: clone produces an independently-owned copy so a single demuxed packet can be fanned out to many sinks, and free releases any native resources it holds.
Example
import { MediaPacket } from '@seydx/rtsp';
function fanOut(packet: MediaPacket, sinks: { write(p: MediaPacket): void }[]) {
for (const sink of sinks) {
sink.write(packet.clone());
}
packet.free();
}See
Properties
av?
readonlyoptionalav?:Packet
Defined in: types.ts:380
Underlying node-av Packet.
Present for AV-backed sources and carries the encoded payload AV-backed sinks need to write to a muxer. Never inspected by the relay core; absent for plain (non-AV) packets.
dts?
readonlyoptionaldts?:number
Defined in: types.ts:371
Decode timestamp, in the track's time base.
The time at which the packet should be decoded, which can differ from MediaPacket.pts for streams with B-frames. May be absent when the source does not provide it.
isKeyframe
readonlyisKeyframe:boolean
Defined in: types.ts:354
Whether this packet is a keyframe.
Used by the relay to gate sinks until a decodable starting point arrives, so downstream consumers begin on a clean frame rather than mid-GOP.
pts?
readonlyoptionalpts?:number
Defined in: types.ts:362
Presentation timestamp, in the track's time base.
The time at which the decoded frame should be presented. May be absent when the source does not provide it.
streamIndex
readonlystreamIndex:number
Defined in: types.ts:346
Index of the track this packet belongs to.
Matches the TrackInfo.index of the describing track, letting the relay and sinks route the packet to the correct stream.
Methods
clone()
clone():
MediaPacket
Defined in: types.ts:397
Return an independently-owned copy of this packet for fan-out.
The copy can be handed to another holder without affecting this one; for native packets the copy is cheap and reference-counted. Each clone must be freed independently.
Returns
MediaPacket
A new, independently-owned packet referring to the same media
Example
const copy = packet.clone();
sink.write(copy);free()
free():
void
Defined in: types.ts:410
Release the packet's underlying native resources.
Must be called once the holder is done with the packet. A no-op for plain packets that hold no native resources.
Returns
void
Example
packet.free();