libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
RtpPacket Class Reference

A BufferView that interprets its data as an RTP packet. More...

#include <rtppacket.h>

Inheritance diagram for RtpPacket:
Collaboration diagram for RtpPacket:

Public Types

using List = promeki::List< RtpPacket >
 List of RtpPacket values.
 
using SizeList = promeki::List< size_t >
 List of sizes.
 
- Public Types inherited from BufferView
using List = promeki::List< BufferView >
 List of BufferView values.
 

Public Member Functions

 RtpPacket ()=default
 Default constructor.
 
 RtpPacket (Buffer::Ptr buf, size_t offset, size_t size)
 Constructs an RtpPacket referencing a region of a shared buffer.
 
bool isNull () const
 Returns true if the buffer pointer is null.
 
bool isValid () const
 Returns true if this is a valid RTP packet.
 
 RtpPacket (size_t packetSize)
 Convenience constructor that allocates a buffer for a single packet.
 
uint8_t version () const
 Returns the RTP version (normally 2).
 
void setVersion (uint8_t v)
 Sets the RTP version.
 
bool padding () const
 Returns the padding flag.
 
void setPadding (bool p)
 Sets the padding flag.
 
bool extension () const
 Returns the extension flag.
 
void setExtension (bool x)
 Sets the extension flag.
 
uint8_t csrcCount () const
 Returns the CSRC count.
 
bool marker () const
 Returns the marker bit.
 
void setMarker (bool m)
 Sets the marker bit.
 
uint8_t payloadType () const
 Returns the payload type (7 bits).
 
void setPayloadType (uint8_t pt)
 Sets the payload type.
 
uint16_t sequenceNumber () const
 Returns the sequence number.
 
void setSequenceNumber (uint16_t seq)
 Sets the sequence number.
 
uint32_t timestamp () const
 Returns the timestamp.
 
void setTimestamp (uint32_t ts)
 Sets the timestamp.
 
uint32_t ssrc () const
 Returns the SSRC.
 
void setSsrc (uint32_t s)
 Sets the SSRC.
 
size_t headerSize () const
 Returns the full header size including CSRC list and extension.
 
uint16_t extensionProfile () const
 Returns the extension profile ID, or 0 if no extension is present.
 
uint16_t extensionLength () const
 Returns the extension data length in 32-bit words, or 0 if no extension.
 
const uint8_tpayload () const
 Returns a pointer to the payload data (after the full header).
 
uint8_tpayload ()
 Returns a pointer to the payload data (after the full header).
 
size_t payloadSize () const
 Returns the payload size in bytes.
 
void clear ()
 Zeroes the packet data and resets the RTP version to 2.
 
- Public Member Functions inherited from BufferView
 BufferView ()=default
 Default constructor. Creates an empty view with no buffer.
 
 BufferView (Buffer::Ptr buf, size_t offset, size_t size)
 Constructs a BufferView referencing a region of a shared buffer.
 
const Buffer::Ptrbuffer () const
 Returns the shared backing buffer.
 
size_t offset () const
 Returns the byte offset into the buffer.
 
size_t size () const
 Returns the byte size of this view.
 
const uint8_tdata () const
 Returns a const pointer to this view's data.
 
uint8_tdata ()
 Returns a mutable pointer to this view's data.
 
bool isNull () const
 Returns true if no buffer is set.
 
bool isValid () const
 Returns true if a buffer is set.
 

Static Public Member Functions

static List createList (size_t count, size_t packetSize)
 Creates a list of N RtpPackets packed into a single shared buffer.
 
static List createList (const SizeList &sizes)
 Creates a list of RtpPackets with varying sizes, packed into a single shared buffer.
 

Static Public Attributes

static constexpr size_t HeaderSize = 12
 Minimum RTP fixed header size in bytes.
 

Detailed Description

A BufferView that interprets its data as an RTP packet.

RtpPacket extends BufferView with accessors that read and write the standard 12-byte RTP header directly in the buffer data. No fields are stored separately — the buffer is the source of truth.

RTP Header Layout (RFC 3550)
Byte 0: V(2) | P(1) | X(1) | CC(4)
Byte 1: M(1) | PT(7)
Bytes 2-3: Sequence number (big-endian)
[Bytes 12..(12+CC*4-1): CSRC list, if CC > 0]
2 bytes profile-specific ID
2 bytes extension length (in 32-bit words)
length*4 bytes extension data]
const uint8_t * data() const
Returns a const pointer to this view's data.
Definition bufferview.h:74
bool extension() const
Returns the extension flag.
Definition rtppacket.h:187
promeki::List< RtpPacket > List
List of RtpPacket values.
Definition rtppacket.h:62
Construction
The convenience constructor RtpPacket(size_t) allocates a standalone buffer for a single packet. This is simple but incurs one allocation per packet — for bulk work, use createList() which packs N packets into one shared buffer.
Example
// Single packet (convenience)
RtpPacket pkt(1400);
pkt.setPayloadType(96);
pkt.setSequenceNumber(1000);
// Bulk allocation — 100 packets sharing one buffer
auto pkts = RtpPacket::createList(100, 1400);
for(size_t i = 0; i < pkts.size(); ++i) {
pkts[i].setSequenceNumber(i);
}
A BufferView that interprets its data as an RTP packet.
Definition rtppacket.h:59
static List createList(size_t count, size_t packetSize)
Creates a list of N RtpPackets packed into a single shared buffer.
Definition rtppacket.h:130

Constructor & Destructor Documentation

◆ RtpPacket() [1/2]

RtpPacket::RtpPacket ( Buffer::Ptr  buf,
size_t  offset,
size_t  size 
)
inline

Constructs an RtpPacket referencing a region of a shared buffer.

Parameters
bufThe shared backing buffer.
offsetByte offset into the buffer where this packet begins.
sizeByte size of this packet.

◆ RtpPacket() [2/2]

RtpPacket::RtpPacket ( size_t  packetSize)
inlineexplicit

Convenience constructor that allocates a buffer for a single packet.

Parameters
packetSizeTotal packet size in bytes (header + payload).

Allocates a dedicated buffer, zeroes it, and sets the RTP version to 2. This is convenient for one-off packets but allocates a separate buffer per packet — for bulk packet construction, prefer createList().

Member Function Documentation

◆ clear()

void RtpPacket::clear ( )
inline

Zeroes the packet data and resets the RTP version to 2.

Useful for reusing packets from a pre-allocated pool.

◆ createList() [1/2]

static List RtpPacket::createList ( const SizeList sizes)
inlinestatic

Creates a list of RtpPackets with varying sizes, packed into a single shared buffer.

Parameters
sizesList of per-packet sizes in bytes (header + payload each).
Returns
A List of RtpPacket objects sharing one buffer.

Each packet gets the size specified by the corresponding entry in sizes. All packets are zeroed and have their RTP version set to 2. Like the uniform-size overload, this allocates a single shared buffer to avoid per-packet allocation overhead.

◆ createList() [2/2]

static List RtpPacket::createList ( size_t  count,
size_t  packetSize 
)
inlinestatic

Creates a list of N RtpPackets packed into a single shared buffer.

Parameters
countNumber of packets to create.
packetSizeTotal size of each packet in bytes (header + payload).
Returns
A List of RtpPacket objects sharing one buffer.

All packets are zeroed and have their RTP version set to 2. This is the preferred way to allocate packets in bulk, as it avoids per-packet allocation overhead.

◆ extensionLength()

uint16_t RtpPacket::extensionLength ( ) const
inline

Returns the extension data length in 32-bit words, or 0 if no extension.

Returns
Extension length in 32-bit words.

◆ extensionProfile()

uint16_t RtpPacket::extensionProfile ( ) const
inline

Returns the extension profile ID, or 0 if no extension is present.

Returns
The 16-bit profile-specific extension identifier.

◆ headerSize()

size_t RtpPacket::headerSize ( ) const
inline

Returns the full header size including CSRC list and extension.

Returns
The header size in bytes, or 0 if the packet is too small to contain the header fields it declares.

Computes: 12 + CC*4 + (if X=1: 4 + extensionLength*4). Returns 0 if the packet's size() is too small to hold the declared CSRC entries or extension data.

◆ isNull()

bool RtpPacket::isNull ( ) const
inline

Returns true if the buffer pointer is null.

A null packet has no backing buffer and cannot be read or written.

◆ isValid()

bool RtpPacket::isValid ( ) const
inline

Returns true if this is a valid RTP packet.

A valid packet has a non-null buffer, is large enough to hold the fixed 12-byte header, has RTP version 2, and is large enough to contain any CSRC entries and extension header that it declares.

◆ payload() [1/2]

uint8_t * RtpPacket::payload ( )
inline

Returns a pointer to the payload data (after the full header).

Returns
Pointer to the payload, or nullptr if the packet is too small.

Accounts for CSRC entries and the extension header when present.

◆ payload() [2/2]

const uint8_t * RtpPacket::payload ( ) const
inline

Returns a pointer to the payload data (after the full header).

Returns
Pointer to the payload, or nullptr if the packet is too small.

Accounts for CSRC entries and the extension header when present.

◆ payloadSize()

size_t RtpPacket::payloadSize ( ) const
inline

Returns the payload size in bytes.

Returns
Payload size, or 0 if the packet is too small for its header.

Accounts for CSRC entries and the extension header when present.


The documentation for this class was generated from the following file: