Group PJMEDIA_SDP

group PJMEDIA_SDP

SDP data structure representation and parsing.

The basic SDP session descriptor and elements are described in header file <pjmedia/sdp.h>. This file contains declaration for SDP session descriptor and SDP media descriptor, along with their attributes. This file also declares functions to parse SDP message.

Defines

PJMEDIA_MAX_SDP_FMT

The PJMEDIA_MAX_SDP_FMT macro defines maximum format in a media line.

PJMEDIA_MAX_SDP_BANDW

The PJMEDIA_MAX_SDP_BANDW macro defines maximum bandwidth information lines in a media line.

PJMEDIA_MAX_SDP_ATTR

The PJMEDIA_MAX_SDP_ATTR macro defines maximum SDP attributes in media and session descriptor.

PJMEDIA_MAX_SDP_MEDIA

The PJMEDIA_MAX_SDP_MEDIA macro defines maximum SDP media lines in a SDP session descriptor.

Functions

pjmedia_sdp_attr *pjmedia_sdp_attr_create(pj_pool_t *pool, const char *name, const pj_str_t *value)

Create SDP attribute.

Return

The new SDP attribute.

Parameters
  • pool: Pool to create the attribute.

  • name: Attribute name.

  • value: Optional attribute value.

pjmedia_sdp_attr *pjmedia_sdp_attr_clone(pj_pool_t *pool, const pjmedia_sdp_attr *attr)

Clone attribute

Return

New attribute as cloned from the attribute.

Parameters
  • pool: Pool to be used.

  • attr: The attribute to clone.

pjmedia_sdp_attr *pjmedia_sdp_attr_find(unsigned count, pjmedia_sdp_attr *const attr_array[], const pj_str_t *name, const pj_str_t *fmt)

Find the first attribute with the specified type.

Return

The specified attribute, or NULL if it can’t be found.

See

pjmedia_sdp_attr_find2, pjmedia_sdp_media_find_attr, pjmedia_sdp_media_find_attr2

Parameters
  • count: Number of attributes in the array.

  • attr_array: Array of attributes.

  • name: Attribute name to find.

  • fmt: Optional string to indicate which payload format to find for rtpmap and fmt attributes. For other types of attributes, the value should be NULL.

pjmedia_sdp_attr *pjmedia_sdp_attr_find2(unsigned count, pjmedia_sdp_attr *const attr_array[], const char *name, const pj_str_t *fmt)

Find the first attribute with the specified type.

Return

The specified attribute, or NULL if it can’t be found.

See

pjmedia_sdp_attr_find, pjmedia_sdp_media_find_attr, pjmedia_sdp_media_find_attr2

Parameters
  • count: Number of attributes in the array.

  • attr_array: Array of attributes.

  • name: Attribute name to find.

  • fmt: Optional string to indicate which payload format to find for rtpmap and fmt attributes. For other types of attributes, the value should be NULL.

pj_status_t pjmedia_sdp_attr_add(unsigned *count, pjmedia_sdp_attr *attr_array[], pjmedia_sdp_attr *attr)

Add a new attribute to array of attributes.

Return

PJ_SUCCESS or the error code.

See

pjmedia_sdp_media_add_attr

Parameters
  • count: Number of attributes in the array.

  • attr_array: Array of attributes.

  • attr: The attribute to add.

unsigned pjmedia_sdp_attr_remove_all(unsigned *count, pjmedia_sdp_attr *attr_array[], const char *name)

Remove all attributes with the specified name in array of attributes.

Return

Number of attributes removed.

See

pjmedia_sdp_media_remove_all_attr

Parameters
  • count: Number of attributes in the array.

  • attr_array: Array of attributes.

  • name: Attribute name to find.

pj_status_t pjmedia_sdp_attr_remove(unsigned *count, pjmedia_sdp_attr *attr_array[], pjmedia_sdp_attr *attr)

Remove the specified attribute from the attribute array.

Return

PJ_SUCCESS when attribute has been removed, or PJ_ENOTFOUND when the attribute can not be found.

See

pjmedia_sdp_media_remove_attr

Parameters
  • count: Number of attributes in the array.

  • attr_array: Array of attributes.

  • attr: The attribute instance to remove.

pj_status_t pjmedia_sdp_attr_to_rtpmap(pj_pool_t *pool, const pjmedia_sdp_attr *attr, pjmedia_sdp_rtpmap **p_rtpmap)

Convert generic attribute to SDP rtpmap. This function allocates a new attribute and call pjmedia_sdp_attr_get_rtpmap().

Return

PJ_SUCCESS if the attribute can be successfully converted to rtpmap type.

See

pjmedia_sdp_attr_get_rtpmap

Parameters
  • pool: Pool used to create the rtpmap attribute.

  • attr: Generic attribute to be converted to rtpmap, which name must be “rtpmap”.

  • p_rtpmap: Pointer to receive SDP rtpmap attribute.

pj_status_t pjmedia_sdp_attr_get_rtpmap(const pjmedia_sdp_attr *attr, pjmedia_sdp_rtpmap *rtpmap)

Get the rtpmap representation of the same SDP attribute.

Return

PJ_SUCCESS if the attribute can be successfully converted to rtpmap attribute.

See

pjmedia_sdp_attr_to_rtpmap

Parameters
  • attr: Generic attribute to be converted to rtpmap, which name must be “rtpmap”.

  • rtpmap: SDP rtpmap attribute to be initialized.

pj_status_t pjmedia_sdp_rtpmap_to_attr(pj_pool_t *pool, const pjmedia_sdp_rtpmap *rtpmap, pjmedia_sdp_attr **p_attr)

Convert rtpmap attribute to generic attribute.

Return

PJ_SUCCESS on success.

Parameters
  • pool: Pool to be used.

  • rtpmap: The rtpmap attribute.

  • p_attr: Pointer to receive the generic SDP attribute.

pj_status_t pjmedia_sdp_attr_get_fmtp(const pjmedia_sdp_attr *attr, pjmedia_sdp_fmtp *fmtp)

Get the fmtp representation of the same SDP attribute.

Return

PJ_SUCCESS on success.

Parameters
  • attr: Generic attribute to be converted to fmtp, which name must be “fmtp”.

  • fmtp: SDP fmtp attribute to be initialized.

pj_status_t pjmedia_sdp_attr_get_rtcp(const pjmedia_sdp_attr *attr, pjmedia_sdp_rtcp_attr *rtcp)

Parse a generic SDP attribute to get SDP rtcp attribute values.

Return

PJ_SUCCESS on success.

Parameters
  • attr: Generic attribute to be converted to rtcp, which name must be “rtcp”.

  • rtcp: SDP rtcp attribute to be initialized.

pjmedia_sdp_attr *pjmedia_sdp_attr_create_rtcp(pj_pool_t *pool, const pj_sockaddr *a)

Create a=rtcp attribute.

Return

SDP RTCP attribute.

Parameters
  • pool: Pool to create the attribute.

  • a: Socket address.

pj_status_t pjmedia_sdp_attr_get_ssrc(const pjmedia_sdp_attr *attr, pjmedia_sdp_ssrc_attr *rtcp)

Parse a generic SDP attribute to get SDP ssrc attribute values.

Return

PJ_SUCCESS on success.

Parameters
  • attr: Generic attribute to be converted to ssrc, which name must be “ssrc”.

  • ssrc: SDP ssrc attribute to be initialized.

pjmedia_sdp_attr *pjmedia_sdp_attr_create_ssrc(pj_pool_t *pool, pj_uint32_t ssrc, const pj_str_t *cname)

Create a=ssrc attribute.

Return

SDP SSRC attribute.

Parameters
  • pool: Pool to create the attribute.

  • ssrc: SSRC identifier.

  • cname: CNAME.

pjmedia_sdp_conn *pjmedia_sdp_conn_clone(pj_pool_t *pool, const pjmedia_sdp_conn *rhs)

Clone connection info.

Return

The new connection info.

Parameters
  • pool: Pool to allocate memory for the new connection info.

  • rhs: The connection into to clone.

pj_status_t pjmedia_sdp_conn_cmp(const pjmedia_sdp_conn *conn1, const pjmedia_sdp_conn *conn2, unsigned option)

Compare connection info.

Return

PJ_SUCCESS when both connection info are equal, otherwise returns PJMEDIA_SDP_ECONNNOTEQUAL.

Parameters
  • conn1: The first connection info to compare.

  • conn1: The second connection info to compare.

  • option: Comparison option, which should be zero for now.

pjmedia_sdp_bandw *pjmedia_sdp_bandw_clone(pj_pool_t *pool, const pjmedia_sdp_bandw *rhs)

Clone bandwidth info.

Return

The new bandwidth info.

Parameters
  • pool: Pool to allocate memory for the new bandwidth info.

  • rhs: The bandwidth into to clone.

pjmedia_sdp_media *pjmedia_sdp_media_clone(pj_pool_t *pool, const pjmedia_sdp_media *rhs)

Clone SDP media description.

Return

New media description.

Parameters
  • pool: Pool to allocate memory for the new media description.

  • rhs: The media descriptin to clone.

pjmedia_sdp_attr *pjmedia_sdp_media_find_attr(const pjmedia_sdp_media *m, const pj_str_t *name, const pj_str_t *fmt)

Find the first occurence of the specified attribute name in the media descriptor. Optionally the format may be specified.

Return

The first instance of the specified attribute or NULL.

Parameters
  • m: The SDP media description.

  • name: Attribute name to find.

  • fmt: Optional payload type to match in the attribute list, when the attribute is rtpmap or fmtp. For other types of SDP attributes, this value should be NULL.

pjmedia_sdp_attr *pjmedia_sdp_media_find_attr2(const pjmedia_sdp_media *m, const char *name, const pj_str_t *fmt)

Find the first occurence of the specified attribute name in the SDP media descriptor. Optionally the format may be specified.

Return

The first instance of the specified attribute or NULL.

Parameters
  • m: The SDP media description.

  • name: Attribute name to find.

  • fmt: Optional payload type to match in the attribute list, when the attribute is rtpmap or fmtp. For other types of SDP attributes, this value should be NULL.

pj_status_t pjmedia_sdp_media_add_attr(pjmedia_sdp_media *m, pjmedia_sdp_attr *attr)

Add new attribute to the media descriptor.

Return

PJ_SUCCESS or the appropriate error code.

Parameters
  • m: The SDP media description.

  • attr: Attribute to add.

unsigned pjmedia_sdp_media_remove_all_attr(pjmedia_sdp_media *m, const char *name)

Remove all attributes with the specified name from the SDP media descriptor.

Return

The number of attributes removed.

Parameters
  • m: The SDP media description.

  • name: Attribute name to remove.

pj_status_t pjmedia_sdp_media_remove_attr(pjmedia_sdp_media *m, pjmedia_sdp_attr *attr)

Remove the occurence of the specified attribute from the SDP media descriptor.

Return

PJ_SUCCESS if the attribute can be found and has been removed from the array.

Parameters
  • m: The SDP media descriptor.

  • attr: The attribute to find and remove.

pj_status_t pjmedia_sdp_media_cmp(const pjmedia_sdp_media *sd1, const pjmedia_sdp_media *sd2, unsigned option)

Compare two SDP media for equality.

Return

PJ_SUCCESS when both SDP medias are equal, or the appropriate status code describing which part of the descriptors that are not equal.

Parameters
  • sd1: The first SDP media to compare.

  • sd2: The second SDP media to compare.

  • option: Comparison option, which should be zero for now.

pj_status_t pjmedia_sdp_transport_cmp(const pj_str_t *t1, const pj_str_t *t2)

Compare two media transports for compatibility.

Return

PJ_SUCCESS when both media transports are compatible, otherwise returns PJMEDIA_SDP_ETPORTNOTEQUAL.

Parameters
  • t1: The first media transport to compare.

  • t2: The second media transport to compare.

pj_uint32_t pjmedia_sdp_transport_get_proto(const pj_str_t *tp)

Get media transport protocol info, i.e: base transport and profiles, from the provided SDP media transport name string.

Return

Media transport info, combination of transport protocol and profile bit flag defined in pjmedia_tp_proto.

Parameters
  • tp: The SDP media transport name.

pj_status_t pjmedia_sdp_media_deactivate(pj_pool_t *pool, pjmedia_sdp_media *m)

Deactivate SDP media.

Return

PJ_SUCCESS when SDP media successfully deactivated, otherwise appropriate status code returned.

Parameters
  • pool: Memory pool to allocate memory from.

  • m: The SDP media to deactivate.

pjmedia_sdp_media *pjmedia_sdp_media_clone_deactivate(pj_pool_t *pool, const pjmedia_sdp_media *rhs)

Clone SDP media description and deactivate the new SDP media.

Return

New media descrption with deactivated indication.

Parameters
  • pool: Memory pool to allocate memory for the clone.

  • rhs: The SDP media to clone.

pj_status_t pjmedia_sdp_parse(pj_pool_t *pool, char *buf, pj_size_t len, pjmedia_sdp_session **p_sdp)

Parse SDP message.

Note that the input message buffer MUST be NULL terminated and have length at least len+1 (len MUST NOT include the NULL terminator).

Return

PJ_SUCCESS if message was successfully parsed into SDP session descriptor.

Parameters
  • pool: The pool to allocate SDP session description.

  • buf: The message buffer, MUST be NULL terminated.

  • len: The length of the message, excluding NULL terminator.

  • p_sdp: Pointer to receive the SDP session descriptor.

int pjmedia_sdp_print(const pjmedia_sdp_session *sdp, char *buf, pj_size_t size)

Print SDP description to a buffer.

Return

the length printed, or -1 if the buffer is too short.

Parameters
  • sdp: The SDP session description.

  • buf: The buffer.

  • size: The buffer length.

pj_status_t pjmedia_sdp_validate(const pjmedia_sdp_session *sdp)

Perform semantic validation for the specified SDP session descriptor. This function perform validation beyond just syntactic verification, such as to verify the value of network type and address type, check the connection line, and verify that rtpmap attribute is present when dynamic payload type is used.

Return

PJ_SUCCESS on success.

Parameters
  • sdp: The SDP session descriptor to validate.

pj_status_t pjmedia_sdp_validate2(const pjmedia_sdp_session *sdp, pj_bool_t strict)

Perform semantic validation for the specified SDP session descriptor. This function perform validation beyond just syntactic verification, such as to verify the value of network type and address type, check the connection line, and verify that rtpmap attribute is present when dynamic payload type is used.

Return

PJ_SUCCESS on success.

Parameters
  • sdp: The SDP session descriptor to validate.

  • strict: Flag whether the check should be strict, i.e: allow media without connection line when port is zero.

pjmedia_sdp_session *pjmedia_sdp_session_clone(pj_pool_t *pool, const pjmedia_sdp_session *sdp)

Clone SDP session descriptor.

Return

New SDP session.

Parameters
  • pool: The pool used to clone the session.

  • sdp: The SDP session to clone.

pj_status_t pjmedia_sdp_session_cmp(const pjmedia_sdp_session *sd1, const pjmedia_sdp_session *sd2, unsigned option)

Compare two SDP session for equality.

Return

PJ_SUCCESS when both SDPs are equal, or otherwise the status code indicates which part of the session descriptors are not equal.

Parameters
  • sd1: The first SDP session to compare.

  • sd2: The second SDP session to compare.

  • option: Must be zero for now.

pj_status_t pjmedia_sdp_session_add_attr(pjmedia_sdp_session *s, pjmedia_sdp_attr *attr)

Add new attribute to the session descriptor.

Return

PJ_SUCCESS or the appropriate error code.

Parameters
  • s: The SDP session description.

  • attr: Attribute to add.

struct pjmedia_sdp_attr
#include <sdp.h>

Generic representation of attribute.

See

pjmedia_sdp_attr

struct pjmedia_sdp_rtpmap
#include <sdp.h>

This structure declares SDP rtpmap attribute.

See

pjmedia_sdp_rtpmap

struct pjmedia_sdp_fmtp
#include <sdp.h>

This structure describes SDP fmtp attribute.

struct pjmedia_sdp_rtcp_attr
#include <sdp.h>

This structure describes SDP rtcp attribute.

struct pjmedia_sdp_ssrc_attr
#include <sdp.h>

This structure describes SDP ssrc attribute.

struct pjmedia_sdp_conn
#include <sdp.h>

This structure describes SDP connection info (“c=” line).

See

pjmedia_sdp_conn

struct pjmedia_sdp_bandw
#include <sdp.h>

This structure describes SDP bandwidth info (“b=” line).

struct pjmedia_sdp_media
#include <sdp.h>

This structure describes SDP media descriptor. A SDP media descriptor starts with “m=” line and contains the media attributes and optional connection line.

See

pjmedia_sdp_media

struct pjmedia_sdp_session
#include <sdp.h>

This structure describes SDP session description. A SDP session descriptor contains complete information about a session, and normally is exchanged with remote media peer using signaling protocol such as SIP.

See

pjmedia_sdp_session