SmolRTSP  0.1.3
A small, portable, extensible RTSP 1.0 implementation in C99
sdp.h File Reference

RFC 4566-compliant SDP implementation. More...

#include <smolrtsp/priv/compiler_attrs.h>
#include <smolrtsp/writer.h>
#include <slice99.h>
Include dependency graph for sdp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SmolRTSP_SdpLine
 An SDP line. More...
 

Macros

#define SMOLRTSP_SDP_DESCRIBE(ret, w, ...)    SMOLRTSP_PRIV_SDP_DESCRIBE(ret, w, __VA_ARGS__)
 Writes a sequence of SDP lines to w. More...
 
#define SMOLRTSP_SDP_VERSION   'v'
 Protocol Version (v=).
 
#define SMOLRTSP_SDP_ORIGIN   'o'
 Origin (o=).
 
#define SMOLRTSP_SDP_SESSION_NAME   's'
 Session Name (s=).
 
#define SMOLRTSP_SDP_INFO   'i'
 Session Information (i=).
 
#define SMOLRTSP_SDP_URI   'u'
 URI (u=).
 
#define SMOLRTSP_SDP_EMAIL   'e'
 Email Address (e=).
 
#define SMOLRTSP_SDP_PHONE   'p'
 Phone Number (p=).
 
#define SMOLRTSP_SDP_CONNECTION   'c'
 Connection Data (c=).
 
#define SMOLRTSP_SDP_BANDWIDTH   'b'
 Bandwidth (b=).
 
#define SMOLRTSP_SDP_TIME   't'
 Timing (t=).
 
#define SMOLRTSP_SDP_REPEAT   'r'
 Repeat Times (r=).
 
#define SMOLRTSP_SDP_TIME_ZONES   'z'
 Time Zones (z=).
 
#define SMOLRTSP_SDP_ENCRYPTION_KEYS   'k'
 Encryption Keys (k=).
 
#define SMOLRTSP_SDP_ATTR   'a'
 Attributes (a=).
 
#define SMOLRTSP_SDP_MEDIA   'm'
 Media Descriptions (m=).
 

Typedefs

typedef char SmolRTSP_SdpType
 An SDP type (one character).
 

Functions

ssize_t SmolRTSP_SdpLine_serialize (const SmolRTSP_SdpLine *restrict self, SmolRTSP_Writer w) SMOLRTSP_PRIV_MUST_USE
 Serialises self into w. More...
 
ssize_t smolrtsp_sdp_printf (SmolRTSP_Writer w, SmolRTSP_SdpType ty, const char *restrict fmt,...) SMOLRTSP_PRIV_MUST_USE SMOLRTSP_PRIV_GCC_ATTR(format(printf
 Printfs a single SDP line to w. More...
 

Detailed Description

RFC 4566-compliant SDP implementation.

Macro Definition Documentation

◆ SMOLRTSP_SDP_DESCRIBE

#define SMOLRTSP_SDP_DESCRIBE (   ret,
  w,
  ... 
)     SMOLRTSP_PRIV_SDP_DESCRIBE(ret, w, __VA_ARGS__)

Writes a sequence of SDP lines to w.

Parameters
[out]retThe variable name of type ssize_t that will be incremented with a number of bytes written to w.
[out]wThe variable name of type SmolRTSP_Writer to be provided with SDP data.

The rest of arguments represent a non-empty sequence of comma-separated tuples (ty, fmt, ...), where

  • ty is an SDP line type (such as SMOLRTSP_SDP_VERSION),
  • fmt is a printf-like format string,
  • and ... are the fmt parameters (may be omitted).

Under the hood, SMOLRTSP_SDP_DESCRIBE just generates a smolrtsp_sdp_printf function invocation for each variadic argument.

Examples

char buffer[256] = {0};
const SmolRTSP_Writer sdp = smolrtsp_string_writer(buffer);
ssize_t ret = 0;
ret, sdp,
(SMOLRTSP_SDP_ORIGIN, "SmolRTSP 3855320066 3855320129 IN IP4 0.0.0.0"),
(SMOLRTSP_SDP_SESSION_NAME, "SmolRTSP test"),
(SMOLRTSP_SDP_CONNECTION, "IN IP4 %s", SERVER_IP_ADDR),
(SMOLRTSP_SDP_MEDIA, "audio %d RTP/AVP %d", AUDIO_PORT,
AUDIO_RTP_PAYLOAD_TYPE),
(SMOLRTSP_SDP_ATTR, "control:audio"));
const char *expected =
"v=0\r\n"
"o=SmolRTSP 3855320066 3855320129 IN IP4 0.0.0.0\r\n"
"s=SmolRTSP test\r\n"
"c=IN IP4 0.0.0.0\r\n"
"t=0 0\r\n"
"m=audio 123 RTP/AVP 456\r\n"
"a=control:audio\r\n";
assert((ssize_t)strlen(expected) == ret);
assert(strcmp(expected, buffer) == 0);
#define SMOLRTSP_SDP_TIME
Timing (t=).
Definition: sdp.h:191
#define SMOLRTSP_SDP_SESSION_NAME
Session Name (s=).
Definition: sdp.h:156
#define SMOLRTSP_SDP_ATTR
Attributes (a=).
Definition: sdp.h:211
#define SMOLRTSP_SDP_CONNECTION
Connection Data (c=).
Definition: sdp.h:181
#define SMOLRTSP_SDP_MEDIA
Media Descriptions (m=).
Definition: sdp.h:216
#define SMOLRTSP_SDP_ORIGIN
Origin (o=).
Definition: sdp.h:151
#define SMOLRTSP_SDP_VERSION
Protocol Version (v=).
Definition: sdp.h:146
#define SMOLRTSP_SDP_DESCRIBE(ret, w,...)
Writes a sequence of SDP lines to w.
Definition: sdp.h:113
SmolRTSP_Writer smolrtsp_string_writer(char *buffer) SMOLRTSP_PRIV_MUST_USE
A writer that invokes strncat on a provided buffer.

Function Documentation

◆ smolrtsp_sdp_printf()

ssize_t smolrtsp_sdp_printf ( SmolRTSP_Writer  w,
SmolRTSP_SdpType  ty,
const char *restrict  fmt,
  ... 
)

Printfs a single SDP line to w.

Parameters
[out]wThe writer to be provided with SDP data.
[in]tyThe type of the SDP line.
[in]fmtThe printf-like format string.
Returns
The number of bytes written or a negative value on error.
Precondition
w.self && w.vptr
fmt != NULL

◆ SmolRTSP_SdpLine_serialize()

ssize_t SmolRTSP_SdpLine_serialize ( const SmolRTSP_SdpLine *restrict  self,
SmolRTSP_Writer  w 
)

Serialises self into w.

Parameters
[in]selfThe instance to be serialised.
[in]wThe writer to be provided with serialised data.
Returns
The number of bytes written or a negative value on error.
Precondition
self != NULL
w.self && w.vptr