Table of Contents

Class StreamMessage

Namespace
SteamNetworkLib.Models
Assembly
SteamNetworkLib.dll

Represents a universal real-time streaming message for audio, video, or continuous data streams. Supports compression, quality settings, and proper sequencing for low-latency communication. Optimized for streaming applications that require minimal delay and high throughput.

public class StreamMessage : P2PMessage
Inheritance
StreamMessage
Inherited Members

Constructors

StreamMessage()

public StreamMessage()

Properties

AckForSequence

Gets or sets the sequence number this message is acknowledging. Used for reliability feedback and flow control mechanisms.

public uint? AckForSequence { get; set; }

Property Value

uint?

BitsPerSample

Gets or sets the bits per sample for audio quality. Common values include 16, 24, 32 bits per sample.

public int BitsPerSample { get; set; }

Property Value

int

CaptureTimestamp

Gets or sets the timestamp of when this data was captured or generated. Used for synchronization between audio and video streams or maintaining timing.

public long CaptureTimestamp { get; set; }

Property Value

long

Channels

Gets or sets the number of audio channels. 1 = mono, 2 = stereo, 6 = 5.1 surround, etc.

public int Channels { get; set; }

Property Value

int

Codec

Gets or sets the compression codec used for the stream data. Common values include "none", "opus", "mp3", "h264", "vp8", etc.

public string Codec { get; set; }

Property Value

string

FrameDurationMs

Gets or sets the expected duration of this frame in milliseconds. Used for timing and buffering calculations on the receiving end.

public int FrameDurationMs { get; set; }

Property Value

int

FrameSamples

Gets or sets the number of samples per frame. For example, 960 samples for 20ms at 48kHz sampling rate.

public int FrameSamples { get; set; }

Property Value

int

IsFecFrame

Gets or sets a value indicating whether this frame contains forward error correction data. FEC data can help recover from packet loss without retransmission.

public bool IsFecFrame { get; set; }

Property Value

bool

IsRetransmit

Gets or sets a value indicating whether this is a retransmitted frame. Used for reliability mechanisms when important frames need to be resent.

public bool IsRetransmit { get; set; }

Property Value

bool

IsStreamEnd

Gets or sets a value indicating whether this is the end of the stream. Signals to the receiver that no more data will be sent for this stream.

public bool IsStreamEnd { get; set; }

Property Value

bool

IsStreamStart

Gets or sets a value indicating whether this is the start of a new stream. Used to initialize stream decoders and reset state on the receiving end.

public bool IsStreamStart { get; set; }

Property Value

bool

MessageType

Gets the message type identifier for stream messages.

public override string MessageType { get; }

Property Value

string

Metadata

Gets or sets additional metadata as a JSON string. Can contain codec-specific parameters, custom headers, or other stream information.

public string Metadata { get; set; }

Property Value

string

PayloadType

Gets or sets the payload type for extensibility. More specific than StreamType, can include "pcm_audio", "h264_video", "metadata", etc.

public string PayloadType { get; set; }

Property Value

string

Priority

Gets or sets the priority level for this frame. Value between 0-255, where higher values indicate more important frames (e.g., keyframes).

public byte Priority { get; set; }

Property Value

byte

Quality

Gets or sets the quality level for compression. Value between 0-100, where higher values mean better quality but larger size.

public int Quality { get; set; }

Property Value

int

RecommendedSendType

Gets or sets the recommended send type for this stream. Defaults to UnreliableNoDelay for real-time audio/video to minimize latency.

public EP2PSend RecommendedSendType { get; set; }

Property Value

EP2PSend

SampleRate

Gets or sets the sample rate for audio streams in Hz. Common values include 44100, 48000, 22050, etc.

public int SampleRate { get; set; }

Property Value

int

SequenceNumber

Gets or sets the sequence number for packet ordering and loss detection. Essential for maintaining proper stream continuity and detecting missing packets.

public uint SequenceNumber { get; set; }

Property Value

uint

StreamData

Gets or sets the actual stream data payload. Contains the raw or compressed audio/video/data bytes.

public byte[] StreamData { get; set; }

Property Value

byte[]

StreamId

Gets or sets the unique stream identifier to handle multiple concurrent streams. Allows multiple independent streams between the same players.

public string StreamId { get; set; }

Property Value

string

StreamType

Gets or sets the type of stream data being transmitted. Common values include "audio", "video", "data", "mixed", etc.

public string StreamType { get; set; }

Property Value

string

Methods

Deserialize(byte[])

Deserializes the stream message from a byte array received over the network. Parses the JSON header and extracts the binary stream data.

public override void Deserialize(byte[] data)

Parameters

data byte[]

The byte array containing the serialized message data.

Serialize()

Serializes the stream message to a byte array for network transmission. Uses a hybrid format with JSON header followed by raw binary stream data.

public override byte[] Serialize()

Returns

byte[]

A byte array containing the serialized message with header and stream data.