Compy 0.2.0
A lightweight RTSP 1.0 server library for embedded systems
Loading...
Searching...
No Matches
rtp_transport.h File Reference

An RTP data transport. More...

#include <compy/droppable.h>
#include <compy/transport.h>
#include <stdbool.h>
#include <stdint.h>
#include <datatype99.h>
#include <slice99.h>
#include <compy/priv/compiler_attrs.h>
Include dependency graph for rtp_transport.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct Compy_RtpTransport Compy_RtpTransport
 An RTP data transport.
 

Functions

 datatype99 (Compy_RtpTimestamp,(Compy_RtpTimestamp_Raw, uint32_t),(Compy_RtpTimestamp_SysClockUs, uint64_t))
 An RTP timestamp.
 
Compy_RtpTransportCompy_RtpTransport_new (Compy_Transport t, uint8_t payload_ty, uint32_t clock_rate) COMPY_PRIV_MUST_USE
 Creates a new RTP transport from the underlying level-4 protocol t.
 
int Compy_RtpTransport_send_packet (Compy_RtpTransport *self, Compy_RtpTimestamp ts, bool marker, U8Slice99 payload_header, U8Slice99 payload) COMPY_PRIV_MUST_USE
 Sends an RTP packet.
 
 declImplExtern99 (Compy_Droppable, Compy_RtpTransport)
 Implements Compy_Droppable_IFACE for Compy_RtpTransport.
 
bool Compy_RtpTransport_is_full (Compy_RtpTransport *self)
 
uint32_t Compy_RtpTransport_get_ssrc (const Compy_RtpTransport *self)
 Returns the SSRC identifier of this transport.
 
void Compy_RtpTransport_set_ssrc (Compy_RtpTransport *self, uint32_t ssrc)
 Sets the SSRC identifier of this transport.
 
void Compy_RtpTransport_set_extension (Compy_RtpTransport *self, uint8_t id, const uint8_t *value, uint8_t len)
 Sets a persistent one-byte RTP header extension (RFC 8285).
 
uint16_t Compy_RtpTransport_get_seq (const Compy_RtpTransport *self)
 Returns the current RTP sequence number of this transport.
 
uint32_t Compy_RtpTransport_get_packet_count (const Compy_RtpTransport *self)
 Returns the total number of RTP packets sent.
 
uint32_t Compy_RtpTransport_get_octet_count (const Compy_RtpTransport *self)
 Returns the total number of payload octets sent (excludes RTP headers).
 
uint32_t Compy_RtpTransport_get_last_rtp_timestamp (const Compy_RtpTransport *self)
 Returns the RTP timestamp of the last sent packet.
 
void Compy_RtpTransport_set_clock_reference (Compy_RtpTransport *self, uint32_t rtp_timestamp, uint64_t monotonic_time_us)
 Supplies a media-clock reference for RTCP Sender Reports.
 
uint32_t Compy_RtpTransport_get_rtp_timestamp_at (const Compy_RtpTransport *self, uint64_t monotonic_time_us)
 Projects the RTP media clock to a CLOCK_MONOTONIC instant.
 
uint32_t Compy_RtpTransport_get_rtp_timestamp_now (const Compy_RtpTransport *self)
 Returns the RTP timestamp extrapolated to the current instant.
 

Detailed Description

An RTP data transport.

Function Documentation

◆ Compy_RtpTransport_get_last_rtp_timestamp()

uint32_t Compy_RtpTransport_get_last_rtp_timestamp ( const Compy_RtpTransport self)

Returns the RTP timestamp of the last sent packet.

Precondition
self != NULL

◆ Compy_RtpTransport_get_octet_count()

uint32_t Compy_RtpTransport_get_octet_count ( const Compy_RtpTransport self)

Returns the total number of payload octets sent (excludes RTP headers).

Precondition
self != NULL

◆ Compy_RtpTransport_get_packet_count()

uint32_t Compy_RtpTransport_get_packet_count ( const Compy_RtpTransport self)

Returns the total number of RTP packets sent.

Precondition
self != NULL

◆ Compy_RtpTransport_get_rtp_timestamp_at()

uint32_t Compy_RtpTransport_get_rtp_timestamp_at ( const Compy_RtpTransport self,
uint64_t  monotonic_time_us 
)

Projects the RTP media clock to a CLOCK_MONOTONIC instant.

Primarily exposed for deterministic clock-mapping tests. Applications normally use Compy_RtpTransport_get_rtp_timestamp_now.

Precondition
self != NULL

◆ Compy_RtpTransport_get_rtp_timestamp_now()

uint32_t Compy_RtpTransport_get_rtp_timestamp_now ( const Compy_RtpTransport self)

Returns the RTP timestamp extrapolated to the current instant.

Uses the latest media clock reference when available, scaled by the RTP clock rate. This gives the RTP clock value at "now," suitable for RTCP SR where the NTP and RTP timestamps must represent the same instant (RFC 3550 Section 6.4.1). Falls back to the last packet's send time for callers that have not supplied a media clock reference.

Precondition
self != NULL

◆ Compy_RtpTransport_get_seq()

uint16_t Compy_RtpTransport_get_seq ( const Compy_RtpTransport self)

Returns the current RTP sequence number of this transport.

Precondition
self != NULL

◆ Compy_RtpTransport_get_ssrc()

uint32_t Compy_RtpTransport_get_ssrc ( const Compy_RtpTransport self)

Returns the SSRC identifier of this transport.

Precondition
self != NULL

◆ Compy_RtpTransport_new()

Compy_RtpTransport * Compy_RtpTransport_new ( Compy_Transport  t,
uint8_t  payload_ty,
uint32_t  clock_rate 
)

Creates a new RTP transport from the underlying level-4 protocol t.

Parameters
[in]tThe level-4 protocol (such as TCP or UDP).
[in]payload_tyThe RTP payload type. The list of payload types is available here: https://en.wikipedia.org/wiki/RTP_payload_formats.
[in]clock_rateThe RTP clock rate of payload_ty (HZ).
Precondition
t.self && t.vptr
The rand PRNG must be set up via srand.

◆ Compy_RtpTransport_send_packet()

int Compy_RtpTransport_send_packet ( Compy_RtpTransport self,
Compy_RtpTimestamp  ts,
bool  marker,
U8Slice99  payload_header,
U8Slice99  payload 
)

Sends an RTP packet.

Parameters
[out]selfThe RTP transport for sending this packet.
[in]tsThe RTP timestamp for this packet.
[in]markerThe RTP marker flag.
[in]payload_headerThe payload header. Can be U8Slice99_empty().
[in]payloadThe payload data.
Precondition
self != NULL
Returns
-1 if an I/O error occurred and sets errno appropriately, 0 on success.

◆ Compy_RtpTransport_set_clock_reference()

void Compy_RtpTransport_set_clock_reference ( Compy_RtpTransport self,
uint32_t  rtp_timestamp,
uint64_t  monotonic_time_us 
)

Supplies a media-clock reference for RTCP Sender Reports.

Associates an RTP timestamp with the CLOCK_MONOTONIC sampling instant that produced it. Applications which send Raw RTP timestamps should update this after sending a media sample. This lets RTCP project the actual media clock to the report instant instead of treating network send scheduling as the sampling clock.

Like every transport operation, callers must serialize this against the send and RTCP paths: the reference is multiple fields and a torn update projects a wildly wrong report (a half-written 64-bit instant is off by whole seconds on 32-bit targets).

Parameters
[out]selfThe RTP transport.
[in]rtp_timestampRTP timestamp of the media sample.
[in]monotonic_time_usSampling instant in CLOCK_MONOTONIC microseconds.
Precondition
self != NULL

◆ Compy_RtpTransport_set_extension()

void Compy_RtpTransport_set_extension ( Compy_RtpTransport self,
uint8_t  id,
const uint8_t *  value,
uint8_t  len 
)

Sets a persistent one-byte RTP header extension (RFC 8285).

The extension is included in every outgoing packet. Profile is 0xBEDE (one-byte header format). The extension element is: [id(4 bits) | len-1(4 bits) | value(len bytes)].

Parameters
[in]idExtension ID (1-14).
[in]valueExtension value bytes.
[in]lenLength of value (1-8 bytes).
Precondition
self != NULL
id >= 1 && id <= 14
len >= 1 && len <= 8

◆ Compy_RtpTransport_set_ssrc()

void Compy_RtpTransport_set_ssrc ( Compy_RtpTransport self,
uint32_t  ssrc 
)

Sets the SSRC identifier of this transport.

Call before sending any packets. Used when the SSRC must match a value declared in the SDP (e.g., WebRTC a=ssrc lines).

Precondition
self != NULL

◆ datatype99()

datatype99 ( Compy_RtpTimestamp  ,
(Compy_RtpTimestamp_Raw, uint32_t)  ,
(Compy_RtpTimestamp_SysClockUs, uint64_t)   
)

An RTP timestamp.

Variants

  • Raw – The value to be assigned to Compy_RtpHeader.timestamp without further conversion.
  • SysClockUs – The timestamp value in microseconds derived from a system clock (e.g., clock_gettime). It should be used when a raw timestamp cannot be computed, as typically occurs with real-time video.

See Datatype99 for the macro usage.

◆ declImplExtern99()

declImplExtern99 ( Compy_Droppable  ,
Compy_RtpTransport   
)

Implements Compy_Droppable_IFACE for Compy_RtpTransport.

See Interface99 for the macro usage.